On Mon, May 18, 2026 at 8:26 AM H.J. Lu <[email protected]> wrote: > > On Mon, May 18, 2026 at 7:09 AM Andrew Pinski > <[email protected]> wrote: > > > > On Sun, May 17, 2026 at 3:56 PM H.J. Lu <[email protected]> wrote: > > > > > > On Mon, May 18, 2026 at 6:21 AM H.J. Lu <[email protected]> wrote: > > > > > > > > On Sun, May 17, 2026 at 7:57 PM oltolm <[email protected]> wrote: > > > > > > > > > > From: Oleg Tolmatcev <[email protected]> > > > > > > > > > > The preserve_none calling convention uses the six-register > > > > > preserve_none integer parameter set even when the default ABI is MS. > > > > > Update argument register recognition, cumulative argument setup, and > > > > > argument lowering so preserve_none calls on x86_64 MinGW use the > > > > > generic 64-bit path rather than the plain MS ABI path. > > > > > > > > > > Add MinGW compile tests for integer argument remapping and > > > > > sibling-call behavior. > > > > > Update scanasm matching for MinGW. > > > > > > > > > > gcc/config/i386/ChangeLog: > > > > > > > > > > * i386.cc (ix86_function_arg_regno_p): Use six integer argument > > > > > registers for preserve_none under the MS ABI. > > > > > (init_cumulative_args): Likewise. > > > > > (ix86_function_arg): Route preserve_none calls through > > > > > function_arg_64. > > > > > > > > > > gcc/testsuite/ChangeLog: > > > > > > > > > > * gcc.target/i386/preserve-none-31.c: New test. > > > > > * gcc.target/i386/preserve-none-32.c: New test. > > > > > * lib/scanasm.exp (configure_check-function-bodies): Handle x86_64 > > > > > MinGW end markers and instruction indentation. > > > > > > > > > > Signed-off-by: oltolm <[email protected]> > > > > > --- > > > > > gcc/config/i386/i386.cc | 19 +++++++----- > > > > > .../gcc.target/i386/preserve-none-31.c | 30 > > > > > +++++++++++++++++++ > > > > > .../gcc.target/i386/preserve-none-32.c | 24 +++++++++++++++ > > > > > gcc/testsuite/lib/scanasm.exp | 16 ++++++---- > > > > > 4 files changed, 76 insertions(+), 13 deletions(-) > > > > > create mode 100644 gcc/testsuite/gcc.target/i386/preserve-none-31.c > > > > > create mode 100644 gcc/testsuite/gcc.target/i386/preserve-none-32.c > > > > > > > > > > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc > > > > > index 2744c74957..9bb6b6001c 100644 > > > > > --- a/gcc/config/i386/i386.cc > > > > > +++ b/gcc/config/i386/i386.cc > > > > > @@ -1609,8 +1609,13 @@ ix86_function_arg_regno_p (int regno) > > > > > else > > > > > parm_regs = x86_64_int_parameter_registers; > > > > > > > > > > - for (i = 0; i < (call_abi == MS_ABI > > > > > - ? X86_64_MS_REGPARM_MAX : X86_64_REGPARM_MAX); i++) > > > > > + int regparm_max > > > > > + = (call_abi == MS_ABI > > > > > + && !(cfun && cfun->machine->call_saved_registers == > > > > > TYPE_PRESERVE_NONE)) > > > > > + ? X86_64_MS_REGPARM_MAX > > > > > + : X86_64_REGPARM_MAX; > > > > > + for (i = 0; i < regparm_max; i++) > > > > > if (regno == parm_regs[i]) > > > > > return true; > > > > > return false; > > > > > @@ -1920,9 +1925,9 @@ init_cumulative_args (CUMULATIVE_ARGS *cum, /* > > > > > Argument info to initialize */ > > > > > cum->nregs = ix86_regparm; > > > > > if (TARGET_64BIT) > > > > > { > > > > > - cum->nregs = (cum->call_abi == SYSV_ABI > > > > > - ? X86_64_REGPARM_MAX > > > > > - : X86_64_MS_REGPARM_MAX); > > > > > + cum->nregs = (cum->preserve_none_abi || cum->call_abi == > > > > > SYSV_ABI > > > > > + ? X86_64_REGPARM_MAX > > > > > + : X86_64_MS_REGPARM_MAX); > > > > > } > > > > > if (TARGET_SSE) > > > > > { > > > > > @@ -3273,7 +3278,7 @@ ix86_function_arg_advance (cumulative_args_t > > > > > cum_v, > > > > > { > > > > > enum calling_abi call_abi = cum ? cum->call_abi : ix86_abi; > > > > > > > > > > - if (call_abi == MS_ABI) > > > > > + if (call_abi == MS_ABI && !(cum && cum->preserve_none_abi)) > > > > > nregs = function_arg_advance_ms_64 (cum, bytes, words); > > > > > else > > > > > nregs = function_arg_advance_64 (cum, mode, arg.type, words, > > > > > @@ -3604,7 +3609,7 @@ ix86_function_arg (cumulative_args_t cum_v, > > > > > const function_arg_info &arg) > > > > > { > > > > > enum calling_abi call_abi = cum ? cum->call_abi : ix86_abi; > > > > > > > > > > - if (call_abi == MS_ABI) > > > > > + if (call_abi == MS_ABI && !(cum && cum->preserve_none_abi)) > > > > > reg = function_arg_ms_64 (cum, mode, arg.mode, arg.named, > > > > > arg.type, bytes); > > > > > else > > > > > diff --git a/gcc/testsuite/gcc.target/i386/preserve-none-31.c > > > > > b/gcc/testsuite/gcc.target/i386/preserve-none-31.c > > > > > new file mode 100644 > > > > > index 0000000000..d8ab38cdba > > > > > --- /dev/null > > > > > +++ b/gcc/testsuite/gcc.target/i386/preserve-none-31.c > > > > > @@ -0,0 +1,30 @@ > > > > > +/* { dg-do compile { target { x86_64-*-mingw* } } } */ > > > > > > > > Remove { target { x86_64-*-mingw* } }. > > > > > > Please use { target lp64 }. > > > > > > > > +/* { dg-options "-O2 -msse2 -mno-apxf" } */ > > > > > > > > Add -mabi=ms instead. > > > > > > > > > +/* { dg-final { check-function-bodies "**" "" "" { target "*-*-*" } > > > > > } } */ > > > > > > > > { target lp64 } > > > > Actually I think lp64 should be !ia32. The reason is x86_64-mingw is a > > LLP64L32 target so lp64 won't match here. > > It should be > > /* { dg-do compile { target { lp64 || llp64 } } } */ > > BTW, this test crashed on Linux/x86-64: > > [hjl@gnu-tgl-3 gcc]$ cat /tmp/x.c > extern void continuation (double, int, int, int, int, int, int) > __attribute__ ((preserve_none)); > > __attribute__ ((no_callee_saved_registers, sysv_abi)) > void > entry (double fp, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6) > { > continuation (fp, arg1, arg2, arg3, arg4, arg5, arg6); > } > [hjl@gnu-tgl-3 gcc]$ ./xgcc -B./ -O2 -S -mabi=ms -mtune=generic /tmp/x.c > during RTL pass: expand > /tmp/x.c: In function ‘entry’: > /tmp/x.c:8:3: internal compiler error: in expand_call, at calls.cc:3763 > 8 | continuation (fp, arg1, arg2, arg3, arg4, arg5, arg6); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 0x48b4190 internal_error(char const*, ...) > /export/gnu/import/git/gitlab/x86-gcc/gcc/diagnostic-global-context.cc:787 > 0x48c2a83 fancy_abort(char const*, int, char const*) > /export/gnu/import/git/gitlab/x86-gcc/gcc/diagnostics/context.cc:1813 > 0x2185a09 expand_call(tree_node*, rtx_def*, int) > /export/gnu/import/git/gitlab/x86-gcc/gcc/calls.cc:3763 > 0x237d8d3 expand_expr_real_1(tree_node*, rtx_def*, machine_mode, > expand_modifier, rtx_def**, bool) > /export/gnu/import/git/gitlab/x86-gcc/gcc/expr.cc:12677 > 0x236e1a1 expand_expr_real(tree_node*, rtx_def*, machine_mode, > expand_modifier, rtx_def**, bool) > /export/gnu/import/git/gitlab/x86-gcc/gcc/expr.cc:9618 > 0x2173c68 expand_expr(tree_node*, rtx_def*, machine_mode, expand_modifier) > /export/gnu/import/git/gitlab/x86-gcc/gcc/expr.h:323 > 0x21a51af expand_call_stmt > /export/gnu/import/git/gitlab/x86-gcc/gcc/cfgexpand.cc:3205 > 0x21a8e0a expand_gimple_stmt_1 > /export/gnu/import/git/gitlab/x86-gcc/gcc/cfgexpand.cc:4243 > 0x21a9440 expand_gimple_stmt > /export/gnu/import/git/gitlab/x86-gcc/gcc/cfgexpand.cc:4390 > 0x21a956b expand_gimple_tailcall > /export/gnu/import/git/gitlab/x86-gcc/gcc/cfgexpand.cc:4437 > 0x21b206e expand_gimple_basic_block > /export/gnu/import/git/gitlab/x86-gcc/gcc/cfgexpand.cc:6480 > 0x21b480c execute > /export/gnu/import/git/gitlab/x86-gcc/gcc/cfgexpand.cc:7254 > ./cc1 -quiet -iprefix > /export/build/gnu/tools-build/gcc-gitlab-debug/build-x86_64-linux/gcc/../lib/gcc/x86_64-pc-linux-gnu/17.0.0/ > -isystem ./include -isystem ./include-fixed /tmp/x.c -quiet -dumpbase > x.c -dumpbase-ext .c -mabi=ms -mtune=generic -march=x86-64 > -mtls-dialect=gnu2 -O2 -o x.s > Please submit a full bug report, with preprocessed source (by using > -freport-bug). > Please include the complete backtrace with any bug report. > See <https://gcc.gnu.org/bugs/> for instructions. > [hjl@gnu-tgl-3 gcc]$ > > The fix should be done after > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124798 > > has been fixed.
Fixed. Please try users/hjl/pr124798/master branch at https://gitlab.com/x86-gcc/gcc/-/commits/users/hjl/pr124798/master I added more tests. -- H.J.
