[cfe-commits] r160024 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/SemaCXX/constant-expression-cxx11.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Tue Jul 10 15:12:55 PDT 2012
Author: rsmith
Date: Tue Jul 10 17:12:55 2012
New Revision: 160024
URL: http://llvm.org/viewvc/llvm-project?rev=160024&view=rev
Log:
Fix crash when constant-evaluating a CXXConstructExpr representing
value-initialization for an array of class type with a trivial default
constructor.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=160024&r1=160023&r2=160024&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Jul 10 17:12:55 2012
@@ -3911,10 +3911,6 @@
}
bool ArrayExprEvaluator::VisitCXXConstructExpr(const CXXConstructExpr *E) {
- const ConstantArrayType *CAT = Info.Ctx.getAsConstantArrayType(E->getType());
- if (!CAT)
- return Error(E);
-
// FIXME: The Subobject here isn't necessarily right. This rarely matters,
// but sometimes does:
// struct S { constexpr S() : p(&p) {} void *p; };
@@ -3923,17 +3919,22 @@
APValue *Value = &Result;
bool HadZeroInit = true;
- while (CAT) {
+ QualType ElemTy = E->getType();
+ while (const ConstantArrayType *CAT =
+ Info.Ctx.getAsConstantArrayType(ElemTy)) {
Subobject.addArray(Info, E, CAT);
HadZeroInit &= !Value->isUninit();
if (!HadZeroInit)
*Value = APValue(APValue::UninitArray(), 0, CAT->getSize().getZExtValue());
if (!Value->hasArrayFiller())
return true;
- CAT = Info.Ctx.getAsConstantArrayType(CAT->getElementType());
Value = &Value->getArrayFiller();
+ ElemTy = CAT->getElementType();
}
+ if (!ElemTy->isRecordType())
+ return Error(E);
+
const CXXConstructorDecl *FD = E->getConstructor();
bool ZeroInit = E->requiresZeroInitialization();
@@ -3942,7 +3943,7 @@
return true;
if (ZeroInit) {
- ImplicitValueInitExpr VIE(CAT->getElementType());
+ ImplicitValueInitExpr VIE(ElemTy);
return EvaluateInPlace(*Value, Info, Subobject, &VIE);
}
@@ -3963,7 +3964,7 @@
return false;
if (ZeroInit && !HadZeroInit) {
- ImplicitValueInitExpr VIE(CAT->getElementType());
+ ImplicitValueInitExpr VIE(ElemTy);
if (!EvaluateInPlace(*Value, Info, Subobject, &VIE))
return false;
}
Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=160024&r1=160023&r2=160024&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Tue Jul 10 17:12:55 2012
@@ -507,6 +507,14 @@
static_assert(selfref[1][1][0] == 0, "");
static_assert(selfref[1][1][1] == 0, "");
+struct TrivialDefCtor { int n; };
+typedef TrivialDefCtor TDCArray[2][2];
+static_assert(TDCArray{}[1][1].n == 0, "");
+
+struct NonAggregateTDC : TrivialDefCtor {};
+typedef NonAggregateTDC NATDCArray[2][2];
+static_assert(NATDCArray{}[1][1].n == 0, "");
+
}
namespace DependentValues {
More information about the cfe-commits
mailing list