From: Anders Carlsson Date: Wed, 6 Feb 2008 07:23:14 +0000 (+0000) Subject: Add pointer + int (and vice versa) to the constant emitter. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=87a98759d683d9ed23e09744207a4428c4ed5ace;p=clang Add pointer + int (and vice versa) to the constant emitter. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46812 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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(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) {