]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR modula2/119779: ASM examples no longer work
authorGaius Mulley <gaiusmod2@gmail.com>
Mon, 9 Jun 2025 14:26:35 +0000 (15:26 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Mon, 9 Jun 2025 14:26:35 +0000 (15:26 +0100)
This patch introduces a regression test using the example in the
documentation and tests it using -masm=intel on x86_64-*-gnu systems.

gcc/testsuite/ChangeLog:

PR modula2/119779
* gm2.dg/doc/examples/run/pass/doc-examples-run-pass.exp: New test.
* gm2.dg/doc/examples/run/pass/exampleadd2.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
gcc/testsuite/gm2.dg/doc/examples/run/pass/doc-examples-run-pass.exp [new file with mode: 0644]
gcc/testsuite/gm2.dg/doc/examples/run/pass/exampleadd2.mod [new file with mode: 0644]

diff --git a/gcc/testsuite/gm2.dg/doc/examples/run/pass/doc-examples-run-pass.exp b/gcc/testsuite/gm2.dg/doc/examples/run/pass/doc-examples-run-pass.exp
new file mode 100644 (file)
index 0000000..6fb7d6e
--- /dev/null
@@ -0,0 +1,17 @@
+# Compile tests, no torture testing.
+#
+# These tests should all pass.
+
+# Load support procs.
+load_lib gm2-dg.exp
+
+gm2_init_pim4 $srcdir/$subdir -masm=intel
+
+# 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/run/pass/exampleadd2.mod b/gcc/testsuite/gm2.dg/doc/examples/run/pass/exampleadd2.mod
new file mode 100644 (file)
index 0000000..8bab299
--- /dev/null
@@ -0,0 +1,35 @@
+(* { dg-do assemble { target { x86_64-*-gnu* } } } *)
+(* { dg-options "-masm=intel" } *)
+(* { dg-do run { target x86_64-*-gnu* } } *)
+
+MODULE exampleadd2 ;
+
+FROM libc IMPORT printf, exit ;
+
+
+PROCEDURE Example (foo, bar: LONGCARD) : CARDINAL ;
+VAR
+   myout: LONGCARD ;
+BEGIN
+   ASM VOLATILE (
+    "mov rax, %[left]; add rax, %[right]; mov %[output], rax;"
+      : [output] "=rm" (myout)                  (* outputs *)
+      : [left] "rm" (foo), [right] "rm" (bar)   (* inputs  *)
+      : "rax") ;                                (* 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 ("success result from function is %d\n", c) ;
+   ELSE
+      printf ("example failed to return 3, seen %d\n" , c) ;
+      exit (1)
+   END
+END exampleadd2.
\ No newline at end of file