2015-06-22 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / lib / gcc-dg.exp
blob00ca0c5d116d0b77697bf9c7e08361b3222c4a0a
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 set LTO_TORTURE_OPTIONS ""
50 if [info exists TORTURE_OPTIONS] {
51 set DG_TORTURE_OPTIONS $TORTURE_OPTIONS
52 } else {
53 # It is theoretically beneficial to group all of the O2/O3 options together,
54 # as in many cases the compiler will generate identical executables for
55 # all of them--and the c-torture testsuite will skip testing identical
56 # executables multiple times.
57 # Also note that -finline-functions is explicitly included in one of the
58 # items below, even though -O3 is also specified, because some ports may
59 # choose to disable inlining functions by default, even when optimizing.
60 set DG_TORTURE_OPTIONS [list \
61 { -O0 } \
62 { -O1 } \
63 { -O2 } \
64 { -O3 -fomit-frame-pointer } \
65 { -O3 -fomit-frame-pointer -funroll-loops } \
66 { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
67 { -O3 -g } \
68 { -Os } ]
70 if [check_effective_target_lto] {
71 # When having plugin test both slim and fat LTO and plugin/nonplugin
72 # path.
73 if [check_linker_plugin_available] {
74 set LTO_TORTURE_OPTIONS [list \
75 { -O2 -flto -fno-use-linker-plugin -flto-partition=none } \
76 { -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects }
78 set gcc_force_conventional_output "-ffat-lto-objects"
79 } else {
80 set LTO_TORTURE_OPTIONS [list \
81 { -O2 -flto -flto-partition=none } \
82 { -O2 -flto }
88 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
89 set DG_TORTURE_OPTIONS \
90 [concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
93 global orig_environment_saved
95 # This file may be sourced, so don't override environment settings
96 # that have been previously setup.
97 if { $orig_environment_saved == 0 } {
98 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
99 set_ld_library_path_env_vars
102 # Some torture-options cause intermediate code output, unusable for
103 # testing using e.g. scan-assembler. In this variable are the options
104 # how to force it, when needed.
105 global gcc_force_conventional_output
106 set gcc_force_conventional_output ""
108 # Deduce generated files from tool flags, return finalcode string
109 proc schedule-cleanups { opts } {
110 global additional_sources
111 set finalcode ""
112 set testcases {}
113 lappend testcases [lindex [testname-for-summary] 0]
114 verbose "Cleanup testcases: $testcases" 4
115 if { [info exists additional_sources] && $additional_sources != "" } {
116 lappend testcases $additional_sources
117 verbose "Cleanup testcases, additional: $additional_sources" 4
119 verbose "Cleanup all options: $opts" 4
121 # First some fixups to transform stuff to something manageable ..
122 # --dump= should translate to -d with joined operand.
123 if [regexp -- {(^|\s+)--dump=[^\s]+(\s+|$)} $opts] {
124 regsub -all -- {--dump=} $opts {-d} opts
126 # -da and -dx are treated as shorthand for -fdump-rtl-all here
127 if [regexp -- {(^|\s+)-d[ax](\s+|$)} $opts] {
128 verbose "Cleanup -d seen" 4
129 lappend opts "-fdump-rtl-all"
131 # .. and don't question why there is --dump=? and -d?
133 # Then handle options that generate non-dump files
134 # TODO
135 # -fprofile-generate -> cleanup-coverage-files()
136 # -fstack-usage -> cleanup-stack-usage()
137 if [regexp -- {(^|\s+)-fstack-usage(\s+|$)} $opts] {
138 verbose "Cleanup -fstack-usage seen" 4
139 # append finalcode "cleanup-stack-usage\n"
141 global keep_saved_temps_suffixes
142 if [info exists keep_saved_temps_suffixes ] {
143 verbose "dg-keep-saved-temps ${keep_saved_temps_suffixes}" 2
145 # -save-temps -> cleanup-saved-temps()
146 if [regexp -- {(^|\s+)-save-temps(\s+|$)} $opts] {
147 verbose "Cleanup -save-temps seen" 4
148 if [info exists keep_saved_temps_suffixes] {
149 append finalcode "cleanup-saved-temps ${keep_saved_temps_suffixes}\n"
150 } else {
151 append finalcode "cleanup-saved-temps\n"
153 } else {
154 if [info exists keep_saved_temps_suffixes ] {
155 error "dg-keep-saved-temps specified but testcase does not -save-temps"
156 return
159 # Finally see if there are any dumps in opts, otherwise we are done
160 if [regexp -- {(?=(?:^|[ \t]+)?)-fdump-[^ \t]+(?=(?:$|[ \t]+)?)} $opts] {
161 # Ipa, Rtl, Tree for simplicity
162 set ptn "{i,r,t}"
163 } else {
164 return $finalcode
166 # stem.ext.<passnum><fam>.<passname><pass-instances>
167 # (tree)passes can have multiple instances, thus optional trailing *
168 set ptn "\[0-9\]\[0-9\]\[0-9\]$ptn.*"
169 # Handle ltrans files around -flto
170 if [regexp -- {(^|\s+)-flto(\s+|$)} $opts] {
171 verbose "Cleanup -flto seen" 4
172 set ltrans "{ltrans\[0-9\]*.,}"
173 } else {
174 set ltrans ""
176 set ptn "$ltrans$ptn"
177 verbose "Cleanup final ptn: $ptn" 4
178 set tfiles {}
179 foreach src $testcases {
180 set basename [file tail $src]
181 if { $ltrans != "" } {
182 # ??? should we use upvar 1 output_file instead of this (dup ?)
183 set stem [file rootname $basename]
184 set basename_ext [file extension $basename]
185 if {$basename_ext != ""} {
186 regsub -- {^.*\.} $basename_ext {} basename_ext
188 lappend tfiles "$stem.{$basename_ext,exe}"
189 unset basename_ext
190 } else {
191 lappend tfiles $basename
194 if { [llength $tfiles] > 1 } {
195 set tfiles [join $tfiles ","]
196 set tfiles "{$tfiles}"
198 verbose "Cleanup final testcases: $tfiles" 4
199 # We have to quote the regex
200 regsub -all {([][$^?+*()|\\{}])} "$tfiles.$ptn" {\\\1} ptn
201 set final ""
202 append final {remove-build-file }
203 append final "\"$ptn\""
204 verbose "Cleanup final: $final" 4
205 append finalcode "$final\n"
207 return $finalcode
210 # Define gcc callbacks for dg.exp.
212 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
213 # Set up the compiler flags, based on what we're going to do.
215 set options [list]
217 # Tests should be able to use "dg-do repo". However, the dg test
218 # driver checks the argument to dg-do against a list of acceptable
219 # options, and "repo" is not among them. Therefore, we resort to
220 # this ugly approach.
221 if [string match "*-frepo*" $extra_tool_flags] then {
222 set do_what "repo"
225 switch $do_what {
226 "preprocess" {
227 set compile_type "preprocess"
228 set output_file "[file rootname [file tail $prog]].i"
230 "compile" {
231 set compile_type "assembly"
232 set output_file "[file rootname [file tail $prog]].s"
234 "assemble" {
235 set compile_type "object"
236 set output_file "[file rootname [file tail $prog]].o"
238 "precompile" {
239 set compile_type "precompiled_header"
240 set output_file "[file tail $prog].gch"
242 "link" {
243 set compile_type "executable"
244 set output_file "[file rootname [file tail $prog]].exe"
245 # The following line is needed for targets like the i960 where
246 # the default output file is b.out. Sigh.
248 "repo" {
249 set compile_type "object"
250 set output_file "[file rootname [file tail $prog]].o"
252 "run" {
253 set compile_type "executable"
254 # FIXME: "./" is to cope with "." not being in $PATH.
255 # Should this be handled elsewhere?
256 # YES.
257 set output_file "./[file rootname [file tail $prog]].exe"
258 # This is the only place where we care if an executable was
259 # created or not. If it was, dg.exp will try to run it.
260 catch { remote_file build delete $output_file }
262 default {
263 perror "$do_what: not a valid dg-do keyword"
264 return ""
268 # Let { dg-final { action } } force options as returned by an
269 # optional proc ${action}_required_options.
270 upvar 2 dg-final-code finalcode
271 foreach x [split $finalcode "\n"] {
272 set finalcmd [lindex $x 0]
273 if { [info procs ${finalcmd}_required_options] != "" } {
274 set req [${finalcmd}_required_options]
275 if { $req != "" } {
276 lappend extra_tool_flags $req
281 append finalcode [schedule-cleanups "$options $extra_tool_flags"]
282 if { $extra_tool_flags != "" } {
283 lappend options "additional_flags=$extra_tool_flags"
286 verbose "$target_compile $prog $output_file $compile_type $options" 4
287 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
289 # Look for an internal compiler error, which sometimes masks the fact
290 # that we didn't get an expected error message. XFAIL an ICE via
291 # dg-xfail-if and use { dg-prune-output ".*internal compiler error.*" }
292 # to avoid a second failure for excess errors.
293 if [string match "*internal compiler error*" $comp_output] {
294 upvar 2 name name
295 fail "$name (internal compiler error)"
298 if { $do_what == "repo" } {
299 set object_file "$output_file"
300 set output_file "[file rootname [file tail $prog]].exe"
301 set comp_output \
302 [ concat $comp_output \
303 [$target_compile "$object_file" "$output_file" \
304 "executable" $options] ]
307 return [list $comp_output $output_file]
310 proc gcc-dg-test { prog do_what extra_tool_flags } {
311 return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
314 proc gcc-dg-prune { system text } {
315 global additional_prunes
317 # Extra prune rules that will apply to tests defined in a .exp file.
318 # Always remember to clear it in .exp file after executed all tests.
319 global dg_runtest_extra_prunes
321 set text [prune_gcc_output $text]
323 foreach p "$additional_prunes $dg_runtest_extra_prunes" {
324 if { [string length $p] > 0 } {
325 # Following regexp matches a complete line containing $p.
326 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
330 # If we see "region xxx is full" then the testcase is too big for ram.
331 # This is tricky to deal with in a large testsuite like c-torture so
332 # deal with it here. Just mark the testcase as unsupported.
333 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
334 # The format here is important. See dg.exp.
335 return "::unsupported::memory full"
338 if { [regexp "(^|\n)\[^\n\]*: relocation truncated to fit" $text]
339 && [check_effective_target_tiny] } {
340 return "::unsupported::memory full"
343 # Likewise, if we see ".text exceeds local store range" or
344 # similar.
345 if {[string match "spu-*" $system] && \
346 [string match "*exceeds local store*" $text]} {
347 # The format here is important. See dg.exp.
348 return "::unsupported::memory full"
351 return $text
354 # Replace ${tool}_load with a wrapper to provide for an expected nonzero
355 # exit status. Multiple languages include this file so this handles them
356 # all, not just gcc.
357 if { [info procs ${tool}_load] != [list] \
358 && [info procs saved_${tool}_load] == [list] } {
359 rename ${tool}_load saved_${tool}_load
361 proc ${tool}_load { program args } {
362 global tool
363 global shouldfail
364 global set_target_env_var
366 set saved_target_env_var [list]
367 if { [info exists set_target_env_var] \
368 && [llength $set_target_env_var] != 0 } {
369 if { [is_remote target] } {
370 return [list "unsupported" ""]
372 set-target-env-var
374 set result [eval [list saved_${tool}_load $program] $args]
375 if { [info exists set_target_env_var] \
376 && [llength $set_target_env_var] != 0 } {
377 restore-target-env-var
379 if { $shouldfail != 0 } {
380 switch [lindex $result 0] {
381 "pass" { set status "fail" }
382 "fail" { set status "pass" }
384 set result [list $status [lindex $result 1]]
387 set result [list [lindex $result 0] [prune_file_path [lindex $result 1]]]
388 return $result
392 proc dg-set-target-env-var { args } {
393 global set_target_env_var
394 if { [llength $args] != 3 } {
395 error "dg-set-target-env-var: need two arguments"
396 return
398 lappend set_target_env_var [list [lindex $args 1] [lindex $args 2]]
401 proc set-target-env-var { } {
402 global set_target_env_var
403 upvar 1 saved_target_env_var saved_target_env_var
404 foreach env_var $set_target_env_var {
405 set var [lindex $env_var 0]
406 set value [lindex $env_var 1]
407 if [info exists ::env($var)] {
408 lappend saved_target_env_var [list $var 1 $::env($var)]
409 } else {
410 lappend saved_target_env_var [list $var 0]
412 setenv $var $value
416 proc restore-target-env-var { } {
417 upvar 1 saved_target_env_var saved_target_env_var
418 for { set env_vari [llength $saved_target_env_var] } {
419 [incr env_vari -1] >= 0 } {} {
420 set env_var [lindex $saved_target_env_var $env_vari]
421 set var [lindex $env_var 0]
422 if [lindex $env_var 1] {
423 setenv $var [lindex $env_var 2]
424 } else {
425 unsetenv $var
430 # Utility routines.
433 # search_for -- looks for a string match in a file
435 proc search_for { file pattern } {
436 set fd [open $file r]
437 while { [gets $fd cur_line]>=0 } {
438 if [string match "*$pattern*" $cur_line] then {
439 close $fd
440 return 1
443 close $fd
444 return 0
447 # Modified dg-runtest that can cycle through a list of optimization options
448 # as c-torture does.
449 proc gcc-dg-runtest { testcases flags default-extra-flags } {
450 global runtests
452 # Some callers set torture options themselves; don't override those.
453 set existing_torture_options [torture-options-exist]
454 if { $existing_torture_options == 0 } {
455 global DG_TORTURE_OPTIONS LTO_TORTURE_OPTIONS
456 torture-init
457 set-torture-options $DG_TORTURE_OPTIONS [list {}] $LTO_TORTURE_OPTIONS
459 dump-torture-options
461 foreach test $testcases {
462 global torture_with_loops torture_without_loops
463 # If we're only testing specific files and this isn't one of
464 # them, skip it.
465 if ![runtest_file_p $runtests $test] {
466 continue
469 # Look for a loop within the source code - if we don't find one,
470 # don't pass -funroll[-all]-loops.
471 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
472 set option_list $torture_with_loops
473 } else {
474 set option_list $torture_without_loops
477 set nshort [file tail [file dirname $test]]/[file tail $test]
479 foreach flags_t $option_list {
480 verbose "Testing $nshort, $flags $flags_t" 1
481 dg-test $test "$flags $flags_t" ${default-extra-flags}
485 if { $existing_torture_options == 0 } {
486 torture-finish
490 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
491 global srcdir subdir
493 if ![info exists DEBUG_TORTURE_OPTIONS] {
494 set DEBUG_TORTURE_OPTIONS ""
495 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
496 set comp_output [$target_compile \
497 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
498 "additional_flags=$type"]
499 if { ! [string match "*: target system does not support the * debug format*" \
500 $comp_output] } {
501 remove-build-file "trivial.S"
502 foreach level {1 "" 3} {
503 if { ($type == "-gdwarf-2") && ($level != "") } {
504 lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
505 foreach opt $opt_opts {
506 lappend DEBUG_TORTURE_OPTIONS \
507 [list "${type}" "-g${level}" "$opt" ]
509 } else {
510 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
511 foreach opt $opt_opts {
512 lappend DEBUG_TORTURE_OPTIONS \
513 [list "${type}${level}" "$opt" ]
521 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
523 global runtests
525 foreach test $testcases {
526 # If we're only testing specific files and this isn't one of
527 # them, skip it.
528 if ![runtest_file_p $runtests $test] {
529 continue
532 set nshort [file tail [file dirname $test]]/[file tail $test]
534 foreach flags $DEBUG_TORTURE_OPTIONS {
535 set doit 1
537 # These tests check for information which may be deliberately
538 # suppressed at -g1.
539 if { ([string match {*/debug-[126].c} "$nshort"] \
540 || [string match {*/enum-1.c} "$nshort"] \
541 || [string match {*/enum-[12].C} "$nshort"]) \
542 && ([string match "*1" [lindex "$flags" 0] ]
543 || [lindex "$flags" 1] == "-g1") } {
544 set doit 0
547 # High optimization can remove the variable whose existence is tested.
548 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
549 # assembler output, but stabs debugging does not.
550 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
551 if { [string match {*/debug-[12].c} "$nshort"] \
552 && [string match "*O*" "$flags"] \
553 && ( [string match "*coff*" "$flags"] \
554 || [string match "*stabs*" "$flags"] ) } {
555 set doit 0
558 if { $doit } {
559 verbose -log "Testing $nshort, $flags" 1
560 dg-test $test $flags ""
566 # Prune any messages matching ARGS[1] (a regexp) from test output.
567 proc dg-prune-output { args } {
568 global additional_prunes
570 if { [llength $args] != 2 } {
571 error "[lindex $args 1]: need one argument"
572 return
575 lappend additional_prunes [lindex $args 1]
578 # Remove files matching the pattern from the build machine.
579 proc remove-build-file { pat } {
580 verbose "remove-build-file `$pat'" 2
581 set file_list "[glob -nocomplain $pat]"
582 verbose "remove-build-file `$file_list'" 2
583 foreach output_file $file_list {
584 if [is_remote host] {
585 # Ensure the host knows the file is gone by deleting there
586 # first.
587 remote_file host delete $output_file
589 remote_file build delete $output_file
593 # Remove runtime-generated profile file for the current test.
594 proc cleanup-profile-file { } {
595 remove-build-file "mon.out"
596 remove-build-file "gmon.out"
599 # Remove compiler-generated coverage files for the current test.
600 proc cleanup-coverage-files { } {
601 global additional_sources_used
602 set testcase [testname-for-summary]
603 # The name might include a list of options; extract the file name.
604 set testcase [lindex $testcase 0]
605 remove-build-file "[file rootname [file tail $testcase]].gc??"
607 # Clean up coverage files for additional source files.
608 if [info exists additional_sources_used] {
609 foreach srcfile $additional_sources_used {
610 remove-build-file "[file rootname [file tail $srcfile]].gc??"
615 # Remove compiler-generated files from -repo for the current test.
616 proc cleanup-repo-files { } {
617 global additional_sources_used
618 set testcase [testname-for-summary]
619 # The name might include a list of options; extract the file name.
620 set testcase [lindex $testcase 0]
621 remove-build-file "[file rootname [file tail $testcase]].o"
622 remove-build-file "[file rootname [file tail $testcase]].rpo"
624 # Clean up files for additional source files.
625 if [info exists additional_sources_used] {
626 foreach srcfile $additional_sources_used {
627 remove-build-file "[file rootname [file tail $srcfile]].o"
628 remove-build-file "[file rootname [file tail $srcfile]].rpo"
633 # Remove a final insns dump file for the current test.
634 proc cleanup-final-insns-dump { } {
635 set testcase [testname-for-summary]
636 # The name might include a list of options; extract the file name.
637 set testcase [lindex $testcase 0]
638 remove-build-file "[file rootname [file tail $testcase]].s.gkd"
640 # Clean up files for additional source files.
641 if [info exists additional_sources_used] {
642 foreach srcfile $additional_sources_used {
643 remove-build-file "[file rootname [file tail $srcfile]].s.gkd"
648 # Remove a stack usage file for the current test.
649 proc cleanup-stack-usage { } {
650 set testcase [testname-for-summary]
651 # The name might include a list of options; extract the file name.
652 set testcase [lindex $testcase 0]
653 remove-build-file "[file rootname [file tail $testcase]].su"
655 # Clean up files for additional source files.
656 if [info exists additional_sources_used] {
657 foreach srcfile $additional_sources_used {
658 remove-build-file "[file rootname [file tail $srcfile]].su"
663 # Remove an Ada spec file for the current test.
664 proc cleanup-ada-spec { } {
665 global additional_sources_used
666 set testcase [testname-for-summary]
667 remove-build-file "[get_ada_spec_filename $testcase]"
669 # Clean up files for additional source files.
670 if [info exists additional_sources_used] {
671 foreach srcfile $additional_sources_used {
672 remove-build-file "[get_ada_spec_filename $srcfile]"
677 # Remove files kept by --save-temps for the current test.
679 # Currently this is only .i, .ii, .s and .o files, but more can be added
680 # if there are tests generating them.
681 # ARGS is a list of suffixes to NOT delete.
682 proc cleanup-saved-temps { args } {
683 global additional_sources_used
684 set suffixes {}
686 # add the to-be-kept suffixes
687 foreach suffix {".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
688 if {[lsearch $args $suffix] < 0} {
689 lappend suffixes $suffix
693 set testcase [testname-for-summary]
694 # The name might include a list of options; extract the file name.
695 set testcase [lindex $testcase 0]
696 foreach suffix $suffixes {
697 remove-build-file "[file rootname [file tail $testcase]]$suffix"
698 remove-build-file "[file rootname [file tail $testcase]].exe$suffix"
699 remove-build-file "[file rootname [file tail $testcase]].exe.ltrans\[0-9\]*$suffix"
700 # -fcompare-debug dumps
701 remove-build-file "[file rootname [file tail $testcase]].gk$suffix"
704 # Clean up saved temp files for additional source files.
705 if [info exists additional_sources_used] {
706 foreach srcfile $additional_sources_used {
707 foreach suffix $suffixes {
708 remove-build-file "[file rootname [file tail $srcfile]]$suffix"
709 remove-build-file "[file rootname [file tail $srcfile]].exe$suffix"
710 remove-build-file "[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*$suffix"
712 # -fcompare-debug dumps
713 remove-build-file "[file rootname [file tail $srcfile]].gk$suffix"
720 # Files to be kept after cleanup of --save-temps for the current test.
721 # ARGS is a list of suffixes to NOT delete.
722 proc dg-keep-saved-temps { args } {
723 global keep_saved_temps_suffixes
724 set keep_saved_temps_suffixes {}
726 # add the to-be-kept suffixes
727 foreach suffix {".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
728 if {[lsearch $args $suffix] >= 0} {
729 lappend keep_saved_temps_suffixes $suffix
732 if { [llength keep_saved_temps_suffixes] < 1 } {
733 error "dg-keep-saved-temps ${args} did not match any known suffix"
737 # Scan Fortran modules for a given regexp.
739 # Argument 0 is the module name
740 # Argument 1 is the regexp to match
741 proc scan-module { args } {
742 set modfilename [string tolower [lindex $args 0]].mod
743 set fd [open [list | gzip -dc $modfilename] r]
744 set text [read $fd]
745 close $fd
747 set testcase [testname-for-summary]
748 if [regexp -- [lindex $args 1] $text] {
749 pass "$testcase scan-module [lindex $args 1]"
750 } else {
751 fail "$testcase scan-module [lindex $args 1]"
755 # Scan Fortran modules for absence of a given regexp.
757 # Argument 0 is the module name
758 # Argument 1 is the regexp to match
759 proc scan-module-absence { args } {
760 set modfilename [string tolower [lindex $args 0]].mod
761 set fd [open [list | gzip -dc $modfilename] r]
762 set text [read $fd]
763 close $fd
765 set testcase [testname-for-summary]
766 if [regexp -- [lindex $args 1] $text] {
767 fail "$testcase scan-module [lindex $args 1]"
768 } else {
769 pass "$testcase scan-module [lindex $args 1]"
773 # Verify that the compiler output file exists, invoked via dg-final.
774 proc output-exists { args } {
775 # Process an optional target or xfail list.
776 if { [llength $args] >= 1 } {
777 switch [dg-process-target [lindex $args 0]] {
778 "S" { }
779 "N" { return }
780 "F" { setup_xfail "*-*-*" }
781 "P" { }
785 set testcase [testname-for-summary]
786 # Access variable from gcc-dg-test-1.
787 upvar 2 output_file output_file
789 if [file exists $output_file] {
790 pass "$testcase output-exists $output_file"
791 } else {
792 fail "$testcase output-exists $output_file"
796 # Verify that the compiler output file does not exist, invoked via dg-final.
797 proc output-exists-not { args } {
798 # Process an optional target or xfail list.
799 if { [llength $args] >= 1 } {
800 switch [dg-process-target [lindex $args 0]] {
801 "S" { }
802 "N" { return }
803 "F" { setup_xfail "*-*-*" }
804 "P" { }
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 fail "$testcase output-exists-not $output_file"
814 } else {
815 pass "$testcase output-exists-not $output_file"
819 # We need to make sure that additional_* are cleared out after every
820 # test. It is not enough to clear them out *before* the next test run
821 # because gcc-target-compile gets run directly from some .exp files
822 # (outside of any test). (Those uses should eventually be eliminated.)
824 # Because the DG framework doesn't provide a hook that is run at the
825 # end of a test, we must replace dg-test with a wrapper.
827 if { [info procs saved-dg-test] == [list] } {
828 rename dg-test saved-dg-test
830 proc dg-test { args } {
831 global additional_files
832 global additional_sources
833 global additional_prunes
834 global errorInfo
835 global compiler_conditional_xfail_data
836 global shouldfail
837 global testname_with_flags
838 global set_target_env_var
839 global keep_saved_temps_suffixes
841 if { [ catch { eval saved-dg-test $args } errmsg ] } {
842 set saved_info $errorInfo
843 set additional_files ""
844 set additional_sources ""
845 set additional_sources_used ""
846 set additional_prunes ""
847 set shouldfail 0
848 if [info exists compiler_conditional_xfail_data] {
849 unset compiler_conditional_xfail_data
851 if [info exists testname_with_flags] {
852 unset testname_with_flags
854 unset_timeout_vars
855 error $errmsg $saved_info
857 set additional_files ""
858 set additional_sources ""
859 set additional_sources_used ""
860 set additional_prunes ""
861 set shouldfail 0
862 if [info exists set_target_env_var] {
863 unset set_target_env_var
865 if [info exists keep_saved_temps_suffixes] {
866 unset keep_saved_temps_suffixes
868 unset_timeout_vars
869 if [info exists compiler_conditional_xfail_data] {
870 unset compiler_conditional_xfail_data
872 if [info exists testname_with_flags] {
873 unset testname_with_flags
878 if { [info procs saved-dg-warning] == [list] \
879 && [info exists gcc_warning_prefix] } {
880 rename dg-warning saved-dg-warning
882 proc dg-warning { args } {
883 # Make this variable available here and to the saved proc.
884 upvar dg-messages dg-messages
885 global gcc_warning_prefix
887 process-message saved-dg-warning "$gcc_warning_prefix" "$args"
891 if { [info procs saved-dg-error] == [list] \
892 && [info exists gcc_error_prefix] } {
893 rename dg-error saved-dg-error
895 proc dg-error { args } {
896 # Make this variable available here and to the saved proc.
897 upvar dg-messages dg-messages
898 global gcc_error_prefix
900 process-message saved-dg-error "$gcc_error_prefix" "$args"
903 # Override dg-bogus at the same time. It doesn't handle a prefix
904 # but its expression should include a column number. Otherwise the
905 # line number can match the column number for other messages, leading
906 # to insanity.
907 rename dg-bogus saved-dg-bogus
909 proc dg-bogus { args } {
910 upvar dg-messages dg-messages
911 process-message saved-dg-bogus "" $args
915 # Modify the regular expression saved by a DejaGnu message directive to
916 # include a prefix and to force the expression to match a single line.
917 # MSGPROC is the procedure to call.
918 # MSGPREFIX is the prefix to prepend.
919 # DGARGS is the original argument list.
921 proc process-message { msgproc msgprefix dgargs } {
922 upvar dg-messages dg-messages
924 # Process the dg- directive, including adding the regular expression
925 # to the new message entry in dg-messages.
926 set msgcnt [llength ${dg-messages}]
927 eval $msgproc $dgargs
929 # If the target expression wasn't satisfied there is no new message.
930 if { [llength ${dg-messages}] == $msgcnt } {
931 return;
934 # Get the entry for the new message. Prepend the message prefix to
935 # the regular expression and make it match a single line.
936 set newentry [lindex ${dg-messages} end]
937 set expmsg [lindex $newentry 2]
939 # Handle column numbers from the specified expression (if there is
940 # one) and set up the search expression that will be used by DejaGnu.
941 if [regexp "^(\[0-9\]+):" $expmsg "" column] {
942 # The expression in the directive included a column number.
943 # Remove "COLUMN:" from the original expression and move it
944 # to the proper place in the search expression.
945 regsub "^\[0-9\]+:" $expmsg "" expmsg
946 set expmsg "$column: $msgprefix\[^\n\]*$expmsg"
947 } elseif [string match "" [lindex $newentry 0]] {
948 # The specified line number is 0; don't expect a column number.
949 set expmsg "$msgprefix\[^\n\]*$expmsg"
950 } else {
951 # There is no column number in the search expression, but we
952 # should expect one in the message itself.
953 set expmsg "\[0-9\]+: $msgprefix\[^\n\]*$expmsg"
956 set newentry [lreplace $newentry 2 2 $expmsg]
957 set dg-messages [lreplace ${dg-messages} end end $newentry]
958 verbose "process-message:\n${dg-messages}" 2
961 # Look for messages that don't have standard prefixes.
963 proc dg-message { args } {
964 upvar dg-messages dg-messages
965 process-message saved-dg-warning "" $args
968 # Check the existence of a gdb in the path, and return true if there
969 # is one.
971 # Set env(GDB_FOR_GCC_TESTING) accordingly.
973 proc gdb-exists { args } {
974 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
975 global GDB
976 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
977 if [info exists GDB] {
978 setenv GDB_FOR_GCC_TESTING "$GDB"
979 } else {
980 setenv GDB_FOR_GCC_TESTING "[transform gdb]"
984 if { [which $::env(GDB_FOR_GCC_TESTING)] != 0 } {
985 return 1;
987 return 0;
990 set additional_prunes ""
991 set dg_runtest_extra_prunes ""