aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExprConstant.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-02-19 21:44:24 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-02-19 21:44:24 +0000
commite20de512d88cf42a26ef994687d87fc6f5826625 (patch)
tree84a9d90dab2e7265e105bf7184aef69839904046 /lib/CodeGen/CGExprConstant.cpp
parent30c37f4d2ee5811e85f692c22fb67d74ddc88079 (diff)
Remove IRgen constant emission assumption that LValue APValue results
only occur for pointer types; they are also possible for integer types now. - No intended functionality change, IntExprEvaluate doesn't return LValue results yet. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65066 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprConstant.cpp')
-rw-r--r--lib/CodeGen/CGExprConstant.cpp46
1 files changed, 31 insertions, 15 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index 651a283baa..523014f1fb 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -637,28 +637,44 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
assert(0 && "Constant expressions should be initialized.");
return 0;
case APValue::LValue: {
+ const llvm::Type *DestType = getTypes().ConvertTypeForMem(E->getType());
llvm::Constant *Offset =
llvm::ConstantInt::get(llvm::Type::Int64Ty,
Result.Val.getLValueOffset());
+ llvm::Constant *C;
if (const Expr *LVBase = Result.Val.getLValueBase()) {
- llvm::Constant *C =
- ConstExprEmitter(*this, CGF).EmitLValue(const_cast<Expr*>(LVBase));
+ C = ConstExprEmitter(*this, CGF).EmitLValue(const_cast<Expr*>(LVBase));
+
+ // Apply offset if necessary.
+ if (!Offset->isNullValue()) {
+ const llvm::Type *Type =
+ llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
+ llvm::Constant *Casted = llvm::ConstantExpr::getBitCast(C, Type);
+ Casted = llvm::ConstantExpr::getGetElementPtr(Casted, &Offset, 1);
+ C = llvm::ConstantExpr::getBitCast(Casted, C->getType());
+ }
- const llvm::Type *Type =
- llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
- const llvm::Type *DestType = getTypes().ConvertTypeForMem(E->getType());
-
- // FIXME: It's a little ugly that we need to cast to a pointer,
- // apply the GEP and then cast back.
- C = llvm::ConstantExpr::getBitCast(C, Type);
- C = llvm::ConstantExpr::getGetElementPtr(C, &Offset, 1);
-
- return llvm::ConstantExpr::getBitCast(C, DestType);
+ // Convert to the appropriate type; this could be an lvalue for
+ // an integer.
+ if (isa<llvm::PointerType>(DestType))
+ return llvm::ConstantExpr::getBitCast(C, DestType);
+
+ return llvm::ConstantExpr::getPtrToInt(C, DestType);
+ } else {
+ C = Offset;
+
+ // Convert to the appropriate type; this could be an lvalue for
+ // an integer.
+ if (isa<llvm::PointerType>(DestType))
+ return llvm::ConstantExpr::getIntToPtr(C, DestType);
+
+ // If the types don't match this should only be a truncate.
+ if (C->getType() != DestType)
+ return llvm::ConstantExpr::getTrunc(C, DestType);
+
+ return C;
}
-
- return llvm::ConstantExpr::getIntToPtr(Offset,
- getTypes().ConvertType(E->getType()));
}
case APValue::Int: {
llvm::Constant *C = llvm::ConstantInt::get(Result.Val.getInt());