https://gcc.gnu.org/g:9e0a98a47c98fd159a26de4433a3ed1d85afb8c3
commit r15-9421-g9e0a98a47c98fd159a26de4433a3ed1d85afb8c3 Author: Gaius Mulley <gaiusm...@gmail.com> Date: Mon Apr 14 10:13:40 2025 +0100 PR modula2/119779 ASM examples no longer work This patch introduces four dejagnu tests matching four documentation examples. Both asm examples are added and only built if the x86_64 target is available. The other two are hello world using libc and StrIO. The doc/gm2.texi asm examples are changed to use eax rather than rax. gcc/ChangeLog: PR modula2/119779 * doc/gm2.texi (Interface to assembly language): Use eax rather than rax in both examples. gcc/testsuite/ChangeLog: PR modula2/119779 * gm2.dg/doc/examples/pass/doc-examples-pass.exp: New test. * gm2.dg/doc/examples/pass/exampleadd.mod: New test. * gm2.dg/doc/examples/pass/exampleadd2.mod: New test. * gm2.dg/doc/examples/pass/hello.mod: New test. * gm2.dg/doc/examples/pass/hellopim.mod: New test. Signed-off-by: Gaius Mulley <gaiusm...@gmail.com> Diff: --- gcc/doc/gm2.texi | 8 +++--- .../gm2.dg/doc/examples/pass/doc-examples-pass.exp | 18 ++++++++++++ .../gm2.dg/doc/examples/pass/exampleadd.mod | 32 ++++++++++++++++++++++ .../gm2.dg/doc/examples/pass/exampleadd2.mod | 32 ++++++++++++++++++++++ gcc/testsuite/gm2.dg/doc/examples/pass/hello.mod | 10 +++++++ .../gm2.dg/doc/examples/pass/hellopim.mod | 10 +++++++ 6 files changed, 106 insertions(+), 4 deletions(-) diff --git a/gcc/doc/gm2.texi b/gcc/doc/gm2.texi index 8baee24f14e0..cb52e8c0d3e4 100644 --- a/gcc/doc/gm2.texi +++ b/gcc/doc/gm2.texi @@ -2699,10 +2699,10 @@ PROCEDURE Example (foo, bar: CARDINAL) : CARDINAL ; VAR myout: CARDINAL ; BEGIN - ASM VOLATILE ("movq %1,%%rax; addq %2,%%rax; movq %%rax,%0" + ASM VOLATILE ("movl %1,%%eax; addl %2,%%eax; movl %%eax,%0" : "=rm" (myout) (* outputs *) : "rm" (foo), "rm" (bar) (* inputs *) - : "rax") ; (* we trash *) + : "eax") ; (* we trash *) RETURN( myout ) END Example ; @end example @@ -2720,10 +2720,10 @@ VAR myout: CARDINAL ; BEGIN ASM VOLATILE ( - "movq %[left],%%rax; addq %[right],%%rax; movq %%rax,%[output]" + "movl %[left],%%eax; addl %[right],%%eax; movl %%eax,%[output]" : [output] "=rm" (myout) (* outputs *) : [left] "rm" (foo), [right] "rm" (bar) (* inputs *) - : "rax") ; (* we trash *) + : "eax") ; (* we trash *) RETURN( myout ) END Example ; @end example diff --git a/gcc/testsuite/gm2.dg/doc/examples/pass/doc-examples-pass.exp b/gcc/testsuite/gm2.dg/doc/examples/pass/doc-examples-pass.exp new file mode 100644 index 000000000000..0bfcea0f1250 --- /dev/null +++ b/gcc/testsuite/gm2.dg/doc/examples/pass/doc-examples-pass.exp @@ -0,0 +1,18 @@ +# Compile tests, no torture testing. +# +# These tests should all pass. + +# Load support procs. +load_lib gm2-dg.exp + +gm2_init_pim4 $srcdir/$subdir + +# Initialize `dg'. +dg-init + +# Main loop. + +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.mod]] "" "" + +# All done. +dg-finish diff --git a/gcc/testsuite/gm2.dg/doc/examples/pass/exampleadd.mod b/gcc/testsuite/gm2.dg/doc/examples/pass/exampleadd.mod new file mode 100644 index 000000000000..84020a85907d --- /dev/null +++ b/gcc/testsuite/gm2.dg/doc/examples/pass/exampleadd.mod @@ -0,0 +1,32 @@ +(* { dg-do assemble { target { x86_64-*-* } } } *) +(* { dg-options "-g" } *) + +MODULE exampleadd ; + +FROM libc IMPORT printf, exit ; + + +PROCEDURE Example (foo, bar: CARDINAL) : CARDINAL ; +VAR + myout: CARDINAL ; +BEGIN + ASM VOLATILE ("movl %1,%%eax; addl %2,%%eax; movl %%eax,%0" + : "=rm" (myout) (* outputs *) + : "rm" (foo), "rm" (bar) (* inputs *) + : "eax") ; (* we trash *) + RETURN( myout ) +END Example ; + + +VAR + a, b, c: CARDINAL ; +BEGIN + a := 1 ; + b := 2 ; + c := Example (a, b) ; + IF c # 3 + THEN + printf ("Example procedure function failed to return 3, seen %d", c) ; + exit (1) + END +END exampleadd. diff --git a/gcc/testsuite/gm2.dg/doc/examples/pass/exampleadd2.mod b/gcc/testsuite/gm2.dg/doc/examples/pass/exampleadd2.mod new file mode 100644 index 000000000000..f25397fa8ba0 --- /dev/null +++ b/gcc/testsuite/gm2.dg/doc/examples/pass/exampleadd2.mod @@ -0,0 +1,32 @@ +(* { dg-do assemble { target { x86_64-*-* } } } *) +(* { dg-options "-g" } *) + +MODULE exampleadd2 ; + +FROM libc IMPORT printf, exit ; + + +PROCEDURE Example (foo, bar: CARDINAL) : CARDINAL ; +VAR + myout: CARDINAL ; +BEGIN + ASM VOLATILE ( + "movl %[left],%%eax; addl %[right],%%eax; movl %%eax,%[output]" + : [output] "=rm" (myout) (* outputs *) + : [left] "rm" (foo), [right] "rm" (bar) (* inputs *) + : "eax") ; (* we trash *) + RETURN( myout ) +END Example ; + +VAR + a, b, c: CARDINAL ; +BEGIN + a := 1 ; + b := 2 ; + c := Example (a, b) ; + IF c # 3 + THEN + printf ("Example procedure function failed to return 3, seen %d", c) ; + exit (1) + END +END exampleadd2. diff --git a/gcc/testsuite/gm2.dg/doc/examples/pass/hello.mod b/gcc/testsuite/gm2.dg/doc/examples/pass/hello.mod new file mode 100644 index 000000000000..f9770ec237bf --- /dev/null +++ b/gcc/testsuite/gm2.dg/doc/examples/pass/hello.mod @@ -0,0 +1,10 @@ +(* { dg-do run } *) +(* { dg-options "-g -fno-scaffold-dynamic" } *) + +MODULE hello ; + +FROM libc IMPORT printf ; + +BEGIN + printf ("hello world\n") +END hello. diff --git a/gcc/testsuite/gm2.dg/doc/examples/pass/hellopim.mod b/gcc/testsuite/gm2.dg/doc/examples/pass/hellopim.mod new file mode 100644 index 000000000000..b7876cd6feda --- /dev/null +++ b/gcc/testsuite/gm2.dg/doc/examples/pass/hellopim.mod @@ -0,0 +1,10 @@ +(* { dg-do run } *) +(* { dg-options "-g -fno-scaffold-dynamic" } *) + +MODULE hellopim ; + +FROM StrIO IMPORT WriteString, WriteLn ; + +BEGIN + WriteString ("hello world") ; WriteLn +END hellopim.