mirror of
https://github.com/intel/llvm.git
synced 2026-01-21 04:14:03 +08:00
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. llvm-svn: 142832
This commit is contained in:
@@ -3114,9 +3114,12 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) {
|
||||
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 @@ static ICEDiag CheckICE(const Expr* E, ASTContext &Ctx) {
|
||||
case CK_IntegralCast:
|
||||
return CheckICE(SubExpr, Ctx);
|
||||
default:
|
||||
if (isa<FloatingLiteral>(SubExpr->IgnoreParens()))
|
||||
return NoDiag();
|
||||
return ICEDiag(2, E->getLocStart());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ char w[__builtin_constant_p(expr) ? expr : 1];
|
||||
|
||||
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];
|
||||
|
||||
@@ -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 @@ void pr6373(const unsigned x = 0) {
|
||||
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 @@ const int x = 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
|
||||
|
||||
Reference in New Issue
Block a user