Clang import: better handling of ArrayToPointerDecay implicit casts

This commit is contained in:
Daniel Marjamäki 2020-11-08 19:53:28 +01:00
parent 1c742b7995
commit 06909df8f5
2 changed files with 15 additions and 1 deletions

View File

@ -957,7 +957,7 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
}
if (nodeType == ImplicitCastExpr) {
Token *expr = children[0]->createTokens(tokenList);
if (!expr->valueType())
if (!expr->valueType() || contains(mExtTokens, "<ArrayToPointerDecay>"))
setValueType(expr);
return expr;
}

View File

@ -112,6 +112,7 @@ private:
TEST_CASE(valueFlow2);
TEST_CASE(valueType1);
TEST_CASE(valueType2);
}
std::string parse(const char clang[]) {
@ -1110,6 +1111,19 @@ private:
ASSERT(!!tok->valueType());
ASSERT_EQUALS("bool", tok->valueType()->str());
}
void valueType2() {
const char clang[] = "`-VarDecl 0xc9eda0 <1.cpp:2:1, col:17> col:13 s 'const char *' cinit\n"
" `-ImplicitCastExpr 0xc9eef0 <col:17> 'const char *' <ArrayToPointerDecay>\n"
" `-StringLiteral 0xc9eed0 <col:17> 'const char [6]' lvalue \"hello\"\n";
GET_SYMBOL_DB(clang);
const Token *tok = Token::findsimplematch(tokenizer.tokens(), "\"hello\"");
ASSERT(!!tok);
ASSERT(!!tok->valueType());
ASSERT_EQUALS("const signed char *", tok->valueType()->str());
}
};
REGISTER_TEST(TestClangImport)