[PATCH] D121580: [SCCP] Fix crash when function arg is a unused basic block's address
chenglin.bi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 14 01:33:58 PDT 2022
bcl5980 created this revision.
bcl5980 added reviewers: spatel, fhahn, sepavloff, nikic, craig.topper, SjoerdMeijer.
Herald added a subscriber: hiraditya.
Herald added a project: All.
bcl5980 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
For now if Solver never touch a basic block, DTU will erase the basic block even if the basic block address is referenced by function args.
So check the kernel arg is block address or not, if it is we need to mark the basic block executable.
Fix #54238, #54251
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D121580
Files:
llvm/lib/Transforms/Utils/SCCPSolver.cpp
llvm/test/Transforms/SCCP/issue54238.ll
Index: llvm/test/Transforms/SCCP/issue54238.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/SCCP/issue54238.ll
@@ -0,0 +1,18 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes
+; RUN: opt -passes=ipsccp -S %s | FileCheck %s
+; https://github.com/llvm/llvm-project/issues/54238
+
+define i32 @main() {
+ call void @set_return_addr(i64* bitcast (i8* blockaddress(@main, %redirected) to i64*))
+ ret i32 0
+
+redirected:
+ ret i32 0
+}
+
+define internal void @set_return_addr(i64* %addr) {
+ %addr.addr = alloca i64*, i32 0, align 8
+; CHECK: redirected
+ store i64* %addr, i64** %addr.addr, align 8
+ ret void
+}
Index: llvm/lib/Transforms/Utils/SCCPSolver.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SCCPSolver.cpp
+++ llvm/lib/Transforms/Utils/SCCPSolver.cpp
@@ -1249,6 +1249,14 @@
if (AI->hasByValAttr() && !F->onlyReadsMemory()) {
markOverdefined(&*AI);
continue;
+ } else if (const BlockAddress *BA = dyn_cast<BlockAddress>(CAI)) {
+ markBlockExecutable(BA->getBasicBlock());
+ } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CAI)) {
+ for (Value *Op : CE->operands()) {
+ const BlockAddress *BA = dyn_cast<BlockAddress>(Op);
+ if (BA != nullptr)
+ markBlockExecutable(BA->getBasicBlock());
+ }
}
if (auto *STy = dyn_cast<StructType>(AI->getType())) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121580.415025.patch
Type: text/x-patch
Size: 1550 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220314/5a72169f/attachment.bin>
More information about the llvm-commits
mailing list