Fixed #9586 (Valuetype: Wrong type for 'true << 1')

This commit is contained in:
Daniel Marjamäki 2020-01-27 11:46:59 +01:00
parent 8819e19dae
commit 830f901206
2 changed files with 12 additions and 2 deletions

View File

@ -5182,8 +5182,17 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
const ValueType *vt2 = parent->astOperand2() ? parent->astOperand2()->valueType() : nullptr; const ValueType *vt2 = parent->astOperand2() ? parent->astOperand2()->valueType() : nullptr;
if (vt1 && Token::Match(parent, "<<|>>")) { if (vt1 && Token::Match(parent, "<<|>>")) {
if (!mIsCpp || (vt2 && vt2->isIntegral())) if (!mIsCpp || (vt2 && vt2->isIntegral())) {
setValueType(parent, *vt1); if (vt1->type < ValueType::Type::BOOL || vt1->type >= ValueType::Type::INT)
setValueType(parent, *vt1);
else {
ValueType vt(*vt1);
vt.type = ValueType::Type::INT; // Integer promotion
vt.sign = ValueType::Sign::SIGNED;
setValueType(parent, vt);
}
}
return; return;
} }

View File

@ -6564,6 +6564,7 @@ private:
ASSERT_EQUALS("signed int", typeOf("a = 12 >> x;", ">>", "test.c")); ASSERT_EQUALS("signed int", typeOf("a = 12 >> x;", ">>", "test.c"));
ASSERT_EQUALS("", typeOf("a = 12 << x;", "<<", "test.cpp")); // << might be overloaded ASSERT_EQUALS("", typeOf("a = 12 << x;", "<<", "test.cpp")); // << might be overloaded
ASSERT_EQUALS("signed int", typeOf("a = 12 << x;", "<<", "test.c")); ASSERT_EQUALS("signed int", typeOf("a = 12 << x;", "<<", "test.c"));
ASSERT_EQUALS("signed int", typeOf("a = true << 1U;", "<<"));
// assignment => result has same type as lhs // assignment => result has same type as lhs
ASSERT_EQUALS("unsigned short", typeOf("unsigned short x; x = 3;", "=")); ASSERT_EQUALS("unsigned short", typeOf("unsigned short x; x = 3;", "="));