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: 3 additions & 1 deletion integration-tests/c-example/lib/structures/bitfields.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ typedef struct {
// 7 bits: value of b1
// 25 bits: unused
// 6 bits: value of b2
// 3 bits: unused
// 15 bits: value of b3
// 11 bits: unused
// 8 bits: unused
unsigned b1 : 7;
unsigned : 0; // start a new allocation unit
unsigned b2 : 6;
unsigned : 3;
unsigned b3 : 15;
} StrWithUnnamedZeroBitfield;

Expand Down
3 changes: 0 additions & 3 deletions server/src/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,6 @@ std::shared_ptr<StructValueView> KTestObjectParser::structView(const std::vector
std::vector<std::shared_ptr<AbstractValueView>> subViews;

for (const auto &field: curStruct.fields) {
if (field.isUnnamedBitfield()) {
continue;
}
size_t fieldLen = typesHandler.typeSize(field.type);
size_t fieldOffset = offsetInBits + field.offset;

Expand Down
4 changes: 0 additions & 4 deletions server/src/printers/KleeConstraintsPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ void KleeConstraintsPrinter::genConstraintsForStruct(const ConstraintsState &sta
StructInfo curStruct = typesHandler->getStructInfo(state.curType);
bool isStruct = curStruct.subType == SubType::Struct;
for (const auto &field : curStruct.fields) {
if (field.isUnnamedBitfield()) {
noConstraints("unnamed bit fields");
continue;
}
auto access = PrinterUtils::getFieldAccess(state.curElement, field);
ConstraintsState newState = { state.paramName,
access,
Expand Down
1 change: 0 additions & 1 deletion server/src/printers/TestsPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,6 @@ std::string printer::MultiLinePrinter::print(TestsPrinter *printer,
const size_t longestFieldIndexForUnionInit = structInfo.longestFieldIndexForUnionInit;
const bool isStruct = structInfo.subType == types::SubType::Struct;

bool firstField = true;
size_t i = 0;
for (const auto &sview : subViews) {
if (i != 0) {
Expand Down
4 changes: 0 additions & 4 deletions server/src/types/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,6 @@ bool types::TypesHandler::isStructLike(uint64_t id) const {
return typeIsInMap(id, typeMaps.structs);
}

bool types::Field::isUnnamedBitfield() const {
return name.empty() && TypesHandler::isPrimitiveType(type);
}

/*
* Enum types
*/
Expand Down
4 changes: 1 addition & 3 deletions server/src/types/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ namespace types {
AS_none
};
AccessSpecifier accessSpecifier = AS_pubic;
[[nodiscard]] bool isUnnamedBitfield() const;
};

struct TypeInfo {
Expand Down Expand Up @@ -350,8 +349,7 @@ namespace types {
: typeMaps(types), sizeContext(sizeContext){};

/**
* This functions calculates size of a given type. For structs in it calculates sum of sizes of its fields,
* ignoring alignment.
* Calculates size of a given type.
* @return size of given type in @b bits.
*/
size_t typeSize(const types::Type &type) const;
Expand Down
3 changes: 3 additions & 0 deletions server/src/types/TypesResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ void TypesResolver::resolveStructEx(const clang::RecordDecl *D, const std::strin
size_t i = 0;
size_t maxFieldSize = 0;
for (const clang::FieldDecl *F : D->fields()) {
if (F->isUnnamedBitfield()) {
continue;
}
structInfo.hasAnonymousStructOrUnion |= F->isAnonymousStructOrUnion();
types::Field field;
field.name = F->getNameAsString();
Expand Down
3 changes: 0 additions & 3 deletions server/src/visitors/AbstractValueViewVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ namespace visitor {
inUnion = structInfo.subType == types::SubType::Union;
for (int i = 0; i < structInfo.fields.size(); ++i) {
auto const &field = structInfo.fields[i];
if (field.isUnnamedBitfield()) {
continue;
}
auto newName = PrinterUtils::getFieldAccess(name, field);
auto const *newView = (subViews && i < subViews->size()) ? (*subViews)[i].get() : nullptr;
auto newAccess = PrinterUtils::getFieldAccess(access, field);
Expand Down
3 changes: 1 addition & 2 deletions server/src/visitors/FunctionPointerForStubsVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ namespace visitor {
}
for (auto &field : structInfo.fields) {
if (!types::TypesHandler::isPointerToFunction(field.type) &&
!types::TypesHandler::isArrayOfPointersToFunction(field.type) &&
!field.isUnnamedBitfield()) {
!types::TypesHandler::isArrayOfPointersToFunction(field.type)) {
visitAny(field.type, name, nullptr, access, depth + 1);
}
}
Expand Down
29 changes: 29 additions & 0 deletions server/test/framework/Syntax_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3166,4 +3166,33 @@ namespace {
})
);
}

TEST_F(Syntax_Test, bitfields_check_unnamed) {
auto [testGen, status] = createTestForFunction(bitfields_c, 99);

ASSERT_TRUE(status.ok()) << status.error_message();

checkTestCasePredicates(
testGen.tests.at(bitfields_c).methods.begin().value().testCases,
std::vector<TestCasePredicate>(
{
[](const tests::Tests::MethodTestCase &testCase) {
auto &subViews = testCase.paramValues.front().view->getSubViews();
return subViews.size() == 3 &&
checkBitfieldFit<unsigned>(subViews[0], 7) &&
checkBitfieldFit<unsigned>(subViews[1], 6) &&
checkBitfieldFit<unsigned>(subViews[2], 15) &&
testCase.returnValue.view->getEntryValue(nullptr) == "0";
},
[](const tests::Tests::MethodTestCase &testCase) {
auto &subViews = testCase.paramValues.front().view->getSubViews();
return subViews.size() == 3 &&
checkBitfieldFit<unsigned>(subViews[0], 7) &&
checkBitfieldFit<unsigned>(subViews[1], 6) &&
checkBitfieldFit<unsigned>(subViews[2], 15) &&
testCase.returnValue.view->getEntryValue(nullptr) == "13";
}
})
);
}
}
4 changes: 3 additions & 1 deletion server/test/suites/syntax/bitfields.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ typedef struct {
// 7 bits: value of b1
// 25 bits: unused
// 6 bits: value of b2
// 3 bits: unused
// 15 bits: value of b3
// 11 bits: unused
// 8 bits: unused
unsigned b1 : 7;
unsigned : 0; // start a new allocation unit
unsigned b2 : 6;
unsigned : 3;
unsigned b3 : 15;
} StrWithUnnamedZeroBitfield;

Expand Down