@@ -99,22 +99,20 @@ bool TreeVisitor::VisitRecordDecl(clang::RecordDecl *record) {
9999}
100100
101101void TreeVisitor::handleUnion (clang::RecordDecl *record, std::string name) {
102- uint64_t maxSize = 0 ;
103-
104102 std::vector<std::shared_ptr<Field>> fields;
105103
106104 for (const clang::FieldDecl *field : record->fields ()) {
107- uint64_t sizeInBits = astContext->getTypeSize (field->getType ());
108- assert (sizeInBits % 8 == 0 );
109- maxSize = std::max (maxSize, sizeInBits / 8 );
110105 std::string fname = field->getNameAsString ();
111106 std::shared_ptr<Type> ftype =
112107 typeTranslator.translate (field->getType (), &name);
113108
114109 fields.push_back (std::make_shared<Field>(fname, ftype));
115110 }
116111
117- ir.addUnion (name, std::move (fields), maxSize, getLocation (record));
112+ uint64_t sizeInBits = astContext->getTypeSize (record->getTypeForDecl ());
113+ assert (sizeInBits % 8 == 0 );
114+
115+ ir.addUnion (name, std::move (fields), sizeInBits / 8 , getLocation (record));
118116}
119117
120118void TreeVisitor::handleStruct (clang::RecordDecl *record, std::string name) {
@@ -127,7 +125,6 @@ void TreeVisitor::handleStruct(clang::RecordDecl *record, std::string name) {
127125 llvm::errs ().flush ();
128126 }
129127
130- int fieldCnt = 0 ;
131128 std::vector<std::shared_ptr<Field>> fields;
132129
133130 for (const clang::FieldDecl *field : record->fields ()) {
@@ -137,8 +134,6 @@ void TreeVisitor::handleStruct(clang::RecordDecl *record, std::string name) {
137134 std::make_shared<Field>(field->getNameAsString (), ftype));
138135
139136 cycleDetection.AddDependency (newName, field->getType ());
140-
141- fieldCnt++;
142137 }
143138
144139 if (cycleDetection.isCyclic (newName)) {
0 commit comments