Fix #12117 FP integerOverflowCond for shift by 31 bits (#5596)

This commit is contained in:
chrchr-github 2023-10-28 16:47:57 +02:00 committed by GitHub
parent f6fb3334f3
commit cae27c5ec7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -205,8 +205,8 @@ void CheckType::checkIntegerOverflow()
continue; continue;
// For left shift, it's common practice to shift into the sign bit // For left shift, it's common practice to shift into the sign bit
//if (tok->str() == "<<" && value->intvalue > 0 && value->intvalue < (((MathLib::bigint)1) << bits)) if (tok->str() == "<<" && value->intvalue > 0 && value->intvalue < (((MathLib::bigint)1) << bits))
// continue; continue;
integerOverflowError(tok, *value); integerOverflowError(tok, *value);
} }

View File

@ -295,6 +295,11 @@ private:
" return 123456U * x;\n" " return 123456U * x;\n"
"}",settings); "}",settings);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("int f(int i) {\n" // #12117
" return (i == 31) ? 1 << i : 0;\n"
"}", settings);
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 2.\n", errout.str());
} }
void signConversion() { void signConversion() {