Skip to content

Commit 9e687df

Browse files
committed
add tests
1 parent 94993fe commit 9e687df

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

test/testvalueflow.cpp

Lines changed: 36 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,41 @@ 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+
const auto values = tokenValues(code.c_str(), "( S");
9050+
ASSERT(values.size() > 0);
9051+
ASSERT_EQUALS(expectedSize, values.back().intvalue);
9052+
}
9053+
9054+
void bitfields() {
9055+
9056+
// #13653
9057+
testBitfields("unsigned int data_rw: 1;\n"
9058+
"unsigned int page_address: 4;\n"
9059+
"unsigned int register_address: 3;\n",
9060+
4);
9061+
9062+
testBitfields("unsigned char data_rw: 1;\n"
9063+
"unsigned char page_address: 4;\n"
9064+
"unsigned char register_address: 3;\n",
9065+
1);
9066+
9067+
testBitfields("unsigned int a : 1;\n"
9068+
"unsigned int b;\n"
9069+
"unsigned int c : 1;\n",
9070+
12);
9071+
9072+
testBitfields("unsigned int a : 1;\n"
9073+
"unsigned char b;\n"
9074+
"unsigned int c : 1;\n",
9075+
12);
9076+
9077+
testBitfields("unsigned int a : 31;\n"
9078+
"unsigned int b : 2;\n",
9079+
8);
9080+
}
90459081
};
90469082

90479083
REGISTER_TEST(TestValueFlow)

0 commit comments

Comments
 (0)