]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/lib/target-supports-dg.exp
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / lib / target-supports-dg.exp
1 # Copyright (C) 1997-2023 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 # DejaGnu's dg-test defines extra flags that are used to compile a test.
18 # Access them for directives that need to examine all options that are
19 # used for a test, including checks for non-cached effective targets.
20 # We don't know how far up the call chain it is but we know we'll hit
21 # it eventually, and that we're at least 3 calls down.
22
23 proc current_compiler_flags { } {
24 set frames 2
25 while { ![info exists flags1] } {
26 set frames [expr $frames + 1]
27 upvar $frames dg-extra-tool-flags flags1
28 }
29 upvar $frames tool_flags flags2
30 return "$flags1 $flags2"
31 }
32
33 # DejaGnu's dg-test defines a test name that includes torture options
34 # which is used in most pass/fail messages. Grab a copy of it.
35
36 proc testname-for-summary { } {
37 global testname_with_flags
38
39 # A variable called "name" is too generic, so identify dg-test by
40 # the existence of dg-extra-tool-flags.
41 if ![info exists testname_with_flags] {
42 set frames 2
43 while { ![info exists flags] } {
44 set frames [expr $frames + 1]
45 upvar $frames dg-extra-tool-flags flags
46 }
47
48 # We've got the stack level for dg-test; get the variable we want.
49 upvar $frames name name
50 set testname_with_flags $name
51
52 # If there are flags, add an extra space to improve readability of
53 # the test summary.
54 if { [llength $testname_with_flags] > 1 } {
55 set testname_with_flags "$testname_with_flags "
56 }
57 }
58 return "$testname_with_flags"
59 }
60
61 # If this target does not support weak symbols, skip this test.
62
63 proc dg-require-weak { args } {
64 set weak_available [ check_weak_available ]
65 if { $weak_available == -1 } {
66 upvar name name
67 unresolved "$name"
68 }
69 if { $weak_available != 1 } {
70 upvar dg-do-what dg-do-what
71 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
72 }
73 }
74
75 # If this target does not support overriding weak symbols, skip this
76 # test.
77
78 proc dg-require-weak-override { args } {
79 set weak_override_available [ check_weak_override_available ]
80 if { $weak_override_available == -1 } {
81 upvar name name
82 unresolved "$name"
83 }
84 if { $weak_override_available != 1 } {
85 upvar dg-do-what dg-do-what
86 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
87 }
88 }
89
90 # If this target does not support the "visibility" attribute, skip this
91 # test.
92
93 proc dg-require-visibility { args } {
94 set visibility_available [ check_visibility_available [lindex $args 1 ] ]
95 if { $visibility_available == -1 } {
96 upvar name name
97 unresolved "$name"
98 }
99 if { $visibility_available != 1 } {
100 upvar dg-do-what dg-do-what
101 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
102 }
103 }
104
105 # If this target does not support the "alias" attribute, skip this
106 # test.
107
108 proc dg-require-alias { args } {
109 set alias_available [ check_alias_available ]
110 if { $alias_available == -1 } {
111 upvar name name
112 unresolved "$name"
113 }
114 if { $alias_available < 2 } {
115 upvar dg-do-what dg-do-what
116 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
117 }
118 }
119
120 # If this target does not support the "ifunc" attribute, skip this
121 # test.
122
123 proc dg-require-ifunc { args } {
124 if { ![ check_ifunc_available ] } {
125 upvar dg-do-what dg-do-what
126 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
127 }
128 }
129
130 # If this target's linker does not support the --gc-sections flag,
131 # skip this test.
132
133 proc dg-require-gc-sections { args } {
134 if { ![ check_gc_sections_available ] } {
135 upvar dg-do-what dg-do-what
136 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
137 }
138 }
139
140 # If this target does not support profiling, skip this test.
141
142 proc dg-require-profiling { args } {
143 if { ![ check_profiling_available [lindex $args 1] ] } {
144 upvar dg-do-what dg-do-what
145 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
146 }
147 }
148
149 # If this target does not support DLL attributes skip this test.
150
151 proc dg-require-dll { args } {
152 # As a special case, the mcore-*-elf supports these attributes.
153 # All Symbian OS targets also support these attributes.
154 if { [istarget mcore-*-elf]
155 || [istarget *-*-symbianelf] } {
156 return
157 }
158 # PE/COFF targets support dllimport/dllexport.
159 if { [gcc_target_object_format] == "pe" } {
160 return
161 }
162
163 upvar dg-do-what dg-do-what
164 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
165 }
166
167 # If this host does not support an ASCII locale, skip this test.
168
169 proc dg-require-ascii-locale { args } {
170 if { ![ check_ascii_locale_available] } {
171 upvar dg-do-what dg-do-what
172 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
173 }
174 }
175
176 proc dg-require-iconv { args } {
177 if { ![ check_iconv_available ${args} ] } {
178 upvar dg-do-what dg-do-what
179 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
180 }
181 }
182
183 # If this host does not have "dot", skip this test.
184
185 proc dg-require-dot { args } {
186 verbose "dg-require-dot" 2
187 if { ![ check_dot_available ] } {
188 upvar dg-do-what dg-do-what
189 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
190 }
191 }
192
193 # If this target does not have sufficient stack size, skip this test.
194
195 proc dg-require-stack-size { args } {
196 if { ![is-effective-target stack_size] } {
197 return
198 }
199
200 set stack_size [dg-effective-target-value stack_size]
201 set required [expr [lindex $args 1]]
202 if { $stack_size < $required } {
203 upvar dg-do-what dg-do-what
204 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
205 }
206 }
207
208 # If this target does not support named sections skip this test.
209
210 proc dg-require-named-sections { args } {
211 if { ![ check_named_sections_available ] } {
212 upvar dg-do-what dg-do-what
213 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
214 }
215 }
216
217 # If the target does not match the required effective target, skip this test.
218 # Only apply this if the optional selector matches.
219
220 proc dg-require-effective-target { args } {
221 set args [lreplace $args 0 0]
222 # Verify the number of arguments. The last is optional.
223 if { [llength $args] < 1 || [llength $args] > 2 } {
224 error "syntax error, need a single effective-target keyword with optional selector"
225 }
226
227 # Don't bother if we're already skipping the test.
228 upvar dg-do-what dg-do-what
229 if { [lindex ${dg-do-what} 1] == "N" } {
230 return
231 }
232
233 # Evaluate selector if present.
234 if { [llength $args] == 2 } {
235 switch [dg-process-target-1 [lindex $args 1]] {
236 "S" { }
237 "N" { return }
238 }
239 }
240
241 if { ![is-effective-target [lindex $args 0]] } {
242 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
243 }
244 }
245
246 # If this target does not have fork, skip this test.
247
248 proc dg-require-fork { args } {
249 if { ![check_fork_available] } {
250 upvar dg-do-what dg-do-what
251 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
252 }
253 }
254
255 # If this target does not have mkfifo, skip this test.
256
257 proc dg-require-mkfifo { args } {
258 if { ![check_mkfifo_available] } {
259 upvar dg-do-what dg-do-what
260 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
261 }
262 }
263
264 # If this target does not use __cxa_atexit, skip this test.
265
266 proc dg-require-cxa-atexit { args } {
267 if { ![ check_cxa_atexit_available ] } {
268 upvar dg-do-what dg-do-what
269 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
270 }
271 }
272
273 # If the host is remote rather than the same as the build system, skip
274 # this test. Some tests are incompatible with DejaGnu's handling of
275 # remote hosts, which involves copying the source file to the host and
276 # compiling it with a relative path and "-o a.out".
277
278 proc dg-require-host-local { args } {
279 if [ is_remote host ] {
280 upvar dg-do-what dg-do-what
281 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
282 }
283 }
284
285 proc dg-require-linker-plugin { args } {
286 set linker_plugin_available [ check_linker_plugin_available ]
287 if { $linker_plugin_available == 0 } {
288 upvar dg-do-what dg-do-what
289 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
290 }
291 }
292
293 # If this target does not support the "stack-check" option, skip this
294 # test.
295
296 proc dg-require-stack-check { args } {
297 set stack_check_available [ check_stack_check_available [lindex $args 1 ] ]
298 if { $stack_check_available == -1 } {
299 upvar name name
300 unresolved "$name"
301 }
302 if { $stack_check_available != 1 } {
303 upvar dg-do-what dg-do-what
304 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
305 }
306 }
307
308 # Add any target-specific flags needed for accessing the given list
309 # of features. This must come after all dg-options.
310
311 proc dg-add-options { args } {
312 upvar dg-extra-tool-flags extra-tool-flags
313
314 foreach arg [lrange $args 1 end] {
315 if { [info procs add_options_for_$arg] != "" } {
316 set extra-tool-flags \
317 [eval [list add_options_for_$arg ${extra-tool-flags}]]
318 } else {
319 error "Unrecognized option type: $arg"
320 }
321 }
322 }
323
324 # Compare flags for a test directive against flags that will be used to
325 # compile the test: multilib flags, flags for torture options, and either
326 # the default flags for this group of tests or flags specified with a
327 # previous dg-options directive.
328
329 proc check-flags { args } {
330 global compiler_flags
331 global TOOL_OPTIONS
332 global TEST_ALWAYS_FLAGS
333
334 # The args are within another list; pull them out.
335 set args [lindex $args 0]
336
337 # Start the list with a dummy tool name so the list will match "*"
338 # if there are no flags.
339 set compiler_flags " toolname "
340 append compiler_flags [current_compiler_flags]
341 # If running a subset of the test suite, $TOOL_OPTIONS may not exist.
342 catch {append compiler_flags " $TOOL_OPTIONS "}
343 # If running a subset of the test suite, $TEST_ALWAYS_FLAGS may not exist.
344 catch {append compiler_flags " $TEST_ALWAYS_FLAGS "}
345 set dest [target_info name]
346 if [board_info $dest exists cflags] {
347 append compiler_flags "[board_info $dest cflags] "
348 }
349 if [board_info $dest exists multilib_flags] {
350 append compiler_flags "[board_info $dest multilib_flags] "
351 }
352
353 # The next two arguments are optional. If they were not specified,
354 # use the defaults.
355 if { [llength $args] == 2 } {
356 lappend $args [list "*"]
357 }
358 if { [llength $args] == 3 } {
359 lappend $args [list ""]
360 }
361
362 # If the option strings are the defaults, or the same as the
363 # defaults, there is no need to call check_conditional_xfail to
364 # compare them to the actual options.
365 if { [string compare [lindex $args 2] "*"] == 0
366 && [string compare [lindex $args 3] "" ] == 0 } {
367 set result 1
368 } else {
369 # The target list might be an effective-target keyword, so replace
370 # the original list with "*-*-*", since we already know it matches.
371 set result [check_conditional_xfail [lreplace $args 1 1 "*-*-*"]]
372 }
373
374 # Any value in this variable was left over from an earlier test.
375 set compiler_flags ""
376
377 return $result
378 }
379
380 # Skip the test (report it as UNSUPPORTED) if the target list and
381 # included flags are matched and the excluded flags are not matched.
382 #
383 # The first argument is the line number of the dg-skip-if directive
384 # within the test file. Remaining arguments are as for xfail lists:
385 # message { targets } { include } { exclude }
386 #
387 # This tests against multilib flags plus either the default flags for this
388 # group of tests or flags specified with a previous dg-options command.
389
390 proc dg-skip-if { args } {
391 # Verify the number of arguments. The last two are optional.
392 set args [lreplace $args 0 0]
393 if { [llength $args] < 2 || [llength $args] > 4 } {
394 error "dg-skip-if 2: need 2, 3, or 4 arguments"
395 }
396
397 # Don't bother if we're already skipping the test.
398 upvar dg-do-what dg-do-what
399 if { [lindex ${dg-do-what} 1] == "N" } {
400 return
401 }
402
403 set selector [list target [lindex $args 1]]
404 if { [dg-process-target-1 $selector] == "S" } {
405 if [check-flags $args] {
406 upvar dg-do-what dg-do-what
407 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
408 }
409 }
410 }
411
412 # Like check_conditional_xfail, but callable from a dg test.
413
414 proc dg-xfail-if { args } {
415 # Verify the number of arguments. The last three are optional.
416 set args [lreplace $args 0 0]
417 if { [llength $args] < 2 || [llength $args] > 4 } {
418 error "dg-xfail-if: need 2, 3, or 4 arguments"
419 }
420
421 # Don't change anything if we're already skipping the test.
422 upvar dg-do-what dg-do-what
423 if { [lindex ${dg-do-what} 1] == "N" } {
424 return
425 }
426
427 set selector [list target [lindex $args 1]]
428 if { [dg-process-target-1 $selector] == "S" } {
429 global compiler_conditional_xfail_data
430
431 # The target list might be an effective-target keyword. Replace
432 # the original list with "*-*-*", since we already know it matches.
433 set args [lreplace $args 1 1 "*-*-*"]
434
435 # Supply default values for unspecified optional arguments.
436 if { [llength $args] == 2 } {
437 lappend $args [list "*"]
438 }
439 if { [llength $args] == 3 } {
440 lappend $args [list ""]
441 }
442
443 set compiler_conditional_xfail_data $args
444 }
445 }
446
447 # Like dg-xfail-if but for the execute step.
448
449 proc dg-xfail-run-if { args } {
450 # Verify the number of arguments. The last two are optional.
451 set args [lreplace $args 0 0]
452 if { [llength $args] < 2 || [llength $args] > 4 } {
453 error "dg-xfail-run-if: need 2, 3, or 4 arguments"
454 }
455
456 # Don't bother if we're already skipping the test.
457 upvar dg-do-what dg-do-what
458 if { [lindex ${dg-do-what} 1] == "N" } {
459 return
460 }
461
462 set selector [list target [lindex $args 1]]
463 if { [dg-process-target-1 $selector] == "S" } {
464 if [check-flags $args] {
465 upvar dg-do-what dg-do-what
466 set dg-do-what [list [lindex ${dg-do-what} 0] "S" "F"]
467 }
468 }
469 }
470
471 # Record whether the program is expected to return a nonzero status.
472
473 set shouldfail 0
474
475 proc dg-shouldfail { args } {
476 # Don't bother if we're already skipping the test.
477 upvar dg-do-what dg-do-what
478 if { [lindex ${dg-do-what} 1] == "N" } {
479 return
480 }
481
482 global shouldfail
483
484 set args [lreplace $args 0 0]
485 if { [llength $args] > 1 } {
486 set selector [list target [lindex $args 1]]
487 if { [dg-process-target-1 $selector] == "S" } {
488 # The target matches, now check the flags.
489 if [check-flags $args] {
490 set shouldfail 1
491 }
492 }
493 } else {
494 set shouldfail 1
495 }
496 }
497
498 # Record whether the compiler is expected (at the moment) to ICE.
499 # Used for tests that test bugs that have not been fixed yet.
500
501 set expect_ice 0
502
503 proc dg-ice { args } {
504 # Don't bother if we're already skipping the test.
505 upvar dg-do-what dg-do-what
506 if { [lindex ${dg-do-what} 1] == "N" } {
507 return
508 }
509
510 global expect_ice
511
512 set args [lreplace $args 0 0]
513 if { [llength $args] > 1 } {
514 set selector [list target [lindex $args 1]]
515 if { [dg-process-target-1 $selector] == "S" } {
516 # The target matches, now check the flags.
517 if [check-flags $args] {
518 set expect_ice 1
519 }
520 }
521 } else {
522 set expect_ice 1
523 }
524 }
525
526 # Intercept the call to the DejaGnu version of dg-process-target to
527 # support use of an effective-target keyword in place of a list of
528 # target triplets to xfail or skip a test.
529 #
530 # The argument to dg-process-target is the keyword "target" or "xfail"
531 # followed by a selector:
532 # target-triplet-1 ...
533 # effective-target-keyword
534 # selector-expression
535 #
536 # For a target list the result is "S" if the target is selected, "N" otherwise.
537 # For an xfail list the result is "F" if the target is affected, "P" otherwise.
538
539 # In contexts that allow either "target" or "xfail" the argument can be
540 # target selector1 xfail selector2
541 # which returns "N" if selector1 is not selected, otherwise the result of
542 # "xfail selector2".
543 #
544 # A selector expression appears within curly braces and uses a single logical
545 # operator: !, &&, or ||. An operand is another selector expression, an
546 # effective-target keyword, or a list of target triplets within quotes or
547 # curly braces.
548
549 if { [info procs saved-dg-process-target] == [list] } {
550 rename dg-process-target saved-dg-process-target
551
552 # Evaluate an operand within a selector expression.
553 proc selector_opd { op } {
554 set selector "target"
555 lappend selector $op
556 set answer [ expr { [dg-process-target $selector] == "S" } ]
557 verbose "selector_opd: `$op' $answer" 2
558 return $answer
559 }
560
561 # Evaluate a target triplet list within a selector expression.
562 # Unlike other operands, this needs to be expanded from a list to
563 # the same string as "target".
564 proc selector_list { op } {
565 set selector "target [join $op]"
566 set answer [ expr { [dg-process-target $selector] == "S" } ]
567 verbose "selector_list: `$op' $answer" 2
568 return $answer
569 }
570
571 # Evaluate a selector expression.
572 proc selector_expression { exp } {
573 if { [llength $exp] >= 2
574 && [string match "any-opts" [lindex $exp 0]] } {
575 set args [list "" { *-*-* } [lrange $exp 1 end] ""]
576 set answer [check_conditional_xfail $args]
577 } elseif { [llength $exp] >= 2
578 && [string match "no-opts" [lindex $exp 0]] } {
579 set args [list "" { *-*-* } "*" [lrange $exp 1 end]]
580 set answer [check_conditional_xfail $args]
581 } elseif { [llength $exp] == 2 } {
582 if [string match "!" [lindex $exp 0]] {
583 set op1 [lindex $exp 1]
584 set answer [expr { ! [selector_opd $op1] }]
585 } else {
586 # Assume it's a list of target triplets.
587 set answer [selector_list $exp]
588 }
589 } elseif { [llength $exp] == 3 } {
590 set op1 [lindex $exp 0]
591 set opr [lindex $exp 1]
592 set op2 [lindex $exp 2]
593 if [string match "&&" $opr] {
594 set answer [expr { [selector_opd $op1] && [selector_opd $op2] }]
595 } elseif [string match "||" $opr] {
596 set answer [expr { [selector_opd $op1] || [selector_opd $op2] }]
597 } else {
598 # Assume it's a list of target triplets.
599 set answer [selector_list $exp]
600 }
601 } else {
602 # Assume it's a list of target triplets.
603 set answer [selector_list $exp]
604 }
605
606 verbose "selector_expression: `$exp' $answer" 2
607 return $answer
608 }
609
610 # Evaluate "target selector" or "xfail selector".
611
612 proc dg-process-target-1 { args } {
613 verbose "dg-process-target-1: `$args'" 2
614
615 # Extract the 'what' keyword from the argument list.
616 set selector [string trim [lindex $args 0]]
617 if [regexp "^xfail " $selector] {
618 set what "xfail"
619 } elseif [regexp "^target " $selector] {
620 set what "target"
621 } else {
622 error "syntax error in target selector \"$selector\""
623 }
624
625 # Extract the rest of the list, which might be a keyword.
626 regsub "^${what}" $selector "" rest
627 set rest [string trim $rest]
628
629 if [is-effective-target-keyword $rest] {
630 # The selector is an effective target keyword.
631 if [is-effective-target $rest] {
632 return [expr { $what == "xfail" ? "F" : "S" }]
633 } else {
634 return [expr { $what == "xfail" ? "P" : "N" }]
635 }
636 }
637
638 if [string match "{*}" $rest] {
639 if [selector_expression [lindex $rest 0]] {
640 return [expr { $what == "xfail" ? "F" : "S" }]
641 } else {
642 return [expr { $what == "xfail" ? "P" : "N" }]
643 }
644 }
645
646 # The selector is not an effective-target keyword, so process
647 # the list of target triplets.
648 return [saved-dg-process-target $selector]
649 }
650
651 # Intercept calls to the DejaGnu function. In addition to
652 # processing "target selector" or "xfail selector", handle
653 # "target selector1 xfail selector2".
654
655 proc dg-process-target { args } {
656 verbose "replacement dg-process-target: `$args'" 2
657
658 set selector [string trim [lindex $args 0]]
659
660 # If the argument list contains both 'target' and 'xfail',
661 # process 'target' and, if that succeeds, process 'xfail'.
662 if [regexp "^target .* xfail .*" $selector] {
663 set xfail_index [string first "xfail" $selector]
664 set xfail_selector [string range $selector $xfail_index end]
665 set target_selector [string range $selector 0 [expr $xfail_index-1]]
666 set target_selector [string trim $target_selector]
667 if { [dg-process-target-1 $target_selector] == "N" } {
668 return "N"
669 }
670 return [dg-process-target-1 $xfail_selector]
671
672 }
673 return [dg-process-target-1 $selector]
674 }
675 }
676
677 # If this target does not support the "symver" attribute, skip this
678 # test.
679
680 proc dg-require-symver { args } {
681 if { ![ check_symver_available ] } {
682 upvar dg-do-what dg-do-what
683 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
684 }
685 }
686
687 # If this target does not provide prog named "$args", skip this test.
688
689 proc dg-require-prog-name-available { args } {
690 # The args are within another list; pull them out.
691 set args [lindex $args 0]
692
693 set prog [lindex $args 1]
694
695 if { ![ check_is_prog_name_available $prog ] } {
696 upvar dg-do-what dg-do-what
697 set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
698 }
699 }
700