diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -2795,12 +2795,7 @@ DL.getTypeAllocSize(Op->getType()).getFixedSize()) return OpExpr; - // Otherwise the pointer is smaller than the resultant integer, mask off - // the high bits so we are sure to get a proper truncation if the input is - // a constant expr. - unsigned InBits = DL.getTypeAllocSizeInBits(Op->getType()); - const MCExpr *MaskExpr = MCConstantExpr::create(~0ULL >> (64-InBits), Ctx); - return MCBinaryExpr::createAnd(OpExpr, MaskExpr, Ctx); + break; // Error } case Instruction::Sub: { diff --git a/llvm/test/CodeGen/X86/ptrtoint-constexpr-invalid.ll b/llvm/test/CodeGen/X86/ptrtoint-constexpr-invalid.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/X86/ptrtoint-constexpr-invalid.ll @@ -0,0 +1,10 @@ +; RUN: not --crash llc < %s -mtriple=i386-linux 2>&1 | FileCheck %s + +; ptrtoint expressions that cast to a wider integer type are not supported. +; A frontend can achieve a similar result by casting to the correct integer +; type and explicitly zeroing any additional bytes. +; { i32, i32 } { i32 ptrtoint (ptr @r to i32), i32 0 } + +; CHECK: LLVM ERROR: Unsupported expression in static initializer: ptrtoint (ptr @r to i64) + +@r = global i64 ptrtoint (ptr @r to i64) diff --git a/llvm/test/CodeGen/X86/ptrtoint-constexpr.ll b/llvm/test/CodeGen/X86/ptrtoint-constexpr.ll --- a/llvm/test/CodeGen/X86/ptrtoint-constexpr.ll +++ b/llvm/test/CodeGen/X86/ptrtoint-constexpr.ll @@ -1,11 +1,11 @@ ; RUN: llc < %s -mtriple=i386-linux | FileCheck %s - %union.x = type { i64 } + %union.x = type { i32 } ; CHECK: .globl r ; CHECK: r: -; CHECK: .quad r&4294967295 +; CHECK: .long r -@r = global %union.x { i64 ptrtoint (ptr @r to i64) }, align 4 +@r = global %union.x { i32 ptrtoint (ptr @r to i32) }, align 4 ; CHECK: .globl x ; CHECK: x: