Skip to content

Commit

Permalink
fix #11496: FP shiftTooManyBits in dead code block (danmar#7074)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludviggunne authored Dec 5, 2024
1 parent af4e5b3 commit dd6975f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/checktype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ void CheckType::checkTooBigBitwiseShift()
if (tok->isCpp() && Token::Match(tok, "[;{}] %name% (") && Token::simpleMatch(tok->linkAt(2), ") ;") && tok->next()->isUpperCaseName() && !tok->next()->function())
tok = tok->linkAt(2);

tok = skipUnreachableBranch(tok);

if (!tok->astOperand1() || !tok->astOperand2())
continue;

Expand Down
13 changes: 13 additions & 0 deletions test/testtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class TestType : public TestFixture {
TEST_CASE(longCastReturn);
TEST_CASE(checkFloatToIntegerOverflow);
TEST_CASE(integerOverflow); // #11794
TEST_CASE(shiftTooManyBits); // #11496
}

#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
Expand Down Expand Up @@ -588,6 +589,18 @@ class TestType : public TestFixture {
"}", s, "test.cpp");
ASSERT_EQUALS("[test.cpp:4]: (error) Signed integer overflow for expression 'i<<2'.\n", errout_str());
}

void shiftTooManyBits() { // #11496
check("template<unsigned int width> struct B {\n"
" unsigned long long f(unsigned int n) const {\n"
" if (width == 1)\n"
" return 1ULL << width;\n"
" return 0;\n"
" }\n"
"};\n"
"static B<64> b;\n", settingsDefault);
ASSERT_EQUALS("", errout_str());
}
};

REGISTER_TEST(TestType)

0 comments on commit dd6975f

Please sign in to comment.