aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2012-04-26 18:10:01 +0000
committerJohn McCall <rjmccall@apple.com>2012-04-26 18:10:01 +0000
commit1de9d7de172379d6af75fd11dda2a713e4f36f62 (patch)
tree1d4c2ad5c3f986da8da02f30edc21b3aa01ed98e
parente855b884799e3f651f59ef64911269eaf3df6e12 (diff)
Fix a crash-on-invalid where the constant evaluator would try to
evaluate certain expressions involving invalidly-defined classes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155645 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/ExprConstant.cpp5
-rw-r--r--test/SemaCXX/constant-expression.cpp7
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 818548127c..2edf4ff335 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -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.
diff --git a/test/SemaCXX/constant-expression.cpp b/test/SemaCXX/constant-expression.cpp
index 23a4dda708..c997f3c525 100644
--- a/test/SemaCXX/constant-expression.cpp
+++ b/test/SemaCXX/constant-expression.cpp
@@ -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; }
+}