From: Erich Keane Date: Tue, 12 Dec 2017 16:02:06 +0000 (+0000) Subject: Fix ICE when __has_unqiue_object_representations called with invalid decl X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=133cba2f9263f63f44b6b086a500f374bff13eee;p=clang Fix ICE when __has_unqiue_object_representations called with invalid decl git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@320489 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index e6471be204..34a925020e 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -2279,6 +2279,9 @@ bool ASTContext::hasUniqueObjectRepresentations(QualType Ty) const { if (Ty->isRecordType()) { const RecordDecl *Record = Ty->getAs()->getDecl(); + if (Record->isInvalidDecl()) + return false; + if (Record->isUnion()) return unionHasUniqueObjectRepresentations(*this, Record); diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 9c842ded1e..641d583944 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -4958,7 +4958,7 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, QualType LhsT, EnterExpressionEvaluationContext Unevaluated( Self, Sema::ExpressionEvaluationContext::Unevaluated); Sema::SFINAETrap SFINAE(Self, /*AccessCheckingSFINAE=*/true); - Sema::ContextRAII TUContext(Self, Self.Context.getTranslationUnitDecl()); + Sema::ContextRAII TUContext(Self, Self.Context.getTranslationUnitDecl()); { ExprResult Result = Self.BuildBinOp(/*S=*/nullptr, KeyLoc, BO_Assign, &Lhs, &Rhs); if (Result.isInvalid() || SFINAE.hasErrorOccurred()) @@ -4981,6 +4981,7 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, QualType LhsT, llvm_unreachable("unhandled type trait"); return false; + } } default: llvm_unreachable("not a BTT"); } diff --git a/test/SemaCXX/type-traits.cpp b/test/SemaCXX/type-traits.cpp index d4d1968218..b334e50755 100644 --- a/test/SemaCXX/type-traits.cpp +++ b/test/SemaCXX/type-traits.cpp @@ -2661,3 +2661,11 @@ static_assert(sizeof(CanBeUniqueIfNoPadding) != 16 || has_unique_object_representations::value, "inherit from std layout"); +namespace ErrorType { + struct S; //expected-note{{forward declaration of 'ErrorType::S'}} + + struct T { + S t; //expected-error{{field has incomplete type 'ErrorType::S'}} + }; + bool b = __has_unique_object_representations(T); +};