]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR modula2/120188: documented example does not work assignvalue m2plugin
authorGaius Mulley <gaiusmod2@gmail.com>
Mon, 12 May 2025 16:59:00 +0000 (17:59 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Mon, 12 May 2025 16:59:00 +0000 (17:59 +0100)
This patch corrects the gm2 command line used in the documentation
to invoke the m2-plugin.  The patch also includes the documentation
example in dejagnu test code with an expect script to check whether
plugins were enabled.

gcc/ChangeLog:

PR modula2/120188
* doc/gm2.texi (Semantic checking): Add -fm2-plugin command line option.

gcc/testsuite/ChangeLog:

PR modula2/120188
* lib/gm2-dg.exp (gm2-dg-frontend-configure-check): New function.
(gm2-dg-runtest): Add -O2 to the option_list.
* gm2.dg/doc/examples/plugin/fail/assignvalue.mod: New test.
* gm2.dg/doc/examples/plugin/fail/doc-examples-plugin-fail.exp: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
gcc/doc/gm2.texi
gcc/testsuite/gm2.dg/doc/examples/plugin/fail/assignvalue.mod [new file with mode: 0644]
gcc/testsuite/gm2.dg/doc/examples/plugin/fail/doc-examples-plugin-fail.exp [new file with mode: 0644]
gcc/testsuite/lib/gm2-dg.exp

index cb52e8c0d3e4303a346c862319010017e48f395b..8293da4994ed9057ffcea43f484271f15b396d87 100644 (file)
@@ -1495,7 +1495,7 @@ from @samp{bad} will cause an overflow to @samp{foo}.  If we compile
 the code with the following options:
 
 @example
-$ gm2 -g -fsoft-check-all -O2 -c assignvalue.mod
+$ gm2 -g -fsoft-check-all -O2 -fm2-plugin -c assignvalue.mod
 assignvalue.mod:16:0:inevitable that this error will occur at run time,
 assignment will result in an overflow
 @end example
diff --git a/gcc/testsuite/gm2.dg/doc/examples/plugin/fail/assignvalue.mod b/gcc/testsuite/gm2.dg/doc/examples/plugin/fail/assignvalue.mod
new file mode 100644 (file)
index 0000000..56eb0bb
--- /dev/null
@@ -0,0 +1,25 @@
+(* { dg-do compile } *)
+(* { dg-options "-fsoft-check-all -fm2-plugin" } *)
+(* { dg-skip-if "" { *-*-* }  { "*" } { "-O2" } } *)
+
+MODULE assignvalue ;  (*!m2iso+gm2*)
+
+PROCEDURE bad () : INTEGER ;
+VAR
+   i: INTEGER ;
+BEGIN
+   i := -1 ;
+   RETURN i
+END bad ;
+
+VAR
+   foo: CARDINAL ;
+BEGIN
+   (* The m2rte plugin will detect this as an error, post
+      optimization.  *)
+   foo := bad ()  (* { dg-error "error: In program module assignvalue" } *)
+   (* { dg-begin-multiline-output "" }
+runtime error will occur, assignment will cause a range error, as the runtime instance value of 'CARDINAL' does not overlap with the type 'INTEGER'
+     { dg-end-multiline-output "" } *)
+
+END assignvalue.
diff --git a/gcc/testsuite/gm2.dg/doc/examples/plugin/fail/doc-examples-plugin-fail.exp b/gcc/testsuite/gm2.dg/doc/examples/plugin/fail/doc-examples-plugin-fail.exp
new file mode 100644 (file)
index 0000000..8a41ff8
--- /dev/null
@@ -0,0 +1,25 @@
+# Compile tests, no torture testing.
+#
+# These tests should all generate errors if the plugin is available.
+
+# Load support procs.
+load_lib gm2-dg.exp
+
+gm2_init_pim4 $srcdir/$subdir
+
+# Initialize `dg'.
+dg-init
+
+# If the --enable-plugin has not been enabled during configure, bail.
+if { ![gm2-dg-frontend-configure-check "enable-plugin" ] } {
+    return
+}
+
+# Main loop.
+
+set tests [lsort [glob -nocomplain $srcdir/$subdir/*.mod]]
+
+gm2-dg-runtest $tests "" ""
+
+# All done.
+dg-finish
index eaed554014f8fbe26e1f66ceefe70ab74ed8b9bb..5a36507317b06be3fee56b3b028cbf1c32164a8b 100644 (file)
@@ -65,7 +65,7 @@ proc gm2-dg-runtest { testcases flags default-extra-flags } {
        if [expr [search_for $test "dg-do run"]] {
            set option_list $TORTURE_OPTIONS
        } else {
-           set option_list [list { -O } ]
+           set option_list [list { -O -O2 } ]
        }
 
        set nshort [file tail [file dirname $test]]/[file tail $test]
@@ -77,3 +77,38 @@ proc gm2-dg-runtest { testcases flags default-extra-flags } {
     }
 }
 
+
+# Check if frontend has been configured with option.
+# This checks a configure build option was used and not
+# the availability of a compiler command line option.
+
+proc gm2-dg-frontend-configure-check { option } {
+    global GCC_UNDER_TEST
+
+    # ignore any arguments after the command
+    set compiler [lindex $GCC_UNDER_TEST 0]
+
+    if ![is_remote host] {
+       set compiler_name [which $compiler]
+    } else {
+       set compiler_name $compiler
+    }
+
+    # verify that the compiler exists
+    if { $compiler_name != 0 } then {
+       set tmp [remote_exec host "$compiler -v"]
+       set status [lindex $tmp 0]
+       set output [lindex $tmp 1]
+       regexp "Configured with.*\[\n\r\]" $output config
+       set option "*${option}*"
+       if { [string match $option $config] } {
+           return 1
+       } else {
+           return 0
+       }
+    } else {
+       # compiler does not exist (this should have already been detected)
+       warning "$compiler does not exist"
+       return 0
+    }
+}