Skip to content

Commit bd9d0df

Browse files
committed
Add workaround and error logging for translate() returning nullptr
1 parent a344255 commit bd9d0df

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

bindgen/CycleDetection.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class CycleDetection {
3535
}
3636

3737
Type *type = tpeTransl.translate(qtpe);
38+
if (type == nullptr) {
39+
return;
40+
}
41+
3842
std::string qtpeString = type->str();
3943
if (type->canBeDeallocated()) {
4044
delete type;

bindgen/TypeTranslator.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,15 @@ Type *TypeTranslator::translateStructOrUnion(const clang::QualType &qtpe) {
106106
Type *TypeTranslator::translateConstantArray(const clang::ConstantArrayType *ar,
107107
const std::string *avoid) {
108108
const uint64_t size = ar->getSize().getZExtValue();
109-
return new ArrayType(translate(ar->getElementType(), avoid), size);
109+
Type *elementType = translate(ar->getElementType(), avoid);
110+
if (elementType == nullptr) {
111+
llvm::errs() << "Failed to translate array type "
112+
<< ar->getElementType().getAsString()
113+
<< "\n";
114+
elementType = new PrimitiveType("Byte");
115+
}
116+
117+
return new ArrayType(elementType, size);
110118
}
111119

112120
Type *TypeTranslator::translate(const clang::QualType &qtpe,

bindgen/ir/IR.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ T IR::getDeclarationWithName(std::vector<T> &declarations,
301301
return declaration;
302302
}
303303
}
304+
llvm::errs() << "Failed to get declaration for " << name << "\n";
304305
return nullptr;
305306
}
306307

0 commit comments

Comments
 (0)