Skip to content

Commit 3513f95

Browse files
authored
TypeGraphv2: correctly handle bitfields in code generation (#495)
Currently in TypeGraph when generating inst::Field objects in the generated source we use the `sizeof` operator to construct the static and exclusive size. As you can't use sizeof() on a bitfield this generates invalid code. This fix special cases bit fields and sets the static and exclusive size to 0 as there size will be rolled up in the parent object.
1 parent 479545d commit 3513f95

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

oi/CodeGen.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -822,17 +822,24 @@ void CodeGen::genClassTreeBuilderInstructions(const Class& c,
822822
code += std::to_string(numFields);
823823
code += "> fields{\n";
824824
index = 0;
825+
825826
for (const auto& m : c.members) {
826827
++index;
827828
if (m.name.starts_with(AddPadding::MemberPrefix))
828829
continue;
829830
std::string fullName = c.name() + "::" + m.name;
831+
bool isbitField = m.bitsize;
830832
bool isPrimitive = dynamic_cast<const Primitive*>(&m.type());
831-
code += " inst::Field{sizeof(";
832-
code += fullName;
833-
code += "), ";
834-
code += std::to_string(calculateExclusiveSize(m.type()));
835-
code += ",\"";
833+
834+
if (!isbitField) {
835+
code += " inst::Field{sizeof(";
836+
code += fullName;
837+
code += "), ";
838+
code += std::to_string(calculateExclusiveSize(m.type()));
839+
} else {
840+
code += " inst::Field{0, 0";
841+
}
842+
code += ", \"";
836843
code += m.inputName;
837844
code += "\", member_";
838845
code += std::to_string(index);

0 commit comments

Comments
 (0)