[cfe-commits] r140459 - in /cfe/trunk: lib/AST/ExprConstant.cpp lib/CodeGen/CGExprScalar.cpp lib/Sema/SemaInit.cpp test/CodeGenCXX/cxx0x-initializer-scalars.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Sat Sep 24 10:48:14 PDT 2011
Author: cornedbee
Date: Sat Sep 24 12:48:14 2011
New Revision: 140459
URL: http://llvm.org/viewvc/llvm-project?rev=140459&view=rev
Log:
Treat list-initialization of scalars as a first-class citizen in C++11.
Allow empty initializer lists for scalars, which mean value-initialization.
Constant evaluation for single-element and empty initializer lists for scalars.
Codegen for empty initializer lists for scalars.
Test case comes in next commit.
Added:
cfe/trunk/test/CodeGenCXX/cxx0x-initializer-scalars.cpp
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=140459&r1=140458&r2=140459&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sat Sep 24 12:48:14 2011
@@ -484,6 +484,13 @@
return Visit(E->getSubExpr());
}
}
+
+ bool VisitInitListExpr(const InitListExpr *E) {
+ if (Info.Ctx.getLangOptions().CPlusPlus0x && E->getNumInits() == 1)
+ return Visit(E->getInit(0));
+ return Error(E);
+ }
+
// FIXME: Missing: __real__, __imag__
};
@@ -1079,7 +1086,9 @@
bool VisitCXXNoexceptExpr(const CXXNoexceptExpr *E);
bool VisitSizeOfPackExpr(const SizeOfPackExpr *E);
-
+
+ bool VisitInitListExpr(const InitListExpr *E);
+
private:
CharUnits GetAlignOfExpr(const Expr *E);
CharUnits GetAlignOfType(QualType T);
@@ -1932,6 +1941,17 @@
return Success(E->getValue(), E);
}
+bool IntExprEvaluator::VisitInitListExpr(const InitListExpr *E) {
+ if (!Info.Ctx.getLangOptions().CPlusPlus0x)
+ return Error(E);
+
+ if (E->getNumInits() == 0)
+ return Success(0, E);
+
+ assert(E->getNumInits() == 1 && "Excess initializers for integer in C++11.");
+ return Visit(E->getInit(0));
+}
+
//===----------------------------------------------------------------------===//
// Float Evaluation
//===----------------------------------------------------------------------===//
@@ -1965,6 +1985,8 @@
bool VisitDeclRefExpr(const DeclRefExpr *E);
+ bool VisitInitListExpr(const InitListExpr *E);
+
// FIXME: Missing: array subscript of vector, member of vector,
// ImplicitValueInitExpr
};
@@ -2233,6 +2255,19 @@
return true;
}
+bool FloatExprEvaluator::VisitInitListExpr(const InitListExpr *E) {
+ if (!Info.Ctx.getLangOptions().CPlusPlus0x)
+ return Error(E);
+
+ if (E->getNumInits() == 0) {
+ Result = APFloat::getZero(Info.Ctx.getFloatTypeSemantics(E->getType()));
+ return true;
+ }
+
+ assert(E->getNumInits() == 1 && "Excess initializers for integer in C++11.");
+ return Visit(E->getInit(0));
+}
+
//===----------------------------------------------------------------------===//
// Complex Evaluation (for float and integer)
//===----------------------------------------------------------------------===//
@@ -2264,7 +2299,7 @@
bool VisitBinaryOperator(const BinaryOperator *E);
bool VisitUnaryOperator(const UnaryOperator *E);
- // FIXME Missing: ImplicitValueInitExpr
+ // FIXME Missing: ImplicitValueInitExpr, InitListExpr
};
} // end anonymous namespace
@@ -2766,7 +2801,6 @@
case Expr::CompoundAssignOperatorClass:
case Expr::CompoundLiteralExprClass:
case Expr::ExtVectorElementExprClass:
- case Expr::InitListExprClass:
case Expr::DesignatedInitExprClass:
case Expr::ImplicitValueInitExprClass:
case Expr::ParenListExprClass:
@@ -2813,6 +2847,17 @@
case Expr::MaterializeTemporaryExprClass:
return ICEDiag(2, E->getLocStart());
+ case Expr::InitListExprClass:
+ if (Ctx.getLangOptions().CPlusPlus0x) {
+ const InitListExpr *ILE = cast<InitListExpr>(E);
+ if (ILE->getNumInits() == 0)
+ return NoDiag();
+ if (ILE->getNumInits() == 1)
+ return CheckICE(ILE->getInit(0), Ctx);
+ // Fall through for more than 1 expression.
+ }
+ return ICEDiag(2, E->getLocStart());
+
case Expr::SizeOfPackExprClass:
case Expr::GNUNullExprClass:
// GCC considers the GNU __null value to be an integral constant expression.
Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=140459&r1=140458&r2=140459&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Sat Sep 24 12:48:14 2011
@@ -837,9 +837,14 @@
llvm::VectorType *VType =
dyn_cast<llvm::VectorType>(ConvertType(E->getType()));
- // We have a scalar in braces. Just use the first element.
- if (!VType)
+ if (!VType) {
+ if (NumInitElements == 0) {
+ // C++11 value-initialization for the scalar.
+ return EmitNullValue(E->getType());
+ }
+ // We have a scalar in braces. Just use the first element.
return Visit(E->getInit(0));
+ }
unsigned ResElts = VType->getNumElements();
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=140459&r1=140458&r2=140459&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Sat Sep 24 12:48:14 2011
@@ -877,11 +877,12 @@
InitListExpr *StructuredList,
unsigned &StructuredIndex) {
if (Index >= IList->getNumInits()) {
- // FIXME: Allowed in C++11.
- if (!VerifyOnly)
- SemaRef.Diag(IList->getLocStart(), diag::err_empty_scalar_initializer)
- << IList->getSourceRange();
- hadError = true;
+ if (!SemaRef.getLangOptions().CPlusPlus0x) {
+ if (!VerifyOnly)
+ SemaRef.Diag(IList->getLocStart(), diag::err_empty_scalar_initializer)
+ << IList->getSourceRange();
+ hadError = true;
+ }
++Index;
++StructuredIndex;
return;
Added: cfe/trunk/test/CodeGenCXX/cxx0x-initializer-scalars.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx0x-initializer-scalars.cpp?rev=140459&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/cxx0x-initializer-scalars.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/cxx0x-initializer-scalars.cpp Sat Sep 24 12:48:14 2011
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c++0x -S -emit-llvm -o - %s | FileCheck %s
+
+void f()
+{
+ // CHECK: store i32 0
+ int i{};
+}
More information about the cfe-commits
mailing list