OSDN Git Service

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