]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/lib/gcc-dg.exp
[testsuite] Add scan-wpa-ipa-dump
[thirdparty/gcc.git] / gcc / testsuite / lib / gcc-dg.exp
1 # Copyright (C) 1997-2018 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
16
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 scanwpaipa.exp
26 load_lib scanlang.exp
27 load_lib timeout.exp
28 load_lib timeout-dg.exp
29 load_lib prune.exp
30 load_lib libgloss.exp
31 load_lib target-libpath.exp
32 load_lib torture-options.exp
33 load_lib fortran-modules.exp
34 load_lib multiline.exp
35
36 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
37 setenv LC_ALL C
38 setenv LANG C
39
40 # Many hosts now default to a non-ASCII C locale, however, so
41 # they can set a charset encoding here if they need.
42 if { [ishost "*-*-cygwin*"] } {
43 setenv LC_ALL C.ASCII
44 setenv LANG C.ASCII
45 }
46
47 # Avoid sporadic data-losses with expect
48 match_max -d 10000
49
50 # Ensure GCC_COLORS is unset, for the rare testcases that verify
51 # how output is colorized.
52 if [info exists ::env(GCC_COLORS) ] {
53 unsetenv GCC_COLORS
54 }
55
56 global GCC_UNDER_TEST
57 if ![info exists GCC_UNDER_TEST] {
58 set GCC_UNDER_TEST "[find_gcc]"
59 }
60
61 # This file may be sourced, so don't override environment settings
62 # that have been previously setup.
63 if { $orig_environment_saved == 0 } {
64 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
65 set_ld_library_path_env_vars
66 }
67
68 # Some torture-options cause intermediate code output, unusable for
69 # testing using e.g. scan-assembler. In this variable are the options
70 # how to force it, when needed.
71 global gcc_force_conventional_output
72 set gcc_force_conventional_output ""
73
74 set LTO_TORTURE_OPTIONS ""
75 if [info exists TORTURE_OPTIONS] {
76 set DG_TORTURE_OPTIONS $TORTURE_OPTIONS
77 } else {
78 # It is theoretically beneficial to group all of the O2/O3 options together,
79 # as in many cases the compiler will generate identical executables for
80 # all of them--and the c-torture testsuite will skip testing identical
81 # executables multiple times.
82 # Also note that -finline-functions is explicitly included in one of the
83 # items below, even though -O3 is also specified, because some ports may
84 # choose to disable inlining functions by default, even when optimizing.
85 set DG_TORTURE_OPTIONS [list \
86 { -O0 } \
87 { -O1 } \
88 { -O2 } \
89 { -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions } \
90 { -O3 -g } \
91 { -Os } ]
92
93 if [check_effective_target_lto] {
94 # When having plugin test both slim and fat LTO and plugin/nonplugin
95 # path.
96 if [check_linker_plugin_available] {
97 set LTO_TORTURE_OPTIONS [list \
98 { -O2 -flto -fno-use-linker-plugin -flto-partition=none } \
99 { -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects }
100 ]
101 } else {
102 set LTO_TORTURE_OPTIONS [list \
103 { -O2 -flto -flto-partition=none } \
104 { -O2 -flto }
105 ]
106 }
107 set gcc_force_conventional_output "-ffat-lto-objects"
108 }
109 }
110
111 if [info exists ADDITIONAL_TORTURE_OPTIONS] {
112 set DG_TORTURE_OPTIONS \
113 [concat $DG_TORTURE_OPTIONS $ADDITIONAL_TORTURE_OPTIONS]
114 }
115
116 global orig_environment_saved
117
118 # Deduce generated files from tool flags, return finalcode string
119 proc schedule-cleanups { opts } {
120 global additional_sources
121 set finalcode ""
122 set testcases {}
123 lappend testcases [lindex [testname-for-summary] 0]
124 verbose "Cleanup testcases: $testcases" 4
125 if { [info exists additional_sources] && $additional_sources != "" } {
126 lappend testcases $additional_sources
127 verbose "Cleanup testcases, additional: $additional_sources" 4
128 }
129 verbose "Cleanup all options: $opts" 4
130
131 # First some fixups to transform stuff to something manageable ..
132 # --dump= should translate to -d with joined operand.
133 if [regexp -- {(^|\s+)--dump=[^\s]+(\s+|$)} $opts] {
134 regsub -all -- {--dump=} $opts {-d} opts
135 }
136 # -da and -dx are treated as shorthand for -fdump-rtl-all here
137 if [regexp -- {(^|\s+)-d[ax](\s+|$)} $opts] {
138 verbose "Cleanup -d seen" 4
139 lappend opts "-fdump-rtl-all"
140 }
141 # .. and don't question why there is --dump=? and -d?
142
143 # Then handle options that generate non-dump files
144 # TODO
145 # -fprofile-generate -> cleanup-coverage-files()
146 # -fstack-usage -> cleanup-stack-usage()
147 if [regexp -- {(^|\s+)-fstack-usage(\s+|$)} $opts] {
148 verbose "Cleanup -fstack-usage seen" 4
149 # append finalcode "cleanup-stack-usage\n"
150 }
151 global keep_saved_temps_suffixes
152 if [info exists keep_saved_temps_suffixes ] {
153 verbose "dg-keep-saved-temps ${keep_saved_temps_suffixes}" 2
154 }
155 # -save-temps -> cleanup-saved-temps()
156 if [regexp -- {(^|\s+)-save-temps(\s+|$)} $opts] {
157 verbose "Cleanup -save-temps seen" 4
158 if [info exists keep_saved_temps_suffixes] {
159 append finalcode "cleanup-saved-temps ${keep_saved_temps_suffixes}\n"
160 } else {
161 append finalcode "cleanup-saved-temps\n"
162 }
163 } else {
164 if [info exists keep_saved_temps_suffixes ] {
165 error "dg-keep-saved-temps specified but testcase does not -save-temps"
166 return
167 }
168 }
169 # Finally see if there are any dumps in opts, otherwise we are done
170 if [regexp -- {(?=(?:^|[ \t]+)?)-fdump-[^ \t]+(?=(?:$|[ \t]+)?)} $opts] {
171 # Lang, Ipa, Rtl, Tree for simplicity
172 set ptn "{l,i,r,t}"
173 } else {
174 return $finalcode
175 }
176 # stem.ext.<passnum><fam>.<passname><pass-instances>
177 # (tree)passes can have multiple instances, thus optional trailing *
178 set ptn "\[0-9\]\[0-9\]\[0-9\]$ptn.*"
179 # Handle ltrans files around -flto
180 if [regexp -- {(^|\s+)-flto(\s+|$)} $opts] {
181 verbose "Cleanup -flto seen" 4
182 set ltrans "{ltrans\[0-9\]*.,}"
183 } else {
184 set ltrans ""
185 }
186 set ptn "$ltrans$ptn"
187 verbose "Cleanup final ptn: $ptn" 4
188 set tfiles {}
189 foreach src $testcases {
190 set basename [file tail $src]
191 if { $ltrans != "" } {
192 # ??? should we use upvar 1 output_file instead of this (dup ?)
193 set stem [file rootname $basename]
194 set basename_ext [file extension $basename]
195 if {$basename_ext != ""} {
196 regsub -- {^.*\.} $basename_ext {} basename_ext
197 }
198 lappend tfiles "$stem.{$basename_ext,exe}"
199 unset basename_ext
200 } else {
201 lappend tfiles $basename
202 }
203 }
204 if { [llength $tfiles] > 1 } {
205 set tfiles [join $tfiles ","]
206 set tfiles "{$tfiles}"
207 }
208 verbose "Cleanup final testcases: $tfiles" 4
209 # We have to quote the regex
210 regsub -all {([][$^?+*()|\\{}])} "$tfiles.$ptn" {\\\1} ptn
211 set final ""
212 append final {remove-build-file }
213 append final "\"$ptn\""
214 verbose "Cleanup final: $final" 4
215 append finalcode "$final\n"
216
217 return $finalcode
218 }
219
220 # Define gcc callbacks for dg.exp.
221
222 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
223 # Set up the compiler flags, based on what we're going to do.
224
225 set options [list]
226
227 # Tests should be able to use "dg-do repo". However, the dg test
228 # driver checks the argument to dg-do against a list of acceptable
229 # options, and "repo" is not among them. Therefore, we resort to
230 # this ugly approach.
231 if [string match "*-frepo*" $extra_tool_flags] then {
232 set do_what "repo"
233 }
234
235 switch $do_what {
236 "preprocess" {
237 set compile_type "preprocess"
238 set output_file "[file rootname [file tail $prog]].i"
239 }
240 "compile" {
241 set compile_type "assembly"
242 set output_file "[file rootname [file tail $prog]].s"
243 }
244 "assemble" {
245 set compile_type "object"
246 set output_file "[file rootname [file tail $prog]].o"
247 }
248 "precompile" {
249 set compile_type "precompiled_header"
250 set output_file "[file tail $prog].gch"
251 }
252 "link" {
253 set compile_type "executable"
254 set output_file "[file rootname [file tail $prog]].exe"
255 # The following line is needed for targets like the i960 where
256 # the default output file is b.out. Sigh.
257 }
258 "repo" {
259 set compile_type "object"
260 set output_file "[file rootname [file tail $prog]].o"
261 }
262 "run" {
263 set compile_type "executable"
264 # FIXME: "./" is to cope with "." not being in $PATH.
265 # Should this be handled elsewhere?
266 # YES.
267 set output_file "./[file rootname [file tail $prog]].exe"
268 # This is the only place where we care if an executable was
269 # created or not. If it was, dg.exp will try to run it.
270 catch { remote_file build delete $output_file }
271 }
272 default {
273 perror "$do_what: not a valid dg-do keyword"
274 return ""
275 }
276 }
277
278 # Let { dg-final { action } } force options as returned by an
279 # optional proc ${action}_required_options.
280 upvar 2 dg-final-code finalcode
281 foreach x [split $finalcode "\n"] {
282 set finalcmd [lindex $x 0]
283 if { [info procs ${finalcmd}_required_options] != "" } {
284 set req [${finalcmd}_required_options]
285 if { $req != "" && [lsearch -exact $extra_tool_flags $req] == -1 } {
286 lappend extra_tool_flags $req
287 }
288 }
289 }
290
291 append finalcode [schedule-cleanups "$options $extra_tool_flags"]
292 if { $extra_tool_flags != "" } {
293 lappend options "additional_flags=$extra_tool_flags"
294 }
295
296 verbose "$target_compile $prog $output_file $compile_type $options" 4
297 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
298
299 # Look for an internal compiler error, which sometimes masks the fact
300 # that we didn't get an expected error message. XFAIL an ICE via
301 # dg-xfail-if and use { dg-prune-output ".*internal compiler error.*" }
302 # to avoid a second failure for excess errors.
303 if [string match "*internal compiler error*" $comp_output] {
304 upvar 2 name name
305 fail "$name (internal compiler error)"
306 }
307
308 if { $do_what == "repo" } {
309 set object_file "$output_file"
310 set output_file "[file rootname [file tail $prog]].exe"
311 set comp_output \
312 [ concat $comp_output \
313 [$target_compile "$object_file" "$output_file" \
314 "executable" $options] ]
315 }
316
317 return [list $comp_output $output_file]
318 }
319
320 proc gcc-dg-test { prog do_what extra_tool_flags } {
321 return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
322 }
323
324 # Global: should blank lines be allowed in the output?
325 # By default, they should not be. (PR other/69006)
326 # However, there are some ways for them to validly occur.
327 set allow_blank_lines 0
328
329 # A command for use by testcases to mark themselves as expecting
330 # blank lines in the output.
331
332 proc dg-allow-blank-lines-in-output { args } {
333 global allow_blank_lines
334 set allow_blank_lines 1
335 }
336
337 proc gcc-dg-prune { system text } {
338 global additional_prunes
339
340 # Extra prune rules that will apply to tests defined in a .exp file.
341 # Always remember to clear it in .exp file after executed all tests.
342 global dg_runtest_extra_prunes
343
344 # Complain about blank lines in the output (PR other/69006)
345 global allow_blank_lines
346 if { !$allow_blank_lines } {
347 set num_blank_lines [llength [regexp -all -inline "\n\n" $text]]
348 if { $num_blank_lines } {
349 global testname_with_flags
350 fail "$testname_with_flags $num_blank_lines blank line(s) in output"
351 }
352 set allow_blank_lines 0
353 }
354
355 set text [prune_gcc_output $text]
356
357 foreach p "$additional_prunes $dg_runtest_extra_prunes" {
358 if { [string length $p] > 0 } {
359 # Following regexp matches a complete line containing $p.
360 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
361 }
362 }
363
364 # If we see "region xxx is full" then the testcase is too big for ram.
365 # This is tricky to deal with in a large testsuite like c-torture so
366 # deal with it here. Just mark the testcase as unsupported.
367 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
368 # The format here is important. See dg.exp.
369 return "::unsupported::memory full"
370 }
371
372 if { [regexp "(^|\n)\[^\n\]*: relocation truncated to fit" $text]
373 && [check_effective_target_tiny] } {
374 return "::unsupported::memory full"
375 }
376
377 # Likewise, if we see ".text exceeds local store range" or
378 # similar.
379 if {[string match "spu-*" $system] && \
380 [string match "*exceeds local store*" $text]} {
381 # The format here is important. See dg.exp.
382 return "::unsupported::memory full"
383 }
384
385 return $text
386 }
387
388 # Replace ${tool}_load with a wrapper to provide for an expected nonzero
389 # exit status. Multiple languages include this file so this handles them
390 # all, not just gcc.
391 if { [info procs ${tool}_load] != [list] \
392 && [info procs saved_${tool}_load] == [list] } {
393 rename ${tool}_load saved_${tool}_load
394
395 proc ${tool}_load { program args } {
396 global tool
397 global shouldfail
398 global set_target_env_var
399
400 set saved_target_env_var [list]
401 if { [info exists set_target_env_var] \
402 && [llength $set_target_env_var] != 0 } {
403 if { [is_remote target] } {
404 return [list "unsupported" ""]
405 }
406 set-target-env-var
407 }
408 set result [eval [list saved_${tool}_load $program] $args]
409 if { [info exists set_target_env_var] \
410 && [llength $set_target_env_var] != 0 } {
411 restore-target-env-var
412 }
413 if { $shouldfail != 0 } {
414 switch [lindex $result 0] {
415 "pass" { set status "fail" }
416 "fail" { set status "pass" }
417 default { set status [lindex $result 0] }
418 }
419 set result [list $status [lindex $result 1]]
420 }
421
422 set result [list [lindex $result 0] [prune_file_path [lindex $result 1]]]
423 return $result
424 }
425 }
426
427 proc dg-set-target-env-var { args } {
428 global set_target_env_var
429 if { [llength $args] != 3 } {
430 error "dg-set-target-env-var: need two arguments"
431 return
432 }
433 lappend set_target_env_var [list [lindex $args 1] [lindex $args 2]]
434 }
435
436 proc set-target-env-var { } {
437 global set_target_env_var
438 upvar 1 saved_target_env_var saved_target_env_var
439 foreach env_var $set_target_env_var {
440 set var [lindex $env_var 0]
441 set value [lindex $env_var 1]
442 if [info exists ::env($var)] {
443 lappend saved_target_env_var [list $var 1 $::env($var)]
444 } else {
445 lappend saved_target_env_var [list $var 0]
446 }
447 setenv $var $value
448 }
449 }
450
451 proc restore-target-env-var { } {
452 upvar 1 saved_target_env_var saved_target_env_var
453 for { set env_vari [llength $saved_target_env_var] } {
454 [incr env_vari -1] >= 0 } {} {
455 set env_var [lindex $saved_target_env_var $env_vari]
456 set var [lindex $env_var 0]
457 if [lindex $env_var 1] {
458 setenv $var [lindex $env_var 2]
459 } else {
460 unsetenv $var
461 }
462 }
463 }
464
465 proc dg-set-compiler-env-var { args } {
466 global set_compiler_env_var
467 global saved_compiler_env_var
468 if { [llength $args] != 3 } {
469 error "dg-set-compiler-env-var: need two arguments"
470 return
471 }
472 set var [lindex $args 1]
473 set value [lindex $args 2]
474 if [info exists ::env($var)] {
475 lappend saved_compiler_env_var [list $var 1 $::env($var)]
476 } else {
477 lappend saved_compiler_env_var [list $var 0]
478 }
479 setenv $var $value
480 lappend set_compiler_env_var [list $var $value]
481 }
482
483 proc restore-compiler-env-var { } {
484 global saved_compiler_env_var
485 for { set env_vari [llength $saved_compiler_env_var] } {
486 [incr env_vari -1] >= 0 } {} {
487 set env_var [lindex $saved_compiler_env_var $env_vari]
488 set var [lindex $env_var 0]
489 if [lindex $env_var 1] {
490 setenv $var [lindex $env_var 2]
491 } else {
492 unsetenv $var
493 }
494 }
495 }
496
497 # Utility routines.
498
499 #
500 # search_for -- looks for a string match in a file
501 #
502 proc search_for { file pattern } {
503 set fd [open $file r]
504 while { [gets $fd cur_line]>=0 } {
505 if [string match "*$pattern*" $cur_line] then {
506 close $fd
507 return 1
508 }
509 }
510 close $fd
511 return 0
512 }
513
514 # Modified dg-runtest that can cycle through a list of optimization options
515 # as c-torture does.
516 proc gcc-dg-runtest { testcases flags default-extra-flags } {
517 global runtests
518
519 # Some callers set torture options themselves; don't override those.
520 set existing_torture_options [torture-options-exist]
521 if { $existing_torture_options == 0 } {
522 global DG_TORTURE_OPTIONS LTO_TORTURE_OPTIONS
523 torture-init
524 set-torture-options $DG_TORTURE_OPTIONS [list {}] $LTO_TORTURE_OPTIONS
525 }
526 dump-torture-options
527
528 foreach test $testcases {
529 global torture_with_loops torture_without_loops
530 # If we're only testing specific files and this isn't one of
531 # them, skip it.
532 if ![runtest_file_p $runtests $test] {
533 continue
534 }
535
536 # Look for a loop within the source code - if we don't find one,
537 # don't pass -funroll[-all]-loops.
538 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
539 set option_list $torture_with_loops
540 } else {
541 set option_list $torture_without_loops
542 }
543
544 set nshort [file tail [file dirname $test]]/[file tail $test]
545
546 foreach flags_t $option_list {
547 global torture_current_flags
548 set torture_current_flags "$flags_t"
549 verbose "Testing $nshort, $flags $flags_t" 1
550 dg-test $test "$flags $flags_t" ${default-extra-flags}
551 }
552 }
553
554 if { $existing_torture_options == 0 } {
555 torture-finish
556 }
557 }
558
559 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
560 global srcdir subdir
561
562 if ![info exists DEBUG_TORTURE_OPTIONS] {
563 set DEBUG_TORTURE_OPTIONS ""
564 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+} {
565 set comp_output [$target_compile \
566 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
567 "additional_flags=$type"]
568 if { ! [string match "*: target system does not support the * debug format*" \
569 $comp_output] } {
570 remove-build-file "trivial.S"
571 foreach level {1 "" 3} {
572 if { ($type == "-gdwarf-2") && ($level != "") } {
573 lappend DEBUG_TORTURE_OPTIONS [list "${type}" "-g${level}"]
574 foreach opt $opt_opts {
575 lappend DEBUG_TORTURE_OPTIONS \
576 [list "${type}" "-g${level}" "$opt" ]
577 }
578 } else {
579 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
580 foreach opt $opt_opts {
581 lappend DEBUG_TORTURE_OPTIONS \
582 [list "${type}${level}" "$opt" ]
583 }
584 }
585 }
586 }
587 }
588 }
589
590 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
591
592 global runtests
593
594 foreach test $testcases {
595 # If we're only testing specific files and this isn't one of
596 # them, skip it.
597 if ![runtest_file_p $runtests $test] {
598 continue
599 }
600
601 set nshort [file tail [file dirname $test]]/[file tail $test]
602
603 foreach flags $DEBUG_TORTURE_OPTIONS {
604 set doit 1
605
606 # These tests check for information which may be deliberately
607 # suppressed at -g1.
608 if { ([string match {*/debug-[126].c} "$nshort"] \
609 || [string match {*/enum-1.c} "$nshort"] \
610 || [string match {*/enum-[12].C} "$nshort"]) \
611 && ([string match "*1" [lindex "$flags" 0] ]
612 || [lindex "$flags" 1] == "-g1") } {
613 set doit 0
614 }
615
616 # High optimization can remove the variable whose existence is tested.
617 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
618 # assembler output, but stabs debugging does not.
619 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
620 if { [string match {*/debug-[12].c} "$nshort"] \
621 && [string match "*O*" "$flags"] \
622 && ( [string match "*coff*" "$flags"] \
623 || [string match "*stabs*" "$flags"] ) } {
624 set doit 0
625 }
626
627 if { $doit } {
628 verbose -log "Testing $nshort, $flags" 1
629 dg-test $test $flags ""
630 }
631 }
632 }
633 }
634
635 # Prune any messages matching ARGS[1] (a regexp) from test output.
636 proc dg-prune-output { args } {
637 global additional_prunes
638
639 if { [llength $args] != 2 } {
640 error "[lindex $args 1]: need one argument"
641 return
642 }
643
644 lappend additional_prunes [lindex $args 1]
645 }
646
647 # Remove files matching the pattern from the build machine.
648 proc remove-build-file { pat } {
649 verbose "remove-build-file `$pat'" 2
650 set file_list "[glob -nocomplain $pat]"
651 verbose "remove-build-file `$file_list'" 2
652 foreach output_file $file_list {
653 if [is_remote host] {
654 # Ensure the host knows the file is gone by deleting there
655 # first.
656 remote_file host delete $output_file
657 }
658 remote_file build delete $output_file
659 }
660 }
661
662 # Remove runtime-generated profile file for the current test.
663 proc cleanup-profile-file { } {
664 remove-build-file "mon.out"
665 remove-build-file "gmon.out"
666 }
667
668 # Remove compiler-generated coverage files for the current test.
669 proc cleanup-coverage-files { } {
670 global additional_sources_used
671 set testcase [testname-for-summary]
672 # The name might include a list of options; extract the file name.
673 set testcase [lindex $testcase 0]
674 remove-build-file "[file rootname [file tail $testcase]].gc??"
675
676 # Clean up coverage files for additional source files.
677 if [info exists additional_sources_used] {
678 foreach srcfile $additional_sources_used {
679 remove-build-file "[file rootname [file tail $srcfile]].gc??"
680 }
681 }
682 }
683
684 # Remove compiler-generated files from -repo for the current test.
685 proc cleanup-repo-files { } {
686 global additional_sources_used
687 set testcase [testname-for-summary]
688 # The name might include a list of options; extract the file name.
689 set testcase [lindex $testcase 0]
690 remove-build-file "[file rootname [file tail $testcase]].o"
691 remove-build-file "[file rootname [file tail $testcase]].rpo"
692
693 # Clean up files for additional source files.
694 if [info exists additional_sources_used] {
695 foreach srcfile $additional_sources_used {
696 remove-build-file "[file rootname [file tail $srcfile]].o"
697 remove-build-file "[file rootname [file tail $srcfile]].rpo"
698 }
699 }
700 }
701
702 # Remove a final insns dump file for the current test.
703 proc cleanup-final-insns-dump { } {
704 set testcase [testname-for-summary]
705 # The name might include a list of options; extract the file name.
706 set testcase [lindex $testcase 0]
707 remove-build-file "[file rootname [file tail $testcase]].s.gkd"
708
709 # Clean up files for additional source files.
710 if [info exists additional_sources_used] {
711 foreach srcfile $additional_sources_used {
712 remove-build-file "[file rootname [file tail $srcfile]].s.gkd"
713 }
714 }
715 }
716
717 # Remove a stack usage file for the current test.
718 proc cleanup-stack-usage { } {
719 set testcase [testname-for-summary]
720 # The name might include a list of options; extract the file name.
721 set testcase [lindex $testcase 0]
722 remove-build-file "[file rootname [file tail $testcase]].su"
723
724 # Clean up files for additional source files.
725 if [info exists additional_sources_used] {
726 foreach srcfile $additional_sources_used {
727 remove-build-file "[file rootname [file tail $srcfile]].su"
728 }
729 }
730 }
731
732 # Remove an Ada spec file for the current test.
733 proc cleanup-ada-spec { } {
734 global additional_sources_used
735 set testcase [testname-for-summary]
736 remove-build-file "[get_ada_spec_filename $testcase]"
737
738 # Clean up files for additional source files.
739 if [info exists additional_sources_used] {
740 foreach srcfile $additional_sources_used {
741 remove-build-file "[get_ada_spec_filename $srcfile]"
742 }
743 }
744 }
745
746 # Remove files kept by --save-temps for the current test.
747 #
748 # Currently this is only .i, .ii, .s and .o files, but more can be added
749 # if there are tests generating them.
750 # ARGS is a list of suffixes to NOT delete.
751 proc cleanup-saved-temps { args } {
752 global additional_sources_used
753 set suffixes {}
754
755 # add the to-be-kept suffixes
756 foreach suffix {".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
757 if {[lsearch $args $suffix] < 0} {
758 lappend suffixes $suffix
759 }
760 }
761
762 set testcase [testname-for-summary]
763 # The name might include a list of options; extract the file name.
764 set testcase [lindex $testcase 0]
765 foreach suffix $suffixes {
766 remove-build-file "[file rootname [file tail $testcase]]$suffix"
767 remove-build-file "[file rootname [file tail $testcase]].exe$suffix"
768 remove-build-file "[file rootname [file tail $testcase]].exe.ltrans\[0-9\]*$suffix"
769 # -fcompare-debug dumps
770 remove-build-file "[file rootname [file tail $testcase]].gk$suffix"
771 }
772
773 # Clean up saved temp files for additional source files.
774 if [info exists additional_sources_used] {
775 foreach srcfile $additional_sources_used {
776 foreach suffix $suffixes {
777 remove-build-file "[file rootname [file tail $srcfile]]$suffix"
778 remove-build-file "[file rootname [file tail $srcfile]].exe$suffix"
779 remove-build-file "[file rootname [file tail $srcfile]].exe.ltrans\[0-9\]*$suffix"
780
781 # -fcompare-debug dumps
782 remove-build-file "[file rootname [file tail $srcfile]].gk$suffix"
783 }
784 }
785 }
786 }
787
788
789 # Files to be kept after cleanup of --save-temps for the current test.
790 # ARGS is a list of suffixes to NOT delete.
791 proc dg-keep-saved-temps { args } {
792 global keep_saved_temps_suffixes
793 set keep_saved_temps_suffixes {}
794
795 # add the to-be-kept suffixes
796 foreach suffix {".mii" ".ii" ".i" ".s" ".o" ".gkd" ".res" ".ltrans.out"} {
797 if {[lsearch $args $suffix] >= 0} {
798 lappend keep_saved_temps_suffixes $suffix
799 }
800 }
801 if { [llength keep_saved_temps_suffixes] < 1 } {
802 error "dg-keep-saved-temps ${args} did not match any known suffix"
803 }
804 }
805
806 # Scan Fortran modules for a given regexp.
807 #
808 # Argument 0 is the module name
809 # Argument 1 is the regexp to match
810 proc scan-module { args } {
811 set modfilename [string tolower [lindex $args 0]].mod
812 set fd [open [list | gzip -dc $modfilename] r]
813 set text [read $fd]
814 close $fd
815
816 set testcase [testname-for-summary]
817 if [regexp -- [lindex $args 1] $text] {
818 pass "$testcase scan-module [lindex $args 1]"
819 } else {
820 fail "$testcase scan-module [lindex $args 1]"
821 }
822 }
823
824 # Scan Fortran modules for absence of a given regexp.
825 #
826 # Argument 0 is the module name
827 # Argument 1 is the regexp to match
828 proc scan-module-absence { args } {
829 set modfilename [string tolower [lindex $args 0]].mod
830 set fd [open [list | gzip -dc $modfilename] r]
831 set text [read $fd]
832 close $fd
833
834 set testcase [testname-for-summary]
835 if [regexp -- [lindex $args 1] $text] {
836 fail "$testcase scan-module [lindex $args 1]"
837 } else {
838 pass "$testcase scan-module [lindex $args 1]"
839 }
840 }
841
842 # Verify that the compiler output file exists, invoked via dg-final.
843 proc output-exists { args } {
844 # Process an optional target or xfail list.
845 if { [llength $args] >= 1 } {
846 switch [dg-process-target [lindex $args 0]] {
847 "S" { }
848 "N" { return }
849 "F" { setup_xfail "*-*-*" }
850 "P" { }
851 }
852 }
853
854 set testcase [testname-for-summary]
855 # Access variable from gcc-dg-test-1.
856 upvar 2 output_file output_file
857
858 if [file exists $output_file] {
859 pass "$testcase output-exists $output_file"
860 } else {
861 fail "$testcase output-exists $output_file"
862 }
863 }
864
865 # Verify that the compiler output file does not exist, invoked via dg-final.
866 proc output-exists-not { args } {
867 # Process an optional target or xfail list.
868 if { [llength $args] >= 1 } {
869 switch [dg-process-target [lindex $args 0]] {
870 "S" { }
871 "N" { return }
872 "F" { setup_xfail "*-*-*" }
873 "P" { }
874 }
875 }
876
877 set testcase [testname-for-summary]
878 # Access variable from gcc-dg-test-1.
879 upvar 2 output_file output_file
880
881 if [file exists $output_file] {
882 fail "$testcase output-exists-not $output_file"
883 } else {
884 pass "$testcase output-exists-not $output_file"
885 }
886 }
887
888 # We need to make sure that additional_* are cleared out after every
889 # test. It is not enough to clear them out *before* the next test run
890 # because gcc-target-compile gets run directly from some .exp files
891 # (outside of any test). (Those uses should eventually be eliminated.)
892
893 # Because the DG framework doesn't provide a hook that is run at the
894 # end of a test, we must replace dg-test with a wrapper.
895
896 if { [info procs saved-dg-test] == [list] } {
897 rename dg-test saved-dg-test
898
899 # Helper function for cleanups that should happen after the call
900 # to the real dg-test, whether or not it returns normally, or
901 # fails with an error.
902 proc cleanup-after-saved-dg-test { } {
903 global additional_files
904 global additional_sources
905 global additional_sources_used
906 global additional_prunes
907 global compiler_conditional_xfail_data
908 global shouldfail
909 global testname_with_flags
910 global set_target_env_var
911 global set_compiler_env_var
912 global saved_compiler_env_var
913 global keep_saved_temps_suffixes
914 global multiline_expected_outputs
915 global freeform_regexps
916 global save_linenr_varnames
917
918 set additional_files ""
919 set additional_sources ""
920 set additional_sources_used ""
921 set additional_prunes ""
922 set shouldfail 0
923 if [info exists set_target_env_var] {
924 unset set_target_env_var
925 }
926 if [info exists set_compiler_env_var] {
927 restore-compiler-env-var
928 unset set_compiler_env_var
929 unset saved_compiler_env_var
930 }
931 if [info exists keep_saved_temps_suffixes] {
932 unset keep_saved_temps_suffixes
933 }
934 unset_timeout_vars
935 if [info exists compiler_conditional_xfail_data] {
936 unset compiler_conditional_xfail_data
937 }
938 if [info exists testname_with_flags] {
939 unset testname_with_flags
940 }
941 set multiline_expected_outputs []
942 set freeform_regexps []
943
944 if { [info exists save_linenr_varnames] } {
945 foreach varname $save_linenr_varnames {
946 # Cleanup varname
947 eval global $varname
948 eval unset $varname
949
950 # Cleanup varname_used, or generate defined-but-not-used
951 # warning.
952 set varname_used used_$varname
953 eval global $varname_used
954 eval set used [info exists $varname_used]
955 if { $used } {
956 eval unset $varname_used
957 } else {
958 regsub {^saved_linenr_} $varname "" org_varname
959 warning "dg-line var $org_varname defined, but not used"
960 }
961 }
962 unset save_linenr_varnames
963 }
964 }
965
966 proc dg-test { args } {
967 global errorInfo
968
969 if { [ catch { eval saved-dg-test $args } errmsg ] } {
970 set saved_info $errorInfo
971 cleanup-after-saved-dg-test
972 error $errmsg $saved_info
973 }
974 cleanup-after-saved-dg-test
975 }
976 }
977
978 if { [info procs saved-dg-warning] == [list] \
979 && [info exists gcc_warning_prefix] } {
980 rename dg-warning saved-dg-warning
981
982 proc dg-warning { args } {
983 # Make this variable available here and to the saved proc.
984 upvar dg-messages dg-messages
985 global gcc_warning_prefix
986
987 process-message saved-dg-warning "$gcc_warning_prefix" "$args"
988 }
989 }
990
991 if { [info procs saved-dg-error] == [list] \
992 && [info exists gcc_error_prefix] } {
993 rename dg-error saved-dg-error
994
995 proc dg-error { args } {
996 # Make this variable available here and to the saved proc.
997 upvar dg-messages dg-messages
998 global gcc_error_prefix
999
1000 process-message saved-dg-error "$gcc_error_prefix" "$args"
1001 }
1002
1003 # Override dg-bogus at the same time. It doesn't handle a prefix
1004 # but its expression should include a column number. Otherwise the
1005 # line number can match the column number for other messages, leading
1006 # to insanity.
1007 rename dg-bogus saved-dg-bogus
1008
1009 proc dg-bogus { args } {
1010 upvar dg-messages dg-messages
1011 process-message saved-dg-bogus "" $args
1012 }
1013 }
1014
1015 # Set variable VARNAME to LINENR
1016
1017 proc dg-line { linenr varname } {
1018 set org_varname $varname
1019 set varname "saved_linenr_$varname"
1020 eval global $varname
1021
1022 # Generate defined-but-previously-defined error.
1023 eval set var_defined [info exists $varname]
1024 if { $var_defined } {
1025 eval set deflinenr \$$varname
1026 error "dg-line var $org_varname defined at line $linenr, but previously defined at line $deflinenr"
1027 return
1028 }
1029
1030 eval set $varname $linenr
1031
1032 # Schedule cleanup of varname by cleanup-after-saved-dg-test
1033 global save_linenr_varnames
1034 if { [info exists save_linenr_varnames] } {
1035 lappend save_linenr_varnames $varname
1036 } else {
1037 set save_linenr_varnames [list $varname]
1038 }
1039 }
1040
1041 # Modify the regular expression saved by a DejaGnu message directive to
1042 # include a prefix and to force the expression to match a single line.
1043 # MSGPROC is the procedure to call.
1044 # MSGPREFIX is the prefix to prepend.
1045 # DGARGS is the original argument list.
1046
1047 proc process-message { msgproc msgprefix dgargs } {
1048 upvar dg-messages dg-messages
1049
1050 if { [llength $dgargs] == 5 } {
1051 if { [regsub "^\.\[+-\](\[0-9\]+)$" [lindex $dgargs 4] "\\1" num] } {
1052 # Handle relative line specification, .+1 or .-1 etc.
1053 set num [expr [lindex $dgargs 0] [string index [lindex $dgargs 4] 1] $num]
1054 set dgargs [lreplace $dgargs 4 4 $num]
1055 } elseif { [regsub "^(\[a-zA-Z\]\[a-zA-Z0-9_\]*)$" [lindex $dgargs 4] "\\1" varname] } {
1056 # Handle linenr variable defined by dg-line
1057
1058 set org_varname $varname
1059 set varname "saved_linenr_$varname"
1060 eval global $varname
1061
1062 # Generate used-but-not-defined error.
1063 eval set var_defined [info exists $varname]
1064 if { ! $var_defined } {
1065 set linenr [expr [lindex $dgargs 0]]
1066 error "dg-line var $org_varname used at line $linenr, but not defined"
1067 return
1068 }
1069
1070 # Note that varname has been used.
1071 set varname_used "used_$varname"
1072 eval global $varname_used
1073 eval set $varname_used 1
1074
1075 # Get line number from var and use it.
1076 eval set num \$$varname
1077 set dgargs [lreplace $dgargs 4 4 $num]
1078 }
1079 }
1080
1081 # Process the dg- directive, including adding the regular expression
1082 # to the new message entry in dg-messages.
1083 set msgcnt [llength ${dg-messages}]
1084 eval $msgproc $dgargs
1085
1086 # If the target expression wasn't satisfied there is no new message.
1087 if { [llength ${dg-messages}] == $msgcnt } {
1088 return;
1089 }
1090
1091 # Get the entry for the new message. Prepend the message prefix to
1092 # the regular expression and make it match a single line.
1093 set newentry [lindex ${dg-messages} end]
1094 set expmsg [lindex $newentry 2]
1095
1096 set column ""
1097 # Handle column numbers from the specified expression (if there is
1098 # one) and set up the search expression that will be used by DejaGnu.
1099 if [regexp {^-:} $expmsg] {
1100 # The expected column is -, so shouldn't appear.
1101 set expmsg [string range $expmsg 2 end]
1102 } elseif [regexp {^[0-9]+:} $expmsg column] {
1103 # The expression in the directive included a column number.
1104 # Remove it from the original expression and move it
1105 # to the proper place in the search expression.
1106 set expmsg [string range $expmsg [string length $column] end]
1107 set column "$column "
1108 } elseif [string match "" [lindex $newentry 0]] {
1109 # The specified line number is 0; don't expect a column number.
1110 } else {
1111 # There is no column number in the search expression, but we
1112 # should expect one in the message itself.
1113 set column {[0-9]+: }
1114 }
1115 set expmsg "$column$msgprefix\[^\n\]*$expmsg"
1116 set newentry [lreplace $newentry 2 2 $expmsg]
1117
1118 set dg-messages [lreplace ${dg-messages} end end $newentry]
1119 verbose "process-message:\n${dg-messages}" 2
1120 }
1121
1122 # Look for messages that don't have standard prefixes.
1123
1124 proc dg-message { args } {
1125 upvar dg-messages dg-messages
1126 process-message saved-dg-warning "" $args
1127 }
1128
1129 # Look for a location marker of the form
1130 # file:line:column:
1131 # with no extra text (e.g. a line-span separator).
1132
1133 proc dg-locus { args } {
1134 upvar dg-messages dg-messages
1135
1136 # Process the dg- directive, including adding the regular expression
1137 # to the new message entry in dg-messages.
1138 set msgcnt [llength ${dg-messages}]
1139 eval saved-dg-warning $args
1140
1141 # If the target expression wasn't satisfied there is no new message.
1142 if { [llength ${dg-messages}] == $msgcnt } {
1143 return;
1144 }
1145
1146 # Get the entry for the new message. Prepend the message prefix to
1147 # the regular expression and make it match a single line.
1148 set newentry [lindex ${dg-messages} end]
1149 set expmsg [lindex $newentry 2]
1150
1151 set newentry [lreplace $newentry 2 2 $expmsg]
1152 set dg-messages [lreplace ${dg-messages} end end $newentry]
1153 verbose "process-message:\n${dg-messages}" 2
1154 }
1155
1156 # Check the existence of a gdb in the path, and return true if there
1157 # is one.
1158 #
1159 # Set env(GDB_FOR_GCC_TESTING) accordingly.
1160
1161 proc gdb-exists { args } {
1162 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
1163 global GDB
1164 if ![info exists ::env(GDB_FOR_GCC_TESTING)] {
1165 if [info exists GDB] {
1166 setenv GDB_FOR_GCC_TESTING "$GDB"
1167 } else {
1168 setenv GDB_FOR_GCC_TESTING "[transform gdb]"
1169 }
1170 }
1171 }
1172 if { [which $::env(GDB_FOR_GCC_TESTING)] != 0 } {
1173 return 1;
1174 }
1175 return 0;
1176 }
1177
1178 set additional_prunes ""
1179 set dg_runtest_extra_prunes ""