OSDN Git Service

PR middle-end/43419
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / fortran-torture.exp
1 # Copyright (C) 2003, 2006, 2007, 2008, 2010 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 # Please email any bugs, comments, and/or additions to this file to
18 # the author.
19
20 # This file was written by Steven Bosscher (s.bosscher@student.tudelft.nl)
21 # based on f-torture.exp, which was written by Rob Savoye.
22
23 load_lib target-supports.exp
24
25 # Return the list of options to use for fortran torture tests.
26 # The default option list can be overridden by
27 # TORTURE_OPTIONS="{ { list1 } ... { listN } }"
28 proc get-fortran-torture-options { } {
29     global TORTURE_OPTIONS
30
31     if [info exists TORTURE_OPTIONS] {
32         return $TORTURE_OPTIONS
33     }
34
35     # determine if host supports vectorization, and the necessary set
36     # of options, based on code from testsuite/vect/vect.exp
37
38     set vectorizer_options [list "-O2" "-ftree-vectorize"]
39
40     if { [istarget "powerpc*-*-*"]
41          && [is-effective-target powerpc_altivec_ok]
42          && [check_vmx_hw_available] } {
43         lappend vectorizer_options "-maltivec"
44         set test_tree_vectorize 1
45     } elseif { [istarget  "spu-*-*"] } {
46         set test_tree_vectorize 1
47     } elseif { ( [istarget "i?86-*-*"] || [istarget "x86_64-*-*"] )
48                && [check_effective_target_sse2]
49                && [check_sse2_hw_available] } {
50         lappend vectorizer_options "-msse2"
51         set test_tree_vectorize 1
52     } elseif { [istarget "mips*-*-*"]
53                && [check_effective_target_mpaired_single]
54                && [check_effective_target_nomips16] } {
55         lappend vectorizer_options "-mpaired-single"
56         set test_tree_vectorize 1
57     } elseif { [istarget "sparc*-*-*"]
58                && [check_effective_target_ultrasparc_hw] } {
59         lappend vectorizer_options "-mcpu=ultrasparc" "-mvis"
60         set test_tree_vectorize 1
61     } elseif { [istarget "alpha*-*-*"]
62                && [check_alpha_max_hw_available] } {
63         lappend vectorizer_options "-mmax"
64         set test_tree_vectorize 1
65     } elseif [istarget "ia64-*-*"] {
66         set test_tree_vectorize 1
67     } else {
68         set test_tree_vectorize 0
69     }
70
71     set options {}
72
73     lappend options \
74         { -O0 } \
75         { -O1 } \
76         { -O2 } \
77         { -O2 -fomit-frame-pointer -finline-functions } \
78         { -O2 -fomit-frame-pointer -finline-functions -funroll-loops } \
79         { -O2 -fbounds-check } \
80         { -O3 -g } \
81         { -Os }
82     if { $test_tree_vectorize } {
83         lappend options $vectorizer_options
84     }
85
86     if [info exists ADDITIONAL_TORTURE_OPTIONS] {
87         set options [concat $options $ADDITIONAL_TORTURE_OPTIONS]
88     }
89
90     return $options
91 }
92
93
94 #
95 # fortran-torture-compile -- compile a gfortran.fortran-torture testcase.
96 #
97 # SRC is the full pathname of the testcase.
98 # OPTION is the specific compiler flag we're testing (eg: -O2).
99 #
100 proc fortran-torture-compile { src option } {
101     global output
102     global srcdir tmpdir
103     global host_triplet
104
105     set output "$tmpdir/[file tail [file rootname $src]].o"
106
107     regsub "(?q)$srcdir/" $src "" testcase
108
109     # If we couldn't rip $srcdir out of `src' then just do the best we can.
110     # The point is to reduce the unnecessary noise in the logs.  Don't strip
111     # out too much because different testcases with the same name can confuse
112     # `test-tool'.
113     if [string match "/*" $testcase] {
114         set testcase "[file tail [file dirname $src]]/[file tail $src]"
115     }
116
117     verbose "Testing $testcase, $option" 1
118
119     # Run the compiler and get results in comp_output.
120     set options ""
121     lappend options "additional_flags=-w $option"
122
123     set comp_output [gfortran_target_compile "$src" "$output" object $options]
124     
125     # See if we got something bad.
126     set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
127  
128     if [string match "$fatal_signal 6" $comp_output] then {
129         gfortran_fail $testcase "Got Signal 6, $option"
130         catch { remote_file build delete $output }
131         return
132     }
133
134     if [string match "$fatal_signal 11" $comp_output] then {
135         gfortran_fail $testcase "Got Signal 11, $option"
136         catch { remote_file build delete $output }
137         return
138     }
139
140     if [string match "*internal compiler error*" $comp_output] then {
141         gfortran_fail $testcase "$option (internal compiler error)"
142         catch { remote_file build delete $output }
143         return
144     }
145
146     # We shouldn't get these because of -w, but just in case.
147     if [string match "*95*:*warning:*" $comp_output] then {
148         warning "$testcase: (with warnings) $option"
149         send_log "$comp_output\n"
150         unresolved "$testcase, $option"
151         catch { remote_file build delete $output }
152         return
153     }
154
155     # Prune warnings we know are unwanted.
156     set comp_output [prune_warnings $comp_output]
157
158     # Report if the testcase is not supported.
159     set unsupported_message [gfortran_check_unsupported_p $comp_output]
160     if { $unsupported_message != "" } {
161         unsupported "$testcase: $unsupported_message"
162         catch { remote_file build delete $output }
163         return
164     }
165
166     # remove any leftover LF/CR to make sure any output is legit
167     regsub -all -- "\[\r\n\]*" $comp_output "" comp_output
168
169     # If any message remains, we fail.
170     if ![string match "" $comp_output] then {
171         gfortran_fail $testcase $option
172         catch { remote_file build delete $output }
173         return
174     }
175
176     gfortran_pass $testcase $option
177     catch { remote_file build delete $output }
178 }
179
180
181 #
182 # fortran-torture-execute -- compile and execute a testcase.
183 #
184 # SRC is the full pathname of the testcase.
185 #
186 # If the testcase has an associated .x file, we source that to run the
187 # test instead.  We use .x so that we don't lengthen the existing filename
188 # to more than 14 chars.
189 #
190 proc fortran-torture-execute { src } {
191     global output
192     global srcdir tmpdir
193     global tool
194     global compiler_conditional_xfail_data
195     global torture_with_loops
196
197     # Check for alternate driver.
198     set additional_flags ""
199     if [file exists [file rootname $src].x] {
200         verbose "Using alternate driver [file rootname [file tail $src]].x" 2
201         set done_p 0
202         catch "set done_p \[source [file rootname $src].x\]"
203         if { $done_p } {
204             return
205         }
206     }
207
208     # Setup the options for the testcase run.
209     set option_list $torture_with_loops
210     set executable $tmpdir/[file tail [file rootname $src].x]
211     regsub "(?q)$srcdir/" $src "" testcase
212
213     # If we couldn't rip $srcdir out of `src' then just do the best we can.
214     # The point is to reduce the unnecessary noise in the logs.  Don't strip
215     # out too much because different testcases with the same name can confuse
216     # `test-tool'.
217     if [string match "/*" $testcase] {
218         set testcase "[file tail [file dirname $src]]/[file tail $src]"
219     }
220
221     # Walk the list of options and copmile and run the testcase for all
222     # options that are not explicitly disabled by the .x script (if present).
223     foreach option $option_list {
224
225         # Torture_{compile,execute}_xfail are set by the .x script.
226         if [info exists torture_compile_xfail] {
227             setup_xfail $torture_compile_xfail
228         }
229
230         # Torture_execute_before_{compile,execute} can be set by the .x script.
231         if [info exists torture_eval_before_compile] {
232             set ignore_me [eval $torture_eval_before_compile]
233         }
234
235         # FIXME: We should make sure that the modules required by this testcase
236         # exist.  If not, the testcase should XFAIL.
237
238         # Compile the testcase.
239         catch { remote_file build delete $executable }
240         verbose "Testing $testcase, $option" 1
241
242         set options ""
243         lappend options "additional_flags=-w $option"
244         if { $additional_flags != "" } {
245             lappend options "additional_flags=$additional_flags"
246         }
247         set comp_output [gfortran_target_compile "$src" "$executable" executable $options]
248
249         # See if we got something bad.
250         set fatal_signal "*95*: Internal compiler error: program*got fatal signal"
251         
252         if [string match "$fatal_signal 6" $comp_output] then {
253             gfortran_fail $testcase "Got Signal 6, $option"
254             catch { remote_file build delete $executable }
255             continue
256         }
257         
258         if [string match "$fatal_signal 11" $comp_output] then {
259             gfortran_fail $testcase "Got Signal 11, $option"
260             catch { remote_file build delete $executable }
261             continue
262         }
263
264         if [string match "*internal compiler error*" $comp_output] then {
265             gfortran_fail $testcase "$option (internal compiler error)"
266             catch { remote_file build delete $executable }
267             continue
268         }
269         
270         # We shouldn't get these because of -w, but just in case.
271         if [string match "*95*:*warning:*" $comp_output] then {
272             warning "$testcase: (with warnings) $option"
273             send_log "$comp_output\n"
274             unresolved "$testcase, $option"
275             catch { remote_file build delete $executable }
276             continue
277         }
278         
279         # Prune warnings we know are unwanted.
280         set comp_output [prune_warnings $comp_output]
281
282         # Report if the testcase is not supported.
283         set unsupported_message [gfortran_check_unsupported_p $comp_output]
284         if { $unsupported_message != "" } {
285             unsupported "$testcase: $unsupported_message"
286             continue
287         } elseif ![file exists $executable] {
288             if ![is3way] {
289                 fail "$testcase compilation, $option"
290                 untested "$testcase execution, $option"
291                 continue
292             } else {
293                 # FIXME: since we can't test for the existence of a remote
294                 # file without short of doing an remote file list, we assume
295                 # that since we got no output, it must have compiled.
296                 pass "$testcase compilation, $option"           
297             }
298         } else {
299             pass "$testcase compilation, $option"
300         }
301
302         # See if this source file uses INTEGER(KIND=8) types, if it does, and
303         # no_long_long is set, skip execution of the test.
304         # FIXME: We should also look for F95 style "_8" or select_int_kind()
305         # integers, but that is obviously much harder than just regexping this.
306         # So maybe we should just avoid those in testcases.
307         if [target_info exists no_long_long] then {
308             if [expr [search_for_re $src "integer\*8"] \
309                      +[search_for_re $src "integer *( *8 *)"] \
310                      +[search_for_re $src "integer *( *kind *= *8 *)"]] \
311               then {
312                 untested "$testcase execution, $option"
313                 continue
314             }
315         }
316
317         if [info exists torture_execute_xfail] {
318             setup_xfail $torture_execute_xfail
319         }
320
321         if [info exists torture_eval_before_execute] {
322             set ignore_me [eval $torture_eval_before_execute]
323         }
324
325         # Run the testcase, and analyse the output.
326         set result [gfortran_load "$executable" "" ""]
327         set status [lindex $result 0]
328         set output [lindex $result 1]
329         if { $status == "pass" } {
330             catch { remote_file build delete $executable }
331         }
332         $status "$testcase execution, $option"
333     }
334 }
335
336
337 #
338 # search_for_re -- looks for a string match in a file
339 #
340 proc search_for_re { file pattern } {
341     set fd [open $file r]
342     while { [gets $fd cur_line]>=0 } {
343         set lower [string tolower $cur_line]
344         if [regexp "$pattern" $lower] then {
345             close $fd
346             return 1
347         }
348     }
349     close $fd
350     return 0
351 }
352
353
354 #
355 # fortran-torture -- the fortran-torture testcase source file processor
356 #
357 # This runs compilation only tests (no execute tests).
358 #
359 # SRC is the full pathname of the testcase, or just a file name in which
360 # case we prepend $srcdir/$subdir.
361 #
362 # If the testcase has an associated .x file, we source that to run the
363 # test instead.  We use .x so that we don't lengthen the existing filename
364 # to more than 14 chars.
365 #
366 proc fortran-torture { args } {
367     global srcdir subdir
368     global compiler_conditional_xfail_data
369     global torture_with_loops
370
371     set src [lindex $args 0]
372     if { [llength $args] > 1 } {
373         set options [lindex $args 1]
374     } else {
375         set options ""
376     }
377
378     # Prepend $srdir/$subdir if missing.
379     if ![string match "*/*" $src] {
380         set src "$srcdir/$subdir/$src"
381     }
382
383     # Check for alternate driver.
384     if [file exists [file rootname $src].x] {
385         verbose "Using alternate driver [file rootname [file tail $src]].x" 2
386         set done_p 0
387         catch "set done_p \[source [file rootname $src].x\]"
388         if { $done_p } {
389             return
390         }
391     }
392    
393     # loop through all the options
394     set option_list $torture_with_loops
395     foreach option $option_list {
396
397         # torture_compile_xfail is set by the .x script (if present)
398         if [info exists torture_compile_xfail] {
399             setup_xfail $torture_compile_xfail
400         }
401
402         # torture_execute_before_compile is set by the .x script (if present)
403         if [info exists torture_eval_before_compile] {
404             set ignore_me [eval $torture_eval_before_compile]
405         }
406
407         fortran-torture-compile $src "$option $options"
408     }
409 }
410
411 #
412 # add-ieee-options -- add options necessary for 100% ieee conformance.
413 #
414 proc add-ieee-options { } {
415     # Ensure that excess precision does not cause problems.
416     if { [istarget "i?86-*-*"]
417          || [istarget "m68k-*-*"] } then {
418       uplevel 1 lappend additional_flags "-ffloat-store"
419     }
420
421     # Enable full IEEE compliance mode.
422     if { [istarget "alpha*-*-*"]
423          || [istarget "sh*-*-*"] } then {
424       uplevel 1 lappend additional_flags "-mieee"
425     }
426 }