1 # Copyright (C) 1997-2018 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
24 load_lib scanltranstree.exp
26 load_lib scanwpaipa.exp
29 load_lib timeout-dg.exp
32 load_lib target-libpath.exp
33 load_lib torture-options.exp
34 load_lib fortran-modules.exp
35 load_lib multiline.exp
37 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
41 # Many hosts now default to a non-ASCII C locale, however, so
42 # they can set a charset encoding here if they need.
43 if { [ishost "*-*-cygwin*"] } {
48 # Avoid sporadic data-losses with expect
51 # Ensure GCC_COLORS is unset, for the rare testcases that verify
52 # how output is colorized.
53 if [info exists ::env(GCC_COLORS) ] {
58 if ![info exists GCC_UNDER_TEST] {
59 set GCC_UNDER_TEST "[find_gcc]"
62 # This file may be sourced, so don't override environment settings
63 # that have been previously setup.
64 if { $orig_environment_saved == 0 } {
65 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
66 set_ld_library_path_env_vars
69 # Some torture-options cause intermediate code output, unusable for
70 # testing using e.g. scan-assembler. In this variable are the options
71 # how to force it, when needed.
72 global gcc_force_conventional_output
73 set gcc_force_conventional_output ""
75 set LTO_TORTURE_OPTIONS ""
76 if [info exists TORTURE_OPTIONS] {
77 set DG_TORTURE_OPTIONS $TORTURE_OPTIONS
79 # It is theoretically beneficial to group all of the O2/O3 options together,
80 # as in many cases the compiler will generate identical executables for
81 # all of them--and the c-torture testsuite will skip testing identical
82 # executables multiple times.
83 # Also note that -finline-functions is explicitly included in one of the
84 # items below, even though -O3 is also specified, because some ports may
85 # choose to disable inlining functions by default, even when optimizing.
86 set DG_TORTURE_OPTIONS [list \
90 { -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions } \
94 if [check_effective_target_lto] {
95 # When having plugin test both slim and fat LTO and plugin/nonplugin
97 if [check_linker_plugin_available] {
98 set LTO_TORTURE_OPTIONS [list \
99 { -O2 -flto -fno-use-linker-plugin -flto-partition=none } \
100 { -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects }
103 set LTO_TORTURE_OPTIONS [list \
104 { -O2 -flto -flto-partition=none } \
108 set gcc_force_conventional_output "-ffat-lto-objects"
112 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
113 set DG_TORTURE_OPTIONS \
114 [concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
117 proc dg-final { args } {
118 upvar dg-final-code final-code
120 if { [llength $args] > 2 } {
121 error "[lindex $args 0]: too many arguments"
123 set line [lindex $args 0]
124 set code [lindex $args 1]
125 set directive [lindex $code 0]
128 set code [linsert $code 1 $line]
131 append final-code "$code\n"
134 global orig_environment_saved
136 # Deduce generated files from tool flags, return finalcode string
137 proc schedule-cleanups { opts } {
138 global additional_sources
141 lappend testcases [lindex [testname-for-summary] 0]
142 verbose "Cleanup testcases: $testcases" 4
143 if { [info exists additional_sources] && $additional_sources != "" } {
144 lappend testcases $additional_sources
145 verbose "Cleanup testcases, additional: $additional_sources" 4
147 verbose "Cleanup all options: $opts" 4
149 # First some fixups to transform stuff to something manageable ..
150 # --dump= should translate to -d with joined operand.
151 if [regexp -- {(^|\s+)--dump=[^\s]+(\s+|$)} $opts] {
152 regsub -all -- {--dump=} $opts {-d} opts
154 # -da and -dx are treated as shorthand for -fdump-rtl-all here
155 if [regexp -- {(^|\s+)-d[ax](\s+|$)} $opts] {
156 verbose "Cleanup -d seen" 4
157 lappend opts "-fdump-rtl-all"
159 # .. and don't question why there is --dump=? and -d?
161 # Then handle options that generate non-dump files
163 # -fprofile-generate -> cleanup-coverage-files()
164 # -fstack-usage -> cleanup-stack-usage()
165 if [regexp -- {(^|\s+)-fstack-usage(\s+|$)} $opts] {
166 verbose "Cleanup -fstack-usage seen" 4
167 # append finalcode "cleanup-stack-usage\n"
169 global keep_saved_temps_suffixes
170 if [info exists keep_saved_temps_suffixes ] {
171 verbose "dg-keep-saved-temps ${keep_saved_temps_suffixes}" 2
173 # -save-temps -> cleanup-saved-temps()
174 if [regexp -- {(^|\s+)-save-temps(\s+|$)} $opts] {
175 verbose "Cleanup -save-temps seen" 4
176 if [info exists keep_saved_temps_suffixes] {
177 append finalcode "cleanup-saved-temps ${keep_saved_temps_suffixes}\n"
179 append finalcode "cleanup-saved-temps\n"
182 if [info exists keep_saved_temps_suffixes ] {
183 error "dg-keep-saved-temps specified but testcase does not -save-temps"
187 # Finally see if there are any dumps in opts, otherwise we are done
188 if [regexp -- {(?=(?:^|[ \t]+)?)-fdump-[^ \t]+(?=(?:$|[ \t]+)?)} $opts] {
189 # Lang, Ipa, Rtl, Tree for simplicity
194 # stem.ext.<passnum><fam>.<passname><pass-instances>
195 # (tree)passes can have multiple instances, thus optional trailing *
196 set ptn "\[0-9\]\[0-9\]\[0-9\]$ptn.*"
197 # Handle ltrans files around -flto
198 if [regexp -- {(^|\s+)-flto(\s+|$)} $opts] {
199 verbose "Cleanup -flto seen" 4
200 set ltrans "{ltrans\[0-9\]*.,}"
204 set ptn "$ltrans$ptn"
205 verbose "Cleanup final ptn: $ptn" 4
207 foreach src $testcases {
208 set basename [file tail $src]
209 if { $ltrans != "" } {
210 # ??? should we use upvar 1 output_file instead of this (dup ?)
211 set stem [file rootname $basename]
212 set basename_ext [file extension $basename]
213 if {$basename_ext != ""} {
214 regsub -- {^.*\.} $basename_ext {} basename_ext
216 lappend tfiles "$stem.{$basename_ext,exe}"
219 lappend tfiles $basename
222 if { [llength $tfiles] > 1 } {
223 set tfiles [join $tfiles ","]
224 set tfiles "{$tfiles}"
226 verbose "Cleanup final testcases: $tfiles" 4
227 # We have to quote the regex
228 regsub -all {([][$^?+*()|\\{}])} "$tfiles.$ptn" {\\\1} ptn
230 append final {remove-build-file }
231 append final "\"$ptn\""
232 verbose "Cleanup final: $final" 4
233 append finalcode "$final\n"
238 # Define gcc callbacks for dg.exp.
240 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
241 # Set up the compiler flags, based on what we're going to do.
245 # Tests should be able to use "dg-do repo". However, the dg test
246 # driver checks the argument to dg-do against a list of acceptable
247 # options, and "repo" is not among them. Therefore, we resort to
248 # this ugly approach.
249 if [string match "*-frepo*" $extra_tool_flags] then {
255 set compile_type "preprocess"
256 set output_file "[file rootname [file tail $prog]].i"
259 set compile_type "assembly"
260 set output_file "[file rootname [file tail $prog]].s"
263 set compile_type "object"
264 set output_file "[file rootname [file tail $prog]].o"
267 set compile_type "precompiled_header"
268 set output_file "[file tail $prog].gch"
271 set compile_type "executable"
272 set output_file "[file rootname [file tail $prog]].exe"
273 # The following line is needed for targets like the i960 where
274 # the default output file is b.out. Sigh.
277 set compile_type "object"
278 set output_file "[file rootname [file tail $prog]].o"
281 set compile_type "executable"
282 # FIXME: "./" is to cope with "." not being in $PATH.
283 # Should this be handled elsewhere?
285 set output_file "./[file rootname [file tail $prog]].exe"
286 # This is the only place where we care if an executable was
287 # created or not. If it was, dg.exp will try to run it.
288 catch { remote_file build delete $output_file }
291 perror "$do_what: not a valid dg-do keyword"
296 # Let { dg-final { action } } force options as returned by an
297 # optional proc ${action}_required_options.
298 upvar 2 dg-final-code finalcode
299 foreach x [split $finalcode "\n"] {
300 set finalcmd [lindex $x 0]
301 if { [info procs ${finalcmd}_required_options] != "" } {
302 foreach req [${finalcmd}_required_options] {
304 && [lsearch -exact $extra_tool_flags $req] == -1 } {
305 lappend extra_tool_flags $req
311 append finalcode [schedule-cleanups "$options $extra_tool_flags"]
312 if { $extra_tool_flags != "" } {
313 lappend options "additional_flags=$extra_tool_flags"
316 verbose "$target_compile $prog $output_file $compile_type $options" 4
317 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
319 # Look for an internal compiler error, which sometimes masks the fact
320 # that we didn't get an expected error message. XFAIL an ICE via
321 # dg-xfail-if and use { dg-prune-output ".*internal compiler error.*" }
322 # to avoid a second failure for excess errors.
323 if [string match "*internal compiler error*" $comp_output] {
325 fail "$name (internal compiler error)"
328 if { $do_what == "repo" } {
329 set object_file "$output_file"
330 set output_file "[file rootname [file tail $prog]].exe"
332 [ concat $comp_output \
333 [$target_compile "$object_file" "$output_file" \
334 "executable" $options] ]
337 return [list $comp_output $output_file]
340 proc gcc-dg-test { prog do_what extra_tool_flags } {
341 return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
344 # Global: should blank lines be allowed in the output?
345 # By default, they should not be. (PR other/69006)
346 # However, there are some ways for them to validly occur.
347 set allow_blank_lines 0
349 # A command for use by testcases to mark themselves as expecting
350 # blank lines in the output.
352 proc dg-allow-blank-lines-in-output { args } {
353 global allow_blank_lines
354 set allow_blank_lines 1
357 proc gcc-dg-prune { system text } {
358 global additional_prunes
360 # Extra prune rules that will apply to tests defined in a .exp file.
361 # Always remember to clear it in .exp file after executed all tests.
362 global dg_runtest_extra_prunes
364 # Complain about blank lines in the output (PR other/69006)
365 global allow_blank_lines
366 if { !$allow_blank_lines } {
367 set num_blank_lines [llength [regexp -all -inline "\n\n" $text]]
368 if { $num_blank_lines } {
369 global testname_with_flags
370 fail "$testname_with_flags $num_blank_lines blank line(s) in output"
372 set allow_blank_lines 0
375 set text [prune_gcc_output $text]
377 foreach p "$additional_prunes $dg_runtest_extra_prunes" {
378 if { [string length $p] > 0 } {
379 # Following regexp matches a complete line containing $p.
380 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
384 # If we see "region xxx is full" then the testcase is too big for ram.
385 # This is tricky to deal with in a large testsuite like c-torture so
386 # deal with it here. Just mark the testcase as unsupported.
387 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
388 # The format here is important. See dg.exp.
389 return "::unsupported::memory full"
392 if { [regexp "(^|\n)\[^\n\]*: relocation truncated to fit" $text]
393 && [check_effective_target_tiny] } {
394 return "::unsupported::memory full"
397 # Likewise, if we see ".text exceeds local store range" or
399 if {[string match "spu-*" $system] && \
400 [string match "*exceeds local store*" $text]} {
401 # The format here is important. See dg.exp.
402 return "::unsupported::memory full"
408 # Replace ${tool}_load with a wrapper to provide for an expected nonzero
409 # exit status. Multiple languages include this file so this handles them
411 if { [info procs ${tool}_load] != [list] \
412 && [info procs saved_${tool}_load] == [list] } {
413 rename ${tool}_load saved_${tool}_load
415 proc ${tool}_load { program args } {
418 global set_target_env_var
420 set saved_target_env_var [list]
421 if { [info exists set_target_env_var] \
422 && [llength $set_target_env_var] != 0 } {
423 if { [is_remote target] } {
424 return [list "unsupported" ""]
428 set result [eval [list saved_${tool}_load $program] $args]
429 if { [info exists set_target_env_var] \
430 && [llength $set_target_env_var] != 0 } {
431 restore-target-env-var
433 if { $shouldfail != 0 } {
434 switch [lindex $result 0] {
435 "pass" { set status "fail" }
436 "fail" { set status "pass" }
437 default { set status [lindex $result 0] }
439 set result [list $status [lindex $result 1]]
442 set result [list [lindex $result 0] [prune_file_path [lindex $result 1]]]
447 proc dg-set-target-env-var { args } {
448 global set_target_env_var
449 if { [llength $args] != 3 } {
450 error "dg-set-target-env-var: need two arguments"
453 lappend set_target_env_var [list [lindex $args 1] [lindex $args 2]]
456 proc set-target-env-var { } {
457 global set_target_env_var
458 upvar 1 saved_target_env_var saved_target_env_var
459 foreach env_var $set_target_env_var {
460 set var [lindex $env_var 0]
461 set value [lindex $env_var 1]
462 if [info exists ::env($var)] {
463 lappend saved_target_env_var [list $var 1 $::env($var)]
465 lappend saved_target_env_var [list $var 0]
471 proc restore-target-env-var { } {
472 upvar 1 saved_target_env_var saved_target_env_var
473 for { set env_vari [llength $saved_target_env_var] } {
474 [incr env_vari -1] >= 0 } {} {
475 set env_var [lindex $saved_target_env_var $env_vari]
476 set var [lindex $env_var 0]
477 if [lindex $env_var 1] {
478 setenv $var [lindex $env_var 2]
485 proc dg-set-compiler-env-var { args } {
486 global set_compiler_env_var
487 global saved_compiler_env_var
488 if { [llength $args] != 3 } {
489 error "dg-set-compiler-env-var: need two arguments"
492 set var [lindex $args 1]
493 set value [lindex $args 2]
494 if [info exists ::env($var)] {
495 lappend saved_compiler_env_var [list $var 1 $::env($var)]
497 lappend saved_compiler_env_var [list $var 0]
500 lappend set_compiler_env_var [list $var $value]
503 proc restore-compiler-env-var { } {
504 global saved_compiler_env_var
505 for { set env_vari [llength $saved_compiler_env_var] } {
506 [incr env_vari -1] >= 0 } {} {
507 set env_var [lindex $saved_compiler_env_var $env_vari]
508 set var [lindex $env_var 0]
509 if [lindex $env_var 1] {
510 setenv $var [lindex $env_var 2]
520 # search_for -- looks for a string match in a file
522 proc search_for { file pattern } {
523 set fd [open $file r]
524 while { [gets $fd cur_line]>=0 } {
525 if [string match "*$pattern*" $cur_line] then {
534 # Modified dg-runtest that can cycle through a list of optimization options
536 proc gcc-dg-runtest { testcases flags default-extra-flags } {
539 # Some callers set torture options themselves; don't override those.
540 set existing_torture_options [torture-options-exist]
541 if { $existing_torture_options == 0 } {
542 global DG_TORTURE_OPTIONS LTO_TORTURE_OPTIONS
544 set-torture-options $DG_TORTURE_OPTIONS [list {}] $LTO_TORTURE_OPTIONS
548 foreach test $testcases {
549 global torture_with_loops torture_without_loops
550 # If we're only testing specific files and this isn't one of
552 if ![runtest_file_p $runtests $test] {
556 # Look for a loop within the source code - if we don't find one,
557 # don't pass -funroll[-all]-loops.
558 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
559 set option_list $torture_with_loops
561 set option_list $torture_without_loops
564 set nshort [file tail [file dirname $test]]/[file tail $test]
566 foreach flags_t $option_list {
567 global torture_current_flags
568 set torture_current_flags "$flags_t"
569 verbose "Testing $nshort, $flags $flags_t" 1
570 dg-test $test "$flags $flags_t" ${default-extra-flags}
574 if { $existing_torture_options == 0 } {
579 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
582 if ![info exists DEBUG_TORTURE_OPTIONS] {
583 set DEBUG_TORTURE_OPTIONS ""
584 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+} {
585 set comp_output [$target_compile \
586 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
587 "additional_flags=$type"]
588 if { ! [string match "*: target system does not support the * debug format*" \
590 remove-build-file "trivial.S"
591 foreach level {1 "" 3} {
592 if { ($type == "-gdwarf-2") && ($level != "") } {
593 lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
594 foreach opt $opt_opts {
595 lappend DEBUG_TORTURE_OPTIONS \
596 [list "${type}" "-g${level}" "$opt" ]
599 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
600 foreach opt $opt_opts {
601 lappend DEBUG_TORTURE_OPTIONS \
602 [list "${type}${level}" "$opt" ]
610 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
614 foreach test $testcases {
615 # If we're only testing specific files and this isn't one of
617 if ![runtest_file_p $runtests $test] {
621 set nshort [file tail [file dirname $test]]/[file tail $test]
623 foreach flags $DEBUG_TORTURE_OPTIONS {
626 # These tests check for information which may be deliberately
628 if { ([string match {*/debug-[126].c} "$nshort"] \
629 || [string match {*/enum-1.c} "$nshort"] \
630 || [string match {*/enum-[12].C} "$nshort"]) \
631 && ([string match "*1" [lindex "$flags" 0] ]
632 || [lindex "$flags" 1] == "-g1") } {
636 # High optimization can remove the variable whose existence is tested.
637 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
638 # assembler output, but stabs debugging does not.
639 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
640 if { [string match {*/debug-[12].c} "$nshort"] \
641 && [string match "*O*" "$flags"] \
642 && ( [string match "*coff*" "$flags"] \
643 || [string match "*stabs*" "$flags"] ) } {
648 verbose -log "Testing $nshort, $flags" 1
649 dg-test $test $flags ""
655 # Prune any messages matching ARGS[1] (a regexp) from test output.
656 proc dg-prune-output { args } {
657 global additional_prunes
659 if { [llength $args] != 2 } {
660 error "[lindex $args 1]: need one argument"
664 lappend additional_prunes [lindex $args 1]
667 # Remove files matching the pattern from the build machine.
668 proc remove-build-file { pat } {
669 verbose "remove-build-file `$pat'" 2
670 set file_list "[glob -nocomplain $pat]"
671 verbose "remove-build-file `$file_list'" 2
672 foreach output_file $file_list {
673 if [is_remote host] {
674 # Ensure the host knows the file is gone by deleting there
676 remote_file host delete $output_file
678 remote_file build delete $output_file
682 # Remove runtime-generated profile file for the current test.
683 proc cleanup-profile-file { } {
684 remove-build-file "mon.out"
685 remove-build-file "gmon.out"
688 # Remove compiler-generated coverage files for the current test.
689 proc cleanup-coverage-files { } {
690 global additional_sources_used
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 remove-build-file "[file rootname [file tail $testcase]].gc??"
696 # Clean up coverage files for additional source files.
697 if [info exists additional_sources_used] {
698 foreach srcfile $additional_sources_used {
699 remove-build-file "[file rootname [file tail $srcfile]].gc??"
704 # Remove compiler-generated files from -repo for the current test.
705 proc cleanup-repo-files { } {
706 global additional_sources_used
707 set testcase [testname-for-summary]
708 # The name might include a list of options; extract the file name.
709 set testcase [lindex $testcase 0]
710 remove-build-file "[file rootname [file tail $testcase]].o"
711 remove-build-file "[file rootname [file tail $testcase]].rpo"
713 # Clean up files for additional source files.
714 if [info exists additional_sources_used] {
715 foreach srcfile $additional_sources_used {
716 remove-build-file "[file rootname [file tail $srcfile]].o"
717 remove-build-file "[file rootname [file tail $srcfile]].rpo"
722 # Remove a final insns dump file for the current test.
723 proc cleanup-final-insns-dump { } {
724 set testcase [testname-for-summary]
725 # The name might include a list of options; extract the file name.
726 set testcase [lindex $testcase 0]
727 remove-build-file "[file rootname [file tail $testcase]].s.gkd"
729 # Clean up files for additional source files.
730 if [info exists additional_sources_used] {
731 foreach srcfile $additional_sources_used {
732 remove-build-file "[file rootname [file tail $srcfile]].s.gkd"
737 # Remove a stack usage file for the current test.
738 proc cleanup-stack-usage { } {
739 set testcase [testname-for-summary]
740 # The name might include a list of options; extract the file name.
741 set testcase [lindex $testcase 0]
742 remove-build-file "[file rootname [file tail $testcase]].su"
744 # Clean up files for additional source files.
745 if [info exists additional_sources_used] {
746 foreach srcfile $additional_sources_used {
747 remove-build-file "[file rootname [file tail $srcfile]].su"
752 # Remove an Ada spec file for the current test.
753 proc cleanup-ada-spec { } {
754 global additional_sources_used
755 set testcase [testname-for-summary]
756 remove-build-file "[get_ada_spec_filename $testcase]"
758 # Clean up files for additional source files.
759 if [info exists additional_sources_used] {
760 foreach srcfile $additional_sources_used {
761 remove-build-file "[get_ada_spec_filename $srcfile]"
766 # Remove files kept by --save-temps for the current test.
768 # Currently this is only .i, .ii, .s and .o files, but more can be added
769 # if there are tests generating them.
770 # ARGS is a list of suffixes to NOT delete.
771 proc cleanup-saved-temps { args } {
772 global additional_sources_used
775 # add the to-be-kept suffixes
776 foreach suffix {".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
777 if {[lsearch $args $suffix] < 0} {
778 lappend suffixes $suffix
782 set testcase [testname-for-summary]
783 # The name might include a list of options; extract the file name.
784 set testcase [lindex $testcase 0]
785 foreach suffix $suffixes {
786 remove-build-file "[file rootname [file tail $testcase]]$suffix"
787 remove-build-file "[file rootname [file tail $testcase]].exe$suffix"
788 remove-build-file "[file rootname [file tail $testcase]].exe.ltrans\[0-9\]*$suffix"
789 # -fcompare-debug dumps
790 remove-build-file "[file rootname [file tail $testcase]].gk$suffix"
793 # Clean up saved temp files for additional source files.
794 if [info exists additional_sources_used] {
795 foreach srcfile $additional_sources_used {
796 foreach suffix $suffixes {
797 remove-build-file "[file rootname [file tail $srcfile]]$suffix"
798 remove-build-file "[file rootname [file tail $srcfile]].exe$suffix"
799 remove-build-file "[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*$suffix"
801 # -fcompare-debug dumps
802 remove-build-file "[file rootname [file tail $srcfile]].gk$suffix"
809 # Files to be kept after cleanup of --save-temps for the current test.
810 # ARGS is a list of suffixes to NOT delete.
811 proc dg-keep-saved-temps { args } {
812 global keep_saved_temps_suffixes
813 set keep_saved_temps_suffixes {}
815 # add the to-be-kept suffixes
816 foreach suffix {".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
817 if {[lsearch $args $suffix] >= 0} {
818 lappend keep_saved_temps_suffixes $suffix
821 if { [llength keep_saved_temps_suffixes] < 1 } {
822 error "dg-keep-saved-temps ${args} did not match any known suffix"
826 # Scan Fortran modules for a given regexp.
828 # Argument 0 is the module name
829 # Argument 1 is the regexp to match
830 proc scan-module { args } {
831 set modfilename [string tolower [lindex $args 0]].mod
832 set fd [open [list | gzip -dc $modfilename] r]
836 set testcase [testname-for-summary]
837 if [regexp -- [lindex $args 1] $text] {
838 pass "$testcase scan-module [lindex $args 1]"
840 fail "$testcase scan-module [lindex $args 1]"
844 # Scan Fortran modules for absence of a given regexp.
846 # Argument 0 is the module name
847 # Argument 1 is the regexp to match
848 proc scan-module-absence { args } {
849 set modfilename [string tolower [lindex $args 0]].mod
850 set fd [open [list | gzip -dc $modfilename] r]
854 set testcase [testname-for-summary]
855 if [regexp -- [lindex $args 1] $text] {
856 fail "$testcase scan-module [lindex $args 1]"
858 pass "$testcase scan-module [lindex $args 1]"
862 # Verify that the compiler output file exists, invoked via dg-final.
863 proc output-exists { args } {
864 # Process an optional target or xfail list.
865 if { [llength $args] >= 1 } {
866 switch [dg-process-target [lindex $args 0]] {
869 "F" { setup_xfail "*-*-*" }
874 set testcase [testname-for-summary]
875 # Access variable from gcc-dg-test-1.
876 upvar 2 output_file output_file
878 if [file exists $output_file] {
879 pass "$testcase output-exists $output_file"
881 fail "$testcase output-exists $output_file"
885 # Verify that the compiler output file does not exist, invoked via dg-final.
886 proc output-exists-not { args } {
887 # Process an optional target or xfail list.
888 if { [llength $args] >= 1 } {
889 switch [dg-process-target [lindex $args 0]] {
892 "F" { setup_xfail "*-*-*" }
897 set testcase [testname-for-summary]
898 # Access variable from gcc-dg-test-1.
899 upvar 2 output_file output_file
901 if [file exists $output_file] {
902 fail "$testcase output-exists-not $output_file"
904 pass "$testcase output-exists-not $output_file"
908 # We need to make sure that additional_* are cleared out after every
909 # test. It is not enough to clear them out *before* the next test run
910 # because gcc-target-compile gets run directly from some .exp files
911 # (outside of any test). (Those uses should eventually be eliminated.)
913 # Because the DG framework doesn't provide a hook that is run at the
914 # end of a test, we must replace dg-test with a wrapper.
916 if { [info procs saved-dg-test] == [list] } {
917 rename dg-test saved-dg-test
919 # Helper function for cleanups that should happen after the call
920 # to the real dg-test, whether or not it returns normally, or
921 # fails with an error.
922 proc cleanup-after-saved-dg-test { } {
923 global additional_files
924 global additional_sources
925 global additional_sources_used
926 global additional_prunes
927 global compiler_conditional_xfail_data
929 global testname_with_flags
930 global set_target_env_var
931 global set_compiler_env_var
932 global saved_compiler_env_var
933 global keep_saved_temps_suffixes
934 global multiline_expected_outputs
935 global freeform_regexps
936 global save_linenr_varnames
938 set additional_files ""
939 set additional_sources ""
940 set additional_sources_used ""
941 set additional_prunes ""
943 if [info exists set_target_env_var] {
944 unset set_target_env_var
946 if [info exists set_compiler_env_var] {
947 restore-compiler-env-var
948 unset set_compiler_env_var
949 unset saved_compiler_env_var
951 if [info exists keep_saved_temps_suffixes] {
952 unset keep_saved_temps_suffixes
955 if [info exists compiler_conditional_xfail_data] {
956 unset compiler_conditional_xfail_data
958 if [info exists testname_with_flags] {
959 unset testname_with_flags
961 set multiline_expected_outputs []
962 set freeform_regexps []
964 if { [info exists save_linenr_varnames] } {
965 foreach varname $save_linenr_varnames {
970 # Cleanup varname_used, or generate defined-but-not-used
972 set varname_used used_$varname
973 eval global $varname_used
974 eval set used [info exists $varname_used]
976 eval unset $varname_used
978 regsub {^saved_linenr_} $varname "" org_varname
979 warning "dg-line var $org_varname defined, but not used"
982 unset save_linenr_varnames
986 proc dg-test { args } {
989 if { [ catch { eval saved-dg-test $args } errmsg ] } {
990 set saved_info $errorInfo
991 cleanup-after-saved-dg-test
992 error $errmsg $saved_info
994 cleanup-after-saved-dg-test
998 if { [info procs saved-dg-warning] == [list] \
999 && [info exists gcc_warning_prefix] } {
1000 rename dg-warning saved-dg-warning
1002 proc dg-warning { args } {
1003 # Make this variable available here and to the saved proc.
1004 upvar dg-messages dg-messages
1005 global gcc_warning_prefix
1007 process-message saved-dg-warning "$gcc_warning_prefix" "$args"
1011 if { [info procs saved-dg-error] == [list] \
1012 && [info exists gcc_error_prefix] } {
1013 rename dg-error saved-dg-error
1015 proc dg-error { args } {
1016 # Make this variable available here and to the saved proc.
1017 upvar dg-messages dg-messages
1018 global gcc_error_prefix
1020 process-message saved-dg-error "$gcc_error_prefix" "$args"
1023 # Override dg-bogus at the same time. It doesn't handle a prefix
1024 # but its expression should include a column number. Otherwise the
1025 # line number can match the column number for other messages, leading
1027 rename dg-bogus saved-dg-bogus
1029 proc dg-bogus { args } {
1030 upvar dg-messages dg-messages
1031 process-message saved-dg-bogus "" $args
1035 # Set variable VARNAME to LINENR
1037 proc dg-line { linenr varname } {
1038 set org_varname $varname
1039 set varname "saved_linenr_$varname"
1040 eval global $varname
1042 # Generate defined-but-previously-defined error.
1043 eval set var_defined [info exists $varname]
1044 if { $var_defined } {
1045 eval set deflinenr \$$varname
1046 error "dg-line var $org_varname defined at line $linenr, but previously defined at line $deflinenr"
1050 eval set $varname $linenr
1052 # Schedule cleanup of varname by cleanup-after-saved-dg-test
1053 global save_linenr_varnames
1054 if { [info exists save_linenr_varnames] } {
1055 lappend save_linenr_varnames $varname
1057 set save_linenr_varnames [list $varname]
1061 # Get the absolute line number corresponding to:
1062 # - a relative line number (a non-null useline is required), or
1063 # - a line number variable reference.
1064 # Argument 0 is the line number on which line was used
1065 # Argument 1 is the relative line number or line number variable reference
1067 proc get-absolute-line { useline line } {
1068 if { "$line" == "." } {
1072 if { [regsub "^\.\[+-\](\[0-9\]+)$" $line "\\1" num] && $useline != "" } {
1073 # Handle relative line specification, .+1 or .-1 etc.
1074 set num [expr $useline [string index $line 1] $num]
1078 if { ! [regsub "^(\[a-zA-Z\]\[a-zA-Z0-9_\]*)$" $line "\\1" varname] } {
1082 # Handle linenr variable defined by dg-line
1083 set org_varname $varname
1084 set varname "saved_linenr_$varname"
1085 eval global $varname
1087 # Generate used-but-not-defined error.
1088 eval set var_defined [info exists $varname]
1089 if { ! $var_defined } {
1090 if { "$useline" != "" } {
1091 error "dg-line var $org_varname used at line $useline, but not defined"
1093 error "dg-line var $org_varname used, but not defined"
1098 # Note that varname has been used.
1099 set varname_used "used_$varname"
1100 eval global $varname_used
1101 eval set $varname_used 1
1103 # Get line number from var and use it.
1104 eval set num \$$varname
1108 # Modify the regular expression saved by a DejaGnu message directive to
1109 # include a prefix and to force the expression to match a single line.
1110 # MSGPROC is the procedure to call.
1111 # MSGPREFIX is the prefix to prepend.
1112 # DGARGS is the original argument list.
1114 proc process-message { msgproc msgprefix dgargs } {
1115 upvar dg-messages dg-messages
1117 if { [llength $dgargs] == 5 } {
1118 set num [get-absolute-line [lindex $dgargs 0] [lindex $dgargs 4]]
1119 set dgargs [lreplace $dgargs 4 4 $num]
1122 # Process the dg- directive, including adding the regular expression
1123 # to the new message entry in dg-messages.
1124 set msgcnt [llength ${dg-messages}]
1125 eval $msgproc $dgargs
1127 # If the target expression wasn't satisfied there is no new message.
1128 if { [llength ${dg-messages}] == $msgcnt } {
1132 # Get the entry for the new message. Prepend the message prefix to
1133 # the regular expression and make it match a single line.
1134 set newentry [lindex ${dg-messages} end]
1135 set expmsg [lindex $newentry 2]
1138 # Handle column numbers from the specified expression (if there is
1139 # one) and set up the search expression that will be used by DejaGnu.
1140 if [regexp {^-:} $expmsg] {
1141 # The expected column is -, so shouldn't appear.
1142 set expmsg [string range $expmsg 2 end]
1143 } elseif [regexp {^[0-9]+:} $expmsg column] {
1144 # The expression in the directive included a column number.
1145 # Remove it from the original expression and move it
1146 # to the proper place in the search expression.
1147 set expmsg [string range $expmsg [string length $column] end]
1148 set column "$column "
1149 } elseif [string match "" [lindex $newentry 0]] {
1150 # The specified line number is 0; don't expect a column number.
1152 # There is no column number in the search expression, but we
1153 # should expect one in the message itself.
1154 set column {[0-9]+: }
1156 set expmsg "$column$msgprefix\[^\n\]*$expmsg"
1157 set newentry [lreplace $newentry 2 2 $expmsg]
1159 set dg-messages [lreplace ${dg-messages} end end $newentry]
1160 verbose "process-message:\n${dg-messages}" 2
1163 # Look for messages that don't have standard prefixes.
1165 proc dg-message { args } {
1166 upvar dg-messages dg-messages
1167 process-message saved-dg-warning "" $args
1170 # Look for a location marker of the form
1172 # with no extra text (e.g. a line-span separator).
1174 proc dg-locus { args } {
1175 upvar dg-messages dg-messages
1177 # Process the dg- directive, including adding the regular expression
1178 # to the new message entry in dg-messages.
1179 set msgcnt [llength ${dg-messages}]
1180 eval saved-dg-warning $args
1182 # If the target expression wasn't satisfied there is no new message.
1183 if { [llength ${dg-messages}] == $msgcnt } {
1187 # Get the entry for the new message. Prepend the message prefix to
1188 # the regular expression and make it match a single line.
1189 set newentry [lindex ${dg-messages} end]
1190 set expmsg [lindex $newentry 2]
1192 set newentry [lreplace $newentry 2 2 $expmsg]
1193 set dg-messages [lreplace ${dg-messages} end end $newentry]
1194 verbose "process-message:\n${dg-messages}" 2
1197 # Handle output from -fopt-info for MSG_OPTIMIZED_LOCATIONS:
1198 # a successful optimization.
1200 proc dg-optimized { args } {
1201 # Make this variable available here and to the saved proc.
1202 upvar dg-messages dg-messages
1204 process-message saved-dg-error "optimized: " "$args"
1207 # Handle output from -fopt-info for MSG_MISSED_OPTIMIZATION:
1208 # a missed optimization.
1210 proc dg-missed { args } {
1211 # Make this variable available here and to the saved proc.
1212 upvar dg-messages dg-messages
1214 process-message saved-dg-error "missed: " "$args"
1217 # Check the existence of a gdb in the path, and return true if there
1220 # Set env(GDB_FOR_GCC_TESTING) accordingly.
1222 proc gdb-exists { args } {
1223 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
1225 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
1226 if [info exists GDB] {
1227 setenv GDB_FOR_GCC_TESTING "$GDB"
1229 setenv GDB_FOR_GCC_TESTING "[transform gdb]"
1233 if { [which $::env(GDB_FOR_GCC_TESTING)] != 0 } {
1239 set additional_prunes ""
1240 set dg_runtest_extra_prunes ""