aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorGaius Mulley <gaiusmod2@gmail.com>2025-05-12 17:59:00 +0100
committerGaius Mulley <gaiusmod2@gmail.com>2025-05-12 17:59:00 +0100
commit9ce4c801e8275fcf0336ae2fb548f6ebb3ca068b (patch)
tree11c1905d5345a453923f3bea65057eb26b300063 /gcc
parentb5f48e7872db30b8f174cb2c497868a358bf75d6 (diff)
downloadgcc-9ce4c801e8275fcf0336ae2fb548f6ebb3ca068b.zip
gcc-9ce4c801e8275fcf0336ae2fb548f6ebb3ca068b.tar.gz
gcc-9ce4c801e8275fcf0336ae2fb548f6ebb3ca068b.tar.bz2
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. Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/doc/gm2.texi2
-rw-r--r--gcc/testsuite/gm2.dg/doc/examples/plugin/fail/assignvalue.mod25
-rw-r--r--gcc/testsuite/gm2.dg/doc/examples/plugin/fail/doc-examples-plugin-fail.exp25
-rw-r--r--gcc/testsuite/lib/gm2-dg.exp37
4 files changed, 87 insertions, 2 deletions
diff --git a/gcc/doc/gm2.texi b/gcc/doc/gm2.texi
index cb52e8c..8293da4 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 0000000..56eb0bb
--- /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 0000000..8a41ff8
--- /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 eaed554..5a36507 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
+ }
+}