]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/lib/g++.exp
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / lib / g++.exp
1 # Copyright (C) 1992-2019 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 # 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>.
20
21 #
22 # g++ support library routines
23 #
24 load_lib prune.exp
25 load_lib gcc-defs.exp
26 load_lib timeout.exp
27 load_lib target-libpath.exp
28
29 #
30 # GXX_UNDER_TEST is the compiler under test.
31 #
32
33
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) ","]
38 }
39
40 #
41 # g++_version -- extract and print the version number of the compiler
42 #
43
44 proc g++_version { } {
45 global GXX_UNDER_TEST
46
47 g++_init
48
49 # ignore any arguments after the command
50 set compiler [lindex $GXX_UNDER_TEST 0]
51
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"
63 }
64 } else {
65 clone_output "Couldn't determine version of [which $compiler]\n"
66 }
67 } else {
68 # compiler does not exist (this should have already been detected)
69 warning "$compiler does not exist"
70 }
71 }
72
73 #
74 # g++_include_flags -- provide new version of g++_include_flags
75 # (originally from libgloss.exp) which knows about the gcc tree structure
76 #
77 proc g++_include_flags { paths } {
78 global srcdir
79 global HAVE_LIBSTDCXX_V3
80 global TESTING_IN_BUILD_TREE
81
82 set flags ""
83
84 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
85 return "${flags}"
86 }
87
88 set gccpath ${paths}
89
90 set odir [lookfor_file ${gccpath} libstdc++-v3]
91 if { ${odir} != "" } {
92 append flags [exec sh ${odir}/scripts/testsuite_flags --build-includes]
93 }
94
95 return "$flags"
96 }
97
98 #
99 # g++_link_flags -- provide new version of g++_link_flags
100 # (originally from libgloss.exp) which knows about the gcc tree structure
101 #
102
103 proc g++_link_flags { paths } {
104 global srcdir
105 global ld_library_path
106 global GXX_UNDER_TEST
107 global shlib_ext
108
109 set gccpath ${paths}
110 set libio_dir ""
111 set flags ""
112 set ld_library_path "."
113
114 set shlib_ext [get_shlib_extension]
115 verbose "shared lib extension: $shlib_ext"
116
117 if { $gccpath != "" } {
118 if [file exists "${gccpath}/lib/libstdc++.a"] {
119 append ld_library_path ":${gccpath}/lib"
120 }
121 if [file exists "${gccpath}/libg++/libg++.a"] {
122 append flags "-L${gccpath}/libg++ "
123 append ld_library_path ":${gccpath}/libg++"
124 }
125 if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
126 append flags "-L${gccpath}/libstdc++ "
127 append ld_library_path ":${gccpath}/libstdc++"
128 }
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"
135 }
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"
140 }
141
142 if [file exists "${gccpath}/libiberty/libiberty.a"] {
143 append flags "-L${gccpath}/libiberty "
144 }
145 if [file exists "${gccpath}/librx/librx.a"] {
146 append flags "-L${gccpath}/librx "
147 }
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"
151 }
152 append ld_library_path [gcc-set-multilib-library-path $GXX_UNDER_TEST]
153 } else {
154 global tool_root_dir
155
156 set libgpp [lookfor_file ${tool_root_dir} libg++]
157 if { $libgpp != "" } {
158 append flags "-L${libgpp} "
159 append ld_library_path ":${libgpp}"
160 }
161 set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
162 if { $libstdcpp != "" } {
163 append flags "-L${libstdcpp} "
164 append ld_library_path ":${libstdcpp}"
165 }
166 set libiberty [lookfor_file ${tool_root_dir} libiberty]
167 if { $libiberty != "" } {
168 append flags "-L${libiberty} "
169 }
170 set librx [lookfor_file ${tool_root_dir} librx]
171 if { $librx != "" } {
172 append flags "-L${librx} "
173 }
174 }
175
176 set_ld_library_path_env_vars
177
178 return "$flags"
179 }
180
181 #
182 # g++_init -- called at the start of each subdir of tests
183 #
184
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
201
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
205
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
211 }
212
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++]]]
221 }
222 }
223 }
224
225 # Bleah, nasty. Bad taste.
226 if [ishost "*-dos-*" ] {
227 regsub "c\\+\\+" "$GXX_UNDER_TEST" "gcc" GXX_UNDER_TEST
228 }
229
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
234 }
235 }
236 if ![info exists tmpdir] {
237 set tmpdir "/tmp"
238 }
239
240 if [info exists gluefile] {
241 unset gluefile
242 }
243
244 g++_maybe_build_wrapper "${tmpdir}/g++-testglue.o" "-fexceptions"
245
246 if {![info exists CXXFLAGS]} {
247 set CXXFLAGS ""
248 }
249
250 set ALWAYS_CXXFLAGS ""
251
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"
257 }
258
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] ]"
266 }
267 }
268
269 if [info exists TOOL_OPTIONS] {
270 lappend ALWAYS_CXXFLAGS "additional_flags=$TOOL_OPTIONS"
271 }
272
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"
276
277 set gcc_warning_prefix "warning:"
278 set gcc_error_prefix "(fatal )?error:"
279
280 if { [istarget *-*-darwin*] } {
281 lappend ALWAYS_CXXFLAGS "ldflags=-multiply_defined suppress"
282 }
283
284 verbose -log "ALWAYS_CXXFLAGS set to $ALWAYS_CXXFLAGS"
285
286 verbose "g++ is initialized" 3
287 }
288
289 #
290 # g++_target_compile -- compile a source file
291 #
292
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
301
302 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
303 lappend options "libs=${gluefile}"
304 lappend options "ldflags=${wrap_flags}"
305 }
306
307 global TEST_EXTRA_LIBS
308 if [info exists TEST_EXTRA_LIBS] {
309 lappend options "ldflags=$TEST_EXTRA_LIBS"
310 }
311
312 lappend options "additional_flags=[libio_include_flags]"
313 lappend options "compiler=$GXX_UNDER_TEST"
314 lappend options "timeout=[timeout_value]"
315
316 set options [concat $gpp_compile_options $options]
317
318 set options [concat "$ALWAYS_CXXFLAGS" $options]
319
320 if { [regexp "(^| )-frepo( |$)" $options] && \
321 [regexp "\.o(|bj)$" $dest] } then {
322 regsub "\.o(|bj)$" $dest ".rpo" rponame
323 exec rm -f $rponame
324 }
325
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"
334 }
335
336 set options [dg-additional-files-options $options $source]
337
338 set result [target_compile $source $dest $type $options]
339
340 if {[board_info $tboard exists multilib_flags]} {
341 set board_info($tboard,multilib_flags) $orig_multilib_flags
342 set flags_to_postpone ""
343 }
344
345 return $result
346 }
347
348 #
349 # ${tool}_option_help
350 #
351 # Changed "additional" to "extra" because runtest.exp treats --a* as --all.
352 #
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
356
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"
359 }
360
361 #
362 # ${tool}_option_proc
363 #
364
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"
371 }
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"
379 }
380 verbose -log "gpp_std_list set to $gpp_std_list"
381 return 1
382 } else {
383 return 0
384 }
385 }