2015-09-24 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / lib / gcc-dg.exp
blob7c1ab85f32e1a26256a43a798323f06cef368da5
1 # Copyright (C) 1997-2015 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/>.
17 load_lib dg.exp
18 load_lib file-format.exp
19 load_lib target-supports.exp
20 load_lib target-supports-dg.exp
21 load_lib scanasm.exp
22 load_lib scanrtl.exp
23 load_lib scantree.exp
24 load_lib scanipa.exp
25 load_lib timeout.exp
26 load_lib timeout-dg.exp
27 load_lib prune.exp
28 load_lib libgloss.exp
29 load_lib target-libpath.exp
30 load_lib torture-options.exp
31 load_lib fortran-modules.exp
33 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
34 setenv LC_ALL C
35 setenv LANG C
37 # Many hosts now default to a non-ASCII C locale, however, so
38 # they can set a charset encoding here if they need.
39 if { [ishost "*-*-cygwin*"] } {
40 setenv LC_ALL C.ASCII
41 setenv LANG C.ASCII
44 global GCC_UNDER_TEST
45 if ![info exists GCC_UNDER_TEST] {
46 set GCC_UNDER_TEST "[find_gcc]"
49 # This file may be sourced, so don't override environment settings
50 # that have been previously setup.
51 if { $orig_environment_saved == 0 } {
52 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
53 set_ld_library_path_env_vars
56 # Some torture-options cause intermediate code output, unusable for
57 # testing using e.g. scan-assembler. In this variable are the options
58 # how to force it, when needed.
59 global gcc_force_conventional_output
60 set gcc_force_conventional_output ""
62 set LTO_TORTURE_OPTIONS ""
63 if [info exists TORTURE_OPTIONS] {
64 set DG_TORTURE_OPTIONS $TORTURE_OPTIONS
65 } else {
66 # It is theoretically beneficial to group all of the O2/O3 options together,
67 # as in many cases the compiler will generate identical executables for
68 # all of them--and the c-torture testsuite will skip testing identical
69 # executables multiple times.
70 # Also note that -finline-functions is explicitly included in one of the
71 # items below, even though -O3 is also specified, because some ports may
72 # choose to disable inlining functions by default, even when optimizing.
73 set DG_TORTURE_OPTIONS [list \
74 { -O0 } \
75 { -O1 } \
76 { -O2 } \
77 { -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions } \
78 { -O3 -g } \
79 { -Os } ]
81 if [check_effective_target_lto] {
82 # When having plugin test both slim and fat LTO and plugin/nonplugin
83 # path.
84 if [check_linker_plugin_available] {
85 set LTO_TORTURE_OPTIONS [list \
86 { -O2 -flto -fno-use-linker-plugin -flto-partition=none } \
87 { -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects }
89 set gcc_force_conventional_output "-ffat-lto-objects"
90 } else {
91 set LTO_TORTURE_OPTIONS [list \
92 { -O2 -flto -flto-partition=none } \
93 { -O2 -flto }
99 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
100 set DG_TORTURE_OPTIONS \
101 [concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
104 global orig_environment_saved
106 # Deduce generated files from tool flags, return finalcode string
107 proc schedule-cleanups { opts } {
108 global additional_sources
109 set finalcode ""
110 set testcases {}
111 lappend testcases [lindex [testname-for-summary] 0]
112 verbose "Cleanup testcases: $testcases" 4
113 if { [info exists additional_sources] && $additional_sources != "" } {
114 lappend testcases $additional_sources
115 verbose "Cleanup testcases, additional: $additional_sources" 4
117 verbose "Cleanup all options: $opts" 4
119 # First some fixups to transform stuff to something manageable ..
120 # --dump= should translate to -d with joined operand.
121 if [regexp -- {(^|\s+)--dump=[^\s]+(\s+|$)} $opts] {
122 regsub -all -- {--dump=} $opts {-d} opts
124 # -da and -dx are treated as shorthand for -fdump-rtl-all here
125 if [regexp -- {(^|\s+)-d[ax](\s+|$)} $opts] {
126 verbose "Cleanup -d seen" 4
127 lappend opts "-fdump-rtl-all"
129 # .. and don't question why there is --dump=? and -d?
131 # Then handle options that generate non-dump files
132 # TODO
133 # -fprofile-generate -> cleanup-coverage-files()
134 # -fstack-usage -> cleanup-stack-usage()
135 if [regexp -- {(^|\s+)-fstack-usage(\s+|$)} $opts] {
136 verbose "Cleanup -fstack-usage seen" 4
137 # append finalcode "cleanup-stack-usage\n"
139 global keep_saved_temps_suffixes
140 if [info exists keep_saved_temps_suffixes ] {
141 verbose "dg-keep-saved-temps ${keep_saved_temps_suffixes}" 2
143 # -save-temps -> cleanup-saved-temps()
144 if [regexp -- {(^|\s+)-save-temps(\s+|$)} $opts] {
145 verbose "Cleanup -save-temps seen" 4
146 if [info exists keep_saved_temps_suffixes] {
147 append finalcode "cleanup-saved-temps ${keep_saved_temps_suffixes}\n"
148 } else {
149 append finalcode "cleanup-saved-temps\n"
151 } else {
152 if [info exists keep_saved_temps_suffixes ] {
153 error "dg-keep-saved-temps specified but testcase does not -save-temps"
154 return
157 # Finally see if there are any dumps in opts, otherwise we are done
158 if [regexp -- {(?=(?:^|[ \t]+)?)-fdump-[^ \t]+(?=(?:$|[ \t]+)?)} $opts] {
159 # Ipa, Rtl, Tree for simplicity
160 set ptn "{i,r,t}"
161 } else {
162 return $finalcode
164 # stem.ext.<passnum><fam>.<passname><pass-instances>
165 # (tree)passes can have multiple instances, thus optional trailing *
166 set ptn "\[0-9\]\[0-9\]\[0-9\]$ptn.*"
167 # Handle ltrans files around -flto
168 if [regexp -- {(^|\s+)-flto(\s+|$)} $opts] {
169 verbose "Cleanup -flto seen" 4
170 set ltrans "{ltrans\[0-9\]*.,}"
171 } else {
172 set ltrans ""
174 set ptn "$ltrans$ptn"
175 verbose "Cleanup final ptn: $ptn" 4
176 set tfiles {}
177 foreach src $testcases {
178 set basename [file tail $src]
179 if { $ltrans != "" } {
180 # ??? should we use upvar 1 output_file instead of this (dup ?)
181 set stem [file rootname $basename]
182 set basename_ext [file extension $basename]
183 if {$basename_ext != ""} {
184 regsub -- {^.*\.} $basename_ext {} basename_ext
186 lappend tfiles "$stem.{$basename_ext,exe}"
187 unset basename_ext
188 } else {
189 lappend tfiles $basename
192 if { [llength $tfiles] > 1 } {
193 set tfiles [join $tfiles ","]
194 set tfiles "{$tfiles}"
196 verbose "Cleanup final testcases: $tfiles" 4
197 # We have to quote the regex
198 regsub -all {([][$^?+*()|\\{}])} "$tfiles.$ptn" {\\\1} ptn
199 set final ""
200 append final {remove-build-file }
201 append final "\"$ptn\""
202 verbose "Cleanup final: $final" 4
203 append finalcode "$final\n"
205 return $finalcode
208 # Define gcc callbacks for dg.exp.
210 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
211 # Set up the compiler flags, based on what we're going to do.
213 set options [list]
215 # Tests should be able to use "dg-do repo". However, the dg test
216 # driver checks the argument to dg-do against a list of acceptable
217 # options, and "repo" is not among them. Therefore, we resort to
218 # this ugly approach.
219 if [string match "*-frepo*" $extra_tool_flags] then {
220 set do_what "repo"
223 switch $do_what {
224 "preprocess" {
225 set compile_type "preprocess"
226 set output_file "[file rootname [file tail $prog]].i"
228 "compile" {
229 set compile_type "assembly"
230 set output_file "[file rootname [file tail $prog]].s"
232 "assemble" {
233 set compile_type "object"
234 set output_file "[file rootname [file tail $prog]].o"
236 "precompile" {
237 set compile_type "precompiled_header"
238 set output_file "[file tail $prog].gch"
240 "link" {
241 set compile_type "executable"
242 set output_file "[file rootname [file tail $prog]].exe"
243 # The following line is needed for targets like the i960 where
244 # the default output file is b.out. Sigh.
246 "repo" {
247 set compile_type "object"
248 set output_file "[file rootname [file tail $prog]].o"
250 "run" {
251 set compile_type "executable"
252 # FIXME: "./" is to cope with "." not being in $PATH.
253 # Should this be handled elsewhere?
254 # YES.
255 set output_file "./[file rootname [file tail $prog]].exe"
256 # This is the only place where we care if an executable was
257 # created or not. If it was, dg.exp will try to run it.
258 catch { remote_file build delete $output_file }
260 default {
261 perror "$do_what: not a valid dg-do keyword"
262 return ""
266 # Let { dg-final { action } } force options as returned by an
267 # optional proc ${action}_required_options.
268 upvar 2 dg-final-code finalcode
269 foreach x [split $finalcode "\n"] {
270 set finalcmd [lindex $x 0]
271 if { [info procs ${finalcmd}_required_options] != "" } {
272 set req [${finalcmd}_required_options]
273 if { $req != "" && [lsearch -exact $extra_tool_flags $req] == -1 } {
274 lappend extra_tool_flags $req
279 append finalcode [schedule-cleanups "$options $extra_tool_flags"]
280 if { $extra_tool_flags != "" } {
281 lappend options "additional_flags=$extra_tool_flags"
284 verbose "$target_compile $prog $output_file $compile_type $options" 4
285 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
287 # Look for an internal compiler error, which sometimes masks the fact
288 # that we didn't get an expected error message. XFAIL an ICE via
289 # dg-xfail-if and use { dg-prune-output ".*internal compiler error.*" }
290 # to avoid a second failure for excess errors.
291 if [string match "*internal compiler error*" $comp_output] {
292 upvar 2 name name
293 fail "$name (internal compiler error)"
296 if { $do_what == "repo" } {
297 set object_file "$output_file"
298 set output_file "[file rootname [file tail $prog]].exe"
299 set comp_output \
300 [ concat $comp_output \
301 [$target_compile "$object_file" "$output_file" \
302 "executable" $options] ]
305 return [list $comp_output $output_file]
308 proc gcc-dg-test { prog do_what extra_tool_flags } {
309 return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
312 proc gcc-dg-prune { system text } {
313 global additional_prunes
315 # Extra prune rules that will apply to tests defined in a .exp file.
316 # Always remember to clear it in .exp file after executed all tests.
317 global dg_runtest_extra_prunes
319 set text [prune_gcc_output $text]
321 foreach p "$additional_prunes $dg_runtest_extra_prunes" {
322 if { [string length $p] > 0 } {
323 # Following regexp matches a complete line containing $p.
324 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
328 # If we see "region xxx is full" then the testcase is too big for ram.
329 # This is tricky to deal with in a large testsuite like c-torture so
330 # deal with it here. Just mark the testcase as unsupported.
331 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
332 # The format here is important. See dg.exp.
333 return "::unsupported::memory full"
336 if { [regexp "(^|\n)\[^\n\]*: relocation truncated to fit" $text]
337 && [check_effective_target_tiny] } {
338 return "::unsupported::memory full"
341 # Likewise, if we see ".text exceeds local store range" or
342 # similar.
343 if {[string match "spu-*" $system] && \
344 [string match "*exceeds local store*" $text]} {
345 # The format here is important. See dg.exp.
346 return "::unsupported::memory full"
349 return $text
352 # Replace ${tool}_load with a wrapper to provide for an expected nonzero
353 # exit status. Multiple languages include this file so this handles them
354 # all, not just gcc.
355 if { [info procs ${tool}_load] != [list] \
356 && [info procs saved_${tool}_load] == [list] } {
357 rename ${tool}_load saved_${tool}_load
359 proc ${tool}_load { program args } {
360 global tool
361 global shouldfail
362 global set_target_env_var
364 set saved_target_env_var [list]
365 if { [info exists set_target_env_var] \
366 && [llength $set_target_env_var] != 0 } {
367 if { [is_remote target] } {
368 return [list "unsupported" ""]
370 set-target-env-var
372 set result [eval [list saved_${tool}_load $program] $args]
373 if { [info exists set_target_env_var] \
374 && [llength $set_target_env_var] != 0 } {
375 restore-target-env-var
377 if { $shouldfail != 0 } {
378 switch [lindex $result 0] {
379 "pass" { set status "fail" }
380 "fail" { set status "pass" }
382 set result [list $status [lindex $result 1]]
385 set result [list [lindex $result 0] [prune_file_path [lindex $result 1]]]
386 return $result
390 proc dg-set-target-env-var { args } {
391 global set_target_env_var
392 if { [llength $args] != 3 } {
393 error "dg-set-target-env-var: need two arguments"
394 return
396 lappend set_target_env_var [list [lindex $args 1] [lindex $args 2]]
399 proc set-target-env-var { } {
400 global set_target_env_var
401 upvar 1 saved_target_env_var saved_target_env_var
402 foreach env_var $set_target_env_var {
403 set var [lindex $env_var 0]
404 set value [lindex $env_var 1]
405 if [info exists ::env($var)] {
406 lappend saved_target_env_var [list $var 1 $::env($var)]
407 } else {
408 lappend saved_target_env_var [list $var 0]
410 setenv $var $value
414 proc restore-target-env-var { } {
415 upvar 1 saved_target_env_var saved_target_env_var
416 for { set env_vari [llength $saved_target_env_var] } {
417 [incr env_vari -1] >= 0 } {} {
418 set env_var [lindex $saved_target_env_var $env_vari]
419 set var [lindex $env_var 0]
420 if [lindex $env_var 1] {
421 setenv $var [lindex $env_var 2]
422 } else {
423 unsetenv $var
428 # Utility routines.
431 # search_for -- looks for a string match in a file
433 proc search_for { file pattern } {
434 set fd [open $file r]
435 while { [gets $fd cur_line]>=0 } {
436 if [string match "*$pattern*" $cur_line] then {
437 close $fd
438 return 1
441 close $fd
442 return 0
445 # Modified dg-runtest that can cycle through a list of optimization options
446 # as c-torture does.
447 proc gcc-dg-runtest { testcases flags default-extra-flags } {
448 global runtests
450 # Some callers set torture options themselves; don't override those.
451 set existing_torture_options [torture-options-exist]
452 if { $existing_torture_options == 0 } {
453 global DG_TORTURE_OPTIONS LTO_TORTURE_OPTIONS
454 torture-init
455 set-torture-options $DG_TORTURE_OPTIONS [list {}] $LTO_TORTURE_OPTIONS
457 dump-torture-options
459 foreach test $testcases {
460 global torture_with_loops torture_without_loops
461 # If we're only testing specific files and this isn't one of
462 # them, skip it.
463 if ![runtest_file_p $runtests $test] {
464 continue
467 # Look for a loop within the source code - if we don't find one,
468 # don't pass -funroll[-all]-loops.
469 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
470 set option_list $torture_with_loops
471 } else {
472 set option_list $torture_without_loops
475 set nshort [file tail [file dirname $test]]/[file tail $test]
477 foreach flags_t $option_list {
478 verbose "Testing $nshort, $flags $flags_t" 1
479 dg-test $test "$flags $flags_t" ${default-extra-flags}
483 if { $existing_torture_options == 0 } {
484 torture-finish
488 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
489 global srcdir subdir
491 if ![info exists DEBUG_TORTURE_OPTIONS] {
492 set DEBUG_TORTURE_OPTIONS ""
493 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
494 set comp_output [$target_compile \
495 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
496 "additional_flags=$type"]
497 if { ! [string match "*: target system does not support the * debug format*" \
498 $comp_output] } {
499 remove-build-file "trivial.S"
500 foreach level {1 "" 3} {
501 if { ($type == "-gdwarf-2") && ($level != "") } {
502 lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
503 foreach opt $opt_opts {
504 lappend DEBUG_TORTURE_OPTIONS \
505 [list "${type}" "-g${level}" "$opt" ]
507 } else {
508 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
509 foreach opt $opt_opts {
510 lappend DEBUG_TORTURE_OPTIONS \
511 [list "${type}${level}" "$opt" ]
519 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
521 global runtests
523 foreach test $testcases {
524 # If we're only testing specific files and this isn't one of
525 # them, skip it.
526 if ![runtest_file_p $runtests $test] {
527 continue
530 set nshort [file tail [file dirname $test]]/[file tail $test]
532 foreach flags $DEBUG_TORTURE_OPTIONS {
533 set doit 1
535 # These tests check for information which may be deliberately
536 # suppressed at -g1.
537 if { ([string match {*/debug-[126].c} "$nshort"] \
538 || [string match {*/enum-1.c} "$nshort"] \
539 || [string match {*/enum-[12].C} "$nshort"]) \
540 && ([string match "*1" [lindex "$flags" 0] ]
541 || [lindex "$flags" 1] == "-g1") } {
542 set doit 0
545 # High optimization can remove the variable whose existence is tested.
546 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
547 # assembler output, but stabs debugging does not.
548 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
549 if { [string match {*/debug-[12].c} "$nshort"] \
550 && [string match "*O*" "$flags"] \
551 && ( [string match "*coff*" "$flags"] \
552 || [string match "*stabs*" "$flags"] ) } {
553 set doit 0
556 if { $doit } {
557 verbose -log "Testing $nshort, $flags" 1
558 dg-test $test $flags ""
564 # Prune any messages matching ARGS[1] (a regexp) from test output.
565 proc dg-prune-output { args } {
566 global additional_prunes
568 if { [llength $args] != 2 } {
569 error "[lindex $args 1]: need one argument"
570 return
573 lappend additional_prunes [lindex $args 1]
576 # Remove files matching the pattern from the build machine.
577 proc remove-build-file { pat } {
578 verbose "remove-build-file `$pat'" 2
579 set file_list "[glob -nocomplain $pat]"
580 verbose "remove-build-file `$file_list'" 2
581 foreach output_file $file_list {
582 if [is_remote host] {
583 # Ensure the host knows the file is gone by deleting there
584 # first.
585 remote_file host delete $output_file
587 remote_file build delete $output_file
591 # Remove runtime-generated profile file for the current test.
592 proc cleanup-profile-file { } {
593 remove-build-file "mon.out"
594 remove-build-file "gmon.out"
597 # Remove compiler-generated coverage files for the current test.
598 proc cleanup-coverage-files { } {
599 global additional_sources_used
600 set testcase [testname-for-summary]
601 # The name might include a list of options; extract the file name.
602 set testcase [lindex $testcase 0]
603 remove-build-file "[file rootname [file tail $testcase]].gc??"
605 # Clean up coverage files for additional source files.
606 if [info exists additional_sources_used] {
607 foreach srcfile $additional_sources_used {
608 remove-build-file "[file rootname [file tail $srcfile]].gc??"
613 # Remove compiler-generated files from -repo for the current test.
614 proc cleanup-repo-files { } {
615 global additional_sources_used
616 set testcase [testname-for-summary]
617 # The name might include a list of options; extract the file name.
618 set testcase [lindex $testcase 0]
619 remove-build-file "[file rootname [file tail $testcase]].o"
620 remove-build-file "[file rootname [file tail $testcase]].rpo"
622 # Clean up files for additional source files.
623 if [info exists additional_sources_used] {
624 foreach srcfile $additional_sources_used {
625 remove-build-file "[file rootname [file tail $srcfile]].o"
626 remove-build-file "[file rootname [file tail $srcfile]].rpo"
631 # Remove a final insns dump file for the current test.
632 proc cleanup-final-insns-dump { } {
633 set testcase [testname-for-summary]
634 # The name might include a list of options; extract the file name.
635 set testcase [lindex $testcase 0]
636 remove-build-file "[file rootname [file tail $testcase]].s.gkd"
638 # Clean up files for additional source files.
639 if [info exists additional_sources_used] {
640 foreach srcfile $additional_sources_used {
641 remove-build-file "[file rootname [file tail $srcfile]].s.gkd"
646 # Remove a stack usage file for the current test.
647 proc cleanup-stack-usage { } {
648 set testcase [testname-for-summary]
649 # The name might include a list of options; extract the file name.
650 set testcase [lindex $testcase 0]
651 remove-build-file "[file rootname [file tail $testcase]].su"
653 # Clean up files for additional source files.
654 if [info exists additional_sources_used] {
655 foreach srcfile $additional_sources_used {
656 remove-build-file "[file rootname [file tail $srcfile]].su"
661 # Remove an Ada spec file for the current test.
662 proc cleanup-ada-spec { } {
663 global additional_sources_used
664 set testcase [testname-for-summary]
665 remove-build-file "[get_ada_spec_filename $testcase]"
667 # Clean up files for additional source files.
668 if [info exists additional_sources_used] {
669 foreach srcfile $additional_sources_used {
670 remove-build-file "[get_ada_spec_filename $srcfile]"
675 # Remove files kept by --save-temps for the current test.
677 # Currently this is only .i, .ii, .s and .o files, but more can be added
678 # if there are tests generating them.
679 # ARGS is a list of suffixes to NOT delete.
680 proc cleanup-saved-temps { args } {
681 global additional_sources_used
682 set suffixes {}
684 # add the to-be-kept suffixes
685 foreach suffix {".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
686 if {[lsearch $args $suffix] < 0} {
687 lappend suffixes $suffix
691 set testcase [testname-for-summary]
692 # The name might include a list of options; extract the file name.
693 set testcase [lindex $testcase 0]
694 foreach suffix $suffixes {
695 remove-build-file "[file rootname [file tail $testcase]]$suffix"
696 remove-build-file "[file rootname [file tail $testcase]].exe$suffix"
697 remove-build-file "[file rootname [file tail $testcase]].exe.ltrans\[0-9\]*$suffix"
698 # -fcompare-debug dumps
699 remove-build-file "[file rootname [file tail $testcase]].gk$suffix"
702 # Clean up saved temp files for additional source files.
703 if [info exists additional_sources_used] {
704 foreach srcfile $additional_sources_used {
705 foreach suffix $suffixes {
706 remove-build-file "[file rootname [file tail $srcfile]]$suffix"
707 remove-build-file "[file rootname [file tail $srcfile]].exe$suffix"
708 remove-build-file "[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*$suffix"
710 # -fcompare-debug dumps
711 remove-build-file "[file rootname [file tail $srcfile]].gk$suffix"
718 # Files to be kept after cleanup of --save-temps for the current test.
719 # ARGS is a list of suffixes to NOT delete.
720 proc dg-keep-saved-temps { args } {
721 global keep_saved_temps_suffixes
722 set keep_saved_temps_suffixes {}
724 # add the to-be-kept suffixes
725 foreach suffix {".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
726 if {[lsearch $args $suffix] >= 0} {
727 lappend keep_saved_temps_suffixes $suffix
730 if { [llength keep_saved_temps_suffixes] < 1 } {
731 error "dg-keep-saved-temps ${args} did not match any known suffix"
735 # Scan Fortran modules for a given regexp.
737 # Argument 0 is the module name
738 # Argument 1 is the regexp to match
739 proc scan-module { args } {
740 set modfilename [string tolower [lindex $args 0]].mod
741 set fd [open [list | gzip -dc $modfilename] r]
742 set text [read $fd]
743 close $fd
745 set testcase [testname-for-summary]
746 if [regexp -- [lindex $args 1] $text] {
747 pass "$testcase scan-module [lindex $args 1]"
748 } else {
749 fail "$testcase scan-module [lindex $args 1]"
753 # Scan Fortran modules for absence of a given regexp.
755 # Argument 0 is the module name
756 # Argument 1 is the regexp to match
757 proc scan-module-absence { args } {
758 set modfilename [string tolower [lindex $args 0]].mod
759 set fd [open [list | gzip -dc $modfilename] r]
760 set text [read $fd]
761 close $fd
763 set testcase [testname-for-summary]
764 if [regexp -- [lindex $args 1] $text] {
765 fail "$testcase scan-module [lindex $args 1]"
766 } else {
767 pass "$testcase scan-module [lindex $args 1]"
771 # Verify that the compiler output file exists, invoked via dg-final.
772 proc output-exists { args } {
773 # Process an optional target or xfail list.
774 if { [llength $args] >= 1 } {
775 switch [dg-process-target [lindex $args 0]] {
776 "S" { }
777 "N" { return }
778 "F" { setup_xfail "*-*-*" }
779 "P" { }
783 set testcase [testname-for-summary]
784 # Access variable from gcc-dg-test-1.
785 upvar 2 output_file output_file
787 if [file exists $output_file] {
788 pass "$testcase output-exists $output_file"
789 } else {
790 fail "$testcase output-exists $output_file"
794 # Verify that the compiler output file does not exist, invoked via dg-final.
795 proc output-exists-not { args } {
796 # Process an optional target or xfail list.
797 if { [llength $args] >= 1 } {
798 switch [dg-process-target [lindex $args 0]] {
799 "S" { }
800 "N" { return }
801 "F" { setup_xfail "*-*-*" }
802 "P" { }
806 set testcase [testname-for-summary]
807 # Access variable from gcc-dg-test-1.
808 upvar 2 output_file output_file
810 if [file exists $output_file] {
811 fail "$testcase output-exists-not $output_file"
812 } else {
813 pass "$testcase output-exists-not $output_file"
817 # We need to make sure that additional_* are cleared out after every
818 # test. It is not enough to clear them out *before* the next test run
819 # because gcc-target-compile gets run directly from some .exp files
820 # (outside of any test). (Those uses should eventually be eliminated.)
822 # Because the DG framework doesn't provide a hook that is run at the
823 # end of a test, we must replace dg-test with a wrapper.
825 if { [info procs saved-dg-test] == [list] } {
826 rename dg-test saved-dg-test
828 proc dg-test { args } {
829 global additional_files
830 global additional_sources
831 global additional_prunes
832 global errorInfo
833 global compiler_conditional_xfail_data
834 global shouldfail
835 global testname_with_flags
836 global set_target_env_var
837 global keep_saved_temps_suffixes
839 if { [ catch { eval saved-dg-test $args } errmsg ] } {
840 set saved_info $errorInfo
841 set additional_files ""
842 set additional_sources ""
843 set additional_sources_used ""
844 set additional_prunes ""
845 set shouldfail 0
846 if [info exists compiler_conditional_xfail_data] {
847 unset compiler_conditional_xfail_data
849 if [info exists testname_with_flags] {
850 unset testname_with_flags
852 unset_timeout_vars
853 error $errmsg $saved_info
855 set additional_files ""
856 set additional_sources ""
857 set additional_sources_used ""
858 set additional_prunes ""
859 set shouldfail 0
860 if [info exists set_target_env_var] {
861 unset set_target_env_var
863 if [info exists keep_saved_temps_suffixes] {
864 unset keep_saved_temps_suffixes
866 unset_timeout_vars
867 if [info exists compiler_conditional_xfail_data] {
868 unset compiler_conditional_xfail_data
870 if [info exists testname_with_flags] {
871 unset testname_with_flags
876 if { [info procs saved-dg-warning] == [list] \
877 && [info exists gcc_warning_prefix] } {
878 rename dg-warning saved-dg-warning
880 proc dg-warning { args } {
881 # Make this variable available here and to the saved proc.
882 upvar dg-messages dg-messages
883 global gcc_warning_prefix
885 process-message saved-dg-warning "$gcc_warning_prefix" "$args"
889 if { [info procs saved-dg-error] == [list] \
890 && [info exists gcc_error_prefix] } {
891 rename dg-error saved-dg-error
893 proc dg-error { args } {
894 # Make this variable available here and to the saved proc.
895 upvar dg-messages dg-messages
896 global gcc_error_prefix
898 process-message saved-dg-error "$gcc_error_prefix" "$args"
901 # Override dg-bogus at the same time. It doesn't handle a prefix
902 # but its expression should include a column number. Otherwise the
903 # line number can match the column number for other messages, leading
904 # to insanity.
905 rename dg-bogus saved-dg-bogus
907 proc dg-bogus { args } {
908 upvar dg-messages dg-messages
909 process-message saved-dg-bogus "" $args
913 # Modify the regular expression saved by a DejaGnu message directive to
914 # include a prefix and to force the expression to match a single line.
915 # MSGPROC is the procedure to call.
916 # MSGPREFIX is the prefix to prepend.
917 # DGARGS is the original argument list.
919 proc process-message { msgproc msgprefix dgargs } {
920 upvar dg-messages dg-messages
922 # Process the dg- directive, including adding the regular expression
923 # to the new message entry in dg-messages.
924 set msgcnt [llength ${dg-messages}]
925 eval $msgproc $dgargs
927 # If the target expression wasn't satisfied there is no new message.
928 if { [llength ${dg-messages}] == $msgcnt } {
929 return;
932 # Get the entry for the new message. Prepend the message prefix to
933 # the regular expression and make it match a single line.
934 set newentry [lindex ${dg-messages} end]
935 set expmsg [lindex $newentry 2]
937 # Handle column numbers from the specified expression (if there is
938 # one) and set up the search expression that will be used by DejaGnu.
939 if [regexp "^(\[0-9\]+):" $expmsg "" column] {
940 # The expression in the directive included a column number.
941 # Remove "COLUMN:" from the original expression and move it
942 # to the proper place in the search expression.
943 regsub "^\[0-9\]+:" $expmsg "" expmsg
944 set expmsg "$column: $msgprefix\[^\n\]*$expmsg"
945 } elseif [string match "" [lindex $newentry 0]] {
946 # The specified line number is 0; don't expect a column number.
947 set expmsg "$msgprefix\[^\n\]*$expmsg"
948 } else {
949 # There is no column number in the search expression, but we
950 # should expect one in the message itself.
951 set expmsg "\[0-9\]+: $msgprefix\[^\n\]*$expmsg"
954 set newentry [lreplace $newentry 2 2 $expmsg]
955 set dg-messages [lreplace ${dg-messages} end end $newentry]
956 verbose "process-message:\n${dg-messages}" 2
959 # Look for messages that don't have standard prefixes.
961 proc dg-message { args } {
962 upvar dg-messages dg-messages
963 process-message saved-dg-warning "" $args
966 # Check the existence of a gdb in the path, and return true if there
967 # is one.
969 # Set env(GDB_FOR_GCC_TESTING) accordingly.
971 proc gdb-exists { args } {
972 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
973 global GDB
974 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
975 if [info exists GDB] {
976 setenv GDB_FOR_GCC_TESTING "$GDB"
977 } else {
978 setenv GDB_FOR_GCC_TESTING "[transform gdb]"
982 if { [which $::env(GDB_FOR_GCC_TESTING)] != 0 } {
983 return 1;
985 return 0;
988 set additional_prunes ""
989 set dg_runtest_extra_prunes ""