On Tue, Aug 18, 2026 at 5:21 PM H.J. Lu <[email protected]> wrote:
>
> We can't use
>
> void
> test (long a, long b, long c, long d, long e)
> {
>   ...
>   __asm__ __volatile__ ("subq $8,%%rsp":::"cc");
>   ret = do_test_unaligned (a, b, c, d, e);
>   __asm__ __volatile__ ("addq $8,%%rsp":::"cc");
>   ...
> }

Uh, this violates GCC's inline-asm contract for %rsp. GCC requires the
stack pointer to have the identical value on exit from an asm as it
had on entry.

> to call do_test_unaligned, which is marked with ms_abi attribute, with
> an unaligned stack since GCC may save a function argument on stack and
> retrieve it from stack to pass it to do_test_unaligned.  When it happens,
> stack adjustment in asm statements can lead to a random value in the
> outgoing argument.  Add an assembly function, call_do_test_unaligned, to
> call do_test_unaligned with an unaligned stack.
>
> PR testsuite/126927
> * gcc.target/x86_64/abi/ms-sysv/do-test.S (call_do_test_unaligned):
> New.
> * gcc.target/x86_64/abi/ms-sysv/gen.cc (make_do_tests_decl):
> Replace do_test_unaligned with call_do_test_unaligned.
> (make_do_test): Remove asm statements with stack adjustment.

OK with a couple of simplifications below.

Thanks,
Uros.

diff --git a/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/do-test.S
b/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/do-test.S
index 9bc108b3e98..7432994bc95 100644
--- a/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/do-test.S
+++ b/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/do-test.S

+FUNC_BEGIN(call_do_test_unaligned)
+ # Load the 5th argument to R10.
+ movq 0x28(%rsp), %r10
+ # Unalign stack.
+ subq $8, %rsp
+ # Push the 5th argument.
+ pushq %r10
+ subq $32, %rsp
+ call do_test_unaligned
+ addq $32, %rsp
+ addq $16, %rsp

addq $48, %rsp

+ ret
+FUNC_END(call_do_test_unaligned)

diff --git a/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/gen.cc
b/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/gen.cc
index 818a8875a6d..ceade25cd29 100644
--- a/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/gen.cc
+++ b/gcc/testsuite/gcc.target/x86_64/abi/ms-sysv/gen.cc

-  out << ") = (void*)do_test_" << (unaligned ? "un" : "")
+  out << ") = (void*)" << (unaligned ? "call_" : "")
+      << "do_test_" << (unaligned ? "un" : "")
       << "aligned;" << endl;

out << ") = (void*)" << (unaligned ? "call_do_test_unaligned" :
"do_test_aligned")
    << ";" << endl;

Reply via email to