================
@@ -3384,9 +3384,30 @@ ASTContext::getASTRecordLayout(const RecordDecl *D)
const {
// not a complete definition (which is what isCompleteDefinition() tests)
// until we *finish* parsing the definition.
D = D->getDefinition();
- assert(D && "Cannot get layout of forward declarations!");
- assert(!D->isInvalidDecl() && "Cannot get layout of invalid decl!");
- assert(D->isCompleteDefinition() && "Cannot layout type before complete!");
+
+ // Handle invalid declarations gracefully during error recovery
+ // This can happen when there are template specialization errors
+ if (!D || D->isInvalidDecl() || !D->isCompleteDefinition()) {
+ // Check if we already have a cached layout
+ const ASTRecordLayout *Entry = ASTRecordLayouts[D];
+ if (Entry)
+ return *Entry;
+
+ // Create a minimal safe layout for error recovery
+ // Use 1-byte size and alignment to avoid division by zero or other issues
+ ASTRecordLayout *NewEntry =
+ new (*this) ASTRecordLayout(*this,
+ /*Size=*/CharUnits::One(),
+ /*Alignment=*/CharUnits::One(),
+ /*PreferredAlignment=*/CharUnits::One(),
+ /*UnadjustedAlignment=*/CharUnits::One(),
+ /*RequiredAlignment=*/CharUnits::One(),
+ /*DataSize=*/CharUnits::One(),
+ /*FieldOffsets=*/ArrayRef<uint64_t>());
+
+ ASTRecordLayouts[D] = NewEntry;
----------------
erichkeane wrote:
But what if `!D`?
https://github.com/llvm/llvm-project/pull/208153
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits