[llvm] Skip tranformConstExprCastCall for naked function (PR #76496)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 28 01:10:28 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: None (hstk30-hw)
<details>
<summary>Changes</summary>
Fix this issue https://github.com/llvm/llvm-project/issues/72843 .
For naked function, assembly might be using an argument, or otherwise rely on the frame layout, so don't transformConstExprCastCall
---
Full diff: https://github.com/llvm/llvm-project/pull/76496.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp (+6)
- (added) llvm/test/Transforms/InstCombine/cast-call-naked.ll (+16)
``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 3b7fe7fa226607..43d4496571be50 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3850,6 +3850,12 @@ bool InstCombinerImpl::transformConstExprCastCall(CallBase &Call) {
if (Callee->hasFnAttribute("thunk"))
return false;
+ // If this is a call to a naked function, the assembly might be
+ // using an argument, or otherwise rely on the frame layout,
+ // the function prototype will mismatch.
+ if (Callee->hasFnAttribute(Attribute::Naked))
+ return false;
+
// If this is a musttail call, the callee's prototype must match the caller's
// prototype with the exception of pointee types. The code below doesn't
// implement that, so we can't do this transform.
diff --git a/llvm/test/Transforms/InstCombine/cast-call-naked.ll b/llvm/test/Transforms/InstCombine/cast-call-naked.ll
new file mode 100644
index 00000000000000..a0b0d48b44d4eb
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/cast-call-naked.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+define dso_local void @naked_func() #0 {
+entry:
+ tail call void asm sideeffect "mov r1, r0", ""()
+ unreachable
+}
+
+define i32 @main() {
+; CHECK: call void @naked_func(i32 noundef 1)
+entry:
+ call void @naked_func(i32 noundef 1)
+ ret i32 0
+}
+
+attributes #0 = { naked }
``````````
</details>
https://github.com/llvm/llvm-project/pull/76496
More information about the llvm-commits
mailing list