Fix PR2400 by more graceful handling of invalid decls. Don't try to layout
an invalid struct decl. Thanks to Martin Doucha for the
isIncompleteArrayType part of this patch.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54592 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index a20236f..0325ba5 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -325,6 +325,12 @@
break;
}
case Type::Tagged: {
+ if (cast<TagType>(T)->getDecl()->isInvalidDecl()) {
+ Width = 1;
+ Align = 1;
+ break;
+ }
+
if (EnumType *ET = dyn_cast<EnumType>(cast<TagType>(T)))
return getTypeInfo(ET->getDecl()->getIntegerType());
@@ -377,8 +383,8 @@
if (!FD->getIdentifier())
FieldAlign = 1;
} else {
- if (FD->getType()->isIncompleteType()) {
- // This must be a flexible array member; we can't directly
+ if (FD->getType()->isIncompleteArrayType()) {
+ // This is a flexible array member; we can't directly
// query getTypeInfo about these, so we figure it out here.
// Flexible array members don't have any size, but they
// have to be aligned appropriately for their element type.