| 1 |
# Copyright (C) 2004-2025 Free Software Foundation, Inc. |
| 2 |
|
| 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. |
| 12 |
# |
| 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/>. |
| 16 |
|
| 17 |
load_lib gcc-dg.exp |
| 18 |
load_lib torture-options.exp |
| 19 |
|
| 20 |
# Define gfortran callbacks for dg.exp. |
| 21 |
|
| 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] |
| 25 |
|
| 26 |
set comp_output [lindex $result 0] |
| 27 |
set output_file [lindex $result 1] |
| 28 |
|
| 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. |
| 32 |
# |
| 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. |
| 36 |
# |
| 37 |
# gfortran error messages with caret-printing look like this: |
| 38 |
# [name]:[locus]: |
| 39 |
# |
| 40 |
# some code |
| 41 |
# 1 |
| 42 |
# Error: Some error at (1) |
| 43 |
# or |
| 44 |
# [name]:[locus]: |
| 45 |
# |
| 46 |
# some code |
| 47 |
# 1 |
| 48 |
# [name]:[locus2]: |
| 49 |
# |
| 50 |
# some other code |
| 51 |
# 2 |
| 52 |
# Error: Some error at (1) and (2) |
| 53 |
# or |
| 54 |
# [name]:[locus]: |
| 55 |
# |
| 56 |
# some code and some more code |
| 57 |
# 1 2 |
| 58 |
# Error: Some error at (1) and (2) |
| 59 |
# |
| 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] |
| 64 |
} |
| 65 |
|
| 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) |
| 72 |
# |
| 73 |
# Where [locus] is either [line] or [line].[column] or |
| 74 |
# [line].[column]-[column] . |
| 75 |
# |
| 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) |
| 81 |
# |
| 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" |
| 87 |
|
| 88 |
# We proceed in steps: |
| 89 |
|
| 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" |
| 95 |
|
| 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" |
| 100 |
|
| 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" |
| 105 |
|
| 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" |
| 110 |
|
| 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] |
| 115 |
} |
| 116 |
|
| 117 |
proc gfortran-dg-prune { system text } { |
| 118 |
return [gcc-dg-prune $system $text] |
| 119 |
} |
| 120 |
|
| 121 |
# Utility routines. |
| 122 |
|
| 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 |
| 128 |
|
| 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 |
| 133 |
} |
| 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 |
| 139 |
} |
| 140 |
dump-torture-options |
| 141 |
|
| 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 |
| 147 |
} |
| 148 |
|
| 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 |
if { [ expr [search_for $test "dg-options*\[ \t\"\{]-O"] ] \ |
| 153 |
|| [ expr [search_for $test \ |
| 154 |
"dg-additional-options*\[ \t\"\{]-O"] ] } { |
| 155 |
set option_list [list { -O } ] |
| 156 |
} else { |
| 157 |
set option_list $torture_with_loops |
| 158 |
} |
| 159 |
} else { |
| 160 |
set option_list [list { -O } ] |
| 161 |
} |
| 162 |
|
| 163 |
set nshort [file tail [file dirname $test]]/[file tail $test] |
| 164 |
list-module-names $test |
| 165 |
|
| 166 |
foreach flags_t $option_list { |
| 167 |
verbose "Testing $nshort, $flags $flags_t" 1 |
| 168 |
dg-test $test "$flags $flags_t" ${default-extra-flags} |
| 169 |
fortran-delete-unit-files $test |
| 170 |
cleanup-modules "" |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
if { $existing_torture_init == 0 } { |
| 175 |
torture-finish |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
proc gfortran-dg-debug-runtest { target_compile trivial opt_opts testcases } { |
| 180 |
global srcdir subdir DEBUG_TORTURE_OPTIONS |
| 181 |
|
| 182 |
if ![info exists DEBUG_TORTURE_OPTIONS] { |
| 183 |
set DEBUG_TORTURE_OPTIONS "" |
| 184 |
set type_list [list "-gdwarf-2" ] |
| 185 |
foreach type $type_list { |
| 186 |
set comp_output [$target_compile \ |
| 187 |
"$srcdir/$subdir/$trivial" "trivial.S" assembly \ |
| 188 |
"additional_flags=$type"] |
| 189 |
if { [string match "exit status *" $comp_output] } { |
| 190 |
continue |
| 191 |
} |
| 192 |
if { [string match \ |
| 193 |
"* target system does not support the * debug format*" \ |
| 194 |
$comp_output] |
| 195 |
} { |
| 196 |
continue |
| 197 |
} |
| 198 |
remove-build-file "trivial.S" |
| 199 |
foreach level {1 "" 3} { |
| 200 |
if { ($type == "-gdwarf-2") && ($level != "") } { |
| 201 |
lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"] |
| 202 |
foreach opt $opt_opts { |
| 203 |
lappend DEBUG_TORTURE_OPTIONS \ |
| 204 |
[list "${type}" "-g${level}" "$opt" ] |
| 205 |
} |
| 206 |
} else { |
| 207 |
lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"] |
| 208 |
foreach opt $opt_opts { |
| 209 |
lappend DEBUG_TORTURE_OPTIONS \ |
| 210 |
[list "${type}${level}" "$opt" ] |
| 211 |
} |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
verbose -log "Using options $DEBUG_TORTURE_OPTIONS" |
| 218 |
|
| 219 |
global runtests |
| 220 |
|
| 221 |
foreach test $testcases { |
| 222 |
# If we're only testing specific files and this isn't one of |
| 223 |
# them, skip it. |
| 224 |
if ![runtest_file_p $runtests $test] { |
| 225 |
continue |
| 226 |
} |
| 227 |
|
| 228 |
set nshort [file tail [file dirname $test]]/[file tail $test] |
| 229 |
list-module-names $test |
| 230 |
|
| 231 |
foreach flags $DEBUG_TORTURE_OPTIONS { |
| 232 |
set doit 1 |
| 233 |
# gcc-specific checking removed here |
| 234 |
|
| 235 |
if { $doit } { |
| 236 |
verbose -log "Testing $nshort, $flags" 1 |
| 237 |
dg-test $test $flags "" |
| 238 |
cleanup-modules "" |
| 239 |
} |
| 240 |
} |
| 241 |
} |
| 242 |
} |