aboutsummaryrefslogtreecommitdiff
path: root/CodeGen/CGExprConstant.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CodeGen/CGExprConstant.cpp')
-rw-r--r--CodeGen/CGExprConstant.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/CodeGen/CGExprConstant.cpp b/CodeGen/CGExprConstant.cpp
index 85f0697348..8c319a0eb3 100644
--- a/CodeGen/CGExprConstant.cpp
+++ b/CodeGen/CGExprConstant.cpp
@@ -385,8 +385,16 @@ public:
if (!E->getType()->isPointerType())
return llvm::ConstantExpr::getAdd(LHS, RHS);
- assert(0 && "Unhandled bin add types!");
- return 0;
+ llvm::Constant *Ptr, *Idx;
+ if (isa<llvm::PointerType>(LHS->getType())) { // pointer + int
+ Ptr = LHS;
+ Idx = RHS;
+ } else { // int + pointer
+ Ptr = RHS;
+ Idx = LHS;
+ }
+
+ return llvm::ConstantExpr::getGetElementPtr(Ptr, &Idx, 1);
}
llvm::Constant *VisitBinAnd(const BinaryOperator *E) {