OSDN Git Service

2008-12-19 Joel Sherrill <joel.sherrill@oarcorp.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / target-supports-dg.exp
1 #   Copyright (C) 1997, 1999, 2000, 2003, 2004, 2005, 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 # If this target does not support weak symbols, skip this test.
19
20 proc dg-require-weak { args } {
21     set weak_available [ check_weak_available ]
22     if { $weak_available == -1 } {
23         upvar name name
24         unresolved "$name"
25     }
26     if { $weak_available != 1 } {
27         upvar dg-do-what dg-do-what
28         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
29     }
30 }
31
32 # If this target does not support the "visibility" attribute, skip this
33 # test.
34
35 proc dg-require-visibility { args } {
36     set visibility_available [ check_visibility_available [lindex $args 1 ] ]
37     if { $visibility_available == -1 } {
38         upvar name name
39         unresolved "$name"
40     }
41     if { $visibility_available != 1 } {
42         upvar dg-do-what dg-do-what
43         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
44     }
45 }
46
47 # If this target does not support the "alias" attribute, skip this
48 # test.
49
50 proc dg-require-alias { args } {
51     set alias_available [ check_alias_available ]
52     if { $alias_available == -1 } {
53         upvar name name
54         unresolved "$name"
55     }
56     if { $alias_available < 2 } {
57         upvar dg-do-what dg-do-what
58         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
59     }
60 }
61
62 # If this target's linker does not support the --gc-sections flag,
63 # skip this test.
64
65 proc dg-require-gc-sections { args } {
66     if { ![ check_gc_sections_available ] } {
67         upvar dg-do-what dg-do-what
68         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
69     }
70 }
71
72 # If this target does not support profiling, skip this test.
73
74 proc dg-require-profiling { args } {
75     if { ![ check_profiling_available ${args} ] } {
76         upvar dg-do-what dg-do-what
77         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
78     }
79 }
80
81 # If this target does not support DLL attributes skip this test.
82
83 proc dg-require-dll { args } {
84     global target_triplet
85     # As a special case, the mcore-*-elf supports these attributes.
86     # All Symbian OS targets also support these attributes.
87     if { [string match "mcore-*-elf" $target_triplet]
88          || [string match "*-*-symbianelf" $target_triplet]} {
89         return
90     }
91     # PE/COFF targets support dllimport/dllexport.
92     if { [gcc_target_object_format] == "pe" } {
93         return
94     }
95
96     upvar dg-do-what dg-do-what
97     set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
98 }
99
100 proc dg-require-iconv { args } {
101     if { ![ check_iconv_available ${args} ] } {
102         upvar dg-do-what dg-do-what
103         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
104     }
105 }
106
107 # If this target does not support named sections skip this test.
108
109 proc dg-require-named-sections { args } {
110     if { ![ check_named_sections_available ] } {
111         upvar dg-do-what dg-do-what
112         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
113     }
114 }
115
116 # If the target does not match the required effective target, skip this test.
117
118 proc dg-require-effective-target { args } {
119     set args [lreplace $args 0 0]
120     if { [llength $args] != 1 } {
121         error "syntax error, need a single effective-target keyword"
122     }
123     if { ![is-effective-target [lindex $args 0]] } {
124         upvar dg-do-what dg-do-what
125         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
126     }
127 }
128
129 # If this target does not have fork, skip this test.
130
131 proc dg-require-fork { args } {
132     if { ![check_fork_available] } {
133         upvar dg-do-what dg-do-what
134         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
135     }
136 }
137
138 # If this target does not have mkfifo, skip this test.
139
140 proc dg-require-mkfifo { args } {
141     if { ![check_mkfifo_available] } {
142         upvar dg-do-what dg-do-what
143         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
144     }
145 }
146
147 # If this target does not use __cxa_atexit, skip this test.
148
149 proc dg-require-cxa-atexit { args } {
150     if { ![ check_cxa_atexit_available ] } {
151         upvar dg-do-what dg-do-what
152         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
153     }
154 }
155
156 # If the host is remote rather than the same as the build system, skip
157 # this test.  Some tests are incompatible with DejaGnu's handling of
158 # remote hosts, which involves copying the source file to the host and
159 # compiling it with a relative path and "-o a.out".
160
161 proc dg-require-host-local { args } {
162     if [ is_remote host ] {
163         upvar dg-do-what dg-do-what
164         set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
165     }
166 }
167
168 # Add any target-specific flags needed for accessing the given list
169 # of features.  This must come after all dg-options.
170
171 proc dg-add-options { args } {
172     upvar dg-extra-tool-flags extra-tool-flags
173
174     foreach arg [lrange $args 1 end] {
175         if { [info procs add_options_for_$arg] != "" } {
176             set extra-tool-flags \
177                 [eval [list add_options_for_$arg ${extra-tool-flags}]]
178         } else {
179             error "Unrecognized option type: $arg"
180         }
181     }
182 }
183
184 # Check the flags with which the test will be run against options in
185 # a test directive that will skip or xfail that test.  The DejaGnu proc
186 # check_conditional_xfail will look at the options in compiler_flags, so
187 # set that up for this test based on flags we know about.
188
189 proc check_test_flags { args } {
190     global compiler_flags
191     upvar 2 dg-extra-tool-flags extra_tool_flags
192
193     # Pull the args out of the enclosing list.
194     set args [lindex $args 0]
195
196     # Start the list with a dummy tool name so the list will match "*"
197     # if there are no flags.
198     set compiler_flags " toolname "
199     append compiler_flags $extra_tool_flags
200     set dest [target_info name]
201     if [board_info $dest exists multilib_flags] {
202         append compiler_flags "[board_info $dest multilib_flags] "
203     }
204
205     set answer [check_conditional_xfail $args]
206
207     # Any value in this variable originally was left over from an earlier test.
208     set compiler_flags ""
209
210     verbose "check_test_flags: $args $answer" 2
211     return $answer
212 }
213
214 # Compare flags for a test directive against flags that will be used to
215 # compile the test: multilib flags, flags for torture options, and either
216 # the default flags for this group of tests or flags specified with a
217 # previous dg-options directive.
218
219 proc check-flags { args } {
220     global compiler_flags
221     global TOOL_OPTIONS
222     # These variables are from DejaGnu's dg-test.
223     upvar dg-extra-tool-flags extra_tool_flags
224     upvar tool_flags tool_flags
225
226     # The args are within another list; pull them out.
227     set args [lindex $args 0]
228
229     # Start the list with a dummy tool name so the list will match "*"
230     # if there are no flags.
231     set compiler_flags " toolname "
232     append compiler_flags $extra_tool_flags
233     append compiler_flags $tool_flags
234     # If running a subset of the test suite, $TOOL_OPTIONS may not exist.
235     catch {append compiler_flags " $TOOL_OPTIONS "}
236     set dest [target_info name]
237     if [board_info $dest exists multilib_flags] {
238         append compiler_flags "[board_info $dest multilib_flags] "
239     }
240
241     # The target list might be an effective-target keyword, so replace
242     # the original list with "*-*-*", since we already know it matches.
243     set result [check_conditional_xfail [lreplace $args 1 1 "*-*-*"]]
244
245     # Any value in this variable was left over from an earlier test.
246     set compiler_flags ""
247
248     return $result
249 }
250
251 # Skip the test (report it as UNSUPPORTED) if the target list and
252 # included flags are matched and the excluded flags are not matched.
253 #
254 # The first argument is the line number of the dg-skip-if directive
255 # within the test file.   Remaining arguments are as for xfail lists:
256 # message { targets } { include } { exclude }
257 #
258 # This tests against multilib flags plus either the default flags for this
259 # group of tests or flags specified with a previous dg-options command.
260
261 proc dg-skip-if { args } {
262     # Don't bother if we're already skipping the test.
263     upvar dg-do-what dg-do-what
264     if { [lindex ${dg-do-what} 1] == "N" } {
265       return
266     }
267
268     set args [lreplace $args 0 0]
269
270     set selector [list target [lindex $args 1]]
271     if { [dg-process-target $selector] == "S" } {
272         # These are defined in DejaGnu's dg-test, needed by check-flags.
273         upvar dg-extra-tool-flags dg-extra-tool-flags
274         upvar tool_flags tool_flags
275
276         if [check-flags $args] {
277             upvar dg-do-what dg-do-what
278             set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
279         }
280     }
281 }
282
283 # Like check_conditional_xfail, but callable from a dg test.
284
285 proc dg-xfail-if { args } {
286     # Don't change anything if we're already skipping the test.
287     upvar dg-do-what dg-do-what
288     if { [lindex ${dg-do-what} 1] == "N" } {
289       return
290     }
291
292     set args [lreplace $args 0 0]
293     set selector [list target [lindex $args 1]]
294     if { [dg-process-target $selector] == "S" } {
295         global compiler_conditional_xfail_data
296         set compiler_conditional_xfail_data [lreplace $args 1 1 "*-*-*"]
297     }
298 }
299
300 # Like dg-xfail-if but for the execute step.
301
302 proc dg-xfail-run-if { args } {
303     # Don't bother if we're already skipping the test.
304     upvar dg-do-what dg-do-what
305     if { [lindex ${dg-do-what} 1] == "N" } {
306       return
307     }
308
309     set args [lreplace $args 0 0]
310
311     set selector [list target [lindex $args 1]]
312     if { [dg-process-target $selector] == "S" } {
313         # These are defined in DejaGnu's dg-test, needed by check-flags.
314         upvar dg-extra-tool-flags dg-extra-tool-flags
315         upvar tool_flags tool_flags
316
317         if [check-flags $args] {
318             upvar dg-do-what dg-do-what
319             set dg-do-what [list [lindex ${dg-do-what} 0] "S" "F"]
320         }
321     }
322 }
323
324 # Record whether the program is expected to return a nonzero status.
325
326 set shouldfail 0
327
328 proc dg-shouldfail { args } {
329     # Don't bother if we're already skipping the test.
330     upvar dg-do-what dg-do-what
331     if { [lindex ${dg-do-what} 1] == "N" } {
332       return
333     }
334
335     global shouldfail
336
337     set args [lreplace $args 0 0]
338     if { [llength $args] > 1 } {
339         set selector [list target [lindex $args 1]]
340         if { [dg-process-target $selector] == "S" } {
341             # The target matches, now check the flags.  These variables
342             # are defined in DejaGnu's dg-test, needed by check-flags.
343             upvar dg-extra-tool-flags dg-extra-tool-flags
344             upvar tool_flags tool_flags
345
346             if [check-flags $args] {
347                 set shouldfail 1
348             }
349         }
350     } else {
351         set shouldfail 1
352     }
353 }
354
355 # Intercept the call to the DejaGnu version of dg-process-target to
356 # support use of an effective-target keyword in place of a list of
357 # target triplets to xfail or skip a test.
358 #
359 # selector is one of:
360 #    xfail target-triplet-1 ...
361 #    xfail effective-target-keyword
362 #    xfail selector-expression
363 #    target target-triplet-1 ...
364 #    target effective-target-keyword
365 #    target selector-expression
366 #
367 # For a target list the result is "S" if the target is selected, "N" otherwise.
368 # For an xfail list the result is "F" if the target is affected, "P" otherwise.
369 #
370 # A selector expression appears within curly braces and uses a single logical
371 # operator: !, &&, or ||.  An operand is another selector expression, an
372 # effective-target keyword, or a list of target triplets within quotes or
373 # curly braces.
374
375 if { [info procs saved-dg-process-target] == [list] } {
376     rename dg-process-target saved-dg-process-target
377
378     # Evaluate an operand within a selector expression.
379     proc selector_opd { op } {
380         set selector "target"
381         lappend selector $op
382         set answer [ expr { [dg-process-target $selector] == "S" } ]
383         verbose "selector_opd: `$op' $answer" 2
384         return $answer
385     }
386
387     # Evaluate a target triplet list within a selector expression.
388     # Unlike other operands, this needs to be expanded from a list to
389     # the same string as "target".
390     proc selector_list { op } {
391         set selector "target [join $op]"
392         set answer [ expr { [dg-process-target $selector] == "S" } ]
393         verbose "selector_list: `$op' $answer" 2
394         return $answer
395     }
396
397     # Evaluate a selector expression.
398     proc selector_expression { exp } {
399         if { [llength $exp] == 2 } {
400             if [string match "!" [lindex $exp 0]] {
401                 set op1 [lindex $exp 1]
402                 set answer [expr { ! [selector_opd $op1] }]
403             } else {
404                 # Assume it's a list of target triplets.
405                 set answer [selector_list $exp]
406             }
407         } elseif { [llength $exp] == 3 } {
408             set op1 [lindex $exp 0]
409             set opr [lindex $exp 1]
410             set op2 [lindex $exp 2]
411             if [string match "&&" $opr] {
412                 set answer [expr { [selector_opd $op1] && [selector_opd $op2] }]
413             } elseif [string match "||" $opr] {
414                 set answer [expr { [selector_opd $op1] || [selector_opd $op2] }]
415             } else {
416                 # Assume it's a list of target triplets.
417                 set answer [selector_list $exp]
418             }
419         } else {
420             # Assume it's a list of target triplets.
421             set answer [selector_list $exp]
422         }
423
424         verbose "selector_expression: `$exp' $answer" 2
425         return $answer
426     }
427
428     proc dg-process-target { args } {
429         verbose "replacement dg-process-target: `$args'" 2
430         
431         # Extract the 'what' keyword from the argument list.
432         set selector [string trim [lindex $args 0]]
433         if [regexp "^xfail " $selector] {
434             set what "xfail"
435         } elseif [regexp "^target " $selector] {
436             set what "target"
437         } else {
438             error "syntax error in target selector \"$selector\""
439         }
440
441         # Extract the rest of the list, which might be a keyword.
442         regsub "^${what}" $selector "" rest
443         set rest [string trim $rest]
444
445         if [is-effective-target-keyword $rest] {
446             # The selector is an effective target keyword.
447             if [is-effective-target $rest] {
448                 return [expr { $what == "xfail" ? "F" : "S" }]
449             } else {
450                 return [expr { $what == "xfail" ? "P" : "N" }]
451             }
452         }
453
454         if [string match "{*}" $rest] {
455             if [selector_expression [lindex $rest 0]] {
456                 return [expr { $what == "xfail" ? "F" : "S" }]
457             } else {
458                 return [expr { $what == "xfail" ? "P" : "N" }]
459             }
460         }
461
462         # The selector is not an effective-target keyword, so process
463         # the list of target triplets.
464         return [saved-dg-process-target $selector]
465     }
466 }