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