Debian Codegraph @

gcc/testsuite/lib/gcc-dg.exp

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