Skip to content

Commit 8f3d36a

Browse files
authored
fix #13995: performance regression (hang) in 2.18dev (danmar#7653)
1 parent 6b6d9c5 commit 8f3d36a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/valueflow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,8 @@ size_t ValueFlow::getSizeOf(const ValueType &vt, const Settings &settings, Accur
541541
const size_t charBit = settings.platform.char_bit;
542542
size_t n = ValueFlow::getSizeOf(vt2, settings,accuracy, ++maxRecursion);
543543
size_t a = getAlignOf(vt2, settings, accuracy);
544+
if (n == 0 || a == 0)
545+
return accuracy == Accuracy::ExactOrZero ? 0 : total;
544546
if (bits == 0) {
545547
if (currentBitfieldAlloc == 0) {
546548
bits = n * charBit;
@@ -565,8 +567,6 @@ size_t ValueFlow::getSizeOf(const ValueType &vt, const Settings &settings, Accur
565567
currentBitCount += bits;
566568
return ret;
567569
}
568-
if (n == 0 || a == 0)
569-
return accuracy == Accuracy::ExactOrZero ? 0 : total;
570570
n *= dim;
571571
size_t padding = (a - (total % a)) % a;
572572
if (currentBitCount > 0) {

test/testvalueflow.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ class TestValueFlow : public TestFixture {
176176

177177
TEST_CASE(performanceIfCount);
178178
TEST_CASE(bitfields);
179+
180+
TEST_CASE(bitfieldsHang);
179181
}
180182

181183
static bool isNotTokValue(const ValueFlow::Value &val) {
@@ -9136,6 +9138,12 @@ class TestValueFlow : public TestFixture {
91369138
testBitfields("unsigned char a : 16;\n",
91379139
2);
91389140
}
9141+
9142+
void bitfieldsHang() {
9143+
const char *code = "struct S { unknown_type x : 1; };\n"
9144+
"const size_t size = sizeof(S);\n";
9145+
(void)valueOfTok(code, "x");
9146+
}
91399147
};
91409148

91419149
REGISTER_TEST(TestValueFlow)

0 commit comments

Comments
 (0)