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