[cfe-commits] r140812 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/SemaCXX/i-c-e-cxx.cpp

Eli Friedman eli.friedman at gmail.com
Thu Sep 29 16:49:34 CDT 2011


Author: efriedma
Date: Thu Sep 29 16:49:34 2011
New Revision: 140812

URL: http://llvm.org/viewvc/llvm-project?rev=140812&view=rev
Log:
PR11040: CheckICE should not allow an lvalue bitcast as part of an integer constant expression.


Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    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=140812&r1=140811&r2=140812&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Sep 29 16:49:34 2011
@@ -3089,11 +3089,17 @@
   case Expr::CXXConstCastExprClass: 
   case Expr::ObjCBridgedCastExprClass: {
     const Expr *SubExpr = cast<CastExpr>(E)->getSubExpr();
-    if (SubExpr->getType()->isIntegralOrEnumerationType())
+    switch (cast<CastExpr>(E)->getCastKind()) {
+    case CK_LValueToRValue:
+    case CK_NoOp:
+    case CK_IntegralToBoolean:
+    case CK_IntegralCast:
       return CheckICE(SubExpr, Ctx);
-    if (isa<FloatingLiteral>(SubExpr->IgnoreParens()))
-      return NoDiag();
-    return ICEDiag(2, E->getLocStart());
+    default:
+      if (isa<FloatingLiteral>(SubExpr->IgnoreParens()))
+        return NoDiag();
+      return ICEDiag(2, E->getLocStart());
+    }
   }
   case Expr::BinaryConditionalOperatorClass: {
     const BinaryConditionalOperator *Exp = cast<BinaryConditionalOperator>(E);

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=140812&r1=140811&r2=140812&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp (original)
+++ cfe/trunk/test/SemaCXX/i-c-e-cxx.cpp Thu Sep 29 16:49:34 2011
@@ -54,4 +54,6 @@
 int foo() { return A::B; }
 }
 
-
+// PR11040
+const int x = 10;
+int* y = reinterpret_cast<const char&>(x); // expected-error {{cannot initialize}}




More information about the cfe-commits mailing list