target-supports-dg.exp (dg-require-effective-target): Return early if the test is...
[official-gcc.git] / gcc / testsuite / lib / target-supports-dg.exp
blob68e250ba87249dee3a0dc3976432a2d078c7754c
1 # Copyright (C) 1997, 1999, 2000, 2003, 2004, 2005, 2007, 2008, 2009, 2010,
2 # 2011 Free Software Foundation, Inc.
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.
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.
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/>.
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.
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
30 upvar $frames tool_flags flags2
31 return "$flags1 $flags2"
34 # If this target does not support weak symbols, skip this test.
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"
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"]
48 # If this target does not support overriding weak symbols, skip this
49 # test.
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"
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"]
63 # If this target does not support the "visibility" attribute, skip this
64 # test.
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"
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"]
78 # If this target does not support the "alias" attribute, skip this
79 # test.
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"
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"]
93 # If this target does not support the "ifunc" attribute, skip this
94 # test.
96 proc dg-require-ifunc { args } {
97 if { ![ check_ifunc_available ] } {
98 upvar dg-do-what dg-do-what
99 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
103 # If this target's linker does not support the --gc-sections flag,
104 # skip this test.
106 proc dg-require-gc-sections { args } {
107 if { ![ check_gc_sections_available ] } {
108 upvar dg-do-what dg-do-what
109 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
113 # If this target does not support profiling, skip this test.
115 proc dg-require-profiling { args } {
116 if { ![ check_profiling_available [lindex $args 1] ] } {
117 upvar dg-do-what dg-do-what
118 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
122 # If this target does not support DLL attributes skip this test.
124 proc dg-require-dll { args } {
125 global target_triplet
126 # As a special case, the mcore-*-elf supports these attributes.
127 # All Symbian OS targets also support these attributes.
128 if { [string match "mcore-*-elf" $target_triplet]
129 || [string match "*-*-symbianelf" $target_triplet]} {
130 return
132 # PE/COFF targets support dllimport/dllexport.
133 if { [gcc_target_object_format] == "pe" } {
134 return
137 upvar dg-do-what dg-do-what
138 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
141 # If this host does not support an ASCII locale, skip this test.
143 proc dg-require-ascii-locale { args } {
144 if { ![ check_ascii_locale_available] } {
145 upvar dg-do-what dg-do-what
146 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
150 proc dg-require-iconv { args } {
151 if { ![ check_iconv_available ${args} ] } {
152 upvar dg-do-what dg-do-what
153 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
157 # If this target does not support named sections skip this test.
159 proc dg-require-named-sections { args } {
160 if { ![ check_named_sections_available ] } {
161 upvar dg-do-what dg-do-what
162 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
166 # If the target does not match the required effective target, skip this test.
167 # Only apply this if the optional selector matches.
169 proc dg-require-effective-target { args } {
170 set args [lreplace $args 0 0]
171 # Verify the number of arguments. The last is optional.
172 if { [llength $args] < 1 || [llength $args] > 2 } {
173 error "syntax error, need a single effective-target keyword with optional selector"
176 # Don't bother if we're already skipping the test.
177 upvar dg-do-what dg-do-what
178 if { [lindex ${dg-do-what} 1] == "N" } {
179 return
182 # Evaluate selector if present.
183 if { [llength $args] == 2 } {
184 switch [dg-process-target [lindex $args 1]] {
185 "S" { }
186 "N" { return }
190 if { ![is-effective-target [lindex $args 0]] } {
191 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
195 # If this target does not have fork, skip this test.
197 proc dg-require-fork { args } {
198 if { ![check_fork_available] } {
199 upvar dg-do-what dg-do-what
200 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
204 # If this target does not have mkfifo, skip this test.
206 proc dg-require-mkfifo { args } {
207 if { ![check_mkfifo_available] } {
208 upvar dg-do-what dg-do-what
209 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
213 # If this target does not use __cxa_atexit, skip this test.
215 proc dg-require-cxa-atexit { args } {
216 if { ![ check_cxa_atexit_available ] } {
217 upvar dg-do-what dg-do-what
218 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
222 # If the host is remote rather than the same as the build system, skip
223 # this test. Some tests are incompatible with DejaGnu's handling of
224 # remote hosts, which involves copying the source file to the host and
225 # compiling it with a relative path and "-o a.out".
227 proc dg-require-host-local { args } {
228 if [ is_remote host ] {
229 upvar dg-do-what dg-do-what
230 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
234 proc dg-require-linker-plugin { args } {
235 set linker_plugin_available [ check_linker_plugin_available ]
236 if { $linker_plugin_available == 0 } {
237 upvar dg-do-what dg-do-what
238 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
242 # Add any target-specific flags needed for accessing the given list
243 # of features. This must come after all dg-options.
245 proc dg-add-options { args } {
246 upvar dg-extra-tool-flags extra-tool-flags
248 foreach arg [lrange $args 1 end] {
249 if { [info procs add_options_for_$arg] != "" } {
250 set extra-tool-flags \
251 [eval [list add_options_for_$arg ${extra-tool-flags}]]
252 } else {
253 error "Unrecognized option type: $arg"
258 # Compare flags for a test directive against flags that will be used to
259 # compile the test: multilib flags, flags for torture options, and either
260 # the default flags for this group of tests or flags specified with a
261 # previous dg-options directive.
263 proc check-flags { args } {
264 global compiler_flags
265 global TOOL_OPTIONS
267 # The args are within another list; pull them out.
268 set args [lindex $args 0]
270 # Start the list with a dummy tool name so the list will match "*"
271 # if there are no flags.
272 set compiler_flags " toolname "
273 append compiler_flags [current_compiler_flags]
274 # If running a subset of the test suite, $TOOL_OPTIONS may not exist.
275 catch {append compiler_flags " $TOOL_OPTIONS "}
276 set dest [target_info name]
277 if [board_info $dest exists multilib_flags] {
278 append compiler_flags "[board_info $dest multilib_flags] "
281 # The next two arguments are optional. If they were not specified,
282 # use the defaults.
283 if { [llength $args] == 2 } {
284 lappend $args [list "*"]
286 if { [llength $args] == 3 } {
287 lappend $args [list ""]
290 # If the option strings are the defaults, or the same as the
291 # defaults, there is no need to call check_conditional_xfail to
292 # compare them to the actual options.
293 if { [string compare [lindex $args 2] "*"] == 0
294 && [string compare [lindex $args 3] "" ] == 0 } {
295 set result 1
296 } else {
297 # The target list might be an effective-target keyword, so replace
298 # the original list with "*-*-*", since we already know it matches.
299 set result [check_conditional_xfail [lreplace $args 1 1 "*-*-*"]]
302 # Any value in this variable was left over from an earlier test.
303 set compiler_flags ""
305 return $result
308 # Skip the test (report it as UNSUPPORTED) if the target list and
309 # included flags are matched and the excluded flags are not matched.
311 # The first argument is the line number of the dg-skip-if directive
312 # within the test file. Remaining arguments are as for xfail lists:
313 # message { targets } { include } { exclude }
315 # This tests against multilib flags plus either the default flags for this
316 # group of tests or flags specified with a previous dg-options command.
318 proc dg-skip-if { args } {
319 # Verify the number of arguments. The last two are optional.
320 set args [lreplace $args 0 0]
321 if { [llength $args] < 2 || [llength $args] > 4 } {
322 error "dg-skip-if 2: need 2, 3, or 4 arguments"
325 # Don't bother if we're already skipping the test.
326 upvar dg-do-what dg-do-what
327 if { [lindex ${dg-do-what} 1] == "N" } {
328 return
331 set selector [list target [lindex $args 1]]
332 if { [dg-process-target $selector] == "S" } {
333 if [check-flags $args] {
334 upvar dg-do-what dg-do-what
335 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
340 # Like check_conditional_xfail, but callable from a dg test.
342 proc dg-xfail-if { args } {
343 # Verify the number of arguments. The last three are optional.
344 set args [lreplace $args 0 0]
345 if { [llength $args] < 2 || [llength $args] > 4 } {
346 error "dg-xfail-if: need 2, 3, or 4 arguments"
349 # Don't change anything if we're already skipping the test.
350 upvar dg-do-what dg-do-what
351 if { [lindex ${dg-do-what} 1] == "N" } {
352 return
355 set selector [list target [lindex $args 1]]
356 if { [dg-process-target $selector] == "S" } {
357 global compiler_conditional_xfail_data
359 # The target list might be an effective-target keyword. Replace
360 # the original list with "*-*-*", since we already know it matches.
361 set args [lreplace $args 1 1 "*-*-*"]
363 # Supply default values for unspecified optional arguments.
364 if { [llength $args] == 2 } {
365 lappend $args [list "*"]
367 if { [llength $args] == 3 } {
368 lappend $args [list ""]
371 set compiler_conditional_xfail_data $args
375 # Like dg-xfail-if but for the execute step.
377 proc dg-xfail-run-if { args } {
378 # Verify the number of arguments. The last two are optional.
379 set args [lreplace $args 0 0]
380 if { [llength $args] < 2 || [llength $args] > 4 } {
381 error "dg-xfail-run-if: need 2, 3, or 4 arguments"
384 # Don't bother if we're already skipping the test.
385 upvar dg-do-what dg-do-what
386 if { [lindex ${dg-do-what} 1] == "N" } {
387 return
390 set selector [list target [lindex $args 1]]
391 if { [dg-process-target $selector] == "S" } {
392 if [check-flags $args] {
393 upvar dg-do-what dg-do-what
394 set dg-do-what [list [lindex ${dg-do-what} 0] "S" "F"]
399 # Record whether the program is expected to return a nonzero status.
401 set shouldfail 0
403 proc dg-shouldfail { args } {
404 # Don't bother if we're already skipping the test.
405 upvar dg-do-what dg-do-what
406 if { [lindex ${dg-do-what} 1] == "N" } {
407 return
410 global shouldfail
412 set args [lreplace $args 0 0]
413 if { [llength $args] > 1 } {
414 set selector [list target [lindex $args 1]]
415 if { [dg-process-target $selector] == "S" } {
416 # The target matches, now check the flags.
417 if [check-flags $args] {
418 set shouldfail 1
421 } else {
422 set shouldfail 1
426 # Intercept the call to the DejaGnu version of dg-process-target to
427 # support use of an effective-target keyword in place of a list of
428 # target triplets to xfail or skip a test.
430 # selector is one of:
431 # xfail target-triplet-1 ...
432 # xfail effective-target-keyword
433 # xfail selector-expression
434 # target target-triplet-1 ...
435 # target effective-target-keyword
436 # target selector-expression
438 # For a target list the result is "S" if the target is selected, "N" otherwise.
439 # For an xfail list the result is "F" if the target is affected, "P" otherwise.
441 # A selector expression appears within curly braces and uses a single logical
442 # operator: !, &&, or ||. An operand is another selector expression, an
443 # effective-target keyword, or a list of target triplets within quotes or
444 # curly braces.
446 if { [info procs saved-dg-process-target] == [list] } {
447 rename dg-process-target saved-dg-process-target
449 # Evaluate an operand within a selector expression.
450 proc selector_opd { op } {
451 set selector "target"
452 lappend selector $op
453 set answer [ expr { [dg-process-target $selector] == "S" } ]
454 verbose "selector_opd: `$op' $answer" 2
455 return $answer
458 # Evaluate a target triplet list within a selector expression.
459 # Unlike other operands, this needs to be expanded from a list to
460 # the same string as "target".
461 proc selector_list { op } {
462 set selector "target [join $op]"
463 set answer [ expr { [dg-process-target $selector] == "S" } ]
464 verbose "selector_list: `$op' $answer" 2
465 return $answer
468 # Evaluate a selector expression.
469 proc selector_expression { exp } {
470 if { [llength $exp] == 2 } {
471 if [string match "!" [lindex $exp 0]] {
472 set op1 [lindex $exp 1]
473 set answer [expr { ! [selector_opd $op1] }]
474 } else {
475 # Assume it's a list of target triplets.
476 set answer [selector_list $exp]
478 } elseif { [llength $exp] == 3 } {
479 set op1 [lindex $exp 0]
480 set opr [lindex $exp 1]
481 set op2 [lindex $exp 2]
482 if [string match "&&" $opr] {
483 set answer [expr { [selector_opd $op1] && [selector_opd $op2] }]
484 } elseif [string match "||" $opr] {
485 set answer [expr { [selector_opd $op1] || [selector_opd $op2] }]
486 } else {
487 # Assume it's a list of target triplets.
488 set answer [selector_list $exp]
490 } else {
491 # Assume it's a list of target triplets.
492 set answer [selector_list $exp]
495 verbose "selector_expression: `$exp' $answer" 2
496 return $answer
499 proc dg-process-target { args } {
500 verbose "replacement dg-process-target: `$args'" 2
502 # Extract the 'what' keyword from the argument list.
503 set selector [string trim [lindex $args 0]]
504 if [regexp "^xfail " $selector] {
505 set what "xfail"
506 } elseif [regexp "^target " $selector] {
507 set what "target"
508 } else {
509 error "syntax error in target selector \"$selector\""
512 # Extract the rest of the list, which might be a keyword.
513 regsub "^${what}" $selector "" rest
514 set rest [string trim $rest]
516 if [is-effective-target-keyword $rest] {
517 # The selector is an effective target keyword.
518 if [is-effective-target $rest] {
519 return [expr { $what == "xfail" ? "F" : "S" }]
520 } else {
521 return [expr { $what == "xfail" ? "P" : "N" }]
525 if [string match "{*}" $rest] {
526 if [selector_expression [lindex $rest 0]] {
527 return [expr { $what == "xfail" ? "F" : "S" }]
528 } else {
529 return [expr { $what == "xfail" ? "P" : "N" }]
533 # The selector is not an effective-target keyword, so process
534 # the list of target triplets.
535 return [saved-dg-process-target $selector]