LoongArch: Fix eh_return epilogue for normal returns.
commit4b421728289e6f1caa0dfaa953a11698ab95d37d
authorYang Yujie <yangyujie@loongson.cn>
Fri, 8 Dec 2023 10:01:18 +0000 (8 18:01 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Tue, 12 Dec 2023 02:02:03 +0000 (12 10:02 +0800)
tree6da9a92785d6030ff769006e35222bdc8423cf0d
parent46cfafad9b3e64e9cd060b7a26bfe1890c74135f
LoongArch: Fix eh_return epilogue for normal returns.

On LoongArch, the regitsters $r4 - $r7 (EH_RETURN_DATA_REGNO) will be saved
and restored in the function prologue and epilogue if the given function calls
__builtin_eh_return.  This causes the return value to be overwritten on normal
return paths and breaks a rare case of libgcc's _Unwind_RaiseException.

gcc/ChangeLog:

* config/loongarch/loongarch.cc: Do not restore the saved eh_return
data registers ($r4-$r7) for a normal return of a function that calls
__builtin_eh_return elsewhere.
* config/loongarch/loongarch-protos.h: Same.
* config/loongarch/loongarch.md: Same.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/eh_return-normal-return.c: New test.
gcc/config/loongarch/loongarch-protos.h
gcc/config/loongarch/loongarch.cc
gcc/config/loongarch/loongarch.md
gcc/testsuite/gcc.target/loongarch/eh_return-normal-return.c [new file with mode: 0644]