]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/lib/gcc-dg.exp
c-tree.h (grokfield): New argument.
[thirdparty/gcc.git] / gcc / testsuite / lib / gcc-dg.exp
1 # Copyright (C) 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with GCC; see the file COPYING3. If not see
16 # <http://www.gnu.org/licenses/>.
17
18 load_lib dg.exp
19 load_lib file-format.exp
20 load_lib target-supports.exp
21 load_lib target-supports-dg.exp
22 load_lib scanasm.exp
23 load_lib scanrtl.exp
24 load_lib scantree.exp
25 load_lib scanipa.exp
26 load_lib prune.exp
27 load_lib libgloss.exp
28 load_lib target-libpath.exp
29 load_lib torture-options.exp
30
31 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
32 setenv LC_ALL C
33 setenv LANG C
34
35 if [info exists TORTURE_OPTIONS] {
36 set DG_TORTURE_OPTIONS $TORTURE_OPTIONS
37 } else {
38 # It is theoretically beneficial to group all of the O2/O3 options together,
39 # as in many cases the compiler will generate identical executables for
40 # all of them--and the c-torture testsuite will skip testing identical
41 # executables multiple times.
42 # Also note that -finline-functions is explicitly included in one of the
43 # items below, even though -O3 is also specified, because some ports may
44 # choose to disable inlining functions by default, even when optimizing.
45 set DG_TORTURE_OPTIONS [list \
46 { -O0 } \
47 { -O1 } \
48 { -O2 } \
49 { -O3 -fomit-frame-pointer } \
50 { -O3 -fomit-frame-pointer -funroll-loops } \
51 { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \
52 { -O3 -g } \
53 { -Os } ]
54 }
55
56 global GCC_UNDER_TEST
57 if ![info exists GCC_UNDER_TEST] {
58 set GCC_UNDER_TEST "[find_gcc]"
59 }
60
61 global orig_environment_saved
62
63 # This file may be sourced, so don't override environment settings
64 # that have been previously setup.
65 if { $orig_environment_saved == 0 } {
66 append ld_library_path [gcc-set-multilib-library-path $GCC_UNDER_TEST]
67 set_ld_library_path_env_vars
68 }
69
70 # Define gcc callbacks for dg.exp.
71
72 proc gcc-dg-test-1 { target_compile prog do_what extra_tool_flags } {
73 # Set up the compiler flags, based on what we're going to do.
74
75 set options [list]
76
77 # Tests should be able to use "dg-do repo". However, the dg test
78 # driver checks the argument to dg-do against a list of acceptable
79 # options, and "repo" is not among them. Therefore, we resort to
80 # this ugly approach.
81 if [string match "*-frepo*" $extra_tool_flags] then {
82 set do_what "repo"
83 }
84
85 switch $do_what {
86 "preprocess" {
87 set compile_type "preprocess"
88 set output_file "[file rootname [file tail $prog]].i"
89 }
90 "compile" {
91 set compile_type "assembly"
92 set output_file "[file rootname [file tail $prog]].s"
93 }
94 "assemble" {
95 set compile_type "object"
96 set output_file "[file rootname [file tail $prog]].o"
97 }
98 "precompile" {
99 set compile_type "precompiled_header"
100 set output_file "[file tail $prog].gch"
101 }
102 "link" {
103 set compile_type "executable"
104 set output_file "[file rootname [file tail $prog]].exe"
105 # The following line is needed for targets like the i960 where
106 # the default output file is b.out. Sigh.
107 }
108 "repo" {
109 set compile_type "object"
110 set output_file "[file rootname [file tail $prog]].o"
111 }
112 "run" {
113 set compile_type "executable"
114 # FIXME: "./" is to cope with "." not being in $PATH.
115 # Should this be handled elsewhere?
116 # YES.
117 set output_file "./[file rootname [file tail $prog]].exe"
118 # This is the only place where we care if an executable was
119 # created or not. If it was, dg.exp will try to run it.
120 catch { remote_file build delete $output_file }
121 }
122 default {
123 perror "$do_what: not a valid dg-do keyword"
124 return ""
125 }
126 }
127
128 if { $extra_tool_flags != "" } {
129 lappend options "additional_flags=$extra_tool_flags"
130 }
131
132 set comp_output [$target_compile "$prog" "$output_file" "$compile_type" $options]
133
134 # Look for an internal compiler error, which sometimes masks the fact
135 # that we didn't get an expected error message. XFAIL an ICE via
136 # dg-xfail-if and use { dg-prune-output ".*internal compiler error.*" }
137 # to avoid a second failure for excess errors.
138 if [string match "*internal compiler error*" $comp_output] {
139 upvar 2 name name
140 fail "$name (internal compiler error)"
141 }
142
143 if { $do_what == "repo" } {
144 set object_file "$output_file"
145 set output_file "[file rootname [file tail $prog]].exe"
146 set comp_output \
147 [ concat $comp_output \
148 [$target_compile "$object_file" "$output_file" \
149 "executable" $options] ]
150 }
151
152 return [list $comp_output $output_file]
153 }
154
155 proc gcc-dg-test { prog do_what extra_tool_flags } {
156 return [gcc-dg-test-1 gcc_target_compile $prog $do_what $extra_tool_flags]
157 }
158
159 proc gcc-dg-prune { system text } {
160 global additional_prunes
161
162 set text [prune_gcc_output $text]
163
164 foreach p $additional_prunes {
165 if { [string length $p] > 0 } {
166 # Following regexp matches a complete line containing $p.
167 regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text
168 }
169 }
170
171 # If we see "region xxx is full" then the testcase is too big for ram.
172 # This is tricky to deal with in a large testsuite like c-torture so
173 # deal with it here. Just mark the testcase as unsupported.
174 if [regexp "(^|\n)\[^\n\]*: region \[^\n\]* is full" $text] {
175 # The format here is important. See dg.exp.
176 return "::unsupported::memory full"
177 }
178
179 # Likewise, if we see ".text exceeds local store range" or
180 # similar.
181 if {[string match "spu-*" $system] && \
182 [string match "*exceeds local store range*" $text]} {
183 # The format here is important. See dg.exp.
184 return "::unsupported::memory full"
185 }
186
187 return $text
188 }
189
190 # Replace ${tool}_load with a wrapper to provide for an expected nonzero
191 # exit status. Multiple languages include this file so this handles them
192 # all, not just gcc.
193 if { [info procs ${tool}_load] != [list] \
194 && [info procs saved_${tool}_load] == [list] } {
195 rename ${tool}_load saved_${tool}_load
196
197 proc ${tool}_load { program args } {
198 global tool
199 global shouldfail
200 set result [eval [list saved_${tool}_load $program] $args]
201 if { $shouldfail != 0 } {
202 switch [lindex $result 0] {
203 "pass" { set status "fail" }
204 "fail" { set status "pass" }
205 }
206 set result [list $status [lindex $result 1]]
207 }
208 return $result
209 }
210 }
211
212 # Utility routines.
213
214 #
215 # search_for -- looks for a string match in a file
216 #
217 proc search_for { file pattern } {
218 set fd [open $file r]
219 while { [gets $fd cur_line]>=0 } {
220 if [string match "*$pattern*" $cur_line] then {
221 close $fd
222 return 1
223 }
224 }
225 close $fd
226 return 0
227 }
228
229 # Modified dg-runtest that can cycle through a list of optimization options
230 # as c-torture does.
231 proc gcc-dg-runtest { testcases default-extra-flags } {
232 global runtests
233
234 # Some callers set torture options themselves; don't override those.
235 set existing_torture_options [torture-options-exist]
236 if { $existing_torture_options == 0 } {
237 global DG_TORTURE_OPTIONS
238 torture-init
239 set-torture-options $DG_TORTURE_OPTIONS
240 }
241 dump-torture-options
242
243 foreach test $testcases {
244 global torture_with_loops torture_without_loops
245 # If we're only testing specific files and this isn't one of
246 # them, skip it.
247 if ![runtest_file_p $runtests $test] {
248 continue
249 }
250
251 # Look for a loop within the source code - if we don't find one,
252 # don't pass -funroll[-all]-loops.
253 if [expr [search_for $test "for*("]+[search_for $test "while*("]] {
254 set option_list $torture_with_loops
255 } else {
256 set option_list $torture_without_loops
257 }
258
259 set nshort [file tail [file dirname $test]]/[file tail $test]
260
261 foreach flags $option_list {
262 verbose "Testing $nshort, $flags" 1
263 dg-test $test $flags ${default-extra-flags}
264 }
265 }
266
267 if { $existing_torture_options == 0 } {
268 torture-finish
269 }
270 }
271
272 proc gcc-dg-debug-runtest { target_compile trivial opt_opts testcases } {
273 global srcdir subdir
274
275 if ![info exists DEBUG_TORTURE_OPTIONS] {
276 set DEBUG_TORTURE_OPTIONS ""
277 foreach type {-gdwarf-2 -gstabs -gstabs+ -gxcoff -gxcoff+ -gcoff} {
278 set comp_output [$target_compile \
279 "$srcdir/$subdir/$trivial" "trivial.S" assembly \
280 "additional_flags=$type"]
281 if { ! [string match "*: target system does not support the * debug format*" \
282 $comp_output] } {
283 remove-build-file "trivial.S"
284 foreach level {1 "" 3} {
285 lappend DEBUG_TORTURE_OPTIONS [list "${type}${level}"]
286 foreach opt $opt_opts {
287 lappend DEBUG_TORTURE_OPTIONS \
288 [list "${type}${level}" "$opt" ]
289 }
290 }
291 }
292 }
293 }
294
295 verbose -log "Using options $DEBUG_TORTURE_OPTIONS"
296
297 global runtests
298
299 foreach test $testcases {
300 # If we're only testing specific files and this isn't one of
301 # them, skip it.
302 if ![runtest_file_p $runtests $test] {
303 continue
304 }
305
306 set nshort [file tail [file dirname $test]]/[file tail $test]
307
308 foreach flags $DEBUG_TORTURE_OPTIONS {
309 set doit 1
310
311 # These tests check for information which may be deliberately
312 # suppressed at -g1.
313 if { ([string match {*/debug-[126].c} "$nshort"] \
314 || [string match {*/enum-1.c} "$nshort"] \
315 || [string match {*/enum-[12].C} "$nshort"]) \
316 && [string match "*1" [lindex "$flags" 0] ] } {
317 set doit 0
318 }
319
320 # High optimization can remove the variable whose existence is tested.
321 # Dwarf debugging with commentary (-dA) preserves the symbol name in the
322 # assembler output, but stabs debugging does not.
323 # http://gcc.gnu.org/ml/gcc-regression/2003-04/msg00095.html
324 if { [string match {*/debug-[12].c} "$nshort"] \
325 && [string match "*O*" "$flags"] \
326 && ( [string match "*coff*" "$flags"] \
327 || [string match "*stabs*" "$flags"] ) } {
328 set doit 0
329 }
330
331 if { $doit } {
332 verbose -log "Testing $nshort, $flags" 1
333 dg-test $test $flags ""
334 }
335 }
336 }
337 }
338
339 # Prune any messages matching ARGS[1] (a regexp) from test output.
340 proc dg-prune-output { args } {
341 global additional_prunes
342
343 if { [llength $args] != 2 } {
344 error "[lindex $args 1]: need one argument"
345 return
346 }
347
348 lappend additional_prunes [lindex $args 1]
349 }
350
351 # Remove files matching the pattern from the build machine.
352 proc remove-build-file { pat } {
353 verbose "remove-build-file `$pat'" 2
354 set file_list "[glob -nocomplain $pat]"
355 verbose "remove-build-file `$file_list'" 2
356 foreach output_file $file_list {
357 if [is_remote host] {
358 # Ensure the host knows the file is gone by deleting there
359 # first.
360 remote_file host delete $output_file
361 }
362 remote_file build delete $output_file
363 }
364 }
365
366 # Remove runtime-generated profile file for the current test.
367 proc cleanup-profile-file { } {
368 remove-build-file "mon.out"
369 remove-build-file "gmon.out"
370 }
371
372 # Remove compiler-generated coverage files for the current test.
373 proc cleanup-coverage-files { } {
374 # This assumes that we are two frames down from dg-test or some other proc
375 # that stores the filename of the testcase in a local variable "name".
376 # A cleaner solution would require a new DejaGnu release.
377 upvar 2 name testcase
378 remove-build-file "[file rootname [file tail $testcase]].gc??"
379
380 # Clean up coverage files for additional source files.
381 if [info exists additional_sources] {
382 foreach srcfile $additional_sources {
383 remove-build-file "[file rootname [file tail $srcfile]].gc??"
384 }
385 }
386 }
387
388 # Remove compiler-generated files from -repo for the current test.
389 proc cleanup-repo-files { } {
390 # This assumes that we are two frames down from dg-test or some other proc
391 # that stores the filename of the testcase in a local variable "name".
392 # A cleaner solution would require a new DejaGnu release.
393 upvar 2 name testcase
394 remove-build-file "[file rootname [file tail $testcase]].o"
395 remove-build-file "[file rootname [file tail $testcase]].rpo"
396
397 # Clean up files for additional source files.
398 if [info exists additional_sources] {
399 foreach srcfile $additional_sources {
400 remove-build-file "[file rootname [file tail $srcfile]].o"
401 remove-build-file "[file rootname [file tail $srcfile]].rpo"
402 }
403 }
404 }
405
406 # Remove compiler-generated RTL dump files for the current test.
407 #
408 # SUFFIX is the filename suffix pattern.
409 proc cleanup-rtl-dump { suffix } {
410 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]r.$suffix"
411 }
412
413 # Remove a specific tree dump file for the current test.
414 #
415 # SUFFIX is the tree dump file suffix pattern.
416 proc cleanup-tree-dump { suffix } {
417 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]t.$suffix"
418 }
419
420 # Remove a specific ipa dump file for the current test.
421 #
422 # SUFFIX is the ipa dump file suffix pattern.
423 proc cleanup-ipa-dump { suffix } {
424 cleanup-dump "\[0-9\]\[0-9\]\[0-9\]i.$suffix"
425 }
426
427 # Remove all dump files with the provided suffix.
428 proc cleanup-dump { suffix } {
429 # This assumes that we are three frames down from dg-test or some other
430 # proc that stores the filename of the testcase in a local variable
431 # "name". A cleaner solution would require a new DejaGnu release.
432 upvar 3 name testcase
433 # The name might include a list of options; extract the file name.
434 set src [file tail [lindex $testcase 0]]
435 remove-build-file "[file tail $src].$suffix"
436
437 # Clean up dump files for additional source files.
438 if [info exists additional_sources] {
439 foreach srcfile $additional_sources {
440 remove-build-file "[file tail $srcfile].$suffix"
441 }
442 }
443 }
444
445 # Remove files kept by --save-temps for the current test.
446 #
447 # Currently this is only .i, .ii and .s files, but more can be added
448 # if there are tests generating them.
449 # ARGS is a list of suffixes to NOT delete.
450 proc cleanup-saved-temps { args } {
451 global additional_sources
452 set suffixes {}
453
454 # add the to-be-kept suffixes
455 foreach suffix {".ii" ".i" ".s"} {
456 if {[lsearch $args $suffix] < 0} {
457 lappend suffixes $suffix
458 }
459 }
460
461 # This assumes that we are two frames down from dg-test or some other proc
462 # that stores the filename of the testcase in a local variable "name".
463 # A cleaner solution would require a new DejaGnu release.
464 upvar 2 name testcase
465 foreach suffix $suffixes {
466 remove-build-file "[file rootname [file tail $testcase]]$suffix"
467 }
468
469 # Clean up saved temp files for additional source files.
470 if [info exists additional_sources] {
471 foreach srcfile $additional_sources {
472 foreach suffix $suffixes {
473 remove-build-file "[file rootname [file tail $srcfile]]$suffix"
474 }
475 }
476 }
477 }
478
479 # Remove files for specified Fortran modules.
480 proc cleanup-modules { modlist } {
481 foreach modname $modlist {
482 remove-build-file [string tolower $modname].mod
483 }
484 }
485
486 # Scan Fortran modules for a given regexp.
487 #
488 # Argument 0 is the module name
489 # Argument 1 is the regexp to match
490 proc scan-module { args } {
491 set modfilename [string tolower [lindex $args 0]].mod
492 set fd [open $modfilename r]
493 set text [read $fd]
494 close $fd
495
496 upvar 2 name testcase
497 if [regexp -- [lindex $args 1] $text] {
498 pass "$testcase scan-module [lindex $args 1]"
499 } else {
500 fail "$testcase scan-module [lindex $args 1]"
501 }
502 }
503
504 # Verify that the compiler output file exists, invoked via dg-final.
505 proc output-exists { args } {
506 # Process an optional target or xfail list.
507 if { [llength $args] >= 1 } {
508 switch [dg-process-target [lindex $args 0]] {
509 "S" { }
510 "N" { return }
511 "F" { setup_xfail "*-*-*" }
512 "P" { }
513 }
514 }
515
516 # Access variables from gcc-dg-test-1.
517 upvar 2 name testcase
518 upvar 2 output_file output_file
519
520 if [file exists $output_file] {
521 pass "$testcase output-exists $output_file"
522 } else {
523 fail "$testcase output-exists $output_file"
524 }
525 }
526
527 # Verify that the compiler output file does not exist, invoked via dg-final.
528 proc output-exists-not { args } {
529 # Process an optional target or xfail list.
530 if { [llength $args] >= 1 } {
531 switch [dg-process-target [lindex $args 0]] {
532 "S" { }
533 "N" { return }
534 "F" { setup_xfail "*-*-*" }
535 "P" { }
536 }
537 }
538
539 # Access variables from gcc-dg-test-1.
540 upvar 2 name testcase
541 upvar 2 output_file output_file
542
543 if [file exists $output_file] {
544 fail "$testcase output-exists-not $output_file"
545 } else {
546 pass "$testcase output-exists-not $output_file"
547 }
548 }
549
550 # We need to make sure that additional_* are cleared out after every
551 # test. It is not enough to clear them out *before* the next test run
552 # because gcc-target-compile gets run directly from some .exp files
553 # (outside of any test). (Those uses should eventually be eliminated.)
554
555 # Because the DG framework doesn't provide a hook that is run at the
556 # end of a test, we must replace dg-test with a wrapper.
557
558 if { [info procs saved-dg-test] == [list] } {
559 rename dg-test saved-dg-test
560
561 proc dg-test { args } {
562 global additional_files
563 global additional_sources
564 global additional_prunes
565 global errorInfo
566 global compiler_conditional_xfail_data
567 global shouldfail
568
569 if { [ catch { eval saved-dg-test $args } errmsg ] } {
570 set saved_info $errorInfo
571 set additional_files ""
572 set additional_sources ""
573 set additional_prunes ""
574 set shouldfail 0
575 if [info exists compiler_conditional_xfail_data] {
576 unset compiler_conditional_xfail_data
577 }
578 error $errmsg $saved_info
579 }
580 set additional_files ""
581 set additional_sources ""
582 set additional_prunes ""
583 set shouldfail 0
584 if [info exists compiler_conditional_xfail_data] {
585 unset compiler_conditional_xfail_data
586 }
587 }
588 }
589
590 if { [info procs saved-dg-warning] == [list] \
591 && [info exists gcc_warning_prefix] } {
592 rename dg-warning saved-dg-warning
593
594 proc dg-warning { args } {
595 # Make this variable available here and to the saved proc.
596 upvar dg-messages dg-messages
597 global gcc_warning_prefix
598
599 process-message saved-dg-warning "$gcc_warning_prefix" "$args"
600 }
601 }
602
603 if { [info procs saved-dg-error] == [list] \
604 && [info exists gcc_error_prefix] } {
605 rename dg-error saved-dg-error
606
607 proc dg-error { args } {
608 # Make this variable available here and to the saved proc.
609 upvar dg-messages dg-messages
610 global gcc_error_prefix
611
612 process-message saved-dg-error "$gcc_error_prefix" "$args"
613 }
614 }
615
616 # Modify the regular expression saved by a DejaGnu message directive to
617 # include a prefix and to force the expression to match a single line.
618 # MSGPROC is the procedure to call.
619 # MSGPREFIX is the prefix to prepend.
620 # DGARGS is the original argument list.
621
622 proc process-message { msgproc msgprefix dgargs } {
623 upvar dg-messages dg-messages
624
625 # Process the dg- directive, including adding the regular expression
626 # to the new message entry in dg-messages.
627 set msgcnt [llength ${dg-messages}]
628 catch { eval $msgproc $dgargs }
629
630 # If the target expression wasn't satisfied there is no new message.
631 if { [llength ${dg-messages}] == $msgcnt } {
632 return;
633 }
634
635 # Prepend the message prefix to the regular expression and make
636 # it match a single line.
637 set newentry [lindex ${dg-messages} end]
638 set expmsg [lindex $newentry 2]
639
640 # If we have a column...
641 if [regexp "^(\[0-9\]+):" $expmsg "" column] {
642 # Remove "COLUMN:"
643 regsub "^\[0-9\]+:" $expmsg "" expmsg
644
645 # Include the column in the search expression.
646 set expmsg "$column: $msgprefix\[^\n]*$expmsg"
647 } else {
648 set expmsg "$msgprefix\[^\n]*$expmsg"
649 }
650
651 set newentry [lreplace $newentry 2 2 $expmsg]
652 set dg-messages [lreplace ${dg-messages} end end $newentry]
653 verbose "process-message:\n${dg-messages}" 2
654 }
655
656 # Look for messages that don't have standard prefixes.
657
658 proc dg-message { args } {
659 upvar dg-messages dg-messages
660 process-message saved-dg-warning "" $args
661 }
662
663 set additional_prunes ""