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
4 changes: 2 additions & 2 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ size_t ValueFlow::getSizeOf(const ValueType &vt, const Settings &settings, Accur
const size_t charBit = settings.platform.char_bit;
size_t n = ValueFlow::getSizeOf(vt2, settings,accuracy, ++maxRecursion);
size_t a = getAlignOf(vt2, settings, accuracy);
if (n == 0 || a == 0)
return accuracy == Accuracy::ExactOrZero ? 0 : total;
if (bits == 0) {
if (currentBitfieldAlloc == 0) {
bits = n * charBit;
Expand All @@ -565,8 +567,6 @@ size_t ValueFlow::getSizeOf(const ValueType &vt, const Settings &settings, Accur
currentBitCount += bits;
return ret;
}
if (n == 0 || a == 0)
return accuracy == Accuracy::ExactOrZero ? 0 : total;
n *= dim;
size_t padding = (a - (total % a)) % a;
if (currentBitCount > 0) {
Expand Down
8 changes: 8 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ class TestValueFlow : public TestFixture {

TEST_CASE(performanceIfCount);
TEST_CASE(bitfields);

TEST_CASE(bitfieldsHang);
}

static bool isNotTokValue(const ValueFlow::Value &val) {
Expand Down Expand Up @@ -9136,6 +9138,12 @@ class TestValueFlow : public TestFixture {
testBitfields("unsigned char a : 16;\n",
2);
}

void bitfieldsHang() {
const char *code = "struct S { unknown_type x : 1; };\n"
"const size_t size = sizeof(S);\n";
(void)valueOfTok(code, "x");
}
};

REGISTER_TEST(TestValueFlow)