]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/lib/ubsan-dg.exp
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / lib / ubsan-dg.exp
1 # Copyright (C) 2013-2020 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 # Return 1 if compilation with -fsanitize=undefined is error-free for trivial
18 # code, 0 otherwise.
19
20 proc check_effective_target_fsanitize_undefined {} {
21 return [check_runtime fsanitize_undefined {
22 int main (void) { return 0; }
23 } "-fsanitize=undefined"]
24 }
25
26 #
27 # ubsan_link_flags -- compute library path and flags to find libubsan.
28 # (originally from g++.exp)
29 #
30
31 proc ubsan_link_flags { paths } {
32 global srcdir
33 global ld_library_path
34 global shlib_ext
35 global ubsan_saved_library_path
36
37 set gccpath ${paths}
38 set flags ""
39
40 set shlib_ext [get_shlib_extension]
41 set ubsan_saved_library_path $ld_library_path
42
43 if { $gccpath != "" } {
44 if { [file exists "${gccpath}/libsanitizer/ubsan/.libs/libubsan.a"]
45 || [file exists "${gccpath}/libsanitizer/ubsan/.libs/libubsan.${shlib_ext}"] } {
46 append flags " -B${gccpath}/libsanitizer/ "
47 append flags " -B${gccpath}/libsanitizer/ubsan/ "
48 append flags " -L${gccpath}/libsanitizer/ubsan/.libs"
49 append ld_library_path ":${gccpath}/libsanitizer/ubsan/.libs"
50 append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
51 }
52 } else {
53 global tool_root_dir
54
55 set libubsan [lookfor_file ${tool_root_dir} libubsan]
56 if { $libubsan != "" } {
57 append flags "-L${libubsan} "
58 append ld_library_path ":${libubsan}"
59 }
60 }
61
62 set_ld_library_path_env_vars
63
64 return "$flags"
65 }
66
67 #
68 # ubsan_init -- called at the start of each subdir of tests
69 #
70
71 proc ubsan_init { args } {
72 global TEST_ALWAYS_FLAGS
73 global ALWAYS_CXXFLAGS
74 global TOOL_OPTIONS
75 global ubsan_saved_TEST_ALWAYS_FLAGS
76 global ubsan_saved_ALWAYS_CXXFLAGS
77
78 set link_flags ""
79 if ![is_remote host] {
80 if [info exists TOOL_OPTIONS] {
81 set link_flags "[ubsan_link_flags [get_multilibs ${TOOL_OPTIONS}]]"
82 } else {
83 set link_flags "[ubsan_link_flags [get_multilibs]]"
84 }
85 }
86
87 if [info exists TEST_ALWAYS_FLAGS] {
88 set ubsan_saved_TEST_ALWAYS_FLAGS $TEST_ALWAYS_FLAGS
89 }
90 if [info exists ALWAYS_CXXFLAGS] {
91 set ubsan_saved_ALWAYS_CXXFLAGS $ALWAYS_CXXFLAGS
92 set ALWAYS_CXXFLAGS [concat "{ldflags=$link_flags}" $ALWAYS_CXXFLAGS]
93 } else {
94 if [info exists TEST_ALWAYS_FLAGS] {
95 set TEST_ALWAYS_FLAGS "$link_flags $TEST_ALWAYS_FLAGS"
96 } else {
97 set TEST_ALWAYS_FLAGS "$link_flags"
98 }
99 }
100 }
101
102 #
103 # ubsan_finish -- called at the end of each subdir of tests
104 #
105
106 proc ubsan_finish { args } {
107 global TEST_ALWAYS_FLAGS
108 global ubsan_saved_TEST_ALWAYS_FLAGS
109 global ubsan_saved_ALWAYS_CXXFLAGS
110 global ubsan_saved_library_path
111 global ld_library_path
112
113 if [info exists ubsan_saved_ALWAYS_CXXFLAGS ] {
114 set ALWAYS_CXXFLAGS $ubsan_saved_ALWAYS_CXXFLAGS
115 } else {
116 if [info exists ubsan_saved_TEST_ALWAYS_FLAGS] {
117 set TEST_ALWAYS_FLAGS $ubsan_saved_TEST_ALWAYS_FLAGS
118 } else {
119 unset TEST_ALWAYS_FLAGS
120 }
121 }
122 set ld_library_path $ubsan_saved_library_path
123 set_ld_library_path_env_vars
124 clear_effective_target_cache
125 }