[cfe-commits] r142832 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/Sema/i-c-e.c test/SemaCXX/i-c-e-cxx.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Mon Oct 24 11:26:35 PDT 2011
Author: rsmith
Date: Mon Oct 24 13:26:35 2011
New Revision: 142832
URL: http://llvm.org/viewvc/llvm-project?rev=142832&view=rev
Log:
In accordance with the C89, C99 and C++98 standards, ICEs can only contain
floating-point literals if they are the immediate operands of casts.
ImplicitCastExpr is not a cast in the language-standards sense.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/Sema/i-c-e.c
cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=142832&r1=142831&r2=142832&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Oct 24 13:26:35 2011
@@ -3114,9 +3114,12 @@
case Expr::CXXFunctionalCastExprClass:
case Expr::CXXStaticCastExprClass:
case Expr::CXXReinterpretCastExprClass:
- case Expr::CXXConstCastExprClass:
+ case Expr::CXXConstCastExprClass:
case Expr::ObjCBridgedCastExprClass: {
const Expr *SubExpr = cast<CastExpr>(E)->getSubExpr();
+ if (E->getStmtClass() != Expr::ImplicitCastExprClass &&
+ isa<FloatingLiteral>(SubExpr->IgnoreParenImpCasts()))
+ return NoDiag();
switch (cast<CastExpr>(E)->getCastKind()) {
case CK_LValueToRValue:
case CK_NoOp:
@@ -3124,8 +3127,6 @@
case CK_IntegralCast:
return CheckICE(SubExpr, Ctx);
default:
- if (isa<FloatingLiteral>(SubExpr->IgnoreParens()))
- return NoDiag();
return ICEDiag(2, E->getLocStart());
}
}
Modified: cfe/trunk/test/Sema/i-c-e.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/i-c-e.c?rev=142832&r1=142831&r2=142832&view=diff
==============================================================================
--- cfe/trunk/test/Sema/i-c-e.c (original)
+++ cfe/trunk/test/Sema/i-c-e.c Mon Oct 24 13:26:35 2011
@@ -11,6 +11,9 @@
char v[sizeof(__builtin_constant_p(0)) == sizeof(int) ? 1 : -1];
+int implicitConversion = 1.0;
+char floatArith[(int)(1.0+2.0)]; // expected-warning {{must be an integer constant expression}}
+
// __builtin_constant_p as the condition of ?: allows arbitrary foldable
// constants to be transmogrified into i-c-e's.
char b[__builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+2.0) : -1];
Modified: cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp?rev=142832&r1=142831&r2=142832&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp (original)
+++ cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp Mon Oct 24 13:26:35 2011
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
// C++-specific tests for integral constant expressions.
@@ -48,7 +48,7 @@
namespace rdar9204520 {
struct A {
- static const int B = int(0.75 * 1000 * 1000);
+ static const int B = int(0.75 * 1000 * 1000); // expected-warning {{not a constant expression, accepted as an extension}}
};
int foo() { return A::B; }
@@ -59,5 +59,10 @@
int* y = reinterpret_cast<const char&>(x); // expected-error {{cannot initialize}}
// This isn't an integral constant expression, but make sure it folds anyway.
-struct PR8836 { char _; long long a; };
-int PR8836test[(__typeof(sizeof(int)))&reinterpret_cast<const volatile char&>((((PR8836*)0)->a))];
+struct PR8836 { char _; long long a; }; // expected-warning {{long long}}
+int PR8836test[(__typeof(sizeof(int)))&reinterpret_cast<const volatile char&>((((PR8836*)0)->a))]; // expected-warning {{folded to constant array as an extension}}
+
+const int nonconst = 1.0;
+int arr[nonconst]; // expected-warning {{folded to constant array as an extension}}
+const int castfloat = static_cast<int>(1.0);
+int arr2[castfloat]; // ok
More information about the cfe-commits
mailing list