https://gcc.gnu.org/g:df1407f2122ec6e670d700c090e765d0a06859ee

commit r15-9672-gdf1407f2122ec6e670d700c090e765d0a06859ee
Author: Gaius Mulley <gaiusm...@gmail.com>
Date:   Tue May 13 16:48:52 2025 +0100

    [PATCH] PR modula2/120188: documented example does not work assignvalue 
m2plugin
    
    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.
    
    (cherry picked from commit 9ce4c801e8275fcf0336ae2fb548f6ebb3ca068b)
    
    Signed-off-by: Gaius Mulley <gaiusm...@gmail.com>

Diff:
---
 gcc/doc/gm2.texi                                   |  2 +-
 .../doc/examples/plugin/fail/assignvalue.mod       | 25 +++++++++++++++
 .../plugin/fail/doc-examples-plugin-fail.exp       | 25 +++++++++++++++
 gcc/testsuite/lib/gm2-dg.exp                       | 37 +++++++++++++++++++++-
 4 files changed, 87 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/gm2.texi b/gcc/doc/gm2.texi
index cb52e8c0d3e4..8293da4994ed 100644
--- a/gcc/doc/gm2.texi
+++ b/gcc/doc/gm2.texi
@@ -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
index 000000000000..56eb0bb25319
--- /dev/null
+++ b/gcc/testsuite/gm2.dg/doc/examples/plugin/fail/assignvalue.mod
@@ -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
index 000000000000..8a41ff8bde4c
--- /dev/null
+++ b/gcc/testsuite/gm2.dg/doc/examples/plugin/fail/doc-examples-plugin-fail.exp
@@ -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
diff --git a/gcc/testsuite/lib/gm2-dg.exp b/gcc/testsuite/lib/gm2-dg.exp
index eaed554014f8..5a36507317b0 100644
--- a/gcc/testsuite/lib/gm2-dg.exp
+++ b/gcc/testsuite/lib/gm2-dg.exp
@@ -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
+    }
+}

Reply via email to