Skip to content

Commit 78b157b

Browse files
committed
[libcxx] [test] Fix odr_signature tests with optimizations enabled
If optimization is enabled, the inline `f()` function actually gets inlined, meaning that the functions `tu1()` and `tu2()` trivially return 1 and 2, instead of actually referencing the potentially linker deduplicated function `f()`, which is what the test tries to test. Mark the inline functions with `TEST_NOINLINE` to make sure that they don't get inlined even with optimizations enabled. Also update the TODO comments to explain why we have an XFAIL for msvc mode here. This avoids these tests unexpectedly passing if building in msvc mode, with optimizations enabled (`-DLIBCXX_TEST_PARAMS="optimization=speed"`).
1 parent cca454b commit 78b157b

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

libcxx/test/libcxx/odr_signature.exceptions.sh.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// TODO: Investigate
9+
// ABI tags have no effect in MSVC mode.
1010
// XFAIL: msvc
1111

1212
// Test that we encode whether exceptions are supported in an ABI tag to avoid
@@ -18,17 +18,19 @@
1818
// RUN: %{cxx} %t.tu1.o %t.tu2.o %t.main.o %{flags} %{link_flags} -o %t.exe
1919
// RUN: %{exec} %t.exe
2020

21+
#include "test_macros.h"
22+
2123
// -fno-exceptions
2224
#ifdef TU1
2325
# include <__config>
24-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 1; }
26+
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 1; }
2527
int tu1() { return f(); }
2628
#endif // TU1
2729

2830
// -fexceptions
2931
#ifdef TU2
3032
# include <__config>
31-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 2; }
33+
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 2; }
3234
int tu2() { return f(); }
3335
#endif // TU2
3436

libcxx/test/libcxx/odr_signature.hardening.sh.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
// TODO: Investigate
9+
// ABI tags have no effect in MSVC mode.
1010
// XFAIL: msvc
1111

1212
// Test that we encode the hardening mode in an ABI tag to avoid ODR violations
@@ -21,31 +21,33 @@
2121
// RUN: %{cxx} %t.tu1.o %t.tu2.o %t.tu3.o %t.tu4.o %t.main.o %{flags} %{link_flags} -o %t.exe
2222
// RUN: %{exec} %t.exe
2323

24+
#include "test_macros.h"
25+
2426
// fast hardening mode
2527
#ifdef TU1
2628
# include <__config>
27-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 1; }
29+
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 1; }
2830
int tu1() { return f(); }
2931
#endif // TU1
3032

3133
// extensive hardening mode
3234
#ifdef TU2
3335
# include <__config>
34-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 2; }
36+
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 2; }
3537
int tu2() { return f(); }
3638
#endif // TU2
3739

3840
// debug hardening mode
3941
#ifdef TU3
4042
# include <__config>
41-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 3; }
43+
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 3; }
4244
int tu3() { return f(); }
4345
#endif // TU3
4446

4547
// No hardening
4648
#ifdef TU4
4749
# include <__config>
48-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 4; }
50+
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 4; }
4951
int tu4() { return f(); }
5052
#endif // TU4
5153

0 commit comments

Comments
 (0)