Debian Codegraph @

gcc/testsuite/lib/g++.exp

raw
1 # Copyright (C) 1992-2025 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 ([email protected])
18 # Many modifications by Jeffrey Wheat ([email protected])
19 # With modifications by Mike Stump <[email protected]>.
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 # Allow gpp_std_list to be set in configuration files, e.g., ~/.dejagnurc
36 if ![info exists gpp_std_list] {
37 set gpp_std_list { }
38 }
39 # Allow gpp_std_list to be set from the environment.
40 if [info exists env(GXX_TESTSUITE_STDS)] {
41 set gpp_std_list [split $env(GXX_TESTSUITE_STDS) ","]
42 }
43
44 #
45 # g++_version -- extract and print the version number of the compiler
46 #
47
48 proc g++_version { } {
49 global GXX_UNDER_TEST
50
51 g++_init
52
53 # ignore any arguments after the command
54 set compiler [lindex $GXX_UNDER_TEST 0]
55
56 # verify that the compiler exists
57 if { [is_remote host] || [which $compiler] != 0 } then {
58 set tmp [remote_exec host "$compiler -v"]
59 set status [lindex $tmp 0]
60 set output [lindex $tmp 1]
61 regexp " version \[^\n\r\]*" $output version
62 if { $status == 0 && [info exists version] } then {
63 if [is_remote host] {
64 clone_output "$compiler $version\n"
65 } else {
66 clone_output "[which $compiler] $version\n"
67 }
68 } else {
69 clone_output "Couldn't determine version of [which $compiler]\n"
70 }
71 } else {
72 # compiler does not exist (this should have already been detected)
73 warning "$compiler does not exist"
74 }
75 }
76
77 #
78 # g++_include_flags -- provide new version of g++_include_flags
79 # (originally from libgloss.exp) which knows about the gcc tree structure
80 #
81 proc g++_include_flags { paths } {
82 global srcdir
83 global HAVE_LIBSTDCXX_V3
84 global TESTING_IN_BUILD_TREE
85
86 set flags ""
87
88 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
89 return "${flags}"
90 }
91
92 set gccpath ${paths}
93
94 set odir [lookfor_file ${gccpath} libstdc++-v3]
95 if { ${odir} != "" } {
96 append flags [exec sh ${odir}/scripts/testsuite_flags --build-includes]
97 }
98
99 return "$flags"
100 }
101
102 #
103 # g++_link_flags -- provide new version of g++_link_flags
104 # (originally from libgloss.exp) which knows about the gcc tree structure
105 #
106
107 proc g++_link_flags { paths } {
108 global srcdir
109 global ld_library_path
110 global GXX_UNDER_TEST
111 global shlib_ext
112
113 set gccpath ${paths}
114 set libio_dir ""
115 set flags ""
116 set ld_library_path "."
117
118 set shlib_ext [get_shlib_extension]
119 verbose "shared lib extension: $shlib_ext"
120
121 if { $gccpath != "" } {
122 if [file exists "${gccpath}/lib/libstdc++.a"] {
123 append ld_library_path ":${gccpath}/lib"
124 }
125 if [file exists "${gccpath}/libg++/libg++.a"] {
126 append flags "-L${gccpath}/libg++ "
127 append ld_library_path ":${gccpath}/libg++"
128 }
129 if [file exists "${gccpath}/libstdc++/libstdc++.a"] {
130 append flags "-L${gccpath}/libstdc++ "
131 append ld_library_path ":${gccpath}/libstdc++"
132 }
133 if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] {
134 append flags " -L${gccpath}/libstdc++-v3/src/.libs "
135 # Some targets use libstdc++.a%s in their specs, so they need a
136 # -B option for uninstalled testing.
137 append flags " -B${gccpath}/libstdc++-v3/src/.libs "
138 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
139 }
140 # Look for libstdc++.${shlib_ext}.
141 if [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] {
142 append flags " -L${gccpath}/libstdc++-v3/src/.libs "
143 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
144 }
145 if [file exists "${gccpath}/libstdc++-v3/src/experimental/.libs/libstdc++exp.a"] {
146 append flags " -L${gccpath}/libstdc++-v3/src/experimental/.libs "
147 append ld_library_path ":${gccpath}/libstdc++-v3/src/experimental/.libs"
148 }
149
150 if [file exists "${gccpath}/libiberty/libiberty.a"] {
151 append flags "-L${gccpath}/libiberty "
152 }
153 if [file exists "${gccpath}/librx/librx.a"] {
154 append flags "-L${gccpath}/librx "
155 }
156 if [file exists "${gccpath}/libitm/libitm.spec"] {
157 append flags "-B${gccpath}/libitm/ -L${gccpath}/libitm/.libs"
158 append ld_library_path ":${gccpath}/libitm/.libs"
159 }
160 append ld_library_path [gcc-set-multilib-library-path $GXX_UNDER_TEST]
161 } else {
162 global tool_root_dir
163
164 set libgpp [lookfor_file ${tool_root_dir} libg++]
165 if { $libgpp != "" } {
166 append flags "-L${libgpp} "
167 append ld_library_path ":${libgpp}"
168 }
169 set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
170 if { $libstdcpp != "" } {
171 append flags "-L${libstdcpp} "
172 append ld_library_path ":${libstdcpp}"
173 }
174 set libiberty [lookfor_file ${tool_root_dir} libiberty]
175 if { $libiberty != "" } {
176 append flags "-L${libiberty} "
177 }
178 set librx [lookfor_file ${tool_root_dir} librx]
179 if { $librx != "" } {
180 append flags "-L${librx} "
181 }
182 }
183
184 set_ld_library_path_env_vars
185
186 return "$flags"
187 }
188
189 #
190 # g++_init -- called at the start of each subdir of tests
191 #
192
193 proc g++_init { args } {
194 global subdir
195 global gpp_initialized
196 global base_dir
197 global tmpdir
198 global libdir
199 global gluefile wrap_flags
200 global objdir srcdir
201 global ALWAYS_CXXFLAGS
202 global CXXFLAGS
203 global TOOL_EXECUTABLE TOOL_OPTIONS
204 global GXX_UNDER_TEST
205 global TESTING_IN_BUILD_TREE
206 global gcc_warning_prefix
207 global gcc_error_prefix
208 global TEST_ALWAYS_FLAGS
209
210 # We set LC_ALL and LANG to C so that we get the same error messages as expected.
211 setenv LC_ALL C
212 setenv LANG C
213
214 # Many hosts now default to a non-ASCII C locale, however, so
215 # they can set a charset encoding here if they need.
216 if { [ishost "*-*-cygwin*"] } {
217 setenv LC_ALL C.ASCII
218 setenv LANG C.ASCII
219 }
220
221 if ![info exists GXX_UNDER_TEST] then {
222 if [info exists TOOL_EXECUTABLE] {
223 set GXX_UNDER_TEST $TOOL_EXECUTABLE
224 } else {
225 if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
226 set GXX_UNDER_TEST [transform c++]
227 } else {
228 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++]]]
229 }
230 }
231 }
232
233 # Bleah, nasty. Bad taste.
234 if [ishost "*-dos-*" ] {
235 regsub "c\\+\\+" "$GXX_UNDER_TEST" "gcc" GXX_UNDER_TEST
236 }
237
238 if ![is_remote host] {
239 if { [which $GXX_UNDER_TEST] == 0 } then {
240 perror "GXX_UNDER_TEST ($GXX_UNDER_TEST) does not exist"
241 exit 1
242 }
243 }
244 if ![info exists tmpdir] {
245 set tmpdir "/tmp"
246 }
247
248 if [info exists gluefile] {
249 unset gluefile
250 }
251
252 g++_maybe_build_wrapper "${tmpdir}/g++-testglue.o" "-fexceptions"
253
254 if {![info exists CXXFLAGS]} {
255 set CXXFLAGS ""
256 }
257
258 set ALWAYS_CXXFLAGS ""
259
260 # TEST_ALWAYS_FLAGS are flags that should be passed to every
261 # compilation command. They are passed first to allow individual
262 # tests to override them.
263 if [info exists TEST_ALWAYS_FLAGS] {
264 lappend ALWAYS_CXXFLAGS "additional_flags=$TEST_ALWAYS_FLAGS"
265 }
266
267 if ![is_remote host] {
268 if [info exists TOOL_OPTIONS] {
269 lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs ${TOOL_OPTIONS}] ]"
270 lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
271 } else {
272 lappend ALWAYS_CXXFLAGS "additional_flags=[g++_include_flags [get_multilibs] ]"
273 lappend ALWAYS_CXXFLAGS "ldflags=[g++_link_flags [get_multilibs] ]"
274 }
275 }
276
277 if [info exists TOOL_OPTIONS] {
278 lappend ALWAYS_CXXFLAGS "additional_flags=$TOOL_OPTIONS"
279 }
280
281 # Make sure that lines are not wrapped. That can confuse the
282 # error-message parsing machinery.
283 lappend ALWAYS_CXXFLAGS "additional_flags=-fmessage-length=0"
284
285 set gcc_warning_prefix "warning:"
286 set gcc_error_prefix "(fatal )?error:"
287
288 verbose -log "ALWAYS_CXXFLAGS set to $ALWAYS_CXXFLAGS"
289
290 verbose "g++ is initialized" 3
291 }
292
293 #
294 # g++_target_compile -- compile a source file
295 #
296
297 proc g++_target_compile { source dest type options } {
298 global tmpdir
299 global gpp_compile_options
300 global gluefile wrap_flags
301 global ALWAYS_CXXFLAGS
302 global GXX_UNDER_TEST
303 global flags_to_postpone
304 global board_info
305
306 global TEST_EXTRA_LIBS
307 if [info exists TEST_EXTRA_LIBS] {
308 lappend options "ldflags=$TEST_EXTRA_LIBS"
309 }
310
311 lappend options "additional_flags=[libio_include_flags]"
312 lappend options "compiler=$GXX_UNDER_TEST"
313 lappend options "timeout=[timeout_value]"
314
315 set options [concat $gpp_compile_options $options]
316
317 set options [concat "$ALWAYS_CXXFLAGS" $options]
318
319 # bind_pic_locally adds -fpie/-fPIE flags to flags_to_postpone and it is
320 # appended here to multilib_flags as it can be overridden by the latter
321 # if it was added earlier. After the target_compile, multilib_flags is
322 # restored to its orignal content.
323 set tboard [target_info name]
324 if {[board_info $tboard exists multilib_flags]} {
325 set orig_multilib_flags "[board_info [target_info name] multilib_flags]"
326 append board_info($tboard,multilib_flags) " $flags_to_postpone"
327 }
328
329 set options [dg-additional-files-options $options $source $dest $type]
330
331 if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
332 lappend options "libs=${gluefile}"
333 lappend options "ldflags=${wrap_flags}"
334 }
335
336 set result [target_compile $source $dest $type $options]
337
338 if {[board_info $tboard exists multilib_flags]} {
339 set board_info($tboard,multilib_flags) $orig_multilib_flags
340 set flags_to_postpone ""
341 }
342
343 return $result
344 }
345
346 #
347 # ${tool}_option_help
348 #
349 # Changed "additional" to "extra" because runtest.exp treats --a* as --all.
350 #
351 # This shouldn't be necessary at all; it should be entirely redundant with
352 # --tool_opts, except that --tool_opts currently breaks multilib: see
353 # http://lists.gnu.org/archive/html/dejagnu/2002-10/msg00007.html
354
355 proc ${tool}_option_help { } {
356 send_user " --extra_opts,OPTIONS\t\tUse OPTIONS to compile the testcase files. OPTIONS should be comma-separated.\n"
357 }
358
359 #
360 # ${tool}_option_proc
361 #
362
363 proc ${tool}_option_proc { option } {
364 if [regexp "^--extra_opts," $option] {
365 global gpp_compile_options
366 regsub "^--extra_opts," $option "" option
367 foreach x [split $option ","] {
368 lappend gpp_compile_options "additional_flags=$x"
369 }
370 verbose -log "gpp_compile_options set to $gpp_compile_options"
371 return 1
372 } elseif [regexp "^--stds=" $option] {
373 global gpp_std_list
374 regsub "^--stds=" $option "" option
375 foreach x [split $option ","] {
376 lappend gpp_std_list "$x"
377 }
378 verbose -log "gpp_std_list set to $gpp_std_list"
379 return 1
380 } else {
381 return 0
382 }
383 }