OSDN Git Service

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