r191719 - Tweak changes in r186464 to avoid a crash.
Eli Friedman
eli.friedman at gmail.com
Mon Sep 30 17:28:29 PDT 2013
Author: efriedma
Date: Mon Sep 30 19:28:29 2013
New Revision: 191719
URL: http://llvm.org/viewvc/llvm-project?rev=191719&view=rev
Log:
Tweak changes in r186464 to avoid a crash.
Currently, IR generation can't handle file-scope compound literals with
non-constant initializers in C++.
Fixes PR17415 (the first crash in the bug).
(We should probably change (T){1,2,3} to use the same codepath as T{1,2,3} in
C++ eventually, given that the semantics of the latter are actually defined by
the standard.)
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaCXX/compound-literal.cpp
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=191719&r1=191718&r2=191719&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Mon Sep 30 19:28:29 2013
@@ -2654,9 +2654,6 @@ bool Expr::isConstantInitializer(ASTCont
return Exp->isConstantInitializer(Ctx, false);
}
case InitListExprClass: {
- // FIXME: This doesn't deal with fields with reference types correctly.
- // FIXME: This incorrectly allows pointers cast to integers to be assigned
- // to bitfields.
const InitListExpr *ILE = cast<InitListExpr>(this);
if (ILE->getType()->isArrayType()) {
unsigned numInits = ILE->getNumInits();
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=191719&r1=191718&r2=191719&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Sep 30 19:28:29 2013
@@ -4717,7 +4717,10 @@ Sema::BuildCompoundLiteralExpr(SourceLoc
LiteralExpr = Result.get();
bool isFileScope = getCurFunctionOrMethodDecl() == 0;
- if (!getLangOpts().CPlusPlus && isFileScope) { // 6.5.2.5p3
+ if (isFileScope &&
+ !LiteralExpr->isTypeDependent() &&
+ !LiteralExpr->isValueDependent() &&
+ !literalType->isDependentType()) { // 6.5.2.5p3
if (CheckForConstantInitializer(LiteralExpr, literalType))
return ExprError();
}
Modified: cfe/trunk/test/SemaCXX/compound-literal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compound-literal.cpp?rev=191719&r1=191718&r2=191719&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/compound-literal.cpp (original)
+++ cfe/trunk/test/SemaCXX/compound-literal.cpp Mon Sep 30 19:28:29 2013
@@ -76,3 +76,13 @@ namespace brace_initializers {
(void)(PrivateDtor){1, 2}; // expected-error {{temporary of type 'brace_initializers::PrivateDtor' has private destructor}}
}
}
+
+// This doesn't necessarily need to be an error, but CodeGen can't handle it
+// at the moment.
+int PR17415 = (int){PR17415}; // expected-error {{initializer element is not a compile-time constant}}
+
+// Make sure we accept this. (Not sure if we actually should... but we do
+// at the moment.)
+template<unsigned> struct Value { };
+template<typename T>
+int &check_narrowed(Value<sizeof((T){1.1})>);
More information about the cfe-commits
mailing list