Rebase.
[official-gcc.git] / gcc / testsuite / lib / gcc-dg.exp
blob3390caac47bb978aead27116b3f08928bab0d7ba
1 # Copyright (C) 1997-2014 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 if [info exists TORTURE_OPTIONS] {
50 set DG_TORTURE_OPTIONS $TORTURE_OPTIONS
51 } else {
52 # It is theoretically beneficial to group all of the O2/O3 options together,
53 # as in many cases the compiler will generate identical executables for
54 # all of them--and the c-torture testsuite will skip testing identical
55 # executables multiple times.
56 # Also note that -finline-functions is explicitly included in one of the
57 # items below, even though -O3 is also specified, because some ports may
58 # choose to disable inlining functions by default, even when optimizing.
59 set DG_TORTURE_OPTIONS [list \
60 { -O0 } \
61 { -O1 } \
62 { -O2 } \
63 { -O3 -fomit-frame-pointer } \
64 { -O3 -fomit-frame-pointer -funroll-loops } \
65 { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
66 { -O3 -g } \
67 { -Os } ]
70 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
71 set DG_TORTURE_OPTIONS \
72 [concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
75 set LTO_TORTURE_OPTIONS ""
77 # Some torture-options cause intermediate code output, unusable for
78 # testing using e.g. scan-assembler. In this variable are the options
79 # how to force it, when needed.
80 global gcc_force_conventional_output
81 set gcc_force_conventional_output ""
83 if [check_effective_target_lto] {
84 # When having plugin test both slim and fat LTO and plugin/nonplugin
85 # path.
86 if [check_linker_plugin_available] {
87 set LTO_TORTURE_OPTIONS [list \
88 { -O2 -flto -fno-use-linker-plugin -flto-partition=none } \
89 { -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects }
91 set gcc_force_conventional_output "-ffat-lto-objects"
92 } else {
93 set LTO_TORTURE_OPTIONS [list \
94 { -O2 -flto -flto-partition=none } \
95 { -O2 -flto }
100 global orig_environment_saved
102 # This file may be sourced, so don't override environment settings
103 # that have been previously setup.
104 if { $orig_environment_saved == 0 } {
105 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
106 set_ld_library_path_env_vars
109 # Define gcc callbacks for dg.exp.
111 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
112 # Set up the compiler flags, based on what we're going to do.
114 set options [list]
116 # Tests should be able to use "dg-do repo". However, the dg test
117 # driver checks the argument to dg-do against a list of acceptable
118 # options, and "repo" is not among them. Therefore, we resort to
119 # this ugly approach.
120 if [string match "*-frepo*" $extra_tool_flags] then {
121 set do_what "repo"
124 switch $do_what {
125 "preprocess" {
126 set compile_type "preprocess"
127 set output_file "[file rootname [file tail $prog]].i"
129 "compile" {
130 set compile_type "assembly"
131 set output_file "[file rootname [file tail $prog]].s"
133 "assemble" {
134 set compile_type "object"
135 set output_file "[file rootname [file tail $prog]].o"
137 "precompile" {
138 set compile_type "precompiled_header"
139 set output_file "[file tail $prog].gch"
141 "link" {
142 set compile_type "executable"
143 set output_file "[file rootname [file tail $prog]].exe"
144 # The following line is needed for targets like the i960 where
145 # the default output file is b.out. Sigh.
147 "repo" {
148 set compile_type "object"
149 set output_file "[file rootname [file tail $prog]].o"
151 "run" {
152 set compile_type "executable"
153 # FIXME: "./" is to cope with "." not being in $PATH.
154 # Should this be handled elsewhere?
155 # YES.
156 set output_file "./[file rootname [file tail $prog]].exe"
157 # This is the only place where we care if an executable was
158 # created or not. If it was, dg.exp will try to run it.
159 catch { remote_file build delete $output_file }
161 default {
162 perror "$do_what: not a valid dg-do keyword"
163 return ""
167 # Let { dg-final { action } } force options as returned by an
168 # optional proc ${action}_required_options.
169 upvar 2 dg-final-code finalcode
170 foreach x [split $finalcode "\n"] {
171 set finalcmd [lindex $x 0]
172 if { [info procs ${finalcmd}_required_options] != "" } {
173 set req [${finalcmd}_required_options]
174 if { $req != "" } {
175 lappend extra_tool_flags $req
180 if { $extra_tool_flags != "" } {
181 lappend options "additional_flags=$extra_tool_flags"
184 verbose "$target_compile $prog $output_file $compile_type $options" 4
185 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
187 # Look for an internal compiler error, which sometimes masks the fact
188 # that we didn't get an expected error message. XFAIL an ICE via
189 # dg-xfail-if and use { dg-prune-output ".*internal compiler error.*" }
190 # to avoid a second failure for excess errors.
191 if [string match "*internal compiler error*" $comp_output] {
192 upvar 2 name name
193 fail "$name (internal compiler error)"
196 if { $do_what == "repo" } {
197 set object_file "$output_file"
198 set output_file "[file rootname [file tail $prog]].exe"
199 set comp_output \
200 [ concat $comp_output \
201 [$target_compile "$object_file" "$output_file" \
202 "executable" $options] ]
205 return [list $comp_output $output_file]
208 proc gcc-dg-test { prog do_what extra_tool_flags } {
209 return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
212 proc gcc-dg-prune { system text } {
213 global additional_prunes
215 # Extra prune rules that will apply to tests defined in a .exp file.
216 # Always remember to clear it in .exp file after executed all tests.
217 global dg_runtest_extra_prunes
219 set text [prune_gcc_output $text]
221 foreach p "$additional_prunes $dg_runtest_extra_prunes" {
222 if { [string length $p] > 0 } {
223 # Following regexp matches a complete line containing $p.
224 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
228 # If we see "region xxx is full" then the testcase is too big for ram.
229 # This is tricky to deal with in a large testsuite like c-torture so
230 # deal with it here. Just mark the testcase as unsupported.
231 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
232 # The format here is important. See dg.exp.
233 return "::unsupported::memory full"
236 # Likewise, if we see ".text exceeds local store range" or
237 # similar.
238 if {[string match "spu-*" $system] && \
239 [string match "*exceeds local store*" $text]} {
240 # The format here is important. See dg.exp.
241 return "::unsupported::memory full"
244 return $text
247 # Replace ${tool}_load with a wrapper to provide for an expected nonzero
248 # exit status. Multiple languages include this file so this handles them
249 # all, not just gcc.
250 if { [info procs ${tool}_load] != [list] \
251 && [info procs saved_${tool}_load] == [list] } {
252 rename ${tool}_load saved_${tool}_load
254 proc ${tool}_load { program args } {
255 global tool
256 global shouldfail
257 global set_target_env_var
259 set saved_target_env_var [list]
260 if { [info exists set_target_env_var] \
261 && [llength $set_target_env_var] != 0 } {
262 if { [is_remote target] } {
263 return [list "unsupported" ""]
265 set-target-env-var
267 set result [eval [list saved_${tool}_load $program] $args]
268 if { [info exists set_target_env_var] \
269 && [llength $set_target_env_var] != 0 } {
270 restore-target-env-var
272 if { $shouldfail != 0 } {
273 switch [lindex $result 0] {
274 "pass" { set status "fail" }
275 "fail" { set status "pass" }
277 set result [list $status [lindex $result 1]]
279 return $result
283 proc dg-set-target-env-var { args } {
284 global set_target_env_var
285 if { [llength $args] != 3 } {
286 error "dg-set-target-env-var: need two arguments"
287 return
289 lappend set_target_env_var [list [lindex $args 1] [lindex $args 2]]
292 proc set-target-env-var { } {
293 global set_target_env_var
294 upvar 1 saved_target_env_var saved_target_env_var
295 foreach env_var $set_target_env_var {
296 set var [lindex $env_var 0]
297 set value [lindex $env_var 1]
298 if [info exists env($var)] {
299 lappend saved_target_env_var [list $var 1 $env($var)]
300 } else {
301 lappend saved_target_env_var [list $var 0]
303 setenv $var $value
307 proc restore-target-env-var { } {
308 upvar 1 saved_target_env_var saved_target_env_var
309 for { set env_vari [llength $saved_target_env_var] } {
310 [incr env_vari -1] >= 0 } {} {
311 set env_var [lindex $saved_target_env_var $env_vari]
312 set var [lindex $env_var 0]
313 if [lindex $env_var 1] {
314 setenv $var [lindex $env_var 2]
315 } else {
316 unsetenv $var
321 # Utility routines.
324 # search_for -- looks for a string match in a file
326 proc search_for { file pattern } {
327 set fd [open $file r]
328 while { [gets $fd cur_line]>=0 } {
329 if [string match "*$pattern*" $cur_line] then {
330 close $fd
331 return 1
334 close $fd
335 return 0
338 # Modified dg-runtest that can cycle through a list of optimization options
339 # as c-torture does.
340 proc gcc-dg-runtest { testcases flags default-extra-flags } {
341 global runtests
343 # Some callers set torture options themselves; don't override those.
344 set existing_torture_options [torture-options-exist]
345 if { $existing_torture_options == 0 } {
346 global DG_TORTURE_OPTIONS LTO_TORTURE_OPTIONS
347 torture-init
348 set-torture-options $DG_TORTURE_OPTIONS [list {}] $LTO_TORTURE_OPTIONS
350 dump-torture-options
352 foreach test $testcases {
353 global torture_with_loops torture_without_loops
354 # If we're only testing specific files and this isn't one of
355 # them, skip it.
356 if ![runtest_file_p $runtests $test] {
357 continue
360 # Look for a loop within the source code - if we don't find one,
361 # don't pass -funroll[-all]-loops.
362 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
363 set option_list $torture_with_loops
364 } else {
365 set option_list $torture_without_loops
368 set nshort [file tail [file dirname $test]]/[file tail $test]
370 foreach flags_t $option_list {
371 verbose "Testing $nshort, $flags $flags_t" 1
372 dg-test $test "$flags $flags_t" ${default-extra-flags}
376 if { $existing_torture_options == 0 } {
377 torture-finish
381 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
382 global srcdir subdir
384 if ![info exists DEBUG_TORTURE_OPTIONS] {
385 set DEBUG_TORTURE_OPTIONS ""
386 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
387 set comp_output [$target_compile \
388 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
389 "additional_flags=$type"]
390 if { ! [string match "*: target system does not support the * debug format*" \
391 $comp_output] } {
392 remove-build-file "trivial.S"
393 foreach level {1 "" 3} {
394 if { ($type == "-gdwarf-2") && ($level != "") } {
395 lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
396 foreach opt $opt_opts {
397 lappend DEBUG_TORTURE_OPTIONS \
398 [list "${type}" "-g${level}" "$opt" ]
400 } else {
401 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
402 foreach opt $opt_opts {
403 lappend DEBUG_TORTURE_OPTIONS \
404 [list "${type}${level}" "$opt" ]
412 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
414 global runtests
416 foreach test $testcases {
417 # If we're only testing specific files and this isn't one of
418 # them, skip it.
419 if ![runtest_file_p $runtests $test] {
420 continue
423 set nshort [file tail [file dirname $test]]/[file tail $test]
425 foreach flags $DEBUG_TORTURE_OPTIONS {
426 set doit 1
428 # These tests check for information which may be deliberately
429 # suppressed at -g1.
430 if { ([string match {*/debug-[126].c} "$nshort"] \
431 || [string match {*/enum-1.c} "$nshort"] \
432 || [string match {*/enum-[12].C} "$nshort"]) \
433 && ([string match "*1" [lindex "$flags" 0] ]
434 || [lindex "$flags" 1] == "-g1") } {
435 set doit 0
438 # High optimization can remove the variable whose existence is tested.
439 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
440 # assembler output, but stabs debugging does not.
441 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
442 if { [string match {*/debug-[12].c} "$nshort"] \
443 && [string match "*O*" "$flags"] \
444 && ( [string match "*coff*" "$flags"] \
445 || [string match "*stabs*" "$flags"] ) } {
446 set doit 0
449 if { $doit } {
450 verbose -log "Testing $nshort, $flags" 1
451 dg-test $test $flags ""
457 # Prune any messages matching ARGS[1] (a regexp) from test output.
458 proc dg-prune-output { args } {
459 global additional_prunes
461 if { [llength $args] != 2 } {
462 error "[lindex $args 1]: need one argument"
463 return
466 lappend additional_prunes [lindex $args 1]
469 # Remove files matching the pattern from the build machine.
470 proc remove-build-file { pat } {
471 verbose "remove-build-file `$pat'" 2
472 set file_list "[glob -nocomplain $pat]"
473 verbose "remove-build-file `$file_list'" 2
474 foreach output_file $file_list {
475 if [is_remote host] {
476 # Ensure the host knows the file is gone by deleting there
477 # first.
478 remote_file host delete $output_file
480 remote_file build delete $output_file
484 # Remove runtime-generated profile file for the current test.
485 proc cleanup-profile-file { } {
486 remove-build-file "mon.out"
487 remove-build-file "gmon.out"
490 # Remove compiler-generated coverage files for the current test.
491 proc cleanup-coverage-files { } {
492 set testcase [testname-for-summary]
493 # The name might include a list of options; extract the file name.
494 set testcase [lindex $testcase 0]
495 remove-build-file "[file rootname [file tail $testcase]].gc??"
497 # Clean up coverage files for additional source files.
498 if [info exists additional_sources] {
499 foreach srcfile $additional_sources {
500 remove-build-file "[file rootname [file tail $srcfile]].gc??"
505 # Remove compiler-generated files from -repo for the current test.
506 proc cleanup-repo-files { } {
507 set testcase [testname-for-summary]
508 # The name might include a list of options; extract the file name.
509 set testcase [lindex $testcase 0]
510 remove-build-file "[file rootname [file tail $testcase]].o"
511 remove-build-file "[file rootname [file tail $testcase]].rpo"
513 # Clean up files for additional source files.
514 if [info exists additional_sources] {
515 foreach srcfile $additional_sources {
516 remove-build-file "[file rootname [file tail $srcfile]].o"
517 remove-build-file "[file rootname [file tail $srcfile]].rpo"
522 # Remove compiler-generated RTL dump files for the current test.
524 # SUFFIX is the filename suffix pattern.
525 proc cleanup-rtl-dump { suffix } {
526 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]r.$suffix"
529 # Remove a specific tree dump file for the current test.
531 # SUFFIX is the tree dump file suffix pattern.
532 proc cleanup-tree-dump { suffix } {
533 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]t.$suffix"
536 # Remove a specific ipa dump file for the current test.
538 # SUFFIX is the ipa dump file suffix pattern.
539 proc cleanup-ipa-dump { suffix } {
540 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]i.$suffix"
543 # Remove a stack usage file for the current test.
544 proc cleanup-stack-usage { } {
545 set testcase [testname-for-summary]
546 # The name might include a list of options; extract the file name.
547 set testcase [lindex $testcase 0]
548 remove-build-file "[file rootname [file tail $testcase]].su"
550 # Clean up files for additional source files.
551 if [info exists additional_sources] {
552 foreach srcfile $additional_sources {
553 remove-build-file "[file rootname [file tail $srcfile]].su"
558 # Remove an Ada spec file for the current test.
559 proc cleanup-ada-spec { } {
560 set testcase [testname-for-summary]
561 remove-build-file "[get_ada_spec_filename $testcase]"
563 # Clean up files for additional source files.
564 if [info exists additional_sources] {
565 foreach srcfile $additional_sources {
566 remove-build-file "[get_ada_spec_filename $srcfile]"
571 # Remove all dump files with the provided suffix.
572 proc cleanup-dump { suffix } {
573 set testcase [testname-for-summary]
574 # The name might include a list of options; extract the file name.
575 set src [file tail [lindex $testcase 0]]
576 remove-build-file "[file tail $src].$suffix"
577 remove-build-file "[file rootname [file tail $src]].exe.$suffix"
578 remove-build-file "[file rootname [file tail $src]].exe.ltrans\[0-9\]*.$suffix"
579 # -fcompare-debug dumps
580 remove-build-file "[file tail $src].gk.$suffix"
582 # Clean up dump files for additional source files.
583 if [info exists additional_sources] {
584 foreach srcfile $additional_sources {
585 remove-build-file "[file tail $srcfile].$suffix"
586 remove-build-file "[file rootname [file tail $srcfile]].exe.$suffix"
587 remove-build-file "[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*.$suffix"
588 # -fcompare-debug dumps
589 remove-build-file "[file tail $srcfile].gk.$suffix"
594 # Remove files kept by --save-temps for the current test.
596 # Currently this is only .i, .ii, .s and .o files, but more can be added
597 # if there are tests generating them.
598 # ARGS is a list of suffixes to NOT delete.
599 proc cleanup-saved-temps { args } {
600 global additional_sources
601 set suffixes {}
603 # add the to-be-kept suffixes
604 foreach suffix {".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
605 if {[lsearch $args $suffix] < 0} {
606 lappend suffixes $suffix
610 set testcase [testname-for-summary]
611 # The name might include a list of options; extract the file name.
612 set testcase [lindex $testcase 0]
613 foreach suffix $suffixes {
614 remove-build-file "[file rootname [file tail $testcase]]$suffix"
615 remove-build-file "[file rootname [file tail $testcase]].exe$suffix"
616 remove-build-file "[file rootname [file tail $testcase]].exe.ltrans\[0-9\]*$suffix"
617 # -fcompare-debug dumps
618 remove-build-file "[file rootname [file tail $testcase]].gk$suffix"
621 # Clean up saved temp files for additional source files.
622 if [info exists additional_sources] {
623 foreach srcfile $additional_sources {
624 foreach suffix $suffixes {
625 remove-build-file "[file rootname [file tail $srcfile]]$suffix"
626 remove-build-file "[file rootname [file tail $srcfile]].exe$suffix"
627 remove-build-file "[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*$suffix"
629 # -fcompare-debug dumps
630 remove-build-file "[file rootname [file tail $srcfile]].gk$suffix"
636 # Scan Fortran modules for a given regexp.
638 # Argument 0 is the module name
639 # Argument 1 is the regexp to match
640 proc scan-module { args } {
641 set modfilename [string tolower [lindex $args 0]].mod
642 set fd [open [list | gzip -dc $modfilename] r]
643 set text [read $fd]
644 close $fd
646 set testcase [testname-for-summary]
647 if [regexp -- [lindex $args 1] $text] {
648 pass "$testcase scan-module [lindex $args 1]"
649 } else {
650 fail "$testcase scan-module [lindex $args 1]"
654 # Scan Fortran modules for absence of a given regexp.
656 # Argument 0 is the module name
657 # Argument 1 is the regexp to match
658 proc scan-module-absence { args } {
659 set modfilename [string tolower [lindex $args 0]].mod
660 set fd [open [list | gzip -dc $modfilename] r]
661 set text [read $fd]
662 close $fd
664 set testcase [testname-for-summary]
665 if [regexp -- [lindex $args 1] $text] {
666 fail "$testcase scan-module [lindex $args 1]"
667 } else {
668 pass "$testcase scan-module [lindex $args 1]"
672 # Verify that the compiler output file exists, invoked via dg-final.
673 proc output-exists { args } {
674 # Process an optional target or xfail list.
675 if { [llength $args] >= 1 } {
676 switch [dg-process-target [lindex $args 0]] {
677 "S" { }
678 "N" { return }
679 "F" { setup_xfail "*-*-*" }
680 "P" { }
684 set testcase [testname-for-summary]
685 # Access variable from gcc-dg-test-1.
686 upvar 2 output_file output_file
688 if [file exists $output_file] {
689 pass "$testcase output-exists $output_file"
690 } else {
691 fail "$testcase output-exists $output_file"
695 # Verify that the compiler output file does not exist, invoked via dg-final.
696 proc output-exists-not { args } {
697 # Process an optional target or xfail list.
698 if { [llength $args] >= 1 } {
699 switch [dg-process-target [lindex $args 0]] {
700 "S" { }
701 "N" { return }
702 "F" { setup_xfail "*-*-*" }
703 "P" { }
707 set testcase [testname-for-summary]
708 # Access variable from gcc-dg-test-1.
709 upvar 2 output_file output_file
711 if [file exists $output_file] {
712 fail "$testcase output-exists-not $output_file"
713 } else {
714 pass "$testcase output-exists-not $output_file"
718 # We need to make sure that additional_* are cleared out after every
719 # test. It is not enough to clear them out *before* the next test run
720 # because gcc-target-compile gets run directly from some .exp files
721 # (outside of any test). (Those uses should eventually be eliminated.)
723 # Because the DG framework doesn't provide a hook that is run at the
724 # end of a test, we must replace dg-test with a wrapper.
726 if { [info procs saved-dg-test] == [list] } {
727 rename dg-test saved-dg-test
729 proc dg-test { args } {
730 global additional_files
731 global additional_sources
732 global additional_prunes
733 global errorInfo
734 global compiler_conditional_xfail_data
735 global shouldfail
736 global testname_with_flags
737 global set_target_env_var
739 if { [ catch { eval saved-dg-test $args } errmsg ] } {
740 set saved_info $errorInfo
741 set additional_files ""
742 set additional_sources ""
743 set additional_prunes ""
744 set shouldfail 0
745 if [info exists compiler_conditional_xfail_data] {
746 unset compiler_conditional_xfail_data
748 if [info exists testname_with_flags] {
749 unset testname_with_flags
751 unset_timeout_vars
752 error $errmsg $saved_info
754 set additional_files ""
755 set additional_sources ""
756 set additional_prunes ""
757 set shouldfail 0
758 if [info exists set_target_env_var] {
759 unset set_target_env_var
761 unset_timeout_vars
762 if [info exists compiler_conditional_xfail_data] {
763 unset compiler_conditional_xfail_data
765 if [info exists testname_with_flags] {
766 unset testname_with_flags
771 if { [info procs saved-dg-warning] == [list] \
772 && [info exists gcc_warning_prefix] } {
773 rename dg-warning saved-dg-warning
775 proc dg-warning { args } {
776 # Make this variable available here and to the saved proc.
777 upvar dg-messages dg-messages
778 global gcc_warning_prefix
780 process-message saved-dg-warning "$gcc_warning_prefix" "$args"
784 if { [info procs saved-dg-error] == [list] \
785 && [info exists gcc_error_prefix] } {
786 rename dg-error saved-dg-error
788 proc dg-error { args } {
789 # Make this variable available here and to the saved proc.
790 upvar dg-messages dg-messages
791 global gcc_error_prefix
793 process-message saved-dg-error "$gcc_error_prefix" "$args"
796 # Override dg-bogus at the same time. It doesn't handle a prefix
797 # but its expression should include a column number. Otherwise the
798 # line number can match the column number for other messages, leading
799 # to insanity.
800 rename dg-bogus saved-dg-bogus
802 proc dg-bogus { args } {
803 upvar dg-messages dg-messages
804 process-message saved-dg-bogus "" $args
808 # Modify the regular expression saved by a DejaGnu message directive to
809 # include a prefix and to force the expression to match a single line.
810 # MSGPROC is the procedure to call.
811 # MSGPREFIX is the prefix to prepend.
812 # DGARGS is the original argument list.
814 proc process-message { msgproc msgprefix dgargs } {
815 upvar dg-messages dg-messages
817 # Process the dg- directive, including adding the regular expression
818 # to the new message entry in dg-messages.
819 set msgcnt [llength ${dg-messages}]
820 eval $msgproc $dgargs
822 # If the target expression wasn't satisfied there is no new message.
823 if { [llength ${dg-messages}] == $msgcnt } {
824 return;
827 # Get the entry for the new message. Prepend the message prefix to
828 # the regular expression and make it match a single line.
829 set newentry [lindex ${dg-messages} end]
830 set expmsg [lindex $newentry 2]
832 # Handle column numbers from the specified expression (if there is
833 # one) and set up the search expression that will be used by DejaGnu.
834 if [regexp "^(\[0-9\]+):" $expmsg "" column] {
835 # The expression in the directive included a column number.
836 # Remove "COLUMN:" from the original expression and move it
837 # to the proper place in the search expression.
838 regsub "^\[0-9\]+:" $expmsg "" expmsg
839 set expmsg "$column: $msgprefix\[^\n\]*$expmsg"
840 } elseif [string match "" [lindex $newentry 0]] {
841 # The specified line number is 0; don't expect a column number.
842 set expmsg "$msgprefix\[^\n\]*$expmsg"
843 } else {
844 # There is no column number in the search expression, but we
845 # should expect one in the message itself.
846 set expmsg "\[0-9\]+: $msgprefix\[^\n\]*$expmsg"
849 set newentry [lreplace $newentry 2 2 $expmsg]
850 set dg-messages [lreplace ${dg-messages} end end $newentry]
851 verbose "process-message:\n${dg-messages}" 2
854 # Look for messages that don't have standard prefixes.
856 proc dg-message { args } {
857 upvar dg-messages dg-messages
858 process-message saved-dg-warning "" $args
861 # Check the existence of a gdb in the path, and return true if there
862 # is one.
864 # Set env(GDB_FOR_GCC_TESTING) accordingly.
866 proc gdb-exists { args } {
867 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
868 global GDB
869 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
870 if [info exists GDB] {
871 setenv GDB_FOR_GCC_TESTING "$GDB"
872 } else {
873 setenv GDB_FOR_GCC_TESTING "[transform gdb]"
877 if { [which $::env(GDB_FOR_GCC_TESTING)] != 0 } {
878 return 1;
880 return 0;
883 set additional_prunes ""
884 set dg_runtest_extra_prunes ""