]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR modula2/119779 ASM examples no longer work
authorGaius Mulley <gaiusmod2@gmail.com>
Mon, 14 Apr 2025 09:13:40 +0000 (10:13 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Mon, 14 Apr 2025 09:13:40 +0000 (10:13 +0100)
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 <gaiusmod2@gmail.com>
gcc/doc/gm2.texi
gcc/testsuite/gm2.dg/doc/examples/pass/doc-examples-pass.exp [new file with mode: 0644]
gcc/testsuite/gm2.dg/doc/examples/pass/exampleadd.mod [new file with mode: 0644]
gcc/testsuite/gm2.dg/doc/examples/pass/exampleadd2.mod [new file with mode: 0644]
gcc/testsuite/gm2.dg/doc/examples/pass/hello.mod [new file with mode: 0644]
gcc/testsuite/gm2.dg/doc/examples/pass/hellopim.mod [new file with mode: 0644]

index 8baee24f14e0248b61934d9d5d07ffc75cacaa39..cb52e8c0d3e4303a346c862319010017e48f395b 100644 (file)
@@ -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 (file)
index 0000000..0bfcea0
--- /dev/null
@@ -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 (file)
index 0000000..84020a8
--- /dev/null
@@ -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 (file)
index 0000000..f25397f
--- /dev/null
@@ -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 (file)
index 0000000..f9770ec
--- /dev/null
@@ -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 (file)
index 0000000..b7876cd
--- /dev/null
@@ -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.