Skip to content

Commit 8e27f80

Browse files
committed
Use ASTContext->getTypeSize() to calculate the union size
1 parent 0e5ac3e commit 8e27f80

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

bindgen/visitor/TreeVisitor.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,20 @@ bool TreeVisitor::VisitRecordDecl(clang::RecordDecl *record) {
9999
}
100100

101101
void 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

120118
void TreeVisitor::handleStruct(clang::RecordDecl *record, std::string name) {

0 commit comments

Comments
 (0)