[cfe-commits] r65098 - /cfe/trunk/lib/AST/ExprConstant.cpp

Eli Friedman eli.friedman at gmail.com
Thu Feb 19 17:15:07 PST 2009


Author: efriedma
Date: Thu Feb 19 19:15:07 2009
New Revision: 65098

URL: http://llvm.org/viewvc/llvm-project?rev=65098&view=rev
Log:
ExprConstant handling for a couple more cases of pointer-to-int casts 
from the testsuite.


Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=65098&r1=65097&r2=65098&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Feb 19 19:15:07 2009
@@ -1053,9 +1053,10 @@
     if (!Visit(SubExpr))
       return false;
 
-    // FIXME: Support cast on LValue results.
-    if (!Result.isInt())
-      return false;
+    if (!Result.isInt()) {
+      // Only allow casts of lvalues if they are lossless.
+      return Info.Ctx.getTypeSize(DestType) == Info.Ctx.getTypeSize(SrcType);
+    }
 
     return Success(HandleIntToIntCast(DestType, SrcType,
                                       Result.getInt(), Info.Ctx), E);
@@ -1080,6 +1081,20 @@
     return Success(HandleIntToIntCast(DestType, SrcType, AsInt, Info.Ctx), E);
   }
 
+  if (SrcType->isArrayType() || SrcType->isFunctionType()) {
+    // This handles double-conversion cases, where there's both
+    // an l-value promotion and an implicit conversion to int.
+    APValue LV;
+    if (!EvaluateLValue(SubExpr, LV, Info))
+      return false;
+
+    if (Info.Ctx.getTypeSize(DestType) != Info.Ctx.getTypeSize(Info.Ctx.VoidPtrTy))
+      return false;
+
+    Result = LV;
+    return true;
+  }
+
   if (!SrcType->isRealFloatingType())
     return Error(E->getExprLoc(), diag::note_invalid_subexpr_in_ice, E);
 





More information about the cfe-commits mailing list