1 # Copyright
(C
) 1997-2016 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.
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
/>.
18 load_lib file
-format.exp
19 load_lib target
-supports.exp
20 load_lib target
-supports
-dg.exp
26 load_lib timeout
-dg.exp
29 load_lib target
-libpath.exp
30 load_lib torture
-options.exp
31 load_lib fortran
-modules.exp
32 load_lib multiline.exp
34 # We
set LC_ALL and LANG to C so that we
get the same error messages as expected.
38 # Many hosts now default to a non
-ASCII C locale
, however
, so
39 # they can
set a
charset encoding here
if they need.
40 if { [ishost
"*-*-cygwin*"] } {
46 if ![info exists GCC_UNDER_TEST
] {
47 set GCC_UNDER_TEST
"[find_gcc]"
50 # This file may be sourced
, so don
't override environment settings
51 # that have been previously setup.
52 if { $orig_environment_saved == 0 } {
53 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
54 set_ld_library_path_env_vars
57 # Some torture-options cause intermediate code output, unusable for
58 # testing using e.g. scan-assembler. In this variable are the options
59 # how to force it, when needed.
60 global gcc_force_conventional_output
61 set gcc_force_conventional_output ""
63 set LTO_TORTURE_OPTIONS ""
64 if [info exists TORTURE_OPTIONS] {
65 set DG_TORTURE_OPTIONS $TORTURE_OPTIONS
67 # It is theoretically beneficial to group all of the O2/O3 options together,
68 # as in many cases the compiler will generate identical executables for
69 # all of them--and the c-torture testsuite will skip testing identical
70 # executables multiple times.
71 # Also note that -finline-functions is explicitly included in one of the
72 # items below, even though -O3 is also specified, because some ports may
73 # choose to disable inlining functions by default, even when optimizing.
74 set DG_TORTURE_OPTIONS [list \
78 { -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions } \
82 if [check_effective_target_lto] {
83 # When having plugin test both slim and fat LTO and plugin/nonplugin
85 if [check_linker_plugin_available] {
86 set LTO_TORTURE_OPTIONS [list \
87 { -O2 -flto -fno-use-linker-plugin -flto-partition=none } \
88 { -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects }
90 set gcc_force_conventional_output "-ffat-lto-objects"
92 set LTO_TORTURE_OPTIONS [list \
93 { -O2 -flto -flto-partition=none } \
100 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
101 set DG_TORTURE_OPTIONS \
102 [concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
105 global orig_environment_saved
107 # Deduce generated files from tool flags, return finalcode string
108 proc schedule-cleanups { opts } {
109 global additional_sources
112 lappend testcases [lindex [testname-for-summary] 0]
113 verbose "Cleanup testcases: $testcases" 4
114 if { [info exists additional_sources] && $additional_sources != "" } {
115 lappend testcases $additional_sources
116 verbose "Cleanup testcases, additional: $additional_sources" 4
118 verbose "Cleanup all options: $opts" 4
120 # First some fixups to transform stuff to something manageable ..
121 # --dump= should translate to -d with joined operand.
122 if [regexp -- {(^|\s+)--dump=[^\s]+(\s+|$)} $opts] {
123 regsub -all -- {--dump=} $opts {-d} opts
125 # -da and -dx are treated as shorthand for -fdump-rtl-all here
126 if [regexp -- {(^|\s+)-d[ax](\s+|$)} $opts] {
127 verbose "Cleanup -d seen" 4
128 lappend opts "-fdump-rtl-all"
130 # .. and don't question why there is
--dump
=? and
-d?
132 #
Then handle options that generate non
-dump files
134 #
-fprofile
-generate
-> cleanup
-coverage
-files
()
135 #
-fstack
-usage
-> cleanup
-stack
-usage
()
136 if [regexp
-- {(^|\s
+)-fstack
-usage
(\s
+|$
)} $opts
] {
137 verbose
"Cleanup -fstack-usage seen" 4
138 # append finalcode
"cleanup-stack-usage\n"
140 global keep_saved_temps_suffixes
141 if [info exists keep_saved_temps_suffixes
] {
142 verbose
"dg-keep-saved-temps ${keep_saved_temps_suffixes}" 2
144 #
-save
-temps
-> cleanup
-saved
-temps
()
145 if [regexp
-- {(^|\s
+)-save
-temps
(\s
+|$
)} $opts
] {
146 verbose
"Cleanup -save-temps seen" 4
147 if [info exists keep_saved_temps_suffixes
] {
148 append finalcode
"cleanup-saved-temps ${keep_saved_temps_suffixes}\n"
150 append finalcode
"cleanup-saved-temps\n"
153 if [info exists keep_saved_temps_suffixes
] {
154 error
"dg-keep-saved-temps specified but testcase does not -save-temps"
158 # Finally see
if there are
any dumps in opts
, otherwise we are done
159 if [regexp
-- {(?
=(?
:^|
[ \t]+)?
)-fdump
-[^
\t]+(?
=(?
:$|
[ \t]+)?
)} $opts
] {
160 # Ipa
, Rtl
, Tree
for simplicity
165 # stem.ext.
<passnum
><fam
>.
<passname
><pass
-instances
>
166 #
(tree
)passes can have multiple instances
, thus optional trailing
*
167 set ptn
"\[0-9\]\[0-9\]\[0-9\]$ptn.*"
168 # Handle ltrans files around
-flto
169 if [regexp
-- {(^|\s
+)-flto
(\s
+|$
)} $opts
] {
170 verbose
"Cleanup -flto seen" 4
171 set ltrans
"{ltrans\[0-9\]*.,}"
175 set ptn
"$ltrans$ptn"
176 verbose
"Cleanup final ptn: $ptn" 4
178 foreach src $testcases
{
179 set basename
[file tail $src
]
180 if { $ltrans
!= "" } {
181 # ??? should we use upvar
1 output_file instead of this
(dup ?
)
182 set stem
[file rootname $basename
]
183 set basename_ext
[file extension $basename
]
184 if {$basename_ext
!= ""} {
185 regsub
-- {^.
*\.
} $basename_ext
{} basename_ext
187 lappend tfiles
"$stem.{$basename_ext,exe}"
190 lappend tfiles $basename
193 if { [llength $tfiles
] > 1 } {
194 set tfiles
[join $tfiles
","]
195 set tfiles
"{$tfiles}"
197 verbose
"Cleanup final testcases: $tfiles" 4
198 # We have to quote the regex
199 regsub
-all
{([][$^?
+*()|
\\{}])} "$tfiles.$ptn" {\\\1} ptn
201 append final
{remove
-build
-file
}
202 append final
"\"$ptn\""
203 verbose
"Cleanup final: $final" 4
204 append finalcode
"$final\n"
209 #
Define gcc callbacks
for dg.exp.
211 proc gcc
-dg
-test
-1 { target_compile prog do_what extra_tool_flags
} {
212 #
Set up the compiler flags
, based
on what we
're going to do.
216 # Tests should be able to use "dg-do repo". However, the dg test
217 # driver checks the argument to dg-do against a list of acceptable
218 # options, and "repo" is not among them. Therefore, we resort to
219 # this ugly approach.
220 if [string match "*-frepo*" $extra_tool_flags] then {
226 set compile_type "preprocess"
227 set output_file "[file rootname [file tail $prog]].i"
230 set compile_type "assembly"
231 set output_file "[file rootname [file tail $prog]].s"
234 set compile_type "object"
235 set output_file "[file rootname [file tail $prog]].o"
238 set compile_type "precompiled_header"
239 set output_file "[file tail $prog].gch"
242 set compile_type "executable"
243 set output_file "[file rootname [file tail $prog]].exe"
244 # The following line is needed for targets like the i960 where
245 # the default output file is b.out. Sigh.
248 set compile_type "object"
249 set output_file "[file rootname [file tail $prog]].o"
252 set compile_type "executable"
253 # FIXME: "./" is to cope with "." not being in $PATH.
254 # Should this be handled elsewhere?
256 set output_file "./[file rootname [file tail $prog]].exe"
257 # This is the only place where we care if an executable was
258 # created or not. If it was, dg.exp will try to run it.
259 catch { remote_file build delete $output_file }
262 perror "$do_what: not a valid dg-do keyword"
267 # Let { dg-final { action } } force options as returned by an
268 # optional proc ${action}_required_options.
269 upvar 2 dg-final-code finalcode
270 foreach x [split $finalcode "\n"] {
271 set finalcmd [lindex $x 0]
272 if { [info procs ${finalcmd}_required_options] != "" } {
273 set req [${finalcmd}_required_options]
274 if { $req != "" && [lsearch -exact $extra_tool_flags $req] == -1 } {
275 lappend extra_tool_flags $req
280 append finalcode [schedule-cleanups "$options $extra_tool_flags"]
281 if { $extra_tool_flags != "" } {
282 lappend options "additional_flags=$extra_tool_flags"
285 verbose "$target_compile $prog $output_file $compile_type $options" 4
286 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
288 # Look for an internal compiler error, which sometimes masks the fact
289 # that we didn't
get an expected error message. XFAIL an ICE via
290 # dg
-xfail
-if and use
{ dg
-prune
-output
".*internal compiler error.*" }
291 # to avoid a second failure
for excess errors.
292 if [string match
"*internal compiler error*" $comp_output] {
294 fail
"$name (internal compiler error)"
297 if { $do_what
== "repo" } {
298 set object_file
"$output_file"
299 set output_file
"[file rootname [file tail $prog]].exe"
301 [ concat $comp_output \
302 [$target_compile
"$object_file" "$output_file" \
303 "executable" $options] ]
306 return [list $comp_output $output_file
]
309 proc gcc
-dg
-test
{ prog do_what extra_tool_flags
} {
310 return [gcc
-dg
-test
-1 gcc_target_compile $prog $do_what $extra_tool_flags
]
313 # Global
: should
blank lines be allowed in the output?
314 # By default
, they should not be.
(PR other
/69006)
315 # However
, there are some ways
for them to validly occur.
316 set allow_blank_lines
0
318 # A command
for use by testcases to mark themselves as expecting
319 #
blank lines in the output.
321 proc dg
-allow
-blank-lines
-in
-output
{ args } {
322 global allow_blank_lines
323 set allow_blank_lines
1
326 proc gcc
-dg
-prune
{ system text } {
327 global additional_prunes
329 # Extra prune rules that will apply to tests defined in a .exp file.
330 # Always remember to clear it in .exp file after executed all tests.
331 global dg_runtest_extra_prunes
333 # Complain about
blank lines in the output
(PR other
/69006)
334 global allow_blank_lines
335 if { !$allow_blank_lines
} {
336 set num_blank_lines
[llength
[regexp
-all
-inline
"\n\n" $text]]
337 if { $num_blank_lines
} {
338 global testname_with_flags
339 fail
"$testname_with_flags $num_blank_lines blank line(s) in output"
341 set allow_blank_lines
0
344 set text [prune_gcc_output $
text]
346 foreach p
"$additional_prunes $dg_runtest_extra_prunes" {
347 if { [string length $p
] > 0 } {
348 # Following regexp matches a complete line containing $p.
349 regsub
-all
"(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
353 #
If we see
"region xxx is full" then the testcase is too big for ram.
354 # This is tricky to deal with in a large testsuite like c
-torture so
355 # deal with it here. Just mark the testcase as unsupported.
356 if [regexp
"(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
357 # The format here is important. See dg.exp.
358 return "::unsupported::memory full"
361 if { [regexp
"(^|\n)\[^\n\]*: relocation truncated to fit" $text]
362 && [check_effective_target_tiny
] } {
363 return "::unsupported::memory full"
366 # Likewise
, if we see
".text exceeds local store range" or
368 if {[string match
"spu-*" $system] && \
369 [string match
"*exceeds local store*" $text]} {
370 # The format here is important. See dg.exp.
371 return "::unsupported::memory full"
377 # Replace $
{tool
}_load with a wrapper to provide
for an expected nonzero
378 # exit
status. Multiple languages
include this file so this handles them
380 if { [info procs $
{tool
}_load
] != [list
] \
381 && [info procs saved_$
{tool
}_load
] == [list
] } {
382 rename $
{tool
}_load saved_$
{tool
}_load
384 proc $
{tool
}_load
{ program args } {
387 global set_target_env_var
389 set saved_target_env_var
[list
]
390 if { [info exists set_target_env_var
] \
391 && [llength $set_target_env_var
] != 0 } {
392 if { [is_remote target
] } {
393 return [list
"unsupported" ""]
397 set result
[eval
[list saved_$
{tool
}_load $
program] $
args]
398 if { [info exists set_target_env_var
] \
399 && [llength $set_target_env_var
] != 0 } {
400 restore
-target
-env
-var
402 if { $shouldfail
!= 0 } {
403 switch [lindex $result
0] {
404 "pass" { set status "fail" }
405 "fail" { set status "pass" }
407 set result
[list $
status [lindex $result
1]]
410 set result
[list
[lindex $result
0] [prune_file_path
[lindex $result
1]]]
415 proc dg
-set-target
-env
-var
{ args } {
416 global set_target_env_var
417 if { [llength $
args] != 3 } {
418 error
"dg-set-target-env-var: need two arguments"
421 lappend set_target_env_var
[list
[lindex $
args 1] [lindex $
args 2]]
424 proc
set-target
-env
-var
{ } {
425 global set_target_env_var
426 upvar
1 saved_target_env_var saved_target_env_var
427 foreach env_var $set_target_env_var
{
428 set var
[lindex $env_var
0]
429 set value
[lindex $env_var
1]
430 if [info exists ::env
($var
)] {
431 lappend saved_target_env_var
[list $var
1 $
::env
($var
)]
433 lappend saved_target_env_var
[list $var
0]
439 proc restore
-target
-env
-var
{ } {
440 upvar
1 saved_target_env_var saved_target_env_var
441 for { set env_vari
[llength $saved_target_env_var
] } {
442 [incr env_vari
-1] >= 0 } {} {
443 set env_var
[lindex $saved_target_env_var $env_vari
]
444 set var
[lindex $env_var
0]
445 if [lindex $env_var
1] {
446 setenv $var
[lindex $env_var
2]
456 # search_for
-- looks
for a string match in a file
458 proc search_for
{ file pattern
} {
459 set fd
[open $file r
]
460 while { [gets $fd cur_line
]>=0 } {
461 if [string match
"*$pattern*" $cur_line] then {
470 # Modified dg
-runtest that can cycle through a list of optimization options
472 proc gcc
-dg
-runtest
{ testcases flags default
-extra
-flags
} {
475 # Some callers
set torture options themselves
; don
't override those.
476 set existing_torture_options [torture-options-exist]
477 if { $existing_torture_options == 0 } {
478 global DG_TORTURE_OPTIONS LTO_TORTURE_OPTIONS
480 set-torture-options $DG_TORTURE_OPTIONS [list {}] $LTO_TORTURE_OPTIONS
484 foreach test $testcases {
485 global torture_with_loops torture_without_loops
486 # If we're only testing specific files and this isn
't one of
488 if ![runtest_file_p $runtests $test] {
492 # Look for a loop within the source code - if we don't find one
,
493 # don
't pass -funroll[-all]-loops.
494 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
495 set option_list $torture_with_loops
497 set option_list $torture_without_loops
500 set nshort [file tail [file dirname $test]]/[file tail $test]
502 foreach flags_t $option_list {
503 verbose "Testing $nshort, $flags $flags_t" 1
504 dg-test $test "$flags $flags_t" ${default-extra-flags}
508 if { $existing_torture_options == 0 } {
513 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
516 if ![info exists DEBUG_TORTURE_OPTIONS] {
517 set DEBUG_TORTURE_OPTIONS ""
518 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
519 set comp_output [$target_compile \
520 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
521 "additional_flags=$type"]
522 if { ! [string match "*: target system does not support the * debug format*" \
524 remove-build-file "trivial.S"
525 foreach level {1 "" 3} {
526 if { ($type == "-gdwarf-2") && ($level != "") } {
527 lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
528 foreach opt $opt_opts {
529 lappend DEBUG_TORTURE_OPTIONS \
530 [list "${type}" "-g${level}" "$opt" ]
533 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
534 foreach opt $opt_opts {
535 lappend DEBUG_TORTURE_OPTIONS \
536 [list "${type}${level}" "$opt" ]
544 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
548 foreach test $testcases {
549 # If we're only testing specific files and this isn
't one of
551 if ![runtest_file_p $runtests $test] {
555 set nshort [file tail [file dirname $test]]/[file tail $test]
557 foreach flags $DEBUG_TORTURE_OPTIONS {
560 # These tests check for information which may be deliberately
562 if { ([string match {*/debug-[126].c} "$nshort"] \
563 || [string match {*/enum-1.c} "$nshort"] \
564 || [string match {*/enum-[12].C} "$nshort"]) \
565 && ([string match "*1" [lindex "$flags" 0] ]
566 || [lindex "$flags" 1] == "-g1") } {
570 # High optimization can remove the variable whose existence is tested.
571 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
572 # assembler output, but stabs debugging does not.
573 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
574 if { [string match {*/debug-[12].c} "$nshort"] \
575 && [string match "*O*" "$flags"] \
576 && ( [string match "*coff*" "$flags"] \
577 || [string match "*stabs*" "$flags"] ) } {
582 verbose -log "Testing $nshort, $flags" 1
583 dg-test $test $flags ""
589 # Prune any messages matching ARGS[1] (a regexp) from test output.
590 proc dg-prune-output { args } {
591 global additional_prunes
593 if { [llength $args] != 2 } {
594 error "[lindex $args 1]: need one argument"
598 lappend additional_prunes [lindex $args 1]
601 # Remove files matching the pattern from the build machine.
602 proc remove-build-file { pat } {
603 verbose "remove-build-file `$pat'" 2
604 set file_list
"[glob -nocomplain $pat]"
605 verbose
"remove-build-file `$file_list'" 2
606 foreach output_file $file_list
{
607 if [is_remote host
] {
608 # Ensure the host knows the file is gone by deleting there
610 remote_file host
delete $output_file
612 remote_file build
delete $output_file
616 # Remove runtime
-generated profile file
for the current test.
617 proc cleanup
-profile
-file
{ } {
618 remove
-build
-file
"mon.out"
619 remove
-build
-file
"gmon.out"
622 # Remove compiler
-generated coverage files
for the current test.
623 proc cleanup
-coverage
-files
{ } {
624 global additional_sources_used
625 set testcase
[testname
-for-summary
]
626 # The
name might
include a list of options
; extract the file
name.
627 set testcase
[lindex $testcase
0]
628 remove
-build
-file
"[file rootname [file tail $testcase]].gc??"
630 # Clean up coverage files
for additional source files.
631 if [info exists additional_sources_used
] {
632 foreach srcfile $additional_sources_used
{
633 remove
-build
-file
"[file rootname [file tail $srcfile]].gc??"
638 # Remove compiler
-generated files from
-repo
for the current test.
639 proc cleanup
-repo
-files
{ } {
640 global additional_sources_used
641 set testcase
[testname
-for-summary
]
642 # The
name might
include a list of options
; extract the file
name.
643 set testcase
[lindex $testcase
0]
644 remove
-build
-file
"[file rootname [file tail $testcase]].o"
645 remove
-build
-file
"[file rootname [file tail $testcase]].rpo"
647 # Clean up files
for additional source files.
648 if [info exists additional_sources_used
] {
649 foreach srcfile $additional_sources_used
{
650 remove
-build
-file
"[file rootname [file tail $srcfile]].o"
651 remove
-build
-file
"[file rootname [file tail $srcfile]].rpo"
656 # Remove a final insns dump file
for the current test.
657 proc cleanup
-final
-insns
-dump
{ } {
658 set testcase
[testname
-for-summary
]
659 # The
name might
include a list of options
; extract the file
name.
660 set testcase
[lindex $testcase
0]
661 remove
-build
-file
"[file rootname [file tail $testcase]].s.gkd"
663 # Clean up files
for additional source files.
664 if [info exists additional_sources_used
] {
665 foreach srcfile $additional_sources_used
{
666 remove
-build
-file
"[file rootname [file tail $srcfile]].s.gkd"
671 # Remove a stack usage file
for the current test.
672 proc cleanup
-stack
-usage
{ } {
673 set testcase
[testname
-for-summary
]
674 # The
name might
include a list of options
; extract the file
name.
675 set testcase
[lindex $testcase
0]
676 remove
-build
-file
"[file rootname [file tail $testcase]].su"
678 # Clean up files
for additional source files.
679 if [info exists additional_sources_used
] {
680 foreach srcfile $additional_sources_used
{
681 remove
-build
-file
"[file rootname [file tail $srcfile]].su"
686 # Remove an Ada spec file
for the current test.
687 proc cleanup
-ada
-spec
{ } {
688 global additional_sources_used
689 set testcase
[testname
-for-summary
]
690 remove
-build
-file
"[get_ada_spec_filename $testcase]"
692 # Clean up files
for additional source files.
693 if [info exists additional_sources_used
] {
694 foreach srcfile $additional_sources_used
{
695 remove
-build
-file
"[get_ada_spec_filename $srcfile]"
700 # Remove files kept by
--save
-temps
for the current test.
702 # Currently this is only .i
, .ii
, .s and .o files
, but more can be added
703 #
if there are tests generating them.
704 #
ARGS is a list of suffixes to NOT
delete.
705 proc cleanup
-saved
-temps
{ args } {
706 global additional_sources_used
709 # add the to
-be
-kept suffixes
710 foreach suffix
{".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
711 if {[lsearch $
args $suffix
] < 0} {
712 lappend suffixes $suffix
716 set testcase
[testname
-for-summary
]
717 # The
name might
include a list of options
; extract the file
name.
718 set testcase
[lindex $testcase
0]
719 foreach suffix $suffixes
{
720 remove
-build
-file
"[file rootname [file tail $testcase]]$suffix"
721 remove
-build
-file
"[file rootname [file tail $testcase]].exe$suffix"
722 remove
-build
-file
"[file rootname [file tail $testcase]].exe.ltrans\[0-9\]*$suffix"
723 #
-fcompare
-debug dumps
724 remove
-build
-file
"[file rootname [file tail $testcase]].gk$suffix"
727 # Clean up saved temp files
for additional source files.
728 if [info exists additional_sources_used
] {
729 foreach srcfile $additional_sources_used
{
730 foreach suffix $suffixes
{
731 remove
-build
-file
"[file rootname [file tail $srcfile]]$suffix"
732 remove
-build
-file
"[file rootname [file tail $srcfile]].exe$suffix"
733 remove
-build
-file
"[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*$suffix"
735 #
-fcompare
-debug dumps
736 remove
-build
-file
"[file rootname [file tail $srcfile]].gk$suffix"
743 # Files to be kept after cleanup of
--save
-temps
for the current test.
744 #
ARGS is a list of suffixes to NOT
delete.
745 proc dg
-keep
-saved
-temps
{ args } {
746 global keep_saved_temps_suffixes
747 set keep_saved_temps_suffixes
{}
749 # add the to
-be
-kept suffixes
750 foreach suffix
{".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
751 if {[lsearch $
args $suffix
] >= 0} {
752 lappend keep_saved_temps_suffixes $suffix
755 if { [llength keep_saved_temps_suffixes
] < 1 } {
756 error
"dg-keep-saved-temps ${args} did not match any known suffix"
760 # Scan Fortran modules
for a given regexp.
762 #
Argument 0 is the module
name
763 #
Argument 1 is the regexp to match
764 proc scan
-module
{ args } {
765 set modfilename
[string tolower
[lindex $
args 0]].mod
766 set fd
[open
[list | gzip
-dc $modfilename
] r
]
770 set testcase
[testname
-for-summary
]
771 if [regexp
-- [lindex $
args 1] $
text] {
772 pass
"$testcase scan-module [lindex $args 1]"
774 fail
"$testcase scan-module [lindex $args 1]"
778 # Scan Fortran modules
for absence of a given regexp.
780 #
Argument 0 is the module
name
781 #
Argument 1 is the regexp to match
782 proc scan
-module
-absence
{ args } {
783 set modfilename
[string tolower
[lindex $
args 0]].mod
784 set fd
[open
[list | gzip
-dc $modfilename
] r
]
788 set testcase
[testname
-for-summary
]
789 if [regexp
-- [lindex $
args 1] $
text] {
790 fail
"$testcase scan-module [lindex $args 1]"
792 pass
"$testcase scan-module [lindex $args 1]"
796 # Verify that the compiler output file
exists, invoked via dg
-final.
797 proc output
-exists { args } {
798 # Process an optional target or xfail list.
799 if { [llength $
args] >= 1 } {
800 switch [dg
-process
-target
[lindex $
args 0]] {
803 "F" { setup_xfail "*-*-*" }
808 set testcase
[testname
-for-summary
]
809 # Access
variable from gcc
-dg
-test
-1.
810 upvar
2 output_file output_file
812 if [file
exists $output_file
] {
813 pass
"$testcase output-exists $output_file"
815 fail
"$testcase output-exists $output_file"
819 # Verify that the compiler output file does not exist
, invoked via dg
-final.
820 proc output
-exists-not
{ args } {
821 # Process an optional target or xfail list.
822 if { [llength $
args] >= 1 } {
823 switch [dg
-process
-target
[lindex $
args 0]] {
826 "F" { setup_xfail "*-*-*" }
831 set testcase
[testname
-for-summary
]
832 # Access
variable from gcc
-dg
-test
-1.
833 upvar
2 output_file output_file
835 if [file
exists $output_file
] {
836 fail
"$testcase output-exists-not $output_file"
838 pass
"$testcase output-exists-not $output_file"
842 # We need to make sure that additional_
* are cleared out after
every
843 # test. It is not enough to clear them out
*before
* the next test run
844 # because gcc
-target
-compile gets run directly from some .exp files
845 #
(outside of
any test
).
(Those uses should eventually be eliminated.
)
847 # Because the DG framework doesn
't provide a hook that is run at the
848 # end of a test, we must replace dg-test with a wrapper.
850 if { [info procs saved-dg-test] == [list] } {
851 rename dg-test saved-dg-test
853 # Helper function for cleanups that should happen after the call
854 # to the real dg-test, whether or not it returns normally, or
855 # fails with an error.
856 proc cleanup-after-saved-dg-test { } {
857 global additional_files
858 global additional_sources
859 global additional_sources_used
860 global additional_prunes
861 global compiler_conditional_xfail_data
863 global testname_with_flags
864 global set_target_env_var
865 global keep_saved_temps_suffixes
866 global multiline_expected_outputs
868 set additional_files ""
869 set additional_sources ""
870 set additional_sources_used ""
871 set additional_prunes ""
873 if [info exists set_target_env_var] {
874 unset set_target_env_var
876 if [info exists keep_saved_temps_suffixes] {
877 unset keep_saved_temps_suffixes
880 if [info exists compiler_conditional_xfail_data] {
881 unset compiler_conditional_xfail_data
883 if [info exists testname_with_flags] {
884 unset testname_with_flags
886 set multiline_expected_outputs []
889 proc dg-test { args } {
892 if { [ catch { eval saved-dg-test $args } errmsg ] } {
893 set saved_info $errorInfo
894 cleanup-after-saved-dg-test
895 error $errmsg $saved_info
897 cleanup-after-saved-dg-test
901 if { [info procs saved-dg-warning] == [list] \
902 && [info exists gcc_warning_prefix] } {
903 rename dg-warning saved-dg-warning
905 proc dg-warning { args } {
906 # Make this variable available here and to the saved proc.
907 upvar dg-messages dg-messages
908 global gcc_warning_prefix
910 process-message saved-dg-warning "$gcc_warning_prefix" "$args"
914 if { [info procs saved-dg-error] == [list] \
915 && [info exists gcc_error_prefix] } {
916 rename dg-error saved-dg-error
918 proc dg-error { args } {
919 # Make this variable available here and to the saved proc.
920 upvar dg-messages dg-messages
921 global gcc_error_prefix
923 process-message saved-dg-error "$gcc_error_prefix" "$args"
926 # Override dg-bogus at the same time. It doesn't handle a prefix
927 # but its expression should
include a column number. Otherwise the
928 # line number can match the column number
for other messages
, leading
930 rename dg
-bogus saved
-dg
-bogus
932 proc dg
-bogus
{ args } {
933 upvar dg
-messages dg
-messages
934 process
-message saved
-dg
-bogus
"" $args
938 # Modify the regular expression saved by a DejaGnu message directive to
939 #
include a prefix and to force the expression to match a single line.
940 # MSGPROC is the procedure to
call.
941 # MSGPREFIX is the prefix to prepend.
942 # DGARGS is the original
argument list.
944 proc process
-message
{ msgproc msgprefix dgargs
} {
945 upvar dg
-messages dg
-messages
947 # Process the dg
- directive
, including adding the regular expression
948 # to the new message entry in dg
-messages.
949 set msgcnt
[llength $
{dg
-messages
}]
950 eval $msgproc $dgargs
952 #
If the target expression wasn
't satisfied there is no new message.
953 if { [llength ${dg-messages}] == $msgcnt } {
957 # Get the entry for the new message. Prepend the message prefix to
958 # the regular expression and make it match a single line.
959 set newentry [lindex ${dg-messages} end]
960 set expmsg [lindex $newentry 2]
962 # Handle column numbers from the specified expression (if there is
963 # one) and set up the search expression that will be used by DejaGnu.
964 if [regexp "^(\[0-9\]+):" $expmsg "" column] {
965 # The expression in the directive included a column number.
966 # Remove "COLUMN:" from the original expression and move it
967 # to the proper place in the search expression.
968 regsub "^\[0-9\]+:" $expmsg "" expmsg
969 set expmsg "$column: $msgprefix\[^\n\]*$expmsg"
970 } elseif [string match "" [lindex $newentry 0]] {
971 # The specified line number is 0; don't expect a column number.
972 set expmsg
"$msgprefix\[^\n\]*$expmsg"
974 # There is no column number in the search expression
, but we
975 # should expect one in the message itself.
976 set expmsg
"\[0-9\]+: $msgprefix\[^\n\]*$expmsg"
979 set newentry
[lreplace $newentry
2 2 $expmsg
]
980 set dg
-messages
[lreplace $
{dg
-messages
} end end $newentry
]
981 verbose
"process-message:\n${dg-messages}" 2
984 # Look
for messages that don
't have standard prefixes.
986 proc dg-message { args } {
987 upvar dg-messages dg-messages
988 process-message saved-dg-warning "" $args
991 # Look for a location marker of the form
993 # with no extra text (e.g. a line-span separator).
995 proc dg-locus { args } {
996 upvar dg-messages dg-messages
998 # Process the dg- directive, including adding the regular expression
999 # to the new message entry in dg-messages.
1000 set msgcnt [llength ${dg-messages}]
1001 eval saved-dg-warning $args
1003 # If the target expression wasn't satisfied there is no new message.
1004 if { [llength $
{dg
-messages
}] == $msgcnt
} {
1008 #
Get the entry
for the new message. Prepend the message prefix to
1009 # the regular expression and make it match a single line.
1010 set newentry
[lindex $
{dg
-messages
} end
]
1011 set expmsg
[lindex $newentry
2]
1013 set newentry
[lreplace $newentry
2 2 $expmsg
]
1014 set dg
-messages
[lreplace $
{dg
-messages
} end end $newentry
]
1015 verbose
"process-message:\n${dg-messages}" 2
1018 # Check the existence of a gdb in the path
, and
return true
if there
1021 #
Set env
(GDB_FOR_GCC_TESTING
) accordingly.
1023 proc gdb
-exists { args } {
1024 if ![info exists ::env
(GDB_FOR_GCC_TESTING
)] {
1026 if ![info exists ::env
(GDB_FOR_GCC_TESTING
)] {
1027 if [info exists GDB
] {
1028 setenv GDB_FOR_GCC_TESTING
"$GDB"
1030 setenv GDB_FOR_GCC_TESTING
"[transform gdb]"
1034 if { [which $
::env
(GDB_FOR_GCC_TESTING
)] != 0 } {
1040 set additional_prunes
""
1041 set dg_runtest_extra_prunes
""