[RFC PATCH] LoongArch: drop the vararg special calling convention with COBOL [PR126409]
Xi Ruoyao <[email protected]> Sun, 2 Aug 2026 04:26:54 +0800
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <[email protected]> |
On LoongArch a float-point argument can be passed via FPR if it's fixed,
but not if it's variadic. But the COBOL FE always use a vararg
function_decl for function calls (because COBOL does not have the
concept of function prototype, I guess), thus the FP arguments are
passed in GPR but received in FPR, breaking the ABI.
Treat the variadic arguments as-if they were fixed if we are compiling
COBOL.
gcc/
* config/loongarch/loongarch.cc (loongarch_get_arg_info): Treat
an variadic argument as-if it was fixed if compiling COBOL.
---
I've bootstrapped & regtested this on loongarch64-linux-gnu, but the
change just seems stupid (esp. the strcmp thing, although rs6000 already
performs strcmp on lang_hooks.name) so I made this an RFC.
Thoughts for a better solution?
gcc/config/loongarch/loongarch.cc | 2 ++
1 file changed, 2 insertions(+)
diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc
index b0f7abc0483..a0f91ab2843 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -522,6 +522,7 @@ loongarch_get_arg_info (struct loongarch_arg_info *info,
const CUMULATIVE_ARGS *cum, machine_mode mode,
const_tree type, bool named, bool return_p)
{
+ static bool is_cobol = !strcmp(lang_hooks.name, "GCC COBOL");
unsigned num_bytes, num_words;
unsigned fpr_base = return_p ? FP_RETURN : FP_ARG_FIRST;
unsigned gpr_base = return_p ? GP_RETURN : GP_ARG_FIRST;
@@ -530,6 +531,7 @@ loongarch_get_arg_info (struct loongarch_arg_info *info,
memset (info, 0, sizeof (*info));
info->gpr_offset = cum->num_gprs;
info->fpr_offset = cum->num_fprs;
+ named |= is_cobol;
if (named)
{
--
2.55.0