c++: Fix g++.dg/ext/sve-sizeless-1.C regression
[official-gcc.git] / gcc / testsuite / lib / gfortran-dg.exp
blobfcba95dc39612b91ce78a85f73bb648c410d94eb
1 # Copyright (C) 2004-2024 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
17 load_lib gcc-dg.exp
18 load_lib torture-options.exp
20 # Define gfortran callbacks for dg.exp.
22 proc gfortran-dg-test { prog do_what extra_tool_flags } {
23 set result \
24 [gcc-dg-test-1 gfortran_target_compile $prog $do_what $extra_tool_flags]
26 set comp_output [lindex $result 0]
27 set output_file [lindex $result 1]
29 # gcc's default is to print the caret and source code, but
30 # most test cases implicitly use the flag -fno-diagnostics-show-caret
31 # to disable caret (and source code) printing.
33 # However, a few test cases override this back to the default by
34 # explicily supplying "-fdiagnostics-show-caret", so that we can have
35 # test coverage for caret/source code printing.
37 # gfortran error messages with caret-printing look like this:
38 # [name]:[locus]:
40 # some code
41 # 1
42 # Error: Some error at (1)
43 # or
44 # [name]:[locus]:
46 # some code
47 # 1
48 # [name]:[locus2]:
50 # some other code
51 # 2
52 # Error: Some error at (1) and (2)
53 # or
54 # [name]:[locus]:
56 # some code and some more code
57 # 1 2
58 # Error: Some error at (1) and (2)
60 # If this is such a test case, skip the rest of this function, so
61 # that the test case can explicitly verify the output that it expects.
62 if {[string first "-fdiagnostics-show-caret" $extra_tool_flags] >= 0} {
63 return [list $comp_output $output_file]
66 # Otherwise, caret-printing is disabled.
67 # gfortran errors with caret-printing disabled look like this:
68 # [name]:[locus]: Error: Some error
69 # or
70 # [name]:[locus]: Error: (1)
71 # [name]:[locus2]: Error: Some error at (1) and (2)
73 # Where [locus] is either [line] or [line].[column] or
74 # [line].[column]-[column] .
76 # We collapse these to look like:
77 # [name]:[line]:[column]: Error: Some error at (1) and (2)
78 # or
79 # [name]:[line]:[column]: Error: Some error at (1) and (2)
80 # [name]:[line2]:[column]: Error: Some error at (1) and (2)
82 # Note that these regexps only make sense in the combinations used below.
83 # Note also that is imperative that we first deal with the form with
84 # two loci.
85 set locus_regexp "(\[^\n\]+:\[0-9\]+)\[\.:\](\[0-9\]+)(-\[0-9\]+)?:\n\n\[^\n\]+\n\[^\n\]+\n"
86 set diag_regexp "(\[^\n\]+)\n"
88 # We proceed in steps:
90 # 1. We add first a column number if none exists.
91 # (Some Fortran diagnostics have the locus after Warning|Error)
92 set colnum_regexp "(^|\n)(Warning: |Error: )?(\[^:\n\]+:\[0-9\]+):(\[ \n\])"
93 regsub -all $colnum_regexp $comp_output "\\1\\3:0:\\4\\2" comp_output
94 verbose "comput_output0:\n$comp_output"
96 # 2. We deal with the form with two different locus lines,
97 set two_loci "(^|\n)$locus_regexp$locus_regexp$diag_regexp"
98 regsub -all $two_loci $comp_output "\\1\\2:\\3: \\8\n\\5\:\\6: \\8\n" comp_output
99 verbose "comput_output1:\n$comp_output"
101 set locus_prefix "(\[^:\n\]+:\[0-9\]+:\[0-9\]+: )(Warning: |Error: )"
102 set two_loci2 "(^|\n)$locus_prefix\\(1\\)\n$locus_prefix$diag_regexp"
103 regsub -all $two_loci2 $comp_output "\\1\\2\\3\\6\n\\4\\5\\6\n" comp_output
104 verbose "comput_output2:\n$comp_output"
106 # 3. then with the form with only one locus line.
107 set single_locus "(^|\n)$locus_regexp$diag_regexp"
108 regsub -all $single_locus $comp_output "\\1\\2:\\3: \\5\n" comp_output
109 verbose "comput_output3:\n$comp_output"
111 # 4. Add a line number if none exists
112 regsub -all "(^|\n)(Warning: |Error: )" $comp_output "\\1:0:0: \\2" comp_output
113 verbose "comput_output4:\n$comp_output"
114 return [list $comp_output $output_file]
117 proc gfortran-dg-prune { system text } {
118 return [gcc-dg-prune $system $text]
121 # Utility routines.
123 # Modified dg-runtest that can cycle through a list of optimization options
124 # as c-torture does.
125 proc gfortran-dg-runtest { testcases flags default-extra-flags } {
126 global runtests
127 global torture_with_loops
129 # Some callers initialize torture testing themselves; don't override those.
130 set existing_torture_init [torture-init-done]
131 if { $existing_torture_init == 0 } {
132 torture-init
134 # Some callers set torture options themselves; don't override those.
135 set existing_torture_options [torture-options-exist]
136 if { $existing_torture_options == 0 } {
137 global DG_TORTURE_OPTIONS
138 set-torture-options $DG_TORTURE_OPTIONS
140 dump-torture-options
142 foreach test $testcases {
143 # If we're only testing specific files and this isn't one of
144 # them, skip it.
145 if ![runtest_file_p $runtests $test] {
146 continue
149 # look if this is dg-do-run test, in which case
150 # we cycle through the option list, otherwise we don't
151 if [expr [search_for $test "dg-do run"]] {
152 set option_list $torture_with_loops
153 } else {
154 set option_list [list { -O } ]
157 set nshort [file tail [file dirname $test]]/[file tail $test]
158 list-module-names $test
160 foreach flags_t $option_list {
161 verbose "Testing $nshort, $flags $flags_t" 1
162 dg-test $test "$flags $flags_t" ${default-extra-flags}
163 cleanup-modules ""
167 if { $existing_torture_init == 0 } {
168 torture-finish
172 proc gfortran-dg-debug-runtest { target_compile trivial opt_opts testcases } {
173 global srcdir subdir DEBUG_TORTURE_OPTIONS
175 if ![info exists DEBUG_TORTURE_OPTIONS] {
176 set DEBUG_TORTURE_OPTIONS ""
177 set type_list [list "-gdwarf-2" ]
178 foreach type $type_list {
179 set comp_output [$target_compile \
180 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
181 "additional_flags=$type"]
182 if { [string match "exit status *" $comp_output] } {
183 continue
185 if { [string match \
186 "* target system does not support the * debug format*" \
187 $comp_output]
189 continue
191 remove-build-file "trivial.S"
192 foreach level {1 "" 3} {
193 if { ($type == "-gdwarf-2") && ($level != "") } {
194 lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
195 foreach opt $opt_opts {
196 lappend DEBUG_TORTURE_OPTIONS \
197 [list "${type}" "-g${level}" "$opt" ]
199 } else {
200 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
201 foreach opt $opt_opts {
202 lappend DEBUG_TORTURE_OPTIONS \
203 [list "${type}${level}" "$opt" ]
210 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
212 global runtests
214 foreach test $testcases {
215 # If we're only testing specific files and this isn't one of
216 # them, skip it.
217 if ![runtest_file_p $runtests $test] {
218 continue
221 set nshort [file tail [file dirname $test]]/[file tail $test]
222 list-module-names $test
224 foreach flags $DEBUG_TORTURE_OPTIONS {
225 set doit 1
226 # gcc-specific checking removed here
228 if { $doit } {
229 verbose -log "Testing $nshort, $flags" 1
230 dg-test $test $flags ""
231 cleanup-modules ""