Skip to content

Commit c3efe7d

Browse files
authored
[libcxx] [test] Fix odr_signature tests with optimizations enabled (#144317)
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. Therefore, this test previously actually failed to test what it was supposed to test, if optimization was enabled. 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 4aca3dc commit c3efe7d

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

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

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

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

12+
// XFAIL: FROZEN-CXX03-HEADERS-FIXME
13+
1214
// Test that we encode whether exceptions are supported in an ABI tag to avoid
1315
// ODR violations when linking TUs that have different values for it.
1416

@@ -18,17 +20,19 @@
1820
// RUN: %{cxx} %t.tu1.o %t.tu2.o %t.main.o %{flags} %{link_flags} -o %t.exe
1921
// RUN: %{exec} %t.exe
2022

23+
#include "test_macros.h"
24+
2125
// -fno-exceptions
2226
#ifdef TU1
2327
# include <__config>
24-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 1; }
28+
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 1; }
2529
int tu1() { return f(); }
2630
#endif // TU1
2731

2832
// -fexceptions
2933
#ifdef TU2
3034
# include <__config>
31-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 2; }
35+
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 2; }
3236
int tu2() { return f(); }
3337
#endif // TU2
3438

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

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

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

12+
// XFAIL: FROZEN-CXX03-HEADERS-FIXME
13+
1214
// Test that we encode the hardening mode in an ABI tag to avoid ODR violations
1315
// when linking TUs that have different values for it.
1416

@@ -21,31 +23,33 @@
2123
// RUN: %{cxx} %t.tu1.o %t.tu2.o %t.tu3.o %t.tu4.o %t.main.o %{flags} %{link_flags} -o %t.exe
2224
// RUN: %{exec} %t.exe
2325

26+
#include "test_macros.h"
27+
2428
// fast hardening mode
2529
#ifdef TU1
2630
# include <__config>
27-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 1; }
31+
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 1; }
2832
int tu1() { return f(); }
2933
#endif // TU1
3034

3135
// extensive hardening mode
3236
#ifdef TU2
3337
# include <__config>
34-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 2; }
38+
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 2; }
3539
int tu2() { return f(); }
3640
#endif // TU2
3741

3842
// debug hardening mode
3943
#ifdef TU3
4044
# include <__config>
41-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 3; }
45+
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 3; }
4246
int tu3() { return f(); }
4347
#endif // TU3
4448

4549
// No hardening
4650
#ifdef TU4
4751
# include <__config>
48-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 4; }
52+
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 4; }
4953
int tu4() { return f(); }
5054
#endif // TU4
5155

0 commit comments

Comments
 (0)