Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1915,7 +1915,10 @@ void SymbolDatabase::setArrayDimensionsUsingValueFlow()
}

if (bits > 0 && bits <= 62) {
if (dimension.tok->valueType()->sign == ValueType::Sign::UNSIGNED)
auto sign = dimension.tok->valueType()->sign;
if (sign == ValueType::Sign::UNKNOWN_SIGN && dimension.tok->valueType()->type == ValueType::Type::CHAR)
sign = mDefaultSignedness;
if (sign == ValueType::Sign::UNSIGNED)
dimension.num = 1LL << bits;
else
dimension.num = 1LL << (bits - 1);
Expand Down Expand Up @@ -7636,9 +7639,7 @@ static const Token* parsedecl(const Token* type,

// Set signedness for integral types..
if (valuetype->isIntegral() && valuetype->sign == ValueType::Sign::UNKNOWN_SIGN) {
if (valuetype->type == ValueType::Type::CHAR)
valuetype->sign = defaultSignedness;
else if (valuetype->type >= ValueType::Type::SHORT)
if (valuetype->type >= ValueType::Type::SHORT)
valuetype->sign = ValueType::Sign::SIGNED;
}

Expand Down Expand Up @@ -8756,7 +8757,7 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
return ValueType::MatchResult::UNKNOWN;
}

if (call->isIntegral() && func->isIntegral() && call->sign != ValueType::Sign::UNKNOWN_SIGN && func->sign != ValueType::Sign::UNKNOWN_SIGN && call->sign != func->sign)
if (call->isIntegral() && func->isIntegral() && call->sign != func->sign)
return ValueType::MatchResult::FALLBACK1;

if (func->reference != Reference::None && (func->constness > call->constness || func->volatileness > call->volatileness))
Expand Down
2 changes: 1 addition & 1 deletion test/testclangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ class TestClangImport : public TestFixture {
const Token *tok = Token::findsimplematch(tokenizer.tokens(), "\"hello\"");
ASSERT(!!tok);
ASSERT(!!tok->valueType());
ASSERT_EQUALS("const signed char *", tok->valueType()->str());
ASSERT_EQUALS("const char *", tok->valueType()->str());
}

void stdinLoc() {
Expand Down
12 changes: 2 additions & 10 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4601,11 +4601,7 @@ class TestCondition : public TestFixture {
" if (o[1] == '\\0') {}\n"
" }\n"
"}\n");
if (std::numeric_limits<char>::is_signed) {
ASSERT_EQUALS("[test.cpp:6:18]: (style) Condition 'o[1]=='\\0'' is always false [knownConditionTrueFalse]\n", errout_str());
} else {
ASSERT_EQUALS("[test.cpp:4:25] -> [test.cpp:6:18]: (style) Condition 'o[1]=='\\0'' is always false [knownConditionTrueFalse]\n", errout_str());
}
ASSERT_EQUALS("[test.cpp:6:18]: (style) Condition 'o[1]=='\\0'' is always false [knownConditionTrueFalse]\n", errout_str());

check("void f(int x) {\n" // #11449
" int i = x;\n"
Expand Down Expand Up @@ -5341,11 +5337,7 @@ class TestCondition : public TestFixture {
" buffer.back() == '\\n' ||\n"
" buffer.back() == '\\0') {}\n"
"}\n");
if (std::numeric_limits<char>::is_signed) {
ASSERT_EQUALS("[test.cpp:5:22]: (style) Condition 'buffer.back()=='\\0'' is always false [knownConditionTrueFalse]\n", errout_str());
} else {
ASSERT_EQUALS("[test.cpp:3:22] -> [test.cpp:5:22]: (style) Condition 'buffer.back()=='\\0'' is always false [knownConditionTrueFalse]\n", errout_str());
}
ASSERT_EQUALS("[test.cpp:5:22]: (style) Condition 'buffer.back()=='\\0'' is always false [knownConditionTrueFalse]\n", errout_str());

// #9353
check("struct X { std::string s; };\n"
Expand Down
2 changes: 1 addition & 1 deletion test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2341,7 +2341,7 @@ class TestOther : public TestFixture {
checkInvalidPointerCast("void test(float* data) {\n"
" f.write((char*)data,sizeof(float));\n"
"}", dinit(CheckInvalidPointerCastOptions, $.inconclusive = true)); // #3639
ASSERT_EQUALS("[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\n", errout_str());
ASSERT_EQUALS("[test.cpp:2:13]: (portability, inconclusive) Casting from float * to char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\n", errout_str());


checkInvalidPointerCast("long long* test(float* f) {\n"
Expand Down
20 changes: 10 additions & 10 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(valueType2);
TEST_CASE(valueType3);
TEST_CASE(valueTypeThis);
TEST_CASE(valueTypeChar);

TEST_CASE(variadic1); // #7453
TEST_CASE(variadic2); // #7649
Expand Down Expand Up @@ -7796,20 +7797,12 @@ class TestSymbolDatabase : public TestFixture {
f = Token::findsimplematch(tokenizer.tokens(), "get ( get ( v7 ) ) ;");
ASSERT(f);
ASSERT(f->function());
if (std::numeric_limits<char>::is_signed) {
ASSERT_EQUALS(10, f->function()->tokenDef->linenr());
} else {
ASSERT_EQUALS(5, f->function()->tokenDef->linenr());
}
ASSERT_EQUALS(10, f->function()->tokenDef->linenr());

f = Token::findsimplematch(tokenizer.tokens(), "get ( get ( v8 ) ) ;");
ASSERT(f);
ASSERT(f->function());
if (std::numeric_limits<char>::is_signed) {
ASSERT_EQUALS(5, f->function()->tokenDef->linenr());
} else {
ASSERT_EQUALS(11, f->function()->tokenDef->linenr());
}
ASSERT_EQUALS(11, f->function()->tokenDef->linenr());

f = Token::findsimplematch(tokenizer.tokens(), "get ( get ( v9 ) ) ;");
ASSERT(f);
Expand Down Expand Up @@ -10145,6 +10138,13 @@ class TestSymbolDatabase : public TestFixture {
ASSERT_EQUALS("const C *", typeOf("class C { void foo() const; }; void C::foo() const { *this = 0; }", "this"));
}

void valueTypeChar() {
Settings s = settings2;
s.platform.defaultSign = 's';
ASSERT_EQUALS("char", typeOf("char c; c = 'x';", "c =", true, &s));
ASSERT_EQUALS("char", typeOf("char buf[10]; buf[0] = 'x';", "[ 0 ]", true, &s));
}

void variadic1() { // #7453
{
GET_SYMBOL_DB("CBase* create(const char *c1, ...);\n"
Expand Down
Loading