]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/lib/gcc-dg.exp
gcc-dg.exp (cleanup-saved-temps): Add .mii to suffixes.
[thirdparty/gcc.git] / gcc / testsuite / lib / gcc-dg.exp
1 # Copyright (C) 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
2 # 2010 Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GCC; see the file COPYING3. If not see
16 # <http://www.gnu.org/licenses/>.
17
18 load_lib dg.exp
19 load_lib file-format.exp
20 load_lib target-supports.exp
21 load_lib target-supports-dg.exp
22 load_lib scanasm.exp
23 load_lib scanrtl.exp
24 load_lib scantree.exp
25 load_lib scanipa.exp
26 load_lib timeout.exp
27 load_lib timeout-dg.exp
28 load_lib prune.exp
29 load_lib libgloss.exp
30 load_lib target-libpath.exp
31 load_lib torture-options.exp
32 load_lib fortran-modules.exp
33
34 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
35 setenv LC_ALL C
36 setenv LANG C
37
38 # Many hosts now default to a non-ASCII C locale, however, so
39 # they can set a charset encoding here if they need.
40 if { [ishost "*-*-cygwin*"] } {
41 setenv LC_ALL C.ASCII
42 setenv LANG C.ASCII
43 }
44
45 global GCC_UNDER_TEST
46 if ![info exists GCC_UNDER_TEST] {
47 set GCC_UNDER_TEST "[find_gcc]"
48 }
49
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 } ]
69 }
70
71 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
72 set DG_TORTURE_OPTIONS \
73 [concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
74 }
75
76 set LTO_TORTURE_OPTIONS ""
77
78 # Some torture-options cause intermediate code output, unusable for
79 # testing using e.g. scan-assembler. In this variable are the options
80 # how to force it, when needed.
81 global gcc_force_conventional_output
82 set gcc_force_conventional_output ""
83
84 if [check_effective_target_lto] {
85 # When having plugin test both slim and fat LTO and plugin/nonplugin
86 # path.
87 if [check_linker_plugin_available] {
88 set LTO_TORTURE_OPTIONS [list \
89 { -O2 -flto -fno-use-linker-plugin -flto-partition=none } \
90 { -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects }
91 ]
92 set gcc_force_conventional_output "-ffat-lto-objects"
93 } else {
94 set LTO_TORTURE_OPTIONS [list \
95 { -O2 -flto -flto-partition=none } \
96 { -O2 -flto }
97 ]
98 }
99 }
100
101 global orig_environment_saved
102
103 # This file may be sourced, so don't override environment settings
104 # that have been previously setup.
105 if { $orig_environment_saved == 0 } {
106 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
107 set_ld_library_path_env_vars
108 }
109
110 # Define gcc callbacks for dg.exp.
111
112 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
113 # Set up the compiler flags, based on what we're going to do.
114
115 set options [list]
116
117 # Tests should be able to use "dg-do repo". However, the dg test
118 # driver checks the argument to dg-do against a list of acceptable
119 # options, and "repo" is not among them. Therefore, we resort to
120 # this ugly approach.
121 if [string match "*-frepo*" $extra_tool_flags] then {
122 set do_what "repo"
123 }
124
125 switch $do_what {
126 "preprocess" {
127 set compile_type "preprocess"
128 set output_file "[file rootname [file tail $prog]].i"
129 }
130 "compile" {
131 set compile_type "assembly"
132 set output_file "[file rootname [file tail $prog]].s"
133 }
134 "assemble" {
135 set compile_type "object"
136 set output_file "[file rootname [file tail $prog]].o"
137 }
138 "precompile" {
139 set compile_type "precompiled_header"
140 set output_file "[file tail $prog].gch"
141 }
142 "link" {
143 set compile_type "executable"
144 set output_file "[file rootname [file tail $prog]].exe"
145 # The following line is needed for targets like the i960 where
146 # the default output file is b.out. Sigh.
147 }
148 "repo" {
149 set compile_type "object"
150 set output_file "[file rootname [file tail $prog]].o"
151 }
152 "run" {
153 set compile_type "executable"
154 # FIXME: "./" is to cope with "." not being in $PATH.
155 # Should this be handled elsewhere?
156 # YES.
157 set output_file "./[file rootname [file tail $prog]].exe"
158 # This is the only place where we care if an executable was
159 # created or not. If it was, dg.exp will try to run it.
160 catch { remote_file build delete $output_file }
161 }
162 default {
163 perror "$do_what: not a valid dg-do keyword"
164 return ""
165 }
166 }
167
168 # Let { dg-final { action } } force options as returned by an
169 # optional proc ${action}_required_options.
170 upvar 2 dg-final-code finalcode
171 foreach x [split $finalcode "\n"] {
172 set finalcmd [lindex $x 0]
173 if { [info procs ${finalcmd}_required_options] != "" } {
174 set req [${finalcmd}_required_options]
175 if { $req != "" } {
176 lappend extra_tool_flags $req
177 }
178 }
179 }
180
181 if { $extra_tool_flags != "" } {
182 lappend options "additional_flags=$extra_tool_flags"
183 }
184
185 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
186
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)"
194 }
195
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] ]
203 }
204
205 return [list $comp_output $output_file]
206 }
207
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]
210 }
211
212 proc gcc-dg-prune { system text } {
213 global additional_prunes
214
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
218
219 set text [prune_gcc_output $text]
220
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
225 }
226 }
227
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"
234 }
235
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"
242 }
243
244 return $text
245 }
246
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
253
254 proc ${tool}_load { program args } {
255 global tool
256 global shouldfail
257 set result [eval [list saved_${tool}_load $program] $args]
258 if { $shouldfail != 0 } {
259 switch [lindex $result 0] {
260 "pass" { set status "fail" }
261 "fail" { set status "pass" }
262 }
263 set result [list $status [lindex $result 1]]
264 }
265 return $result
266 }
267 }
268
269 # Utility routines.
270
271 #
272 # search_for -- looks for a string match in a file
273 #
274 proc search_for { file pattern } {
275 set fd [open $file r]
276 while { [gets $fd cur_line]>=0 } {
277 if [string match "*$pattern*" $cur_line] then {
278 close $fd
279 return 1
280 }
281 }
282 close $fd
283 return 0
284 }
285
286 # Modified dg-runtest that can cycle through a list of optimization options
287 # as c-torture does.
288 proc gcc-dg-runtest { testcases default-extra-flags } {
289 global runtests
290
291 # Some callers set torture options themselves; don't override those.
292 set existing_torture_options [torture-options-exist]
293 if { $existing_torture_options == 0 } {
294 global DG_TORTURE_OPTIONS LTO_TORTURE_OPTIONS
295 torture-init
296 set-torture-options $DG_TORTURE_OPTIONS [list {}] $LTO_TORTURE_OPTIONS
297 }
298 dump-torture-options
299
300 foreach test $testcases {
301 global torture_with_loops torture_without_loops
302 # If we're only testing specific files and this isn't one of
303 # them, skip it.
304 if ![runtest_file_p $runtests $test] {
305 continue
306 }
307
308 # Look for a loop within the source code - if we don't find one,
309 # don't pass -funroll[-all]-loops.
310 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
311 set option_list $torture_with_loops
312 } else {
313 set option_list $torture_without_loops
314 }
315
316 set nshort [file tail [file dirname $test]]/[file tail $test]
317
318 foreach flags $option_list {
319 verbose "Testing $nshort, $flags" 1
320 dg-test $test $flags ${default-extra-flags}
321 }
322 }
323
324 if { $existing_torture_options == 0 } {
325 torture-finish
326 }
327 }
328
329 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
330 global srcdir subdir
331
332 if ![info exists DEBUG_TORTURE_OPTIONS] {
333 set DEBUG_TORTURE_OPTIONS ""
334 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
335 set comp_output [$target_compile \
336 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
337 "additional_flags=$type"]
338 if { ! [string match "*: target system does not support the * debug format*" \
339 $comp_output] } {
340 remove-build-file "trivial.S"
341 foreach level {1 "" 3} {
342 if { ($type == "-gdwarf-2") && ($level != "") } {
343 lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
344 foreach opt $opt_opts {
345 lappend DEBUG_TORTURE_OPTIONS \
346 [list "${type}" "-g${level}" "$opt" ]
347 }
348 } else {
349 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
350 foreach opt $opt_opts {
351 lappend DEBUG_TORTURE_OPTIONS \
352 [list "${type}${level}" "$opt" ]
353 }
354 }
355 }
356 }
357 }
358 }
359
360 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
361
362 global runtests
363
364 foreach test $testcases {
365 # If we're only testing specific files and this isn't one of
366 # them, skip it.
367 if ![runtest_file_p $runtests $test] {
368 continue
369 }
370
371 set nshort [file tail [file dirname $test]]/[file tail $test]
372
373 foreach flags $DEBUG_TORTURE_OPTIONS {
374 set doit 1
375
376 # These tests check for information which may be deliberately
377 # suppressed at -g1.
378 if { ([string match {*/debug-[126].c} "$nshort"] \
379 || [string match {*/enum-1.c} "$nshort"] \
380 || [string match {*/enum-[12].C} "$nshort"]) \
381 && ([string match "*1" [lindex "$flags" 0] ]
382 || [lindex "$flags" 1] == "-g1") } {
383 set doit 0
384 }
385
386 # High optimization can remove the variable whose existence is tested.
387 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
388 # assembler output, but stabs debugging does not.
389 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
390 if { [string match {*/debug-[12].c} "$nshort"] \
391 && [string match "*O*" "$flags"] \
392 && ( [string match "*coff*" "$flags"] \
393 || [string match "*stabs*" "$flags"] ) } {
394 set doit 0
395 }
396
397 if { $doit } {
398 verbose -log "Testing $nshort, $flags" 1
399 dg-test $test $flags ""
400 }
401 }
402 }
403 }
404
405 # Prune any messages matching ARGS[1] (a regexp) from test output.
406 proc dg-prune-output { args } {
407 global additional_prunes
408
409 if { [llength $args] != 2 } {
410 error "[lindex $args 1]: need one argument"
411 return
412 }
413
414 lappend additional_prunes [lindex $args 1]
415 }
416
417 # Remove files matching the pattern from the build machine.
418 proc remove-build-file { pat } {
419 verbose "remove-build-file `$pat'" 2
420 set file_list "[glob -nocomplain $pat]"
421 verbose "remove-build-file `$file_list'" 2
422 foreach output_file $file_list {
423 if [is_remote host] {
424 # Ensure the host knows the file is gone by deleting there
425 # first.
426 remote_file host delete $output_file
427 }
428 remote_file build delete $output_file
429 }
430 }
431
432 # Remove runtime-generated profile file for the current test.
433 proc cleanup-profile-file { } {
434 remove-build-file "mon.out"
435 remove-build-file "gmon.out"
436 }
437
438 # Remove compiler-generated coverage files for the current test.
439 proc cleanup-coverage-files { } {
440 set testcase [testname-for-summary]
441 # The name might include a list of options; extract the file name.
442 set testcase [lindex $testcase 0]
443 remove-build-file "[file rootname [file tail $testcase]].gc??"
444
445 # Clean up coverage files for additional source files.
446 if [info exists additional_sources] {
447 foreach srcfile $additional_sources {
448 remove-build-file "[file rootname [file tail $srcfile]].gc??"
449 }
450 }
451 }
452
453 # Remove compiler-generated files from -repo for the current test.
454 proc cleanup-repo-files { } {
455 set testcase [testname-for-summary]
456 # The name might include a list of options; extract the file name.
457 set testcase [lindex $testcase 0]
458 remove-build-file "[file rootname [file tail $testcase]].o"
459 remove-build-file "[file rootname [file tail $testcase]].rpo"
460
461 # Clean up files for additional source files.
462 if [info exists additional_sources] {
463 foreach srcfile $additional_sources {
464 remove-build-file "[file rootname [file tail $srcfile]].o"
465 remove-build-file "[file rootname [file tail $srcfile]].rpo"
466 }
467 }
468 }
469
470 # Remove compiler-generated RTL dump files for the current test.
471 #
472 # SUFFIX is the filename suffix pattern.
473 proc cleanup-rtl-dump { suffix } {
474 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]r.$suffix"
475 }
476
477 # Remove a specific tree dump file for the current test.
478 #
479 # SUFFIX is the tree dump file suffix pattern.
480 proc cleanup-tree-dump { suffix } {
481 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]t.$suffix"
482 }
483
484 # Remove a specific ipa dump file for the current test.
485 #
486 # SUFFIX is the ipa dump file suffix pattern.
487 proc cleanup-ipa-dump { suffix } {
488 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]i.$suffix"
489 }
490
491 # Remove a stack usage file for the current test.
492 proc cleanup-stack-usage { } {
493 set testcase [testname-for-summary]
494 # The name might include a list of options; extract the file name.
495 set testcase [lindex $testcase 0]
496 remove-build-file "[file rootname [file tail $testcase]].su"
497
498 # Clean up files for additional source files.
499 if [info exists additional_sources] {
500 foreach srcfile $additional_sources {
501 remove-build-file "[file rootname [file tail $srcfile]].su"
502 }
503 }
504 }
505
506 # Remove an Ada spec file for the current test.
507 proc cleanup-ada-spec { } {
508 set testcase [testname-for-summary]
509 remove-build-file "[get_ada_spec_filename $testcase]"
510
511 # Clean up files for additional source files.
512 if [info exists additional_sources] {
513 foreach srcfile $additional_sources {
514 remove-build-file "[get_ada_spec_filename $srcfile]"
515 }
516 }
517 }
518
519 # Remove all dump files with the provided suffix.
520 proc cleanup-dump { suffix } {
521 set testcase [testname-for-summary]
522 # The name might include a list of options; extract the file name.
523 set src [file tail [lindex $testcase 0]]
524 remove-build-file "[file tail $src].$suffix"
525 remove-build-file "[file rootname [file tail $src]].exe.$suffix"
526 remove-build-file "[file rootname [file tail $src]].exe.ltrans\[0-9\]*.$suffix"
527 # -fcompare-debug dumps
528 remove-build-file "[file tail $src].gk.$suffix"
529
530 # Clean up dump files for additional source files.
531 if [info exists additional_sources] {
532 foreach srcfile $additional_sources {
533 remove-build-file "[file tail $srcfile].$suffix"
534 remove-build-file "[file rootname [file tail $srcfile]].exe.$suffix"
535 remove-build-file "[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*.$suffix"
536 # -fcompare-debug dumps
537 remove-build-file "[file tail $srcfile].gk.$suffix"
538 }
539 }
540 }
541
542 # Remove files kept by --save-temps for the current test.
543 #
544 # Currently this is only .i, .ii, .s and .o files, but more can be added
545 # if there are tests generating them.
546 # ARGS is a list of suffixes to NOT delete.
547 proc cleanup-saved-temps { args } {
548 global additional_sources
549 set suffixes {}
550
551 # add the to-be-kept suffixes
552 foreach suffix {".mii" ".ii" ".i" ".s" ".o" ".gkd"} {
553 if {[lsearch $args $suffix] < 0} {
554 lappend suffixes $suffix
555 }
556 }
557
558 set testcase [testname-for-summary]
559 # The name might include a list of options; extract the file name.
560 set testcase [lindex $testcase 0]
561 foreach suffix $suffixes {
562 remove-build-file "[file rootname [file tail $testcase]]$suffix"
563 # -fcompare-debug dumps
564 remove-build-file "[file rootname [file tail $testcase]].gk$suffix"
565 }
566
567 # Clean up saved temp files for additional source files.
568 if [info exists additional_sources] {
569 foreach srcfile $additional_sources {
570 foreach suffix $suffixes {
571 remove-build-file "[file rootname [file tail $srcfile]]$suffix"
572 # -fcompare-debug dumps
573 remove-build-file "[file rootname [file tail $srcfile]].gk$suffix"
574 }
575 }
576 }
577 }
578
579 # Scan Fortran modules for a given regexp.
580 #
581 # Argument 0 is the module name
582 # Argument 1 is the regexp to match
583 proc scan-module { args } {
584 set modfilename [string tolower [lindex $args 0]].mod
585 set fd [open $modfilename r]
586 set text [read $fd]
587 close $fd
588
589 set testcase [testname-for-summary]
590 if [regexp -- [lindex $args 1] $text] {
591 pass "$testcase scan-module [lindex $args 1]"
592 } else {
593 fail "$testcase scan-module [lindex $args 1]"
594 }
595 }
596
597 # Scan Fortran modules for absence of a given regexp.
598 #
599 # Argument 0 is the module name
600 # Argument 1 is the regexp to match
601 proc scan-module-absence { args } {
602 set modfilename [string tolower [lindex $args 0]].mod
603 set fd [open $modfilename r]
604 set text [read $fd]
605 close $fd
606
607 set testcase [testname-for-summary]
608 if [regexp -- [lindex $args 1] $text] {
609 fail "$testcase scan-module [lindex $args 1]"
610 } else {
611 pass "$testcase scan-module [lindex $args 1]"
612 }
613 }
614
615 # Verify that the compiler output file exists, invoked via dg-final.
616 proc output-exists { args } {
617 # Process an optional target or xfail list.
618 if { [llength $args] >= 1 } {
619 switch [dg-process-target [lindex $args 0]] {
620 "S" { }
621 "N" { return }
622 "F" { setup_xfail "*-*-*" }
623 "P" { }
624 }
625 }
626
627 set testcase [testname-for-summary]
628 # Access variable from gcc-dg-test-1.
629 upvar 2 output_file output_file
630
631 if [file exists $output_file] {
632 pass "$testcase output-exists $output_file"
633 } else {
634 fail "$testcase output-exists $output_file"
635 }
636 }
637
638 # Verify that the compiler output file does not exist, invoked via dg-final.
639 proc output-exists-not { args } {
640 # Process an optional target or xfail list.
641 if { [llength $args] >= 1 } {
642 switch [dg-process-target [lindex $args 0]] {
643 "S" { }
644 "N" { return }
645 "F" { setup_xfail "*-*-*" }
646 "P" { }
647 }
648 }
649
650 set testcase [testname-for-summary]
651 # Access variable from gcc-dg-test-1.
652 upvar 2 output_file output_file
653
654 if [file exists $output_file] {
655 fail "$testcase output-exists-not $output_file"
656 } else {
657 pass "$testcase output-exists-not $output_file"
658 }
659 }
660
661 # We need to make sure that additional_* are cleared out after every
662 # test. It is not enough to clear them out *before* the next test run
663 # because gcc-target-compile gets run directly from some .exp files
664 # (outside of any test). (Those uses should eventually be eliminated.)
665
666 # Because the DG framework doesn't provide a hook that is run at the
667 # end of a test, we must replace dg-test with a wrapper.
668
669 if { [info procs saved-dg-test] == [list] } {
670 rename dg-test saved-dg-test
671
672 proc dg-test { args } {
673 global additional_files
674 global additional_sources
675 global additional_prunes
676 global errorInfo
677 global compiler_conditional_xfail_data
678 global shouldfail
679 global testname_with_flags
680
681 if { [ catch { eval saved-dg-test $args } errmsg ] } {
682 set saved_info $errorInfo
683 set additional_files ""
684 set additional_sources ""
685 set additional_prunes ""
686 set shouldfail 0
687 if [info exists compiler_conditional_xfail_data] {
688 unset compiler_conditional_xfail_data
689 }
690 if [info exists testname_with_flags] {
691 unset testname_with_flags
692 }
693 unset_timeout_vars
694 error $errmsg $saved_info
695 }
696 set additional_files ""
697 set additional_sources ""
698 set additional_prunes ""
699 set shouldfail 0
700 unset_timeout_vars
701 if [info exists compiler_conditional_xfail_data] {
702 unset compiler_conditional_xfail_data
703 }
704 if [info exists testname_with_flags] {
705 unset testname_with_flags
706 }
707 }
708 }
709
710 if { [info procs saved-dg-warning] == [list] \
711 && [info exists gcc_warning_prefix] } {
712 rename dg-warning saved-dg-warning
713
714 proc dg-warning { args } {
715 # Make this variable available here and to the saved proc.
716 upvar dg-messages dg-messages
717 global gcc_warning_prefix
718
719 process-message saved-dg-warning "$gcc_warning_prefix" "$args"
720 }
721 }
722
723 if { [info procs saved-dg-error] == [list] \
724 && [info exists gcc_error_prefix] } {
725 rename dg-error saved-dg-error
726
727 proc dg-error { args } {
728 # Make this variable available here and to the saved proc.
729 upvar dg-messages dg-messages
730 global gcc_error_prefix
731
732 process-message saved-dg-error "$gcc_error_prefix" "$args"
733 }
734
735 # Override dg-bogus at the same time. It doesn't handle a prefix
736 # but its expression should include a column number. Otherwise the
737 # line number can match the column number for other messages, leading
738 # to insanity.
739 rename dg-bogus saved-dg-bogus
740
741 proc dg-bogus { args } {
742 upvar dg-messages dg-messages
743 process-message saved-dg-bogus "" $args
744 }
745 }
746
747 # Modify the regular expression saved by a DejaGnu message directive to
748 # include a prefix and to force the expression to match a single line.
749 # MSGPROC is the procedure to call.
750 # MSGPREFIX is the prefix to prepend.
751 # DGARGS is the original argument list.
752
753 proc process-message { msgproc msgprefix dgargs } {
754 upvar dg-messages dg-messages
755
756 # Process the dg- directive, including adding the regular expression
757 # to the new message entry in dg-messages.
758 set msgcnt [llength ${dg-messages}]
759 eval $msgproc $dgargs
760
761 # If the target expression wasn't satisfied there is no new message.
762 if { [llength ${dg-messages}] == $msgcnt } {
763 return;
764 }
765
766 # Get the entry for the new message. Prepend the message prefix to
767 # the regular expression and make it match a single line.
768 set newentry [lindex ${dg-messages} end]
769 set expmsg [lindex $newentry 2]
770
771 # Handle column numbers from the specified expression (if there is
772 # one) and set up the search expression that will be used by DejaGnu.
773 if [regexp "^(\[0-9\]+):" $expmsg "" column] {
774 # The expression in the directive included a column number.
775 # Remove "COLUMN:" from the original expression and move it
776 # to the proper place in the search expression.
777 regsub "^\[0-9\]+:" $expmsg "" expmsg
778 set expmsg "$column: $msgprefix\[^\n\]*$expmsg"
779 } elseif [string match "" [lindex $newentry 0]] {
780 # The specified line number is 0; don't expect a column number.
781 set expmsg "$msgprefix\[^\n\]*$expmsg"
782 } else {
783 # There is no column number in the search expression, but we
784 # should expect one in the message itself.
785 set expmsg "\[0-9\]+: $msgprefix\[^\n\]*$expmsg"
786 }
787
788 set newentry [lreplace $newentry 2 2 $expmsg]
789 set dg-messages [lreplace ${dg-messages} end end $newentry]
790 verbose "process-message:\n${dg-messages}" 2
791 }
792
793 # Look for messages that don't have standard prefixes.
794
795 proc dg-message { args } {
796 upvar dg-messages dg-messages
797 process-message saved-dg-warning "" $args
798 }
799
800 # Check the existence of a gdb in the path, and return true if there
801 # is one.
802 #
803 # Set env(GDB_FOR_GCC_TESTING) accordingly.
804
805 proc gdb-exists { args } {
806 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
807 global GDB
808 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
809 if [info exists GDB] {
810 setenv GDB_FOR_GCC_TESTING "$GDB"
811 } else {
812 setenv GDB_FOR_GCC_TESTING "[transform gdb]"
813 }
814 }
815 }
816 if { [which $::env(GDB_FOR_GCC_TESTING)] != 0 } {
817 return 1;
818 }
819 return 0;
820 }
821
822 set additional_prunes ""
823 set dg_runtest_extra_prunes ""