[cfe-commits] r65133 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/CodeGen/const-init.c
Daniel Dunbar
daniel at zuster.org
Fri Feb 20 10:22:23 PST 2009
Author: ddunbar
Date: Fri Feb 20 12:22:23 2009
New Revision: 65133
URL: http://llvm.org/viewvc/llvm-project?rev=65133&view=rev
Log:
Handle constant int -> ptr casts of lvalue results.
- PR3463 (again).
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/CodeGen/const-init.c
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=65133&r1=65132&r2=65133&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Feb 20 12:22:23 2009
@@ -54,6 +54,7 @@
static bool EvaluateLValue(const Expr *E, APValue &Result, EvalInfo &Info);
static bool EvaluatePointer(const Expr *E, APValue &Result, EvalInfo &Info);
static bool EvaluateInteger(const Expr *E, APSInt &Result, EvalInfo &Info);
+static bool EvaluateIntegerOrLValue(const Expr *E, APValue &Result, EvalInfo &Info);
static bool EvaluateFloat(const Expr *E, APFloat &Result, EvalInfo &Info);
static bool EvaluateComplex(const Expr *E, APValue &Result, EvalInfo &Info);
@@ -351,11 +352,17 @@
}
if (SubExpr->getType()->isIntegralType()) {
- llvm::APSInt Result(32);
- if (EvaluateInteger(SubExpr, Result, Info)) {
- Result.extOrTrunc((unsigned)Info.Ctx.getTypeSize(E->getType()));
- return APValue(0, Result.getZExtValue());
+ APValue Result;
+ if (!EvaluateIntegerOrLValue(SubExpr, Result, Info))
+ return APValue();
+
+ if (Result.isInt()) {
+ Result.getInt().extOrTrunc((unsigned)Info.Ctx.getTypeSize(E->getType()));
+ return APValue(0, Result.getInt().getZExtValue());
}
+
+ // Cast is of an lvalue, no need to change value.
+ return Result;
}
if (SubExpr->getType()->isFunctionType() ||
@@ -587,15 +594,17 @@
};
} // end anonymous namespace
-static bool EvaluateInteger(const Expr* E, APSInt &Result, EvalInfo &Info) {
+static bool EvaluateIntegerOrLValue(const Expr* E, APValue &Result, EvalInfo &Info) {
if (!E->getType()->isIntegralType())
return false;
+ return IntExprEvaluator(Info, Result).Visit(const_cast<Expr*>(E));
+}
+
+static bool EvaluateInteger(const Expr* E, APSInt &Result, EvalInfo &Info) {
APValue Val;
- if (!IntExprEvaluator(Info, Val).Visit(const_cast<Expr*>(E)) ||
- !Val.isInt())
+ if (!EvaluateIntegerOrLValue(E, Val, Info) || !Val.isInt())
return false;
-
Result = Val.getInt();
return true;
}
Modified: cfe/trunk/test/CodeGen/const-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/const-init.c?rev=65133&r1=65132&r2=65133&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/const-init.c (original)
+++ cfe/trunk/test/CodeGen/const-init.c Fri Feb 20 12:22:23 2009
@@ -76,4 +76,7 @@
// RUN: grep '@g16 = global i64 4294967295' %t &&
long long g16 = (long long) ((void*) 0xFFFFFFFF);
+// RUN: grep '@g17 = global i32\* @g15' %t &&
+int *g17 = (int *) ((long) &g15);
+
// RUN: true
More information about the cfe-commits
mailing list