[cfe-commits] r155645 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/SemaCXX/constant-expression.cpp
John McCall
rjmccall at apple.com
Thu Apr 26 11:10:01 PDT 2012
Author: rjmccall
Date: Thu Apr 26 13:10:01 2012
New Revision: 155645
URL: http://llvm.org/viewvc/llvm-project?rev=155645&view=rev
Log:
Fix a crash-on-invalid where the constant evaluator would try to
evaluate certain expressions involving invalidly-defined classes.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression.cpp
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=155645&r1=155644&r2=155645&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Apr 26 13:10:01 2012
@@ -3408,6 +3408,7 @@
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 @@
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::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.
Modified: cfe/trunk/test/SemaCXX/constant-expression.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression.cpp?rev=155645&r1=155644&r2=155645&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression.cpp Thu Apr 26 13:10:01 2012
@@ -117,3 +117,10 @@
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; }
+}
More information about the cfe-commits
mailing list