OSDN Git Service

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