[PATCH] D135687: [AArch64] Fix aligning the stack after calling __chkstk

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 14 10:42:56 PDT 2022


efriedma added inline comments.


================
Comment at: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp:1648
+  const bool NeedsRealignment =
+      NumBytes && !IsFunclet && RegInfo->hasStackRealignment(MF);
+  int64_t RealignmentPadding =
----------------
I'm not sure it actually makes sense to check NumBytes here.  If we're forcing realignment with an attribute, we want to make sure it happens even if there aren't any local variables.


================
Comment at: llvm/lib/Target/AArch64/AArch64FrameLowering.cpp:1651
+      (NeedsRealignment && MFI.getMaxAlign() > Align(16))
+          ? MFI.getMaxAlign().value() - 16
+          : 0;
----------------
I suggested subtracting "16" here on the assumption the stack is actually 16-byte aligned on entry.  If we're not assuming the incoming stack is 16-byte aligned, we can't do that.  (Theoretically, we could subtract 1, but we can't actually allocate in increments of less than 16.)

Normally, we shouldn't be using realignment in the first place if we're only trying to align the stack to 16 bytes, but I guess the "stackrealign" attribute forces us to realign the stack even if we think it's already aligned.  (By default, the CPU faults if the alignment of sp is less than 16, so that seems unlikely, but I guess there could be some environment which disables that flag.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135687/new/

https://reviews.llvm.org/D135687



More information about the llvm-commits mailing list