]> granicus.if.org Git - clang/commitdiff
Fix a crash-on-invalid where the constant evaluator would try to
authorJohn McCall <rjmccall@apple.com>
Thu, 26 Apr 2012 18:10:01 +0000 (18:10 +0000)
committerJohn McCall <rjmccall@apple.com>
Thu, 26 Apr 2012 18:10:01 +0000 (18:10 +0000)
evaluate certain expressions involving invalidly-defined classes.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155645 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/SemaCXX/constant-expression.cpp

index 818548127cfbb8e7a7dfd39b4b75c1ce5714eb40..2edf4ff3357f79e3b1552f83f7188b818ee294e1 100644 (file)
@@ -3408,6 +3408,7 @@ static bool HandleClassZeroInitialization(EvalInfo &Info, const Expr *E,
 
 bool RecordExprEvaluator::ZeroInitialization(const Expr *E) {
   const RecordDecl *RD = E->getType()->castAs<RecordType>()->getDecl();
+  if (RD->isInvalidDecl()) return false;
   if (RD->isUnion()) {
     // C++11 [dcl.init]p5: If T is a (possibly cv-qualified) union type, the
     // object's first non-static named data member is zero-initialized
@@ -3470,6 +3471,8 @@ bool RecordExprEvaluator::VisitInitListExpr(const InitListExpr *E) {
     return false;
 
   const RecordDecl *RD = E->getType()->castAs<RecordType>()->getDecl();
+  if (RD->isInvalidDecl()) return false;
+
   const ASTRecordLayout &Layout = Info.Ctx.getASTRecordLayout(RD);
 
   if (RD->isUnion()) {
@@ -3528,6 +3531,8 @@ bool RecordExprEvaluator::VisitInitListExpr(const InitListExpr *E) {
 
 bool RecordExprEvaluator::VisitCXXConstructExpr(const CXXConstructExpr *E) {
   const CXXConstructorDecl *FD = E->getConstructor();
+  if (FD->isInvalidDecl() || FD->getParent()->isInvalidDecl()) return false;
+
   bool ZeroInit = E->requiresZeroInitialization();
   if (CheckTrivialDefaultConstructor(Info, E->getExprLoc(), FD, ZeroInit)) {
     // If we've already performed zero-initialization, we're already done.
index 23a4dda70838c755b63377256cc9751611e46c2e..c997f3c5254bfbbd781c301a7613abb64b77fac1 100644 (file)
@@ -117,3 +117,10 @@ namespace FloatConvert {
   typedef int a[(int)42.997];
   typedef int b[(int)4e10]; // expected-warning {{variable length}} expected-error {{variable length}}
 }
+
+// PR12626
+namespace test3 {
+  struct X; // expected-note {{forward declaration of 'test3::X'}}
+  struct Y { bool b; X x; }; // expected-error {{field has incomplete type 'test3::X'}}
+  int f() { return Y().b; }
+}