2017-12-05 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / lib / g++.exp
blob3442abe344b336af3b4c86d647ebadec8b675abd
1 # Copyright (C) 1992-2017 Free Software Foundation, Inc.
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.
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.
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/>.
17 # This file was written by Rob Savoye (rob@cygnus.com)
18 # Many modifications by Jeffrey Wheat (cassidy@cygnus.com)
19 # With modifications by Mike Stump <mrs@cygnus.com>.
22 # g++ support library routines
24 load_lib prune.exp
25 load_lib gcc-defs.exp
26 load_lib timeout.exp
27 load_lib target-libpath.exp
30 # GXX_UNDER_TEST is the compiler under test.
34 set gpp_compile_options ""
35 set gpp_std_list { }
36 if [info exists env(GXX_TESTSUITE_STDS)] {
37 set gpp_std_list [split $env(GXX_TESTSUITE_STDS) ","]
41 # g++_version -- extract and print the version number of the compiler
44 proc g++_version { } {
45 global GXX_UNDER_TEST
47 g++_init
49 # ignore any arguments after the command
50 set compiler [lindex $GXX_UNDER_TEST 0]
52 # verify that the compiler exists
53 if { [is_remote host] || [which $compiler] != 0 } then {
54 set tmp [remote_exec host "$compiler -v"]
55 set status [lindex $tmp 0]
56 set output [lindex $tmp 1]
57 regexp " version \[^\n\r\]*" $output version
58 if { $status == 0 && [info exists version] } then {
59 if [is_remote host] {
60 clone_output "$compiler $version\n"
61 } else {
62 clone_output "[which $compiler] $version\n"
64 } else {
65 clone_output "Couldn't determine version of [which $compiler]\n"
67 } else {
68 # compiler does not exist (this should have already been detected)
69 warning "$compiler does not exist"
74 # g++_include_flags -- provide new version of g++_include_flags
75 # (originally from libgloss.exp) which knows about the gcc tree structure
77 proc g++_include_flags { paths } {
78 global srcdir
79 global HAVE_LIBSTDCXX_V3
80 global TESTING_IN_BUILD_TREE
82 set flags ""
84 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
85 return "${flags}"
88 set gccpath ${paths}
90 set odir [lookfor_file ${gccpath} libstdc++-v3]
91 if { ${odir} != "" } {
92 append flags [exec sh ${odir}/scripts/testsuite_flags --build-includes]
95 return "$flags"
99 # g++_link_flags -- provide new version of g++_link_flags
100 # (originally from libgloss.exp) which knows about the gcc tree structure
103 proc g++_link_flags { paths } {
104 global srcdir
105 global ld_library_path
106 global GXX_UNDER_TEST
107 global shlib_ext
109 set gccpath ${paths}
110 set libio_dir ""
111 set flags ""
112 set ld_library_path "."
114 set shlib_ext [get_shlib_extension]
115 verbose "shared lib extension: $shlib_ext"
117 if { $gccpath != "" } {
118 if [file exists "${gccpath}/lib/libstdc++.a"] {
119 append ld_library_path ":${gccpath}/lib"
121 if [file exists "${gccpath}/libg++/libg++.a"] {
122 append flags "-L${gccpath}/libg++ "
123 append ld_library_path ":${gccpath}/libg++"
125 if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
126 append flags "-L${gccpath}/libstdc++ "
127 append ld_library_path ":${gccpath}/libstdc++"
129 if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
130 append flags " -L${gccpath}/libstdc++-v3/src/.libs "
131 # Some targets use libstdc++.a%s in their specs, so they need a
132 # -B option for uninstalled testing.
133 append flags " -B${gccpath}/libstdc++-v3/src/.libs "
134 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
136 # Look for libstdc++.${shlib_ext}.
137 if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] {
138 append flags " -L${gccpath}/libstdc++-v3/src/.libs "
139 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
142 if [file exists "${gccpath}/libiberty/libiberty.a"] {
143 append flags "-L${gccpath}/libiberty "
145 if [file exists "${gccpath}/librx/librx.a"] {
146 append flags "-L${gccpath}/librx "
148 if [file exists "${gccpath}/libitm/libitm.spec"] {
149 append flags "-B${gccpath}/libitm/ -L${gccpath}/libitm/.libs"
150 append ld_library_path ":${gccpath}/libitm/.libs"
152 append ld_library_path [gcc-set-multilib-library-path $GXX_UNDER_TEST]
153 } else {
154 global tool_root_dir
156 set libgpp [lookfor_file ${tool_root_dir} libg++]
157 if { $libgpp != "" } {
158 append flags "-L${libgpp} "
159 append ld_library_path ":${libgpp}"
161 set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
162 if { $libstdcpp != "" } {
163 append flags "-L${libstdcpp} "
164 append ld_library_path ":${libstdcpp}"
166 set libiberty [lookfor_file ${tool_root_dir} libiberty]
167 if { $libiberty != "" } {
168 append flags "-L${libiberty} "
170 set librx [lookfor_file ${tool_root_dir} librx]
171 if { $librx != "" } {
172 append flags "-L${librx} "
176 set_ld_library_path_env_vars
178 return "$flags"
182 # g++_init -- called at the start of each subdir of tests
185 proc g++_init { args } {
186 global subdir
187 global gpp_initialized
188 global base_dir
189 global tmpdir
190 global libdir
191 global gluefile wrap_flags
192 global objdir srcdir
193 global ALWAYS_CXXFLAGS
194 global CXXFLAGS
195 global TOOL_EXECUTABLE TOOL_OPTIONS
196 global GXX_UNDER_TEST
197 global TESTING_IN_BUILD_TREE
198 global gcc_warning_prefix
199 global gcc_error_prefix
200 global TEST_ALWAYS_FLAGS
202 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
203 setenv LC_ALL C
204 setenv LANG C
206 # Many hosts now default to a non-ASCII C locale, however, so
207 # they can set a charset encoding here if they need.
208 if { [ishost "*-*-cygwin*"] } {
209 setenv LC_ALL C.ASCII
210 setenv LANG C.ASCII
213 if ![info exists GXX_UNDER_TEST] then {
214 if [info exists TOOL_EXECUTABLE] {
215 set GXX_UNDER_TEST $TOOL_EXECUTABLE
216 } else {
217 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
218 set GXX_UNDER_TEST [transform c++]
219 } else {
220 set GXX_UNDER_TEST [findfile $base_dir/../../xg++ "$base_dir/../../xg++ -B$base_dir/../../" [findfile $base_dir/xg++ "$base_dir/xg++ -B$base_dir/" [transform c++]]]
225 # Bleah, nasty. Bad taste.
226 if [ishost "*-dos-*" ] {
227 regsub "c\\+\\+" "$GXX_UNDER_TEST" "gcc" GXX_UNDER_TEST
230 if ![is_remote host] {
231 if { [which $GXX_UNDER_TEST] == 0 } then {
232 perror "GXX_UNDER_TEST ($GXX_UNDER_TEST) does not exist"
233 exit 1
236 if ![info exists tmpdir] {
237 set tmpdir "/tmp"
240 if [info exists gluefile] {
241 unset gluefile
244 g++_maybe_build_wrapper "${tmpdir}/g++-testglue.o" "-fexceptions"
246 if {![info exists CXXFLAGS]} {
247 set CXXFLAGS ""
250 set ALWAYS_CXXFLAGS ""
252 # TEST_ALWAYS_FLAGS are flags that should be passed to every
253 # compilation command. They are passed first to allow individual
254 # tests to override them.
255 if [info exists TEST_ALWAYS_FLAGS] {
256 lappend ALWAYS_CXXFLAGS "additional_flags=$TEST_ALWAYS_FLAGS"
259 if ![is_remote host] {
260 if [info exists TOOL_OPTIONS] {
261 lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs ${TOOL_OPTIONS}] ]"
262 lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
263 } else {
264 lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs] ]"
265 lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags [get_multilibs] ]"
269 if [info exists TOOL_OPTIONS] {
270 lappend ALWAYS_CXXFLAGS "additional_flags=$TOOL_OPTIONS"
273 # Make sure that lines are not wrapped. That can confuse the
274 # error-message parsing machinery.
275 lappend ALWAYS_CXXFLAGS "additional_flags=-fmessage-length=0"
277 set gcc_warning_prefix "warning:"
278 set gcc_error_prefix "(fatal )?error:"
280 if { [istarget *-*-darwin*] } {
281 lappend ALWAYS_CXXFLAGS "ldflags=-multiply_defined suppress"
284 verbose -log "ALWAYS_CXXFLAGS set to $ALWAYS_CXXFLAGS"
286 verbose "g++ is initialized" 3
290 # g++_target_compile -- compile a source file
293 proc g++_target_compile { source dest type options } {
294 global tmpdir
295 global gpp_compile_options
296 global gluefile wrap_flags
297 global ALWAYS_CXXFLAGS
298 global GXX_UNDER_TEST
299 global flags_to_postpone
300 global board_info
302 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
303 lappend options "libs=${gluefile}"
304 lappend options "ldflags=${wrap_flags}"
307 global TEST_EXTRA_LIBS
308 if [info exists TEST_EXTRA_LIBS] {
309 lappend options "ldflags=$TEST_EXTRA_LIBS"
312 lappend options "additional_flags=[libio_include_flags]"
313 lappend options "compiler=$GXX_UNDER_TEST"
314 lappend options "timeout=[timeout_value]"
316 set options [concat $gpp_compile_options $options]
318 set options [concat "$ALWAYS_CXXFLAGS" $options]
320 if { [regexp "(^| )-frepo( |$)" $options] && \
321 [regexp "\.o(|bj)$" $dest] } then {
322 regsub "\.o(|bj)$" $dest ".rpo" rponame
323 exec rm -f $rponame
326 # bind_pic_locally adds -fpie/-fPIE flags to flags_to_postpone and it is
327 # appended here to multilib_flags as it can be overridden by the latter
328 # if it was added earlier. After the target_compile, multilib_flags is
329 # restored to its orignal content.
330 set tboard [target_info name]
331 if {[board_info $tboard exists multilib_flags]} {
332 set orig_multilib_flags "[board_info [target_info name] multilib_flags]"
333 append board_info($tboard,multilib_flags) " $flags_to_postpone"
336 set options [dg-additional-files-options $options $source]
338 set result [target_compile $source $dest $type $options]
340 if {[board_info $tboard exists multilib_flags]} {
341 set board_info($tboard,multilib_flags) $orig_multilib_flags
342 set flags_to_postpone ""
345 return $result
349 # ${tool}_option_help
351 # Changed "additional" to "extra" because runtest.exp treats --a* as --all.
353 # This shouldn't be necessary at all; it should be entirely redundant with
354 # --tool_opts, except that --tool_opts currently breaks multilib: see
355 # http://lists.gnu.org/archive/html/dejagnu/2002-10/msg00007.html
357 proc ${tool}_option_help { } {
358 send_user " --extra_opts,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
362 # ${tool}_option_proc
365 proc ${tool}_option_proc { option } {
366 if [regexp "^--extra_opts," $option] {
367 global gpp_compile_options
368 regsub "^--extra_opts," $option "" option
369 foreach x [split $option ","] {
370 lappend gpp_compile_options "additional_flags=$x"
372 verbose -log "gpp_compile_options set to $gpp_compile_options"
373 return 1
374 } elseif [regexp "^--stds=" $option] {
375 global gpp_std_list
376 regsub "^--stds=" $option "" option
377 foreach x [split $option ","] {
378 lappend gpp_std_list "$x"
380 verbose -log "gpp_std_list set to $gpp_std_list"
381 return 1
382 } else {
383 return 0