[llvm] [llvm] Consistently respect `naked` fn attribute in `TargetFrameLowering::hasFP()` (PR #106014)

Alex Rønne Petersen via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 28 11:46:45 PDT 2024


================
@@ -286,7 +286,11 @@ class TargetFrameLowering {
   /// hasFP - Return true if the specified function should have a dedicated
   /// frame pointer register. For most targets this is true only if the function
   /// has variable sized allocas or if frame pointer elimination is disabled.
-  virtual bool hasFP(const MachineFunction &MF) const = 0;
+  /// For all targets, this is false if the function has the naked attribute
+  /// since there is no prologue to set up the frame pointer.
+  bool hasFP(const MachineFunction &MF) const {
+    return !MF.getFunction().hasFnAttribute(Attribute::Naked) && hasFPImpl(MF);
----------------
alexrp wrote:

> If my reading of the GCC attribute documentation is correct, naked functions should behave in the same way as if you had just declared a function in assembly plus the appropriate directives to emit `.cfi_{end,start}proc`, `.size` etc. but no code being generated - so the function can only have a frame pointer if the inline assembly sets one up?

This is my understanding too FWIW.

https://github.com/llvm/llvm-project/pull/106014


More information about the llvm-commits mailing list