Skip to content

Commit eb67b34

Browse files
committed
[IPSCCP] Don't crash on ptrtoint
1 parent 4a074f3 commit eb67b34

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3079,7 +3079,6 @@ void llvm::hoistAllInstructionsInto(BasicBlock *DomBlock, Instruction *InsertPt,
30793079

30803080
DIExpression *llvm::getExpressionForConstant(DIBuilder &DIB, const Constant &C,
30813081
Type &Ty) {
3082-
30833082
// Create integer constant expression.
30843083
auto createIntegerExpression = [&DIB](const Constant &CV) -> DIExpression * {
30853084
const APInt &API = cast<ConstantInt>(&CV)->getValue();
@@ -3089,7 +3088,7 @@ DIExpression *llvm::getExpressionForConstant(DIBuilder &DIB, const Constant &C,
30893088
: nullptr;
30903089
};
30913090

3092-
if (Ty.isIntegerTy())
3091+
if (isa<ConstantInt>(C))
30933092
return createIntegerExpression(C);
30943093

30953094
if (Ty.isFloatTy() || Ty.isDoubleTy()) {

llvm/unittests/Transforms/Utils/LocalTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,11 @@ TEST(Local, ExpressionForConstant) {
12231223
EXPECT_NE(Expr, nullptr);
12241224
EXPECT_EQ(Expr->getElement(1), 0x7FFFFFFFFFFFFFFFU);
12251225

1226+
GlobalVariable *String =
1227+
IRBuilder<>(Context).CreateGlobalString("hello", "hello", 0, &M);
1228+
Expr = createExpression(ConstantExpr::getPtrToInt(String, Int32Ty), Int32Ty);
1229+
EXPECT_EQ(Expr, nullptr);
1230+
12261231
// Float.
12271232
Type *FloatTy = Type::getFloatTy(Context);
12281233
Expr = createExpression(ConstantFP::get(FloatTy, 5.55), FloatTy);

0 commit comments

Comments
 (0)