Skip to content

Commit 8dc0e86

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 `__attribute__((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 8dc0e86

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

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

Lines changed: 3 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
@@ -21,14 +21,14 @@
2121
// -fno-exceptions
2222
#ifdef TU1
2323
# include <__config>
24-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 1; }
24+
_LIBCPP_HIDE_FROM_ABI __attribute__((noinline)) inline int f() { return 1; }
2525
int tu1() { return f(); }
2626
#endif // TU1
2727

2828
// -fexceptions
2929
#ifdef TU2
3030
# include <__config>
31-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 2; }
31+
_LIBCPP_HIDE_FROM_ABI __attribute__((noinline)) inline int f() { return 2; }
3232
int tu2() { return f(); }
3333
#endif // TU2
3434

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

Lines changed: 5 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
@@ -24,28 +24,28 @@
2424
// fast hardening mode
2525
#ifdef TU1
2626
# include <__config>
27-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 1; }
27+
_LIBCPP_HIDE_FROM_ABI __attribute__((noinline)) inline int f() { return 1; }
2828
int tu1() { return f(); }
2929
#endif // TU1
3030

3131
// extensive hardening mode
3232
#ifdef TU2
3333
# include <__config>
34-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 2; }
34+
_LIBCPP_HIDE_FROM_ABI __attribute__((noinline)) inline int f() { return 2; }
3535
int tu2() { return f(); }
3636
#endif // TU2
3737

3838
// debug hardening mode
3939
#ifdef TU3
4040
# include <__config>
41-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 3; }
41+
_LIBCPP_HIDE_FROM_ABI __attribute__((noinline)) inline int f() { return 3; }
4242
int tu3() { return f(); }
4343
#endif // TU3
4444

4545
// No hardening
4646
#ifdef TU4
4747
# include <__config>
48-
_LIBCPP_HIDE_FROM_ABI inline int f() { return 4; }
48+
_LIBCPP_HIDE_FROM_ABI __attribute__((noinline)) inline int f() { return 4; }
4949
int tu4() { return f(); }
5050
#endif // TU4
5151

0 commit comments

Comments
 (0)