[PATCH] D154159: [FuncSpec] Avoid crashing when SwitchInst doesn't see ConstantInt
Vincent Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 30 21:12:44 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2fc0d17e8b3d: [FuncSpec] Avoid crashing when SwitchInst doesn't see ConstantInt (authored by thevinster).
Changed prior to commit:
https://reviews.llvm.org/D154159?vs=536023&id=536507#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154159/new/
https://reviews.llvm.org/D154159
Files:
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression6.ll
Index: llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression6.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-expression6.ll
@@ -0,0 +1,22 @@
+; RUN: opt -passes="ipsccp<func-spec>" -force-specialization -S < %s
+; Check that we don't crash when SwitchInst Constant is not ConstantInt.
+
+ at S = external constant [1 x i8]
+
+define i1 @foo() {
+entry:
+ %tmp = call i32 @bar(ptr @S)
+ ret i1 0
+}
+
+define i32 @bar(ptr %arg) {
+entry:
+ %magicptr = ptrtoint ptr %arg to i64
+ switch i64 %magicptr, label %bb2 [
+ i64 0, label %bb1
+ ]
+bb1:
+ ret i32 0
+bb2:
+ ret i32 1
+}
Index: llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
===================================================================
--- llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -190,7 +190,10 @@
if (I.getCondition() != LastVisited->first)
return 0;
- auto *C = cast<ConstantInt>(LastVisited->second);
+ auto *C = dyn_cast<ConstantInt>(LastVisited->second);
+ if (!C)
+ return 0;
+
BasicBlock *Succ = I.findCaseValue(C)->getCaseSuccessor();
// Initialize the worklist with the dead basic blocks. These are the
// destination labels which are different from the one corresponding
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154159.536507.patch
Type: text/x-patch
Size: 1401 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230701/001d7c63/attachment-0001.bin>
More information about the llvm-commits
mailing list