[llvm] Skip tranformConstExprCastCall for naked function (PR #76496)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 28 01:10:00 PST 2023
https://github.com/hstk30-hw created https://github.com/llvm/llvm-project/pull/76496
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
>From 4fe776e990842c6fc9668ee3e856346742e716f0 Mon Sep 17 00:00:00 2001
From: hstk30-hw <hanwei62 at huawei.com>
Date: Thu, 28 Dec 2023 17:02:12 +0800
Subject: [PATCH] Skip tranformConstExprCastCall for naked function
---
.../Transforms/InstCombine/InstCombineCalls.cpp | 6 ++++++
.../Transforms/InstCombine/cast-call-naked.ll | 16 ++++++++++++++++
2 files changed, 22 insertions(+)
create mode 100644 llvm/test/Transforms/InstCombine/cast-call-naked.ll
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 }
More information about the llvm-commits
mailing list