]> granicus.if.org Git - clang/commitdiff
Fix ICE when __has_unqiue_object_representations called with invalid decl
authorErich Keane <erich.keane@intel.com>
Tue, 12 Dec 2017 16:02:06 +0000 (16:02 +0000)
committerErich Keane <erich.keane@intel.com>
Tue, 12 Dec 2017 16:02:06 +0000 (16:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@320489 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp
lib/Sema/SemaExprCXX.cpp
test/SemaCXX/type-traits.cpp

index e6471be20415dd81aaf22f95f05bb13531521635..34a925020e8f80ded09233c57bcf43a986502399 100644 (file)
@@ -2279,6 +2279,9 @@ bool ASTContext::hasUniqueObjectRepresentations(QualType Ty) const {
   if (Ty->isRecordType()) {
     const RecordDecl *Record = Ty->getAs<RecordType>()->getDecl();
 
+    if (Record->isInvalidDecl())
+      return false;
+
     if (Record->isUnion())
       return unionHasUniqueObjectRepresentations(*this, Record);
 
index 9c842ded1e101fd001b5bad389a92b15af4ab9d8..641d583944f1f7a5654d0476803d7879fae51c10 100644 (file)
@@ -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");
   }
index d4d19682182121afc0d19bb8e959dbc49135ca87..b334e507554f0a13426b1a9529ddf7b568aad574 100644 (file)
@@ -2661,3 +2661,11 @@ static_assert(sizeof(CanBeUniqueIfNoPadding) != 16 ||
               has_unique_object_representations<CanBeUniqueIfNoPadding>::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);
+};