[PATCH] D136215: [LoongArch] Add support for ISD::FRAMEADDR and ISD::RETURNADDR
Gong LingQin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 18 19:56:17 PDT 2022
gonglingqin added inline comments.
================
Comment at: llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp:241-246
+ // Currently only support lowering frame address for current frame.
+ unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
+ assert((Depth == 0) &&
+ "Frame address can only be determined for current frame.");
+ if (Depth != 0)
+ return SDValue();
----------------
xen0n wrote:
> Why this limitation? I can't seem to find similar guard in AArch64, CSKY, RISCV or VE, but it is indeed present for MIPS and SystemZ.
Good question! When the depth!=0 and the caller function does not use FP to save the current stack frame, causing an illegal address call, as in the following example:
```
#include <stdio.h>
void __attribute__((noinline)) foo() {
printf("foo\n");
printf("return address: %p\n", __builtin_return_address(2));
}
void __attribute__((noinline)) bar() {
foo();
printf("bar\n");
printf("return address: %p\n", __builtin_return_address(0));
}
int main() {
bar();
return 0;
}
```
Compiling this test case with O2 on riscv64 reproduces this problem.
In reference to 'https://llvm.org/docs/LangRef.html#llvm-frameaddress-intrinsic' and 'https://llvm.org/docs/LangRef.html#llvm-returnaddress', this limitation is increased and returns 0 if depth is not equal to 0.
================
Comment at: llvm/test/CodeGen/LoongArch/frameaddr-returnaddr.ll:6
+declare i8* @llvm.frameaddress(i32)
+declare i8* @llvm.returnaddress(i32)
+
----------------
xen0n wrote:
> Please convert to opaque pointers throughout.
Thanks, I will modify it.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D136215/new/
https://reviews.llvm.org/D136215
More information about the llvm-commits
mailing list