[llvm] eb67b34 - [IPSCCP] Don't crash on ptrtoint
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 24 05:14:51 PDT 2023
Author: Benjamin Kramer
Date: 2023-10-24T14:14:39+02:00
New Revision: eb67b34740b37909f1b213fca6c564257577be25
URL: https://github.com/llvm/llvm-project/commit/eb67b34740b37909f1b213fca6c564257577be25
DIFF: https://github.com/llvm/llvm-project/commit/eb67b34740b37909f1b213fca6c564257577be25.diff
LOG: [IPSCCP] Don't crash on ptrtoint
Added:
Modified:
llvm/lib/Transforms/Utils/Local.cpp
llvm/unittests/Transforms/Utils/LocalTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index d89bd1212bd6860..0326e17a6fa14df 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -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();
@@ -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()) {
diff --git a/llvm/unittests/Transforms/Utils/LocalTest.cpp b/llvm/unittests/Transforms/Utils/LocalTest.cpp
index 64bd25fa4539e98..a27af6efb2c8104 100644
--- a/llvm/unittests/Transforms/Utils/LocalTest.cpp
+++ b/llvm/unittests/Transforms/Utils/LocalTest.cpp
@@ -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);
More information about the llvm-commits
mailing list