Skip to content

Commit dd6975f

Browse files
authored
fix #11496: FP shiftTooManyBits in dead code block (#7074)
1 parent af4e5b3 commit dd6975f

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

lib/checktype.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ void CheckType::checkTooBigBitwiseShift()
7272
if (tok->isCpp() && Token::Match(tok, "[;{}] %name% (") && Token::simpleMatch(tok->linkAt(2), ") ;") && tok->next()->isUpperCaseName() && !tok->next()->function())
7373
tok = tok->linkAt(2);
7474

75+
tok = skipUnreachableBranch(tok);
76+
7577
if (!tok->astOperand1() || !tok->astOperand2())
7678
continue;
7779

test/testtype.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class TestType : public TestFixture {
4444
TEST_CASE(longCastReturn);
4545
TEST_CASE(checkFloatToIntegerOverflow);
4646
TEST_CASE(integerOverflow); // #11794
47+
TEST_CASE(shiftTooManyBits); // #11496
4748
}
4849

4950
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
@@ -588,6 +589,18 @@ class TestType : public TestFixture {
588589
"}", s, "test.cpp");
589590
ASSERT_EQUALS("[test.cpp:4]: (error) Signed integer overflow for expression 'i<<2'.\n", errout_str());
590591
}
592+
593+
void shiftTooManyBits() { // #11496
594+
check("template<unsigned int width> struct B {\n"
595+
" unsigned long long f(unsigned int n) const {\n"
596+
" if (width == 1)\n"
597+
" return 1ULL << width;\n"
598+
" return 0;\n"
599+
" }\n"
600+
"};\n"
601+
"static B<64> b;\n", settingsDefault);
602+
ASSERT_EQUALS("", errout_str());
603+
}
591604
};
592605

593606
REGISTER_TEST(TestType)

0 commit comments

Comments
 (0)