]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/lib/lto.exp
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / lib / lto.exp
1 # Copyright (C) 2009-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 # Contributed by Diego Novillo <dnovillo@google.com>
18
19 # A subroutine of lto_handle_diagnostics: check TEXT for the expected
20 # diagnostics for one specific source file, issuing PASS/FAIL results.
21 # Return TEXT, stripped of any diagnostics that were handled.
22 #
23 # NAME is the testcase name to use when reporting PASS/FAIL results.
24 # FILENAME is the name (with full path) of the file we're interested in.
25 # MESSAGES_FOR_FILE is a list of expected messages, akin to DejaGnu's
26 # "dg-messages" variable.
27 # TEXT is the textual output from the LTO link.
28
29 proc lto_handle_diagnostics_for_file { name filename messages_for_file text } {
30 global dg-linenum-format
31
32 set filename_without_path [file tail $filename]
33
34 # This loop is adapted from the related part of DejaGnu's dg-test,
35 # with changes as detailed below to cope with the LTO case.
36
37 foreach i ${messages_for_file} {
38 verbose "Scanning for message: $i" 4
39
40 # Remove all error messages for the line [lindex $i 0]
41 # in the source file. If we find any, success!
42 set line [lindex $i 0]
43 set pattern [lindex $i 2]
44 set comment [lindex $i 3]
45 verbose "line: $line" 4
46 verbose "pattern: $pattern" 4
47 verbose "comment: $comment" 4
48 #send_user "Before:\n$text\n"
49
50 # Unlike dg-test, we use $filename_without_path in this pattern.
51 # This is to ensure that we have the correct file/line combination.
52 # This imposes the restriction that the filename can't contain
53 # any regexp control characters. We have to strip the path, since
54 # e.g. the '+' in "g++.dg" wouldn't be valid.
55 set pat "(^|\n)(\[^\n\]+$filename_without_path$line\[^\n\]*($pattern)\[^\n\]*\n?)+"
56 if {[regsub -all $pat $text "\n" text]} {
57 set text [string trimleft $text]
58 set ok pass
59 set uhoh fail
60 } else {
61 set ok fail
62 set uhoh pass
63 }
64 #send_user "After:\n$text\n"
65
66 # $line will either be a formatted line number or a number all by
67 # itself. Delete the formatting.
68 scan $line ${dg-linenum-format} line
69
70 # Unlike dg-test, add the filename to the PASS/FAIL message (rather
71 # than just the line number) so that the user can identify the
72 # pertinent directive.
73 set describe_where "$filename_without_path line $line"
74
75 # Issue the PASS/FAIL, adding "LTO" to the messages (e.g. "LTO errors")
76 # to distinguish them from the non-LTO case (in case we ever need to
77 # support both).
78 switch [lindex $i 1] {
79 "ERROR" {
80 $ok "$name $comment (test for LTO errors, $describe_where)"
81 }
82 "XERROR" {
83 x$ok "$name $comment (test for LTO errors, $describe_where)"
84 }
85 "WARNING" {
86 $ok "$name $comment (test for LTO warnings, $describe_where)"
87 }
88 "XWARNING" {
89 x$ok "$name $comment (test for LTO warnings, $describe_where)"
90 }
91 "BOGUS" {
92 $uhoh "$name $comment (test for LTO bogus messages, $describe_where)"
93 }
94 "XBOGUS" {
95 x$uhoh "$name $comment (test for LTO bogus messages, $describe_where)"
96 }
97 "BUILD" {
98 $uhoh "$name $comment (test for LTO build failure, $describe_where)"
99 }
100 "XBUILD" {
101 x$uhoh "$name $comment (test for LTO build failure, $describe_where)"
102 }
103 "EXEC" { }
104 "XEXEC" { }
105 }
106 }
107 return $text
108 }
109
110 # Support for checking for link-time diagnostics: check for
111 # the expected diagnostics within TEXT, issuing PASS/FAIL results.
112 # Return TEXT, stripped of any diagnostics that were handled.
113 #
114 # TEXT is the textual output from the LTO link.
115
116 proc lto_handle_diagnostics { text } {
117 global testcase
118
119 upvar dg-messages-by-file messages_by_file
120
121 verbose "lto_handle_diagnostics: entry: $text" 2
122
123 if { ![array exists messages_by_file] } {
124 error "lto_handle_diagnostics: messages_by_file not defined"
125 }
126
127 foreach src [lsort [array names messages_by_file]] {
128 set dg-messages $messages_by_file($src)
129 verbose " messages for $src: ${dg-messages}" 3
130 set text [lto_handle_diagnostics_for_file $testcase $src \
131 ${dg-messages} $text]
132 }
133
134 verbose "lto_handle_diagnostics: exit: $text" 2
135
136 return $text
137 }
138
139 # Prune messages that aren't useful.
140
141 proc lto_prune_warns { text } {
142
143 verbose "lto_prune_warns: entry: $text" 2
144
145 # Many tests that use visibility will still pass on platforms that don't support it.
146 regsub -all "(^|\n)\[^\n\]*: warning: visibility attribute not supported in this configuration; ignored\[^\n\]*" $text "" text
147
148 # Allow mixed-language LTO tests to pass with make check-c++0x
149 regsub -all "(^|\n)\[^\n\]*: warning: command line option '-std=\[^\n\]*" $text "" text
150
151 # And any stray location lines.
152 regsub -all "(^|\n)\[^\n\]*: In function \[^\n\]*" $text "" text
153 regsub -all "(^|\n)In file included from \[^\n\]*" $text "" text
154 regsub -all "(^|\n)\[ \t\]*from \[^\n\]*" $text "" text
155
156 # Sun ld warns about common symbols with differing sizes. Unlike GNU ld
157 # --warn-common (off by default), they cannot be disabled.
158 regsub -all "(^|\n)ld: warning: symbol \[`'\]\[^\n\]*' has differing sizes:" $text "" text
159 regsub -all "(^|\n)\[ \t\]*\[\(\]file \[^\n\]* value=\[^\n\]*; file \[^\n\]* value=\[^\n\]*\[)\];" $text "" text
160 regsub -all "(^|\n)\[ \t\]*\[^\n\]* definition taken" $text "" text
161
162 # Ignore missing jobserver for tests that do more than 1 LTRANS unit
163 regsub -all "(^|\n)\[^\n\]*: warning: using serial compilation of \[^\n\]*" $text "" text
164 regsub -all "(^|\n)\[^\n\]*: note: see the \[^\n\]*'-flto' option documentation\[^\n\]* for more information" $text "" text
165
166 global prune_notes
167 if { $prune_notes } {
168 # Ignore informational notes.
169 regsub -all "(^|\n)\[^\n\]*: note: \[^\n\]*" $text "" text
170 }
171
172 verbose "lto_prune_warns: exit: $text" 2
173
174 return $text
175 }
176
177 # lto_init -- called at the start of each subdir of tests
178
179 proc lto_init { args } {
180 global LTO_OPTIONS
181
182 if {[info exists args] && $args == "no-mathlib"} {
183 global board_info
184 global saved_mathlib
185
186 set dest [target_info name]
187 if [board_info $dest exists mathlib] {
188 set saved_mathlib [board_info $dest mathlib]
189 }
190 set board_info($dest,mathlib) " "
191 }
192
193 # Each test is run with the compiler options from this list.
194 # The default option lists can be overridden by LTO_OPTIONS="[list
195 # {opts_1} {opts_2}... {opts_n}]" where opts_i are lists of options.
196 # You can put this in the environment before site.exp is written or
197 # add it to site.exp directly.
198 if ![info exists LTO_OPTIONS] {
199 if [check_linker_plugin_available] {
200 set LTO_OPTIONS [list \
201 {-O0 -flto -flto-partition=none -fuse-linker-plugin} \
202 {-O2 -flto -flto-partition=none -fuse-linker-plugin -fno-fat-lto-objects } \
203 {-O0 -flto -flto-partition=1to1 -fno-use-linker-plugin } \
204 {-O2 -flto -flto-partition=1to1 -fno-use-linker-plugin } \
205 {-O0 -flto -fuse-linker-plugin -fno-fat-lto-objects } \
206 {-O2 -flto -fuse-linker-plugin} \
207 ]
208 } else {
209 set LTO_OPTIONS [list \
210 {-O0 -flto -flto-partition=none } \
211 {-O2 -flto -flto-partition=none } \
212 {-O0 -flto -flto-partition=1to1 } \
213 {-O2 -flto -flto-partition=1to1 } \
214 {-O0 -flto } \
215 {-O2 -flto} \
216 ]
217 }
218 }
219 }
220
221 #
222 # lto_finish -- called at the end of each subdir of tests if mathlib is
223 # changed.
224 #
225
226 proc lto_finish { } {
227 global board_info
228 global saved_mathlib
229
230 set dest [target_info name]
231 if [info exists saved_mathlib] {
232 set board_info($dest,mathlib) $saved_mathlib
233 } elseif [board_info $dest exists mathlib] {
234 unset board_info($dest,mathlib)
235 }
236 }
237
238 # Subsets of tests can be selectively disabled by members of this list:
239 # - ATTRIBUTE: disable all tests using the __attribute__ extension,
240 # - COMPLEX: disable all tests using the complex types feature,
241 # - COMPLEX_INT: disable all tests using the complex integral types extension,
242 # - VA: disable all tests using the variable number of arguments feature,
243 # - VLA_IN_STRUCT: disable all tests using the variable-length arrays as
244 # structure members extension,
245 # - ZERO_ARRAY: disable all tests using the zero-sized arrays extension.
246 # The default skip lists can be overriden by
247 # LTO_SKIPS="[list {skip_1}...{skip_n}]"
248 # where skip_i are skip identifiers. You can put this in the environment
249 # before site.exp is written or add it to site.exp directly.
250 if ![info exists LTO_SKIPS] {
251 set LTO_SKIPS [list {}]
252 }
253
254 global lto_skip_list
255 set lto_skip_list $LTO_SKIPS
256
257 load_lib dg.exp
258 load_lib gcc-dg.exp
259 load_lib gcc.exp
260
261 # lto-obj -- compile to an object file
262 #
263 # SOURCE is the source file
264 # DEST is the object file
265 # OPTALL is the list of compiler options to use with all tests
266 # OPTFILE is the list of compiler options to use with this file
267 # OPTSTR is the options to print with test messages
268 # XFAILDATA is the xfail data to be passed to the compiler
269 proc lto-obj { source dest optall optfile optstr xfaildata } {
270 global testcase
271 global tool
272 global compiler_conditional_xfail_data
273 global lto_skip_list
274
275 # Add the skip specifiers.
276 foreach skip $lto_skip_list {
277 if { ![string match $skip ""] } {
278 lappend optall "-DSKIP_$skip"
279 }
280 }
281
282 # Set up the options for compiling this file.
283 set options ""
284 lappend options "additional_flags=$optall $optfile"
285
286 set compiler_conditional_xfail_data $xfaildata
287
288 # Allow C source files to mix freely with other languages
289 if [ string match "*.c" $source ] then {
290 set comp_output [gcc_target_compile "$source" "$dest" object $options]
291 } else {
292 set comp_output [${tool}_target_compile "$source" "$dest" object $options]
293 }
294 # Prune unimportant visibility warnings before checking output.
295 set comp_output [lto_prune_warns $comp_output]
296 ${tool}_check_compile "$testcase $dest assemble" $optstr $dest $comp_output
297 }
298
299 # lto-link-and-maybe-run -- link the object files and run the executable
300 # if compile_type is set to "run"
301 #
302 # TESTNAME is the mixture of object files to link
303 # OBJLIST is the list of object files to link
304 # DEST is the name of the executable
305 # OPTALL is a list of compiler and linker options to use for all tests
306 # OPTFILE is a list of compiler and linker options to use for this test
307 # OPTSTR is the list of options to list in messages
308 proc lto-link-and-maybe-run { testname objlist dest optall optfile optstr } {
309 global testcase
310 global tool
311 global compile_type
312 global board_info
313
314 upvar dg-messages-by-file dg-messages-by-file
315
316 verbose "lto-link-and-maybe-run" 2
317
318 # Check that all of the objects were built successfully.
319 foreach obj [split $objlist] {
320 if ![file_on_host exists $obj] then {
321 unresolved "$testcase $testname link $optstr"
322 unresolved "$testcase $testname execute $optstr"
323 return
324 }
325 }
326
327 # Set up the options for linking this test.
328 set options ""
329 lappend options "additional_flags=$optall $optfile"
330
331 set target_board [target_info name]
332 set relocatable 0
333
334 # Some LTO tests do relocatable linking. Some target boards set
335 # a linker script which can't be used for relocatable linking.
336 # Use the default linker script instead.
337 if { [lsearch -exact [split "$optall $optfile"] "-r"] >= 0 } {
338 set relocatable 1
339 }
340
341 if { $relocatable } {
342 set saved_ldscript [board_info $target_board ldscript]
343 set board_info($target_board,ldscript) ""
344 }
345
346 # Link the objects into an executable.
347 set comp_output [${tool}_target_compile "$objlist" $dest executable \
348 "$options"]
349
350 if { $relocatable } {
351 set board_info($target_board,ldscript) $saved_ldscript
352 }
353
354 # Check for diagnostics specified by directives
355 set comp_output [lto_handle_diagnostics $comp_output]
356
357 # Prune unimportant visibility warnings before checking output.
358 set comp_output [lto_prune_warns $comp_output]
359
360 if ![${tool}_check_compile "$testcase $testname link" $optstr \
361 $dest $comp_output] then {
362 if { ![string compare "execute" $compile_type] } {
363 unresolved "$testcase $testname execute $optstr"
364 }
365 return
366 }
367
368 # Return if we only needed to link.
369 if { ![string compare "link" $compile_type] } {
370 return
371 }
372
373 # Run the self-checking executable.
374 if ![string match "*/*" $dest] then {
375 set dest "./$dest"
376 }
377 set result [${tool}_load $dest "" ""]
378 set status [lindex $result 0]
379 if { $status == "pass" } then {
380 file_on_host delete $dest
381 }
382 $status "$testcase $testname execute $optstr"
383 }
384
385 # Potentially handle the given dg- directive (a list)
386 # Return true is the directive was handled, false otherwise.
387
388 proc lto-can-handle-directive { op } {
389 set cmd [lindex $op 0]
390
391 # dg-warning and dg-message append to dg-messages.
392 upvar dg-messages dg-messages
393
394 # A list of directives to recognize, and a list of directives
395 # to remap them to.
396 # For example, "dg-lto-warning" is implemented by calling "dg-warning".
397 set directives { dg-lto-warning dg-lto-message dg-lto-note }
398 set remapped_directives { dg-warning dg-message dg-note }
399
400 set idx [lsearch -exact $directives $cmd]
401 if { $idx != -1 } {
402 verbose "remapping from: $op" 4
403
404 set remapped_cmd [lindex $remapped_directives $idx]
405 set op [lreplace $op 0 0 $remapped_cmd]
406
407 verbose "remapped to: $op" 4
408
409 set status [catch "$op" errmsg]
410 if { $status != 0 } {
411 if { 0 && [info exists errorInfo] } {
412 # This also prints a backtrace which will just confuse
413 # testcase writers, so it's disabled.
414 perror "$name: $errorInfo\n"
415 } else {
416 perror "$name: $errmsg for \"$op\"\n"
417 }
418 # ??? The call to unresolved here is necessary to clear `errcnt'.
419 # What we really need is a proc like perror that doesn't set errcnt.
420 # It should also set exit_status to 1.
421 unresolved "$name: $errmsg for \"$op\""
422 }
423
424 return true
425 }
426
427 return false
428 }
429
430 # lto-get-options-main -- get target requirements for a test and
431 # options for the primary source file and the test as a whole
432 #
433 # SRC is the full pathname of the primary source file.
434 proc lto-get-options-main { src } {
435 global compile_type
436 global dg-extra-ld-options
437 global dg-suppress-ld-options
438
439 set dg-extra-ld-options ""
440 set dg-suppress-ld-options ""
441
442 # dg-options sets a variable called dg-extra-tool-flags.
443 set dg-extra-tool-flags ""
444
445 # dg-options sets a variable called tool_flags.
446 set tool_flags ""
447
448 # dg-require-* sets dg-do-what.
449 upvar dg-do-what dg-do-what
450 upvar dg-final-code dg-final-code
451 set dg-final-code ""
452
453 # dg-warning and dg-message append to dg-messages.
454 upvar dg-messages-by-file dg-messages-by-file
455 set dg-messages ""
456
457 set tmp [dg-get-options $src]
458 verbose "getting options for $src: $tmp"
459 foreach op $tmp {
460 set cmd [lindex $op 0]
461 verbose "cmd is $cmd"
462 if { [string match "dg-skip-if" $cmd] \
463 || [string match "dg-require-*" $cmd] } {
464 set status [catch "$op" errmsg]
465 if { $status != 0 } {
466 perror "src: $errmsg for \"$op\"\n"
467 unresolved "$src: $errmsg for \"$op\""
468 return
469 }
470 } elseif { [string match "dg-lto-options" $cmd] } {
471 set op [lreplace $op 0 0 "dg-options"]
472 set status [catch "$op" errmsg]
473 if { $status != 0 } {
474 perror "src: $errmsg for \"$op\"\n"
475 unresolved "$src: $errmsg for \"$op\""
476 return
477 }
478 } elseif { ![string compare "dg-xfail-if" $cmd] \
479 || ![string compare "dg-options" $cmd] } {
480 warning "lto.exp does not support $cmd in primary source file"
481 } elseif { ![string compare "dg-lto-do" $cmd] } {
482 if { [llength $op] > 3 } {
483 set kw [lindex [lindex $op 3] 0]
484 if [string match "target" $kw] {
485 perror "$src: dg-lto-do does not support \"target\""
486 } elseif [string match "xfail" $kw] {
487 perror "$src: dg-lto-do does not support \"xfail\""
488 } else {
489 perror "$src: dg-lto-do takes a single argument"
490 }
491 }
492 set dgdo [lindex $op 2]
493 verbose "dg-lto-do command for \"$op\" is $dgdo"
494 if { ![string compare "assemble" $dgdo] } {
495 set compile_type "assemble"
496 } elseif { ![string compare "run" $dgdo] } {
497 set compile_type "run"
498 } elseif { ![string compare "link" $dgdo] } {
499 set compile_type "link"
500 } else {
501 warning "lto.exp does not support dg-lto-do $dgdo"
502 }
503 } elseif { ![string compare "dg-extra-ld-options" $cmd] } {
504 if { [llength $op] > 4 } {
505 error "[lindex $op 0]: too many arguments"
506 } else {
507 if { [llength $op] == 3
508 || ([llength $op] > 3
509 && [dg-process-target [lindex $op 3]] == "S") } {
510 set dg-extra-ld-options [lindex $op 2]
511 verbose \
512 "dg-extra-ld-options for main is ${dg-extra-ld-options}"
513 }
514 }
515 } elseif { ![string compare "dg-suppress-ld-options" $cmd] } {
516 if { [llength $op] > 4 } {
517 error "[lindex $op 0]: too many arguments"
518 } else {
519 if { [llength $op] == 3
520 || ([llength $op] > 3
521 && [dg-process-target [lindex $op 3]] == "S") } {
522 set dg-suppress-ld-options [lindex $op 2]
523 verbose \
524 "dg-suppress-ld-options for main is ${dg-suppress-ld-options}"
525 }
526 }
527 } elseif { ![string compare "dg-final" $cmd] } {
528 if { [llength $op] > 3 } {
529 error "[lindex $op 0]: too many arguments"
530 } else {
531 append dg-final-code "[lindex $op 2]\n"
532 }
533 } elseif { ![lto-can-handle-directive $op] } {
534 # Ignore unrecognized dg- commands, but warn about them.
535 warning "lto.exp does not support $cmd"
536 }
537 }
538
539 verbose "dg-messages: ${dg-messages}" 3
540 set dg-messages-by-file($src) ${dg-messages}
541
542 # Return flags to use for compiling the primary source file and for
543 # linking.
544 verbose "dg-extra-tool-flags for main is ${dg-extra-tool-flags}"
545 return ${dg-extra-tool-flags}
546 }
547
548
549 # lto-get-options -- get special tool flags to use for a secondary
550 # source file
551 #
552 # SRC is the full pathname of the source file.
553 # The result is a list of options to use.
554 #
555 # This code is copied from proc dg-test in dg.exp from DejaGNU.
556 proc lto-get-options { src } {
557 # dg-options sets a variable called dg-extra-tool-flags.
558 set dg-extra-tool-flags ""
559
560 # dg-xfail-if sets compiler_conditional_xfail_data.
561 global compiler_conditional_xfail_data
562 set compiler_conditional_xfail_data ""
563
564 # dg-xfail-if needs access to dg-do-what.
565 upvar dg-do-what dg-do-what
566
567 # dg-warning appends to dg-messages.
568 upvar dg-messages-by-file dg-messages-by-file
569 set dg-messages ""
570
571 set tmp [dg-get-options $src]
572 foreach op $tmp {
573 set cmd [lindex $op 0]
574 if { ![string compare "dg-options" $cmd] \
575 || ![string compare "dg-xfail-if" $cmd] } {
576 set status [catch "$op" errmsg]
577 if { $status != 0 } {
578 perror "src: $errmsg for \"$op\"\n"
579 unresolved "$src: $errmsg for \"$op\""
580 return
581 }
582 } elseif { [string match "dg-require-*" $cmd] } {
583 warning "lto.exp does not support $cmd in secondary source files"
584 } elseif { ![lto-can-handle-directive $op] } {
585 # Ignore unrecognized dg- commands, but warn about them.
586 warning "lto.exp does not support $cmd in secondary source files"
587 }
588 }
589
590 verbose "dg-messages: ${dg-messages}" 3
591 if { [info exists dg-messages-by-file($src)] } {
592 append dg-messages-by-file($src) ${dg-messages}
593 } else {
594 set dg-messages-by-file($src) ${dg-messages}
595 }
596
597 return ${dg-extra-tool-flags}
598 }
599
600 # lto-execute -- compile multi-file tests
601 #
602 # SRC1 is the full pathname of the main file of the testcase.
603 # SID identifies a test suite in the names of temporary files.
604 proc lto-execute-1 { src1 sid } {
605 global srcdir tmpdir
606 global lto_option_list
607 global tool
608 global verbose
609 global testcase
610 global gluefile
611 global compiler_conditional_xfail_data
612 global dg-do-what-default
613 global compile_type
614 global dg-extra-ld-options
615 global dg-suppress-ld-options
616 global LTO_OPTIONS
617 global dg-final-code
618 global testname_with_flags
619
620 # Get extra flags for this test from the primary source file, and
621 # process other dg-* options that this suite supports. Warn about
622 # unsupported flags.
623 verbose "lto-execute: $src1" 1
624 set compile_type "run"
625 set dg-do-what [list ${dg-do-what-default} "" P]
626 array set dg-messages-by-file [list]
627 set extra_flags(0) [lto-get-options-main $src1]
628 set compile_xfail(0) ""
629
630 # If the main file defines dg-options, those flags are used to
631 # overwrite the default lto_option_list taken from LTO_OPTIONS.
632 if { [string length $extra_flags(0)] > 0 } {
633 set lto_option_list $extra_flags(0)
634 set extra_flags(0) ""
635 } else {
636 set lto_option_list $LTO_OPTIONS
637 }
638
639 # Set up the names of the other source files.
640 set dir [file dirname $src1]
641 set base [file rootname $src1]
642 set base [string range $base [string length $dir] end]
643 regsub "_0" $base "" base
644 regsub "/" $base "" base
645 set src_list $src1
646 set i 1
647 set done 0
648 while { !$done } {
649 set names [glob -nocomplain -types f -- "${dir}/${base}_${i}.*"]
650 if { [llength ${names}] > 1 } {
651 warning "lto-execute: more than one file matched ${dir}/${base}_${i}.*"
652 }
653 if { [llength ${names}] == 1 } {
654 lappend src_list [lindex ${names} 0]
655 incr i
656 } else {
657 set num_srcs ${i}
658 set done 1
659 }
660 }
661
662 # Use the dg-options mechanism to specify extra flags for each
663 # of the secondary files.
664 # The extra flags in each file are used to compile that file, and the
665 # extra flags in *_0.* are also used for linking.
666 verbose "\tsrc_list is: $src_list"
667 for {set i 1} {$i < $num_srcs} {incr i} {
668 set extra_flags($i) [lto-get-options [lindex $src_list $i]]
669 set compile_xfail($i) $compiler_conditional_xfail_data
670 }
671
672 # Define the names of the object files.
673 set obj_list ""
674 for {set i 0} {$i < $num_srcs} {incr i} {
675 lappend obj_list "${sid}_${base}_${i}.o"
676 }
677
678 # Get the base name of this test, for use in messages.
679 set testcase [lindex ${src_list} 0]
680
681 # Remove the $srcdir and $tmpdir prefixes from $src1. (It would
682 # be possible to use "regsub" here, if we were careful to escape
683 # all regular expression characters in $srcdir and $tmpdir, but
684 # that would be more complicated that this approach.)
685 if {[string first "$srcdir/" "${testcase}"] == 0} {
686 set testcase [string range "${testcase}" [string length "$srcdir/"] end]
687 }
688 if {[string first "$tmpdir/" "$testcase"] == 0} {
689 set testcase [string range "$testcase" [string length "$tmpdir/"] end]
690 set testcase "tmpdir-$testcase"
691 }
692 # If we couldn't rip $srcdir out of `src1' then just do the best we can.
693 # The point is to reduce the unnecessary noise in the logs. Don't strip
694 # out too much because different testcases with the same name can confuse
695 # `test-tool'.
696 if [string match "/*" $testcase] then {
697 set testcase "[file tail [file dirname $src1]]/[file tail $src1]"
698 }
699
700 # Check whether this test is supported for this target.
701 if { [lindex ${dg-do-what} 1 ] == "N" } {
702 unsupported "$testcase"
703 verbose "$testcase not supported on this target, skipping it" 3
704 return
705 }
706 # Should be safe for non-fortran too but be paranoid..
707 if {$sid eq "f_lto"} {
708 list-module-names $src_list
709 }
710 regsub "_0.*" $testcase "" testcase
711
712 # Set up the base name of executable files so they'll be unique.
713 regsub -all "\[./\]" $testcase "-" execbase
714
715 # Loop through all of the option lists used for this test.
716 set count 0
717 foreach option $lto_option_list {
718 verbose "Testing $testcase, $option"
719
720 # There's a unique name for each executable we generate.
721 set execname "${execbase}-${count}1.exe"
722
723 # The LTO tests don't use dg-test, so testname_with_flags and
724 # output_file need to be defined explicitly for each file. scan-symbol
725 # directives rely on both of these to be defined to find the symbol to
726 # scan and for the text to print in the PASS/FAIL since they can also
727 # be called from dg-test. testname_with_flags is also used via
728 # testname-for-summary when calling into generic function below to
729 # clean temporary files.
730 set output_file $execname
731 set testname_with_flags $execname
732
733 incr count
734
735 file_on_host delete $execname
736
737 # Compile pieces with the compiler under test.
738 set i 0
739 foreach src $src_list obj $obj_list {
740 lto-obj $src $obj $option $extra_flags($i) $option \
741 $compile_xfail($i)
742 incr i
743 }
744
745 # Link (using the compiler under test), run, and clean up tests.
746 if { ![string compare "run" $compile_type] \
747 || ![string compare "link" $compile_type] } {
748
749 # Filter out any link options we were asked to suppress.
750 set reduced {}
751 foreach x [split $option] {
752 if {[lsearch ${dg-suppress-ld-options} $x] == -1} {
753 lappend reduced $x
754 }
755 }
756 set filtered [join $reduced " "]
757
758 lto-link-and-maybe-run \
759 "[lindex $obj_list 0]-[lindex $obj_list end]" \
760 $obj_list $execname $filtered ${dg-extra-ld-options} \
761 $filtered
762 }
763
764
765 # Are there any further tests to perform?
766 # Note that if the program has special run-time requirements, running
767 # of the program can be delayed until here. Ditto for other situations.
768 # It would be a bit cumbersome though.
769
770 if ![string match ${dg-final-code} ""] {
771 regsub -all "\\\\(\[{}\])" ${dg-final-code} "\\1" dg-final-code
772 # Note that the use of `args' here makes this a varargs proc.
773 proc dg-final-proc { args } ${dg-final-code}
774 verbose "Running dg-final tests." 3
775 verbose "dg-final-proc:\n[info body dg-final-proc]" 4
776 if [catch "dg-final-proc $src1" errmsg] {
777 perror "$src1: error executing dg-final: $errmsg"
778 # ??? The call to unresolved here is necessary to clear
779 # `errcnt'. What we really need is a proc like perror that
780 # doesn't set errcnt. It should also set exit_status to 1.
781 unresolved "$src1: error executing dg-final: $errmsg"
782 }
783 }
784
785 # Clean up object files.
786 set files [glob -nocomplain ${sid}_*.o]
787 if { $files != "" } {
788 foreach objfile $files {
789 if { ![info exists gluefile] || $objfile != $gluefile } {
790 eval "file_on_host delete $objfile"
791 }
792 }
793 }
794
795 # Clean up after -save-temps.
796 eval "cleanup-saved-temps"
797
798 for {set i 0} {$i < $num_srcs} {incr i} {
799 set testname_with_flags "${base}_${i}"
800 eval "cleanup-saved-temps"
801 set testname_with_flags "${sid}_${base}_${i}"
802 eval "cleanup-saved-temps"
803 }
804
805 unset testname_with_flags
806
807 if { ![string compare "run" $compile_type] \
808 || ![string compare "link" $compile_type] } {
809 file_on_host delete $execname
810 }
811 # Should be safe for non-fortran too but be paranoid..
812 if {$sid eq "f_lto"} {
813 cleanup-modules ""
814 }
815 }
816 }
817
818 proc lto-execute { src1 sid } {
819 lto-execute-1 $src1 $sid
820
821 # LTO testing doesn't use 'dg-runtest'/'dg-test', and thus doesn't call
822 # 'cleanup-after-saved-dg-test', so we have to clean up manually.
823 initialize_prune_notes
824 }
825
826 # Call pass if object readelf is ok, otherwise fail.
827 # example: /* { dg-final { object-readelf Tag_ABI_enum_size int} } */
828 proc object-readelf { args } {
829 global readelf
830 global base_dir
831 upvar 2 execname execname
832
833 if { [llength $args] < 2 } {
834 error "object-readelf: too few arguments"
835 return
836 }
837 if { [llength $args] > 3 } {
838 error "object-readelf: too many arguments"
839 return
840 }
841 if { [llength $args] >= 3 } {
842 switch [dg-process-target [lindex $args 2]] {
843 "S" { }
844 "N" { return }
845 "F" { setup_xfail "*-*-*" }
846 "P" { }
847 }
848 }
849
850 # Find size like we find g++ in g++.exp.
851 if ![info exists readelf] {
852 set readelf [findfile $base_dir/../../../binutils/readelf \
853 $base_dir/../../../binutils/readelf \
854 [findfile $base_dir/../../readelf $base_dir/../../readelf \
855 [findfile $base_dir/readelf $base_dir/readelf \
856 [transform readelf]]]]
857 verbose -log "readelf is $readelf"
858 }
859
860 set what [lindex $args 0]
861 set with [lindex $args 1]
862
863 if ![file_on_host exists $execname] {
864 verbose -log "$execname does not exist"
865 unresolved "object-readelf $what "
866 return
867 }
868
869 set output [remote_exec host "$readelf -A" "$execname"]
870 set status [lindex $output 0]
871 if { $status != 0 } {
872 verbose -log "object-readelf: $readelf failed"
873 unresolved "object-readelf $what $execname"
874 return
875 }
876
877 set text [lindex $output 1]
878 set lines [split $text "\n"]
879
880 set done 0
881 set i 0
882 while { !$done } {
883 set line_tex [lindex $lines $i]
884 if { [llength ${line_tex}] > 1} {
885 incr i
886 if [regexp -- $what $line_tex] {
887 set match [regexp -- $with $line_tex]
888 set done 1
889 }
890 } else {
891 set done 1
892 }
893 }
894
895 verbose -log "$what size is $with;"
896 if { $match == 1 } {
897 pass "object-readelf $what size is correct."
898 } else {
899 fail "object-readelf $what size is incorrect."
900 }
901 }
902
903