[cfe-commits] r46812 - /cfe/trunk/CodeGen/CGExprConstant.cpp
Anders Carlsson
andersca at mac.com
Tue Feb 5 23:23:14 PST 2008
Author: andersca
Date: Wed Feb 6 01:23:14 2008
New Revision: 46812
URL: http://llvm.org/viewvc/llvm-project?rev=46812&view=rev
Log:
Add pointer + int (and vice versa) to the constant emitter.
Modified:
cfe/trunk/CodeGen/CGExprConstant.cpp
Modified: cfe/trunk/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprConstant.cpp?rev=46812&r1=46811&r2=46812&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/CodeGen/CGExprConstant.cpp Wed Feb 6 01:23:14 2008
@@ -385,8 +385,16 @@
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) {
More information about the cfe-commits
mailing list