diff options
| -rw-r--r-- | clang/lib/CodeGen/CGExprConstant.cpp | 8 | ||||
| -rw-r--r-- | clang/test/CodeGen/const-init.c | 2 |
2 files changed, 8 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index d64c5876ee2..8ad1a4d29cd 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -1314,8 +1314,14 @@ llvm::Constant *CodeGenModule::EmitConstantValue(const APValue &Value, // Convert to the appropriate type; this could be an lvalue for // an integer. - if (isa<llvm::PointerType>(DestTy)) + if (isa<llvm::PointerType>(DestTy)) { + // Convert the integer to a pointer-sized integer before converting it + // to a pointer. + C = llvm::ConstantExpr::getIntegerCast( + C, getDataLayout().getIntPtrType(DestTy), + /*isSigned=*/false); return llvm::ConstantExpr::getIntToPtr(C, DestTy); + } // If the types don't match this should only be a truncate. if (C->getType() != DestTy) diff --git a/clang/test/CodeGen/const-init.c b/clang/test/CodeGen/const-init.c index 9434f1d1b24..3fd231b630e 100644 --- a/clang/test/CodeGen/const-init.c +++ b/clang/test/CodeGen/const-init.c @@ -84,7 +84,7 @@ struct g13_s0 g13[] = { { (long) &g12_tmp } }; -// CHECK: @g14 = global i8* inttoptr (i64 100 to i8*) +// CHECK: @g14 = global i8* inttoptr (i32 100 to i8*) void *g14 = (void*) 100; // CHECK: @g15 = global i32 -1 |

