Debian Codegraph @

libstdc++-v3/testsuite/lib/libstdc++.exp

raw
1 # libstdc++ "tool init file" for DejaGNU
2
3 # Copyright (C) 2001-2025 Free Software Foundation, Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; see the file COPYING3. If not see
17 # <http://www.gnu.org/licenses/>.
18
19
20 # Define callbacks and load other libraries. This file is loaded relatively
21 # early, and before any other file we write ourselves. "load_lib" will
22 # find anything in the DejaGNU installation tree, or in our lib directory.
23 # "load_gcc_lib" will search the core compiler's .exp collection instead.
24 #
25 # The naming rule is that dg.exp looks for "tool-" and runtest.exp looks
26 # for "tool_" when finding callbacks. Utility routines we define for
27 # our callbacks begin with "v3-".
28 #
29 # libstdc++_* callbacks we don't define, but could:
30 # ..._option_help prints additional --help output
31 # ..._option_proc (--foo) process our own options
32 # ..._init (normal.exp) called once per test file
33 # ..._finish bracketing function for libstdc++_init
34 # ...-dg-prune removing output text, see top of system dg.exp
35 #
36 # Useful hook: if ${hostname}_init exists, it will be called, almost
37 # the last thing before testing begins. This can be defined in, e.g.,
38 # ~/.dejagnurc or $DEJAGNU.
39
40 proc load_gcc_lib { filename } {
41 global srcdir loaded_libs
42
43 load_file $srcdir/../../gcc/testsuite/lib/$filename
44 set loaded_libs($filename) ""
45 }
46
47 #
48 # search_for -- looks for a string match in a file
49 #
50 proc search_for { file pattern } {
51 set fd [open $file r]
52 while { [gets $fd cur_line]>=0 } {
53 if [string match "*$pattern*" $cur_line] then {
54 close $fd
55 return 1
56 }
57 }
58 close $fd
59 return 0
60 }
61
62 # system routines
63 load_lib dg.exp
64 load_lib libgloss.exp
65 # compiler routines, then ours
66 load_gcc_lib target-supports.exp
67 load_gcc_lib target-supports-dg.exp
68 load_lib prune.exp
69 load_lib dg-options.exp
70 load_gcc_lib scanasm.exp
71 load_gcc_lib target-libpath.exp
72 load_gcc_lib timeout.exp
73 load_gcc_lib timeout-dg.exp
74 load_gcc_lib wrapper.exp
75 load_gcc_lib target-utils.exp
76 load_gcc_lib dg-test-cleanup.exp
77
78 # Useful for debugging. Pass the name of a variable and the verbosity
79 # threshold (number of -v's on the command line).
80 proc v3track { var n } {
81 upvar $var val
82 verbose "++ $var is $val" $n
83 }
84
85 # Copy file to the target.
86 proc v3-copy-file {src dst} {
87 if { [catch { set symlink [file readlink $src] } x] } then {
88 remote_download target $src $dst
89 } else {
90 if { [regexp "^/" "$symlink"] } then {
91 remote_download target $symlink $dst
92 } else {
93 set dirname [file dirname $f]
94 remote_download target $dirname/$symlink $dst
95 }
96 }
97 }
98
99 # Called by v3-init below. "Static" to this file.
100 proc v3-copy-files {srcfiles} {
101 foreach f $srcfiles {
102 v3-copy-file $f [file tail $f]
103 }
104 }
105
106 # Called once, during runtest.exp setup.
107 proc libstdc++_init { testfile } {
108 global env
109 global v3-sharedlib v3-libgomp
110 global srcdir blddir objdir tool_root_dir
111 global cc cxx cxxflags cxxpchflags cxxldflags cxxvtvflags
112 global includes
113 global gluefile wrap_flags
114 global ld_library_path
115 global target_triplet
116 global flags_file
117 global tool_timeout
118 global DEFAULT_CXXFLAGS
119 global STATIC_LIBCXXFLAGS
120
121 # We set LC_ALL and LANG to C so that we get the same error
122 # messages as expected.
123 setenv LC_ALL C
124 setenv LANG C
125
126 # LANGUAGE changes the behavior of GNU gettext(3) and causes
127 # std::messages tests to fail.
128 array unset env LANGUAGE
129
130 # Many hosts now default to a non-ASCII C locale, however, so
131 # they can set a charset encoding here if they need.
132 if { [ishost "*-*-cygwin*"] } {
133 setenv LC_ALL C.ASCII
134 setenv LANG C.ASCII
135 }
136
137 set blddir [lookfor_file [get_multilibs] libstdc++-v3]
138 set flags_file "${blddir}/scripts/testsuite_flags"
139 set shlib_ext [get_shlib_extension]
140 v3track flags_file 2
141
142 # If a test doesn't have special options, use DEFAULT_CXXFLAGS.
143 # Use this variable if the behavior
144 # 1) only applies to libstdc++ testing
145 # 2) might need to be negated
146 # In particular, some tests have to be run without precompiled
147 # headers, or without assertions.
148
149 if ![info exists DEFAULT_CXXFLAGS] then {
150 set DEFAULT_CXXFLAGS ""
151 # Host specific goo here.
152 if { [string match "powerpc-ibm-aix*" $target_triplet] } {
153 append DEFAULT_CXXFLAGS " -Wl,-bmaxdata:0x20000000"
154 }
155 }
156 v3track DEFAULT_CXXFLAGS 2
157
158 # By default, we assume we want to run program images.
159 global dg-do-what-default
160 set dg-do-what-default run
161
162 set ld_library_path_tmp ""
163
164 # Locate libgcc.a so we don't need to account for different values of
165 # SHLIB_EXT on different platforms
166 set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
167 if {$gccdir != ""} {
168 set gccdir [file dirname $gccdir]
169 append ld_library_path_tmp ":${gccdir}"
170 }
171 v3track gccdir 3
172
173 # Locate libatomic.
174 set v3-libatomic 0
175 set libatomicdir [lookfor_file $blddir/../libatomic .libs/libatomic.$shlib_ext]
176 if {$libatomicdir != ""} {
177 set v3-libatomic 1
178 set libatomicdir [file dirname $libatomicdir]
179 append ld_library_path_tmp ":${libatomicdir}"
180 verbose -log "libatomic support detected"
181 }
182 v3track libatomicdir 3
183
184 # Locate libgomp. This is only required for parallel mode.
185 set v3-libgomp 0
186 set libgompdir [lookfor_file $blddir/../libgomp .libs/libgomp.$shlib_ext]
187 if {$libgompdir != ""} {
188 set v3-libgomp 1
189 set libgompdir [file dirname $libgompdir]
190 append ld_library_path_tmp ":${libgompdir}"
191 verbose -log "libgomp support detected"
192 }
193 v3track libgompdir 3
194
195 # Locate libvtv. This is only required for --enable-vtable-verify.
196 set v3-libvtv 0
197 set libvtvdir [lookfor_file $blddir/../libvtv .libs/libvtv.$shlib_ext]
198 if {$libvtvdir != ""} {
199 set v3-libvtv 1
200 set libvtvdir [file dirname $libvtvdir]
201 append ld_library_path_tmp ":${libvtvdir}"
202 verbose -log "libvtv support detected"
203 }
204 v3track libvtvdir 3
205
206 # Locate libstdc++ shared library. (ie libstdc++.so.)
207 set v3-sharedlib 0
208 set sharedlibdir [lookfor_file $blddir src/.libs/libstdc++.$shlib_ext]
209 if {$sharedlibdir != ""} {
210 if { ([string match "*-*-gnu*" $target_triplet]
211 || [string match "*-*-linux*" $target_triplet]
212 || [string match "*-*-solaris*" $target_triplet])
213 && [isnative] } then {
214 set v3-sharedlib 1
215 verbose -log "shared library support detected"
216 }
217 }
218 v3track v3-sharedlib 3
219
220 set STATIC_LIBCXXFLAGS ""
221 set staticlibdir [lookfor_file $blddir src/.libs/libstdc++.a]
222 if {$staticlibdir != ""} {
223 set staticlibdir [file dirname $staticlibdir]
224 # Some targets use libstdc++.a%s in their specs, so they need a
225 # -B option for uninstalled testing.
226 set STATIC_LIBCXXFLAGS " -B${staticlibdir} "
227 }
228
229 # Compute what needs to be added to the existing LD_LIBRARY_PATH.
230 if {$gccdir != ""} {
231 set compiler ${gccdir}/xg++
232 set ld_library_path ${ld_library_path_tmp}
233 append ld_library_path ":${blddir}/src/.libs"
234
235 if { [is_remote host] == 0 && [which $compiler] != 0 } {
236 foreach i "[exec $compiler --print-multi-lib]" {
237 set mldir ""
238 regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
239 set mldir [string trimright $mldir "\;@"]
240 if { "$mldir" == "." } {
241 continue
242 }
243 if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
244 append ld_library_path ":${gccdir}/${mldir}"
245 }
246 }
247 }
248
249 set_ld_library_path_env_vars
250 if [info exists env(LD_LIBRARY_PATH)] {
251 verbose -log "LD_LIBRARY_PATH = $env(LD_LIBRARY_PATH)"
252 }
253 } else {
254 set compiler [transform "g++"]
255 }
256
257 # Set the default timeout for v3 tests.
258 # You can override this in ~/.dejagnurc or a .exp file named by $DEJAGNU.
259 if {![info exists tool_timeout]} {
260 set tool_timeout 360
261 }
262
263 # Default settings.
264 set cxx [transform "g++"]
265 set cxxflags "-fmessage-length=0 -fno-show-column"
266 set cxxpchflags ""
267 set cxxvtvflags ""
268 set cxxldflags ""
269 set cc [transform "gcc"]
270 # Locate testsuite_hooks.h and other testsuite headers.
271 set includes "-I${srcdir}/util"
272 # Adapt the defaults for special circumstances.
273 if [is_remote host] {
274 # A remote host does not, in general, have access to the
275 # $srcdir so we copy the testsuite headers into the current
276 # directory, and then add that to the search path.
277 foreach src [glob "${srcdir}/util/*.h" \
278 "${srcdir}/util/*.cc" \
279 "${srcdir}/util/*.tcc" \
280 "${srcdir}/util/*.hpp" \
281 "${srcdir}/util/*/*.h" \
282 "${srcdir}/util/*/*.cc" \
283 "${srcdir}/util/*/*.tcc" \
284 "${srcdir}/util/*/*.hpp" \
285 "${srcdir}/util/*/*/*.h" \
286 "${srcdir}/util/*/*/*.cc" \
287 "${srcdir}/util/*/*/*.tcc" \
288 "${srcdir}/util/*/*/*.hpp" \
289 "${srcdir}/util/*/*/*/*.h" \
290 "${srcdir}/util/*/*/*/*.cc" \
291 "${srcdir}/util/*/*/*/*.tcc" \
292 "${srcdir}/util/*/*/*/*.hpp" \
293 "${srcdir}/util/*/*/*/*/*.h" \
294 "${srcdir}/util/*/*/*/*/*.cc" \
295 "${srcdir}/util/*/*/*/*/*.tcc" \
296 "${srcdir}/util/*/*/*/*/*.hpp" ] {
297 # Remove everything up to "util/..."
298 set dst [string range $src [string length "${srcdir}/"] end]
299 # Create the directory containing the file.
300 set dir [file dirname $dst]
301 remote_exec host "mkdir" [list "-p" "$dir"]
302 # Download the file.
303 set result [remote_download host $src $dst]
304 if { $result == "" } {
305 verbose -log "Unable to download ${srcdir}/${src} to host."
306 return "untested"
307 }
308 }
309 set includes "-Iutil"
310 } elseif { [file exists $flags_file] } {
311 # If we find a testsuite_flags file, we're testing in the build dir.
312 set cxx [exec sh $flags_file --build-cxx]
313 set cxxflags [exec sh $flags_file --cxxflags]
314 set cxxpchflags [exec sh $flags_file --cxxpchflags]
315 set cxxvtvflags [exec sh $flags_file --cxxvtvflags]
316 set cxxldflags [exec sh $flags_file --cxxldflags]
317 set cc [exec sh $flags_file --build-cc]
318 set includes [exec sh $flags_file --build-includes]
319 }
320 append cxxflags " "
321 append cxxflags [getenv CXXFLAGS]
322
323 if ![regexp ".*-O" $cxxflags] {
324 append cxxflags " -g -O2"
325 }
326
327 v3track cxxflags 2
328
329 # Should be as good as -fdiagnostics-color=never, but more compatible
330 setenv GCC_COLORS ""
331 # Always use MO files built by this test harness.
332 set ccflags "$cxxflags -DLOCALEDIR=\".\""
333 set cxxflags "$cxxflags -DLOCALEDIR=\".\""
334
335 # If a PCH file is available, use it. We must delay performing
336 # this check until $cxx and such have been initialized because we
337 # perform a test compilation. (Ideally, gcc --print-file-name would
338 # list PCH files, but it does not.)
339 if { $cxxpchflags != "" } {
340 set src "config[pid].cc"
341 set f [open $src "w"]
342 puts $f "int main () {}"
343 close $f
344
345 # Fixme: "additional_flags=$cxxpchflags" fails, but would be
346 # useful as then the requested variant of the pre-build PCH
347 # files could be tested to see if it works.
348 set lines [v3_target_compile $src "config[pid].o" object \
349 "additional_flags=-include additional_flags=bits/stdc++.h"]
350 if { $lines != "" } {
351 verbose -log "Requested PCH file: $cxxpchflags"
352 verbose -log "is not working, and will not be used."
353 set cxxpchflags ""
354 }
355 file delete $src
356 }
357 v3track cxxpchflags 2
358
359 global PCH_CXXFLAGS
360 if ![info exists PCH_CXXFLAGS] then {
361 set PCH_CXXFLAGS $cxxpchflags
362 v3track PCH_CXXFLAGS 2
363 }
364
365 libstdc++_maybe_build_wrapper "${objdir}/testglue.o" "-fexceptions"
366 }
367
368 # Callback for cleanup routines.
369 proc libstdc++_exit { } {
370 global gluefile;
371
372 if [info exists gluefile] {
373 file_on_build delete $gluefile;
374 unset gluefile;
375 }
376 }
377
378 # Callback from system dg-test.
379 proc libstdc++-dg-test { prog do_what extra_tool_flags } {
380 # Set up the compiler flags, based on what we're going to do.
381 switch $do_what {
382 "preprocess" {
383 set compile_type "preprocess"
384 set output_file "[file rootname [file tail $prog]].i"
385 }
386 "compile" {
387 set compile_type "assembly"
388 set output_file "[file rootname [file tail $prog]].s"
389 }
390 "assemble" {
391 set compile_type "object"
392 set output_file "[file rootname [file tail $prog]].o"
393 }
394 "link" {
395 set compile_type "executable"
396 set output_file "./[file rootname [file tail $prog]].exe"
397 }
398 "run" {
399 set compile_type "executable"
400 # FIXME: "./" is to cope with "." not being in $PATH.
401 # Should this be handled elsewhere?
402 # YES.
403 set output_file "./[file rootname [file tail $prog]].exe"
404 # This is the only place where we care if an executable was
405 # created or not. If it was, dg.exp will try to run it.
406 catch { remote_file build delete $output_file }
407 }
408 default {
409 perror "$do_what: not a valid dg-do keyword"
410 return ""
411 }
412 }
413
414 # Short-circut a bunch of complicated goo here for the special
415 # case of compiling a test file as a "C" file, not as C++. Why? So
416 # -nostdc++ doesn't trip us up. So all the extra object files
417 # don't trip us up. So automatically linking in libstdc++ doesn't
418 # happen. So CXXFLAGS don't error.
419 set select_compile "v3_target_compile"
420 set options ""
421 if { $extra_tool_flags != "" } {
422 verbose -log "extra_tool_flags are: $extra_tool_flags"
423 if { [string first "-x c" $extra_tool_flags ] != -1 } {
424 verbose -log "compiling and executing as C, not C++"
425 set edit_tool_flags $extra_tool_flags
426 regsub -all ".x c" $edit_tool_flags "" edit_tool_flags
427 lappend options "additional_flags=$edit_tool_flags"
428 set select_compile "v3_target_compile_as_c"
429 } else {
430 lappend options "additional_flags=$extra_tool_flags"
431 }
432 }
433
434 # There is a libstdc++_compile made for us by default (via the tool-
435 # and-target file), but the defaults are lacking in goodness.
436 set comp_output [$select_compile "$prog" "$output_file" "$compile_type" $options];
437
438 set unsupported_message [libstdc++_check_unsupported_p $comp_output]
439 if { $unsupported_message != "" } {
440 set comp_output "::unsupported::$unsupported_message"
441 }
442
443 return [list $comp_output $output_file]
444 }
445
446 # Override the DejaGnu dg-test in order to clear flags after a test, as
447 # is done for compiler tests in gcc-dg.exp.
448
449 if { [info procs saved-dg-test] == [list] } {
450 rename dg-test saved-dg-test
451
452 proc dg-test { args } {
453 global additional_prunes
454 global errorInfo
455 global testname_with_flags
456
457 if { [ catch { eval saved-dg-test $args } errmsg ] } {
458 set saved_info $errorInfo
459 set additional_prunes ""
460 if [info exists testname_with_flags] {
461 unset testname_with_flags
462 }
463 unset_timeout_vars
464 error $errmsg $saved_info
465 }
466 set additional_prunes ""
467 unset_timeout_vars
468 if [info exists testname_with_flags] {
469 unset testname_with_flags
470 }
471 }
472 }
473
474 # Find the minimum standard required by a test, if higher than the default_std.
475 proc v3-minimum-std { test default_std max_std } {
476 for {set s $default_std} {$s <= $max_std} {incr s 3} {
477 if [search_for $test "\{ dg-do * \{ target c++$s"] {
478 return $s
479 } elseif [search_for $test "\{ dg-require-effective-target c++$s"] {
480 return $s
481 }
482 }
483 # TODO: replace all c++2a with c++20 and remove this case.
484 if [search_for $test "\{ dg-do * \{ target c++2a"] {
485 return 20
486 }
487 return $default_std
488 }
489
490 # Allow v3_std_list to be set in configuration files, e.g., ~/.dejagnurc
491 if ![info exists v3_std_list] {
492 set v3_std_list { }
493 }
494 # Allow v3_std_list to be set from the environment.
495 if [info exists env(GLIBCXX_TESTSUITE_STDS)] {
496 set v3_std_list [split $env(GLIBCXX_TESTSUITE_STDS) ","]
497 }
498
499 # Modified dg-runtest that runs tests in multiple standard modes,
500 # unless they specifically specify one standard.
501 proc v3-dg-runtest { testcases flags default-extra-flags } {
502 global runtests
503
504 foreach test $testcases {
505 # If we're only testing specific files and this isn't one of them, skip it.
506 if ![runtest_file_p $runtests $test] {
507 continue
508 }
509
510 # If the testcase specifies a standard, use that one.
511 # If not, run it under several standards, allowing GNU extensions
512 # unless strict_std is requested.
513 if ![search_for $test "// \{ dg-*options*-std=*++"] {
514 if [search_for $test "{ dg-add-options strict_std }"] {
515 set std_prefix "-std=c++"
516 } else {
517 set std_prefix "-std=gnu++"
518 }
519
520 # See above for the initial value of this list.
521 global v3_std_list
522 if { [llength $v3_std_list] > 0 } {
523 set std_list $v3_std_list
524 } else {
525 # If the test requires a newer C++ version than which
526 # is tested by default, use that C++ version for that
527 # single test.
528 # These should be adjusted whenever the default -std is
529 # updated or newer C++ effective target is added.
530 set default_std 17
531 set max_std 26
532 set min_std [v3-minimum-std $test $default_std $max_std]
533 if { $min_std > $default_std } {
534 set std_list $min_std
535 if { $min_std != $max_std } {
536 # Also test the latest version.
537 lappend std_list "$max_std"
538 }
539 } else {
540 # Only run each test once with the default -std option.
541 # This avoids increasing the run time for most testers.
542 # Libstdc++ developers can override this with v3_std_list.
543 set std_list $default_std
544 }
545 }
546 set option_list { }
547 foreach x $std_list {
548 if { $x eq "impcx" } then { set x "26 -fimplicit-constexpr" }
549 lappend option_list "${std_prefix}$x"
550 }
551 } else {
552 verbose "using -std option specified in [file tail $test]" 2
553 set option_list { "" }
554 }
555
556 set nshort [file tail [file dirname $test]]/[file tail $test]
557
558 foreach flags_t $option_list {
559 verbose "Testing $nshort, $flags $flags_t" 1
560 dg-test $test "$flags $flags_t" ${default-extra-flags}
561 }
562 }
563 }
564
565
566 # True if the library supports wchar_t.
567 set v3-wchar_t 0
568
569 # True if the library supports threads.
570 set v3-threads 0
571
572 # True if the library supports symbol versioning.
573 set v3-symver 0
574
575 # Called from libstdc++-dg-test above. Calls back into system's
576 # target_compile to actually do the work.
577 proc v3_target_compile { source dest type options } {
578 global gluefile
579 global wrap_flags
580 global cxx
581 global cxxflags
582 global cxxvtvflags
583 global cxxldflags
584 global includes
585 global STATIC_LIBCXXFLAGS
586 global tool
587
588 lappend options "additional_flags=-fdiagnostics-plain-output"
589
590 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
591 lappend options "libs=${gluefile}"
592 lappend options "ldflags=${wrap_flags}"
593 }
594
595 set cxx_final $cxx
596 set cxxlibglossflags [libgloss_link_flags]
597 set cxx_final [concat $cxx_final $cxxlibglossflags]
598 set cxx_final [concat $cxx_final $STATIC_LIBCXXFLAGS]
599 set cxx_final [concat $cxx_final $cxxflags]
600 set cxx_final [concat $cxx_final $cxxvtvflags]
601 set cxx_final [concat $cxx_final $includes]
602
603 # Flag setting based on type argument.
604 if { $type == "executable" } {
605 # Link the support objects into executables.
606 lappend options "additional_flags=./libtestc++.a $cxxldflags"
607 } else {
608 if { $type == "sharedlib" } {
609 # Don't link in anything.
610 set type "executable"
611 }
612 }
613
614 # For Windows and Darwin we might want to create a temporary file.
615 # Note that it needs deleting.
616 set file_to_delete ""
617 # Small adjustment for Windows hosts.
618 if { $dest == "/dev/null"
619 && [info exists ::env(OS)] && [string match "Windows*" $::env(OS)] } {
620 if { $type == "executable" } {
621 set dest "x.exe"
622 set file_to_delete ${dest}
623 } else {
624 # Windows uses special file named "nul" as a substitute for
625 # /dev/null
626 set dest "nul"
627 }
628 }
629
630 # Using /dev/null as the executable name does not work on Darwin when
631 # debug is enabled, since the debug linker does not accept /dev/null as
632 # a valid executable name.
633 if { $dest == "/dev/null" && [istarget *-*-darwin*]
634 && $type == "executable" } {
635 set dest dev-null-[pid].exe
636 set file_to_delete ${dest}
637 }
638
639 lappend options "compiler=$cxx_final"
640 lappend options "timeout=[timeout_value]"
641
642 global v3_additional_files
643 # There will be an empty file at the begining of the list so trim it off.
644 foreach file [split [string trim $v3_additional_files] " "] {
645 global srcdir
646 v3-copy-file "$srcdir/data/$file" $file
647 }
648 set v3_additional_files {}
649
650 set comp_output [target_compile $source $dest $type $options]
651
652 # Strip versioned namespace from the compiler output,
653 # so that dg-error and dg-warning patterns can ignore it:
654 regsub -all "std::__8::" $comp_output "std::" comp_output
655
656 if { $type == "executable" && $file_to_delete != "" } {
657 file delete $file_to_delete
658 if { [istarget *-*-darwin*] && [file exists $file_to_delete.dSYM] } {
659 file delete -force $file_to_delete.dSYM
660 }
661 }
662 return $comp_output
663 }
664
665
666 # Called from libstdc++-dg-test above, but only for "C" compilation.
667 # Calls back into system's target_compile to actually do the work.
668 proc v3_target_compile_as_c { source dest type options } {
669 global gluefile
670 global wrap_flags
671 global includes
672 global flags_file
673 global blddir
674 global cc
675 global cxxflags
676 global STATIC_LIBCXXFLAGS
677 global tool
678
679 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
680 lappend options "libs=${gluefile}"
681 lappend options "ldflags=${wrap_flags}"
682 }
683
684 set tname [target_info name]
685 set cc_final $cc
686 set cxxlibglossflags [libgloss_link_flags]
687 set cc_final [concat $cc_final $cxxlibglossflags]
688 set cc_final [concat $cc_final $STATIC_LIBCXXFLAGS]
689 set cc_final [concat $cc_final $cxxflags]
690 set cc_final [concat $cc_final $includes]
691 regsub -all {\s[-]nostdinc[+][+]} $cc_final "" cc_final
692
693 # This is needed for "C" tests, as this type of test may need the
694 # C++ includes. And if we're not testing in the build directory,
695 # the includes variable is not likely to include the necessary
696 # info.
697 if { ![file exists $flags_file] } {
698 # ??? We need a --print-include-dirs option to GCC, so that
699 # we can avoid these hacks. The heuristics here will not
700 # work with non-standard --with-includedir= options.
701 set version [remote_exec host ${cc} -dumpversion]
702 # Remove the trailing newline from the output.
703 set version [string trimright [lindex $version 1]]
704 set machine [remote_exec host ${cc} -dumpmachine]
705 set machine [string trimright [lindex $machine 1]]
706 set comp_base_dir [remote_exec host ${cc} --print-prog-name=cc1]
707 set comp_base_dir [lindex $comp_base_dir 1]
708 set comp_base_dir [file dirname [file dirname [file dirname [file dirname [file dirname $comp_base_dir]]]]]
709 # For a cross compiler, the header files will be located in a
710 # machine-specific subdirectory.
711 set crossbase "${comp_base_dir}/${machine}/include/c++/${version}"
712 set crosstarget "${crossbase}/${machine}"
713 set cc_final [concat $cc_final "-I$crossbase -I$crosstarget"]
714 # For a native compiler, the header files will be located at
715 # the top level.
716 set includesbase "${comp_base_dir}/include/c++/${version}"
717 set includestarget "${includesbase}/${machine}"
718 set cc_final [concat $cc_final "-I$includesbase -I$includestarget"]
719
720 set libdir "-L${comp_base_dir}/lib"
721 } else {
722 set libdir "-L${blddir}/libsupc++/.libs"
723 set libdir [concat $libdir "-L${blddir}/src/.libs"]
724 }
725
726 set cc_final [concat $cc_final "$libdir"]
727
728 lappend options "compiler=$cc_final"
729 lappend options "timeout=[timeout_value]"
730
731 set comp_output [target_compile $source $dest $type $options]
732
733 return $comp_output
734 }
735
736 # Build the support objects linked in with the libstdc++ tests. In
737 # addition, set v3-wchar_t, v3-threads, and v3-symver appropriately.
738 proc v3-build_support { } {
739 global env
740 global srcdir
741 global v3-wchar_t
742 global v3-threads
743 global v3-symver
744 global v3-sharedlib
745
746 # Figure out whether or not the library supports certain features.
747 set v3-wchar_t 0
748 set v3-threads 0
749 set v3-symver 0
750 set libtest_objs ""
751
752 set config_src "config.cc"
753 set config_out "config.ii"
754 set f [open $config_src "w"]
755 puts $f "#include <bits/c++config.h>"
756 puts $f "#include <bits/gthr.h>"
757 close $f
758 v3_target_compile $config_src $config_out preprocess "additional_flags=-dN"
759 set file [open $config_out r]
760 set preprocessed [read $file]
761 close $file
762 if { [string first "_GLIBCXX_USE_WCHAR_T" $preprocessed] != -1 } {
763 verbose -log "wchar_t support detected"
764 set v3-wchar_t 1
765 }
766 if { [string first "_GLIBCXX_SYMVER" $preprocessed] != -1 } {
767 verbose -log "symbol versioning support detected"
768 set v3-symver 1
769 }
770 if { [string first "__GTHREADS" $preprocessed] != -1 } {
771 verbose -log "thread support detected"
772 set v3-threads 1
773 }
774
775 # Try to build the MO files that are used by some of the locale
776 # tests. If we can't build them, that's OK; it just means that
777 # those tests will fail.
778 foreach lang [list "fr" "de"] {
779 catch {
780 file mkdir "$lang/LC_MESSAGES"
781 remote_exec "build" "msgfmt" "-o $lang/LC_MESSAGES/libstdc++.mo $srcdir/../po/$lang.po"
782 if [is_remote host] {
783 remote_exec "host" "mkdir" "-p $lang/LC_MESSAGES"
784 remote_download "host" "$lang/LC_MESSAGES/libstdc++.mo" "$lang/LC_MESSAGES/libstdc++.mo"
785 }
786 }
787 }
788
789 # Build the support objects.
790 set source_files [list testsuite_abi.cc testsuite_allocator.cc \
791 testsuite_character.cc testsuite_hooks.cc \
792 io/verified_cmd_line_input.cc \
793 io/prog_bar.cc performance/time/elapsed_timer.cc ]
794 foreach f $source_files {
795 set obj [file rootname $f].o
796 set object_file [file tail $obj]
797 # Compile with "-w" so that warnings issued by the compiler
798 # do not prevent compilation.
799 # Disable LTO so that ar/ranlib don't need the LTO plugin.
800 if { [v3_target_compile $srcdir/util/$f $object_file "object" \
801 [list "incdir=$srcdir" "additional_flags=-w -fno-lto -fno-freestanding"]]
802 != "" } {
803 error "could not compile $f"
804 }
805 append libtest_objs "$object_file "
806 }
807
808 # Collect into libtestc++.a
809 if [info exists env(AR)] {
810 set ar $env(AR)
811 } else {
812 set ar [transform "ar"]
813 }
814 set arargs "-rc ./libtestc++.a ${libtest_objs}"
815 verbose -log "$ar $arargs"
816 set result [lindex [remote_exec host "$ar" "$arargs"] 0]
817 verbose "link result is $result"
818 if { $result == 0 } {
819 if [info exists env(RANLIB)] {
820 set ranlib $env(RANLIB)
821 } else {
822 set ranlib [transform "ranlib"]
823 }
824 set ranlibargs "./libtestc++.a"
825 verbose -log "$ranlib $ranlibargs"
826 set result [lindex [remote_exec host "$ranlib" "$ranlibargs"] 0]
827 if { $result != 0 } {
828 error "could not link libtestc++.a"
829 }
830 }
831
832 # Build any shared objects needed for regression testing.
833 if { ${v3-sharedlib} == 1 } {
834 set source_files [list testsuite_shared.cc]
835 foreach f $source_files {
836 set object_file [file rootname $f].so
837 # Compile with "-w" so that warnings issued by the compiler
838 # do not prevent compilation.
839 if { [v3_target_compile $srcdir/util/$f $object_file "sharedlib" \
840 [list "incdir=$srcdir" "additional_flags=-fno-inline -w -shared -fPIC -DPIC -std=gnu++98 -fno-freestanding"]]
841 != "" } {
842 error "could not compile $f"
843 }
844 }
845 }
846 }
847
848 # Implement an target check for property PROP by invoking
849 # the Tcl command ARGS and seeing if it returns true.
850
851 proc check_v3_target_prop_cached { prop args } {
852 global et_cache
853
854 set target [current_target_name]
855 if {![info exists et_cache($prop,$target)]} {
856 verbose "check_v3_target_prop_cached $prop: checking $target" 2
857 if {[string is true -strict $args] || [string is false -strict $args]} {
858 error {check_v3_target_prop_cached condition already evaluated; did you pass [...] instead of the expected {...}?}
859 } else {
860 set code [catch {uplevel eval $args} result]
861 if {$code != 0 && $code != 2} {
862 verbose "check_v3_target_prop_cached $prop: evaluation failed for $target" 2
863 return -code $code $result
864 }
865 set et_cache($prop,$target) $result
866 }
867 } else {
868 verbose "check_v3_target_prop_cached $prop $target: using cached result" 2
869 }
870
871 set value $et_cache($prop,$target)
872 verbose "check_v3_target_prop_cached $prop: returning $value for $target" 2
873 return $value
874 }
875
876 proc check_v3_target_fileio { } {
877 return [check_v3_target_prop_cached et_fileio {
878 global tool
879 global srcdir
880
881 # Set up, compile, and execute a C++ test program that tries to use
882 # the file functions
883 set src fileio[pid].cc
884 set exe fileio[pid].x
885 set testfile "cin_unget-1.[pid].txt"
886 v3-copy-file "$srcdir/data/cin_unget-1.txt" "$testfile"
887
888 set f [open $src "w"]
889 puts $f "#include <sys/types.h>"
890 puts $f "#include <sys/stat.h>"
891 puts $f "#include <fcntl.h>"
892 puts $f "#include <unistd.h>"
893 puts $f "#include <errno.h>"
894 puts $f "#include <string.h>"
895 puts $f "using namespace std;"
896 puts $f "int main ()"
897 puts $f "{"
898 puts $f " int fd = open (\"$testfile\", O_RDONLY);"
899 puts $f " int ret = 0;"
900 puts $f " char buf\[10\];"
901 puts $f " if (fd == -1)"
902 puts $f " ret = 1;"
903 puts $f " else"
904 puts $f " {"
905 puts $f " if (lseek (fd, -1, SEEK_CUR) != -1 || errno != EINVAL)"
906 puts $f " ret = 1;"
907 puts $f " errno = 0;"
908 puts $f " if (lseek (fd, 0, SEEK_CUR) != 0"
909 puts $f " || read (fd, buf, 4) != 4"
910 puts $f " || memcmp (buf, \"1234\", 4) != 0"
911 puts $f " || lseek (fd, -2, SEEK_CUR) != 2"
912 puts $f " || read (fd, buf, 2) != 2"
913 puts $f " || memcmp (buf, \"34\", 2) != 0)"
914 puts $f " ret = 1;"
915 puts $f " close (fd);"
916 puts $f " }"
917 puts $f " return ret;"
918 puts $f "}"
919 close $f
920
921 set lines [v3_target_compile $src $exe executable ""]
922 file delete $src
923
924 if [string match "" $lines] {
925 # No error message, compilation succeeded.
926 set result [${tool}_load "./$exe" "" ""]
927 set status [lindex $result 0]
928 remote_file build delete $exe
929
930 verbose "check_v3_target_fileio: status is <$status>" 2
931
932 if { $status == "pass" } {
933 return 1
934 }
935 } else {
936 verbose "check_v3_target_fileio: compilation failed" 2
937 }
938 return 0
939 }]
940 }
941
942 # Eventually we want C90/C99 determining and switching from this.
943 proc check_v3_target_c_std { } {
944 return [check_v3_target_prop_cached et_c_std {
945 global tool
946 # Set up, compile, and execute a C++ test program that tries to use
947 # C99 functionality.
948 # For math bits, could use check_effective_target_c99_math.
949 set src c_std[pid].cc
950 set exe c_std[pid].x
951
952 set f [open $src "w"]
953 puts $f "#include <tr1/cmath>"
954 puts $f "#include <cstdlib>"
955 puts $f "int main ()"
956 puts $f "{"
957 puts $f " float f = 45.55;"
958 puts $f " int i = std::tr1::isnan(f);"
959 puts $f " "
960 puts $f " using std::wctomb;"
961 puts $f " return i;"
962 puts $f "}"
963 close $f
964
965 set lines [v3_target_compile $src $exe executable ""]
966 file delete $src
967
968 if [string match "" $lines] {
969 # No error message, compilation succeeded.
970 set result [${tool}_load "./$exe" "" ""]
971 set status [lindex $result 0]
972 remote_file build delete $exe
973
974 verbose "check_v3_target_c_std: status is <$status>" 2
975
976 if { $status == "pass" } {
977 return 1
978 }
979 } else {
980 verbose "check_v3_target_c_std: compilation failed" 2
981 }
982 return 0
983 }]
984 }
985
986 proc check_v3_target_sharedlib { } {
987 global v3-sharedlib
988 return ${v3-sharedlib}
989 }
990
991 proc check_v3_target_time { } {
992 return [check_v3_target_prop_cached et_target_time {
993 global tool
994 # Set up and compile a C++ test program that tries to use
995 # the time function
996 set src time[pid].cc
997
998 set f [open $src "w"]
999 puts $f "#include <time.h>"
1000 puts $f "using namespace std;"
1001 puts $f "int main ()"
1002 puts $f "{"
1003 puts $f " time (0);"
1004 puts $f "}"
1005 close $f
1006
1007 set lines [v3_target_compile $src /dev/null executable ""]
1008 file delete $src
1009
1010 if [string match "" $lines] {
1011 # No error message, compilation succeeded.
1012 verbose "check_v3_target_time: compilation succeeded" 2
1013 return 1
1014 } else {
1015 verbose "check_v3_target_time: compilation failed" 2
1016 return 0
1017 }
1018 }]
1019 }
1020
1021 proc check_v3_target_namedlocale { args } {
1022 set key "et_namedlocale $args"
1023 return [check_v3_target_prop_cached $key {
1024 global tool
1025 # Set up, compile, and execute a C++ test program that tries to use
1026 # the required named locale.
1027 set exe nlocale[pid].x
1028 set src nlocale[pid].cc
1029
1030 set f [open $src "w"]
1031 puts $f "#include <locale>"
1032 puts $f "#include <cstdio>"
1033 puts $f "#include <cstring>"
1034 puts $f "using namespace std;"
1035 puts $f "char *transform_locale(const char *name)"
1036 puts $f "{"
1037 puts $f " char *result = new char\[50\];"
1038 puts $f " strcpy(result, name);"
1039 puts $f "#if defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__"
1040 puts $f " /* fall-through */"
1041 puts $f "#elif defined __GLIBC__"
1042 puts $f " if (strstr(result, \"ISO8859-15\")) {"
1043 puts $f " strcat(result, \"@euro\");"
1044 puts $f " }"
1045 puts $f "#endif"
1046 puts $f " return result;"
1047 puts $f "}"
1048 puts $f "int main (int argc, char** argv)"
1049 puts $f "{"
1050 puts $f " if (argc < 2)"
1051 puts $f " {"
1052 puts $f " printf(\"locale support test not supported\\n\");"
1053 puts $f " return 1;"
1054 puts $f " }"
1055 puts $f " const char *namedloc = transform_locale(*(argv + 1));"
1056 puts $f " try"
1057 puts $f " {"
1058 puts $f " locale((const char*)namedloc);"
1059 puts $f " delete\[\] namedloc;"
1060 puts $f " return 0;"
1061 puts $f " }"
1062 puts $f " catch(...)"
1063 puts $f " {"
1064 puts $f " printf(\"locale '%s' not supported\\n\", namedloc);"
1065 puts $f " delete\[\] namedloc;"
1066 puts $f " return 1;"
1067 puts $f " }"
1068 puts $f "}"
1069 close $f
1070
1071 set lines [v3_target_compile $src $exe executable ""]
1072 file delete $src
1073
1074 if ![string match "" $lines] {
1075 verbose "check_v3_target_namedlocale: compilation failed" 2
1076 return 0
1077 }
1078
1079 set result [${tool}_load "./$exe" "$args" ""]
1080 set status [lindex $result 0]
1081
1082 verbose "check_v3_target_namedlocale <$args>: status is <$status>" 2
1083
1084 if { $status == "pass" } {
1085 return 1
1086 }
1087 return 0
1088 }]
1089 }
1090
1091 # Returns 1 if the tokens in CODE can be preprocessed successfully using FLAGS,
1092 # returns 0 otherwise.
1093 proc v3_try_preprocess { name code flags } {
1094 global tool
1095 global cxxflags
1096
1097 # Set up and preprocess a C++ translation unit.
1098 set src $name[pid].cc
1099
1100 set f [open $src "w"]
1101 puts $f $code
1102 close $f
1103
1104 set cxxflags_saved $cxxflags
1105 set cxxflags "$flags"
1106
1107 set lines [v3_target_compile $src /dev/null preprocess ""]
1108 set cxxflags $cxxflags_saved
1109 file delete $src
1110
1111 if [string match "" $lines] {
1112 verbose "v3_try_preprocess $name: preprocessing passed" 3
1113 # No error message, preprocessing succeeded.
1114 return 1
1115 }
1116 verbose "v3_try_preprocess $name: preprocessing failed" 2
1117 return 0
1118 }
1119
1120 # Return 1 if COND evaluates to true in the preprocessor, 0 otherwise.
1121 # The <bits/c++config.h> config header is included, and INC, if given,
1122 # is pasted between it and the condition evaluation, so it can be used
1123 # for additional #include's.
1124 proc v3_check_preprocessor_condition { name cond { inc "" } } {
1125 global cxxflags
1126 global DEFAULT_CXXFLAGS
1127
1128 set code "
1129 #include <bits/c++config.h>
1130 $inc
1131 #if ! ($cond)
1132 #error '$cond' is false
1133 #endif
1134 "
1135 set flags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1136
1137 return [v3_try_preprocess name $code $flags]
1138 }
1139
1140 # Return 1 if libstdc++ defines macro for the current target, 0 otherwise.
1141 proc check_v3_target_cpp_feature_test { cond } {
1142 global cxxflags
1143 set cxxflags_saved $cxxflags
1144 # Use the latest standard, so that all feature test macros are defined.
1145 # We need to do it here, because this check happens before v3-dg-runtest
1146 # runs its loop to test multiple times with different -std options.
1147 # This should be updated when a new -std is added.
1148 set cxxflags "$cxxflags -std=gnu++26"
1149 set inc "#include <version>"
1150 set result [v3_check_preprocessor_condition cpp_feature_test "$cond" $inc]
1151 set cxxflags $cxxflags_saved
1152 return $result
1153 }
1154
1155 # Return 1 if Debug Mode is active, 0 otherwise.
1156 proc check_v3_target_debug_mode { } {
1157 global cxxflags
1158 return [check_v3_target_prop_cached et_debug_mode {
1159 set code "
1160 #include <bits/c++config.h>
1161 #if ! defined _GLIBCXX_DEBUG
1162 # error no debug mode
1163 #endif
1164 "
1165 return [v3_try_preprocess debug_mode $code $cxxflags]
1166 }]
1167 }
1168
1169 # Define "debug_mode" as an effective-target keyword.
1170 proc check_effective_target_debug_mode { } {
1171 return [check_v3_target_debug_mode]
1172 }
1173
1174 # Return 1 if normal mode is active, 0 otherwise.
1175 # i.e. neither Debug Mode nor Parallel Mode is active.
1176 proc check_v3_target_normal_mode { } {
1177 global cxxflags
1178 return [check_v3_target_prop_cached et_normal_mode {
1179 set code "
1180 #if defined _GLIBCXX_DEBUG
1181 # error debug mode
1182 #endif
1183 #if defined _GLIBCXX_PARALLEL
1184 # error parallel mode
1185 #endif
1186 "
1187 return [v3_try_preprocess normal_mode $code $cxxflags]
1188 }]
1189 }
1190
1191 # Return 1 if unversioned namespace is in use, 0 otherwise.
1192 # i.e. the library uses namespace std:: not std::__8:: or similar.
1193 proc check_v3_target_normal_namespace { } {
1194 return [check_v3_target_prop_cached et_normal_namespace {
1195 set cond "!_GLIBCXX_INLINE_VERSION"
1196 return [v3_check_preprocessor_condition normal_namespace $cond]
1197 }]
1198 }
1199
1200 # Return 1 if the libgomp is being used, 0 otherwise.
1201 proc check_v3_target_parallel_mode { } {
1202 return [check_v3_target_prop_cached et_parallel_mode {
1203 global cxxflags
1204 global v3-libgomp
1205 # If 'make check-parallel' is running then the test succeeds.
1206 if { ${v3-libgomp} == 1 && [regexp "libgomp" $cxxflags] } {
1207 return 1
1208 }
1209 return 0
1210 }]
1211 }
1212
1213 # Return 1 if the C99 stdint facilities are available, 0 otherwise.
1214 proc check_v3_target_cstdint { } {
1215 return [check_v3_target_prop_cached et_cstdint {
1216 set cond "defined _GLIBCXX_USE_C99_STDINT"
1217 return [v3_check_preprocessor_condition cstdint $cond]
1218 }]
1219 }
1220
1221 # Return 1 if the C99 math facilities are available, 0 otherwise.
1222 proc check_v3_target_cmath { } {
1223 return [check_v3_target_prop_cached et_c99_math {
1224 set cond "defined _GLIBCXX_USE_C99_MATH_FUNCS"
1225 return [v3_check_preprocessor_condition cmath $cond]
1226 }]
1227 }
1228
1229 proc check_v3_target_thread_fence { } {
1230 return [check_v3_target_prop_cached et_thread_fence {
1231 global cxxflags
1232 global DEFAULT_CXXFLAGS
1233
1234 # Set up and link a C++11 test program that depends
1235 # on the thread fence to be available.
1236 set src thread_fence[pid].cc
1237
1238 set f [open $src "w"]
1239 puts $f "
1240 int main() {
1241 __atomic_thread_fence (__ATOMIC_SEQ_CST);
1242 return 0;
1243 }"
1244 close $f
1245
1246 set cxxflags_saved $cxxflags
1247 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror -std=gnu++11"
1248
1249 set lines [v3_target_compile $src /dev/null executable ""]
1250 set cxxflags $cxxflags_saved
1251 file delete $src
1252
1253 if [string match "" $lines] {
1254 # No error message, linking succeeded.
1255 return 1
1256 } else {
1257 verbose "check_v3_target_thread_fence: compilation failed" 2
1258 return 0
1259 }
1260 }]
1261 }
1262
1263 proc check_v3_target_atomic_cmpxchg_word { } {
1264 return [check_v3_target_prop_cached et_atomic_cmpxchg_word {
1265 global cxxflags
1266 global DEFAULT_CXXFLAGS
1267
1268 # Set up and link a C++11 test program that depends on
1269 # atomic-compare-exchange being available for a pointer-sized
1270 # integer. It should be sufficient as gcc can derive all
1271 # other operations when a target implements this operation.
1272 set src atomic_cmpxchg_word[pid].cc
1273
1274 set f [open $src "w"]
1275 puts $f "
1276 __UINTPTR_TYPE__ i, j, k;
1277 int main() {
1278 __atomic_compare_exchange (&i, &j, &k, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
1279 return 0;
1280 }"
1281 close $f
1282
1283 set cxxflags_saved $cxxflags
1284 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror -std=gnu++11"
1285
1286 set lines [v3_target_compile $src /dev/null executable ""]
1287 set cxxflags $cxxflags_saved
1288 file delete $src
1289
1290 if [string match "" $lines] {
1291 # No error message, linking succeeded.
1292 return 1
1293 } else {
1294 verbose "check_v3_target_atomic_cmpxchg_word: compilation failed" 2
1295 return 0
1296 }
1297 }]
1298 }
1299
1300 # Return 1 if atomics_bool and atomic_int are always lock-free, 0 otherwise.
1301 proc check_v3_target_atomic_builtins { } {
1302 return [check_v3_target_prop_cached et_atomic_builtins {
1303 set cond "__GCC_ATOMIC_BOOL_LOCK_FREE > 1 && __GCC_ATOMIC_INT_LOCK_FREE > 1"
1304 return [v3_check_preprocessor_condition atomic_builtins $cond]
1305 }]
1306 }
1307
1308 # Define "atomic_builtins" as an effective-target keyword.
1309 proc check_effective_target_atomic_builtins { } {
1310 return [check_v3_target_atomic_builtins]
1311 }
1312
1313 # Return 1 if C++11 [threads] facilities are available via gthreads,
1314 # 0 otherwise.
1315 proc check_v3_target_gthreads { } {
1316 return [check_v3_target_prop_cached et_gthreads {
1317 set cond "defined _GLIBCXX_HAS_GTHREADS"
1318 return [v3_check_preprocessor_condition gthreads $cond]
1319 }]
1320 }
1321
1322 # Define "gthreads" as an effective-target keyword.
1323 proc check_effective_target_gthreads { } {
1324 return [check_v3_target_gthreads]
1325 }
1326
1327 # Return 1 if C++11 timed mutexes are available via gthreads, 0 otherwise.
1328 proc check_v3_target_gthreads_timed { } {
1329 return [check_v3_target_prop_cached et_gthreads_timed {
1330 if [check_v3_target_gthreads] {
1331 set cond "_GTHREAD_USE_MUTEX_TIMEDLOCK"
1332 return [v3_check_preprocessor_condition gthreads_timed $cond]
1333 } else {
1334 return 0
1335 }
1336 }]
1337 }
1338
1339 # Define "gthreads_timed" as an effective-target keyword.
1340 proc check_effective_target_gthreads_timed { } {
1341 return [check_v3_target_gthreads_timed]
1342 }
1343
1344 # Return 1 if either nanosleep or sleep is available, 0 otherwise.
1345 proc check_v3_target_sleep { } {
1346 return [check_v3_target_prop_cached et_sleep {
1347 set cond "defined _GLIBCXX_USE_NANOSLEEP"
1348 set cond "$cond || defined _GLIBCXX_USE_WIN32_SLEEP"
1349 set cond "$cond || defined _GLIBCXX_HAVE_SLEEP"
1350 return [v3_check_preprocessor_condition sleep $cond]
1351 }]
1352 }
1353
1354 # Return 1 if __gthread_yield is available, 0 otherwise.
1355 proc check_v3_target_sched_yield { } {
1356 return [check_v3_target_prop_cached et_sched_yield {
1357 set cond "defined _GLIBCXX_USE_SCHED_YIELD"
1358 return [v3_check_preprocessor_condition sched_yield $cond]
1359 }]
1360 }
1361
1362 # Return 1 if the [string.conversions] facilities are available, 0 otherwise.
1363 proc check_v3_target_string_conversions { } {
1364 return [check_v3_target_prop_cached et_string_conversions {
1365 set cond "_GLIBCXX_USE_C99_STDIO && _GLIBCXX_USE_C99_STDLIB"
1366 set cond "$cond && _GLIBCXX_USE_C99_WCHAR"
1367 set cond "$cond && !defined _GLIBCXX_HAVE_BROKEN_VSWPRINTF"
1368 return [v3_check_preprocessor_condition string_conversions $cond]
1369 }]
1370 }
1371
1372 # Return 1 if a standard-conforming swprintf is available, 0 otherwise.
1373 proc check_v3_target_swprintf { } {
1374 return [check_v3_target_prop_cached et_swprintf {
1375 set cond "! defined _GLIBCXX_HAVE_BROKEN_VSWPRINTF"
1376 return [v3_check_preprocessor_condition swprintf $cond]
1377 }]
1378 }
1379
1380 # Return 1 if text and binary I/O are the same, 0 otherwise.
1381 proc check_v3_target_binary_io { } {
1382 return [check_v3_target_prop_cached et_binary_io {
1383 set cond "! defined _GLIBCXX_HAVE_DOS_BASED_FILESYSTEM"
1384 return [v3_check_preprocessor_condition binary_io $cond]
1385 }]
1386 }
1387
1388 # Return 1 if get_nprocs or pthreads_num_processors_np or a suitable sysconf
1389 # is available, 0 otherwise.
1390 proc check_v3_target_nprocs { } {
1391 return [check_v3_target_prop_cached et_nprocs {
1392 set cond "defined _GLIBCXX_USE_GET_NPROCS"
1393 set cond "$cond || defined _GLIBCXX_USE_GET_NPROCS_WIN32"
1394 set cond "$cond || defined _GLIBCXX_USE_PTHREADS_NUM_PROCESSORS_NP"
1395 set cond "$cond || defined _GLIBCXX_USE_SYSCTL_HW_NCPU"
1396 set cond "$cond || defined _GLIBCXX_USE_SC_NPROCESSORS_ONLN"
1397 set cond "$cond || defined _GLIBCXX_USE_SC_NPROC_ONLN"
1398 return [v3_check_preprocessor_condition nprocs $cond]
1399 }]
1400 }
1401
1402 # Return 1 if linking with -static-libstdc++ works, 0 otherwise.
1403 proc check_v3_target_static_libstdcxx { } {
1404 return [check_v3_target_prop_cached et_static_libstdcxx {
1405 global cxxflags
1406 global DEFAULT_CXXFLAGS
1407 # Set up and link a C++0x test program that depends
1408 # on static linking
1409 set src static-maybe[pid].cc
1410
1411 set f [open $src "w"]
1412 puts $f "#include <iostream>"
1413 puts $f "int main() {"
1414 puts $f "int i(415);"
1415 puts $f "std::cout<< i << std::endl;"
1416 puts $f "return 0; }"
1417 puts $f ""
1418 close $f
1419
1420 set cxxflags_saved $cxxflags
1421 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -static-libstdc++"
1422
1423 set lines [v3_target_compile $src /dev/null executable ""]
1424 set cxxflags $cxxflags_saved
1425 file delete $src
1426
1427 if [string match "" $lines] {
1428 # No error message, link succeeded.
1429 return 1
1430 } else {
1431 verbose "check_v3_target_static_libstdcxx: compilation failed" 2
1432 return 0
1433 }
1434 }]
1435 }
1436
1437 proc check_v3_target_little_endian { } {
1438 return [check_effective_target_le]
1439 }
1440
1441 # Return 1 if the Filesystem TS is supported, 0 otherwise.
1442 # Cache the result.
1443 proc check_v3_target_filesystem_ts { } {
1444 return [check_v3_target_prop_cached et_filesystem_ts {
1445 global cxxflags
1446 global DEFAULT_CXXFLAGS
1447 # Set up and preprocess a C++ test program that depends
1448 # on the Filesystem TS feature-test macro being defined.
1449 set src filesystem_ts[pid].cc
1450
1451 set f [open $src "w"]
1452 puts $f "#include <experimental/filesystem>"
1453 puts $f "#if ! __cpp_lib_experimental_filesystem"
1454 puts $f "# error No Filesystem TS support"
1455 puts $f "#endif"
1456 close $f
1457
1458 set cxxflags_saved $cxxflags
1459 set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror"
1460
1461 set lines [v3_target_compile $src /dev/null preprocess ""]
1462 set cxxflags $cxxflags_saved
1463 file delete $src
1464
1465 if [string match "" $lines] {
1466 # No error message, preprocessing succeeded.
1467 return 1
1468 }
1469 return 0
1470 }]
1471 }
1472
1473 # Return 1 if the libstdc++ filesystem create_symlinks implementation
1474 # is not an always-failing dummy.
1475 proc check_v3_target_fs_symlinks { } {
1476 set inc "#include <testsuite_fs.h>"
1477 set cond "!defined NO_SYMLINKS"
1478 return [v3_check_preprocessor_condition fs_symlinks $cond $inc]
1479 }
1480
1481 # Return 1 if the libstdc++ filesystem implementation of space is not an
1482 # always-failing dummy.
1483 proc check_v3_target_fs_space { } {
1484 set inc "#include <testsuite_fs.h>"
1485 set cond "!defined NO_SPACE"
1486 return [v3_check_preprocessor_condition fs_space $cond $inc]
1487 }
1488
1489 # Return 1 if the libstdc++ filesystem implementation of
1490 # last_write_time is not an always-failing dummy.
1491 proc check_v3_target_fs_last_write_time { } {
1492 set inc "#include <testsuite_fs.h>"
1493 set cond "!defined NO_LAST_WRITE_TIME"
1494 return [v3_check_preprocessor_condition fs_last_write_time $cond $inc]
1495 }
1496
1497 # Return 1 if the "cxx11" ABI is in use using the current flags, 0 otherwise.
1498 # Any flags provided by RUNTESTFLAGS or a target board will be used here.
1499 # Flags added in the test by dg-options or dg-add-options will not be used.
1500 proc check_effective_target_cxx11_abi { } {
1501 set cond "_GLIBCXX_USE_CXX11_ABI"
1502 return [v3_check_preprocessor_condition cxx11_abi $cond]
1503 }
1504
1505 # Return 1 if std::random_device should be usable using the current flags,
1506 # 0 otherwise.
1507 proc check_effective_target_random_device { } {
1508 set cond "_GLIBCXX_USE_RANDOM_TR1"
1509 return [v3_check_preprocessor_condition random_device $cond]
1510 }
1511
1512 # Return 1 if tbb parallel backend is available, 0 otherwise.
1513 proc check_effective_target_tbb_backend { } {
1514 return [check_v3_target_prop_cached et_tbb {
1515 # Set up and compile a C++ test program that depends on tbb
1516 set src tbb_backend[pid].cc
1517 set exe tbb_backend[pid].x
1518
1519 set f [open $src "w"]
1520 puts $f "#include <tbb/tbb.h>"
1521 puts $f "#if TBB_INTERFACE_VERSION < 10000"
1522 puts $f "# error Intel(R) Threading Building Blocks 2018 is required; older versions are not supported."
1523 puts $f "#endif"
1524 puts $f "int main ()"
1525 puts $f "{"
1526 puts $f " return 0;"
1527 puts $f "}"
1528 close $f
1529
1530 set lines [v3_target_compile $src $exe executable "additional_flags=-std=c++17 additional_flags=-ltbb
1531 additional_flags=-DTBB_SUPPRESS_DEPRECATED_MESSAGES=1"]
1532 file delete $src
1533
1534 if [string match "" $lines] {
1535 # No error message, compilation succeeded.
1536 verbose "check_et_tbb_backend: `1'" 2
1537 return 1
1538 }
1539 verbose "check_et_tbb_backend: `0'" 2
1540 return 0
1541 }]
1542 }
1543
1544 # Return 1 if futex syscall is available
1545 proc check_effective_target_futex { } {
1546 return [check_v3_target_prop_cached et_futex {
1547 set cond "_GLIBCXX_HAVE_LINUX_FUTEX"
1548 return [v3_check_preprocessor_condition futex $cond]
1549 }]
1550 }
1551
1552 # Return 1 if float and double have the IEEE binary32 and binary64 formats.
1553 proc check_effective_target_ieee_floats { } {
1554 return [check_v3_target_prop_cached et_ieee_floats {
1555 set cond "_GLIBCXX_FLOAT_IS_IEEE_BINARY32 && _GLIBCXX_DOUBLE_IS_IEEE_BINARY64"
1556 return [v3_check_preprocessor_condition ieee_floats $cond]
1557 }]
1558 }
1559
1560 # Return 1 if Networking TS net::ip features are available.
1561 proc check_effective_target_net_ts_ip { } {
1562 return [check_v3_target_prop_cached et_net_ts_ip {
1563 set cond "__has_include(<netinet/in.h>)"
1564 return [v3_check_preprocessor_condition net_ts_ip $cond]
1565 }]
1566 }
1567
1568 # Return 1 if libstdc++ was built as --enable-libstdcxx-allocator=new
1569 proc check_effective_target_std_allocator_new { } {
1570 return [check_v3_target_prop_cached et_std_alloc_new {
1571 set cond "_GLIBCXX_USE_ALLOCATOR_NEW"
1572 return [v3_check_preprocessor_condition std_alloc_new $cond]
1573 }]
1574 }
1575
1576 # Return 1 if RTTI is enabled by the current test flags.
1577 proc check_effective_target_rtti { } {
1578 return [check_v3_target_prop_cached et_rtti {
1579 set cond "__cpp_rtti"
1580 return [v3_check_preprocessor_condition rtti $cond]
1581 }]
1582 }
1583
1584 # Return 1 if a hosted implementation is available (i.e. not freestanding).
1585 proc check_effective_target_hosted { } {
1586 return [check_v3_target_prop_cached et_hosted {
1587 set cond "_GLIBCXX_HOSTED"
1588 return [v3_check_preprocessor_condition hosted $cond]
1589 }]
1590 }
1591
1592 # Return 1 if std::chrono::tzdb is supported.
1593 proc check_effective_target_tzdb { } {
1594 if {![check_effective_target_cxx11_abi]} {
1595 return 0
1596 }
1597 return [check_v3_target_prop_cached et_tzdb {
1598 set cond "defined _GLIBCXX_ZONEINFO_DIR || _GLIBCXX_STATIC_TZDATA"
1599 return [v3_check_preprocessor_condition tzdb $cond]
1600 }]
1601 }
1602
1603 set additional_prunes ""
1604
1605 if { [info exists env(GCC_RUNTEST_PARALLELIZE_DIR)] \
1606 && [info procs runtest_file_p] != [list] \
1607 && [info procs gcc_parallelize_saved_runtest_file_p] == [list] } then {
1608 global gcc_runtest_parallelize_counter
1609 global gcc_runtest_parallelize_counter_minor
1610 global gcc_runtest_parallelize_enable
1611 global gcc_runtest_parallelize_dir
1612 global gcc_runtest_parallelize_last
1613
1614 set gcc_runtest_parallelize_counter 0
1615 set gcc_runtest_parallelize_counter_minor 0
1616 set gcc_runtest_parallelize_enable 1
1617 set gcc_runtest_parallelize_dir [getenv GCC_RUNTEST_PARALLELIZE_DIR]
1618 set gcc_runtest_parallelize_last 0
1619
1620 proc gcc_parallel_test_run_p { testcase } {
1621 global gcc_runtest_parallelize_counter
1622 global gcc_runtest_parallelize_counter_minor
1623 global gcc_runtest_parallelize_enable
1624 global gcc_runtest_parallelize_dir
1625 global gcc_runtest_parallelize_last
1626
1627 if { $gcc_runtest_parallelize_enable == 0 } {
1628 return 1
1629 }
1630
1631 # Only test the filesystem every 10th iteration
1632 incr gcc_runtest_parallelize_counter_minor
1633 if { $gcc_runtest_parallelize_counter_minor == 10 } {
1634 set gcc_runtest_parallelize_counter_minor 0
1635 }
1636 if { $gcc_runtest_parallelize_counter_minor != 1 } {
1637 #verbose -log "gcc_parallel_test_run_p $testcase $gcc_runtest_parallelize_counter $gcc_runtest_parallelize_last"
1638 return $gcc_runtest_parallelize_last
1639 }
1640
1641 set path $gcc_runtest_parallelize_dir/$gcc_runtest_parallelize_counter
1642
1643 if {![catch {open $path {RDWR CREAT EXCL} 0600} fd]} {
1644 close $fd
1645 set gcc_runtest_parallelize_last 1
1646 #verbose -log "gcc_parallel_test_run_p $testcase $gcc_runtest_parallelize_counter 1"
1647 incr gcc_runtest_parallelize_counter
1648 return 1
1649 }
1650 set gcc_runtest_parallelize_last 0
1651 #verbose -log "gcc_parallel_test_run_p $testcase $gcc_runtest_parallelize_counter 0"
1652 incr gcc_runtest_parallelize_counter
1653 return 0
1654 }
1655
1656 proc gcc_parallel_test_enable { val } {
1657 global gcc_runtest_parallelize_enable
1658 set gcc_runtest_parallelize_enable $val
1659 }
1660
1661 rename runtest_file_p gcc_parallelize_saved_runtest_file_p
1662 proc runtest_file_p { runtests testcase } {
1663 if ![gcc_parallelize_saved_runtest_file_p $runtests $testcase] {
1664 return 0
1665 }
1666 return [gcc_parallel_test_run_p $testcase]
1667 }
1668
1669 } else {
1670
1671 proc gcc_parallel_test_run_p { testcase } {
1672 return 1
1673 }
1674
1675 proc gcc_parallel_test_enable { val } {
1676 }
1677
1678 }
1679
1680 # Utility functions, invoked via dg-final.
1681
1682 # Compare output file written by test to expected result.
1683 # With two arguments the comparison is done via 'diff arg1 arg2'.
1684 # With one argument the comparison is done via 'diff arg1.tst arg1.txt'.
1685 proc file-io-diff { args } {
1686 set nargs [llength $args]
1687 if { $nargs < 1 } {
1688 error "too few arguments to file-io-diff"
1689 }
1690 if { $nargs > 2 } {
1691 error "too many arguments to file-io-diff"
1692 }
1693
1694 set testcase [testname-for-summary]
1695 set description "$testcase file-io-diff $args"
1696
1697 if { $nargs == 1 } {
1698 set file1 [lindex $args 0]
1699 set file2 "${file1}.txt"
1700 append file1 ".tst"
1701 } else {
1702 set file1 [lindex $args 0]
1703 set file2 [lindex $args 1]
1704 }
1705
1706 if { [catch { exec diff -u $file1 $file2 } msg] } {
1707 fail $description
1708 verbose -log "'diff':\n$msg"
1709 } else {
1710 pass $description
1711 }
1712 return
1713 }