summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-02-20 18:22:23 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-02-20 18:22:23 +0000
commitce39954d5db92ae6523e80ee5a1df27de2da9220 (patch)
treec953bc9432934df941e4a0c777a479d6d093e412 /clang
parentf5b77513b037e908d920031613e008cc9cedf8bf (diff)
downloadbcm5719-llvm-ce39954d5db92ae6523e80ee5a1df27de2da9220.tar.gz
bcm5719-llvm-ce39954d5db92ae6523e80ee5a1df27de2da9220.zip
Handle constant int -> ptr casts of lvalue results.
- PR3463 (again). llvm-svn: 65133
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/AST/ExprConstant.cpp25
-rw-r--r--clang/test/CodeGen/const-init.c3
2 files changed, 20 insertions, 8 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 0fcbdf12f06..64d3fdd8a73 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -54,6 +54,7 @@ struct EvalInfo {
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 @@ APValue PointerExprEvaluator::VisitCastExpr(const CastExpr* E) {
}
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 @@ private:
};
} // 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;
}
diff --git a/clang/test/CodeGen/const-init.c b/clang/test/CodeGen/const-init.c
index 957e3733e41..128bbb54f33 100644
--- a/clang/test/CodeGen/const-init.c
+++ b/clang/test/CodeGen/const-init.c
@@ -76,4 +76,7 @@ int g15 = (int) (char) ((void*) 0 + 255);
// 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
OpenPOWER on IntegriCloud