Skip to content

Commit 67379a2

Browse files
committed
add tests
1 parent 94993fe commit 67379a2

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

test/testvalueflow.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class TestValueFlow : public TestFixture {
175175
mNewTemplate = true;
176176

177177
TEST_CASE(performanceIfCount);
178+
TEST_CASE(bitfields);
178179
}
179180

180181
static bool isNotTokValue(const ValueFlow::Value &val) {
@@ -9042,6 +9043,42 @@ class TestValueFlow : public TestFixture {
90429043
"}\n";
90439044
ASSERT_EQUALS(1U, tokenValues(code, "v .", &s).size());
90449045
}
9046+
9047+
void testBitfields(const std::string &structBody, std::size_t expectedSize) {
9048+
const std::string code = "struct S { " + structBody + " }; const std::size_t size = sizeof(S);";
9049+
Settings s(settings);
9050+
const auto values = tokenValues(code.c_str(), "( S");
9051+
ASSERT(values.size() > 0);
9052+
ASSERT_EQUALS(expectedSize, values.back().intvalue);
9053+
}
9054+
9055+
void bitfields() {
9056+
9057+
// #13653
9058+
testBitfields("unsigned int data_rw: 1;\n"
9059+
"unsigned int page_address: 4;\n"
9060+
"unsigned int register_address: 3;\n",
9061+
4);
9062+
9063+
testBitfields("unsigned char data_rw: 1;\n"
9064+
"unsigned char page_address: 4;\n"
9065+
"unsigned char register_address: 3;\n",
9066+
1);
9067+
9068+
testBitfields("unsigned int a : 1;\n"
9069+
"unsigned int b;\n"
9070+
"unsigned int c : 1;\n",
9071+
12);
9072+
9073+
testBitfields("unsigned int a : 1;\n"
9074+
"unsigned char b;\n"
9075+
"unsigned int c : 1;\n",
9076+
12);
9077+
9078+
testBitfields("unsigned int a : 31;\n"
9079+
"unsigned int b : 2;\n",
9080+
8);
9081+
}
90459082
};
90469083

90479084
REGISTER_TEST(TestValueFlow)

0 commit comments

Comments
 (0)