Skip to content

Commit

Permalink
[IPSCCP] Don't crash on ptrtoint
Browse files Browse the repository at this point in the history
  • Loading branch information
d0k committed Oct 24, 2023
1 parent 4a074f3 commit eb67b34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions llvm/lib/Transforms/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3079,7 +3079,6 @@ void llvm::hoistAllInstructionsInto(BasicBlock *DomBlock, Instruction *InsertPt,

DIExpression *llvm::getExpressionForConstant(DIBuilder &DIB, const Constant &C,
Type &Ty) {

// Create integer constant expression.
auto createIntegerExpression = [&DIB](const Constant &CV) -> DIExpression * {
const APInt &API = cast<ConstantInt>(&CV)->getValue();
Expand All @@ -3089,7 +3088,7 @@ DIExpression *llvm::getExpressionForConstant(DIBuilder &DIB, const Constant &C,
: nullptr;
};

if (Ty.isIntegerTy())
if (isa<ConstantInt>(C))
return createIntegerExpression(C);

if (Ty.isFloatTy() || Ty.isDoubleTy()) {
Expand Down
5 changes: 5 additions & 0 deletions llvm/unittests/Transforms/Utils/LocalTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,11 @@ TEST(Local, ExpressionForConstant) {
EXPECT_NE(Expr, nullptr);
EXPECT_EQ(Expr->getElement(1), 0x7FFFFFFFFFFFFFFFU);

GlobalVariable *String =
IRBuilder<>(Context).CreateGlobalString("hello", "hello", 0, &M);
Expr = createExpression(ConstantExpr::getPtrToInt(String, Int32Ty), Int32Ty);
EXPECT_EQ(Expr, nullptr);

// Float.
Type *FloatTy = Type::getFloatTy(Context);
Expr = createExpression(ConstantFP::get(FloatTy, 5.55), FloatTy);
Expand Down

0 comments on commit eb67b34

Please sign in to comment.