[libcxx-commits] [libcxx] [libcxx] [test] Fix odr_signature tests with optimizations enabled (PR #144317)

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jun 16 02:32:20 PDT 2025


https://github.com/mstorsjo updated https://github.com/llvm/llvm-project/pull/144317

>From 78b157bb18df726cb34747a021562196fde1cda8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Sat, 14 Jun 2025 01:11:51 +0300
Subject: [PATCH] [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"`).
---
 libcxx/test/libcxx/odr_signature.exceptions.sh.cpp |  8 +++++---
 libcxx/test/libcxx/odr_signature.hardening.sh.cpp  | 12 +++++++-----
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/libcxx/test/libcxx/odr_signature.exceptions.sh.cpp b/libcxx/test/libcxx/odr_signature.exceptions.sh.cpp
index 6bf60b5e82d3c..5eaad00f262d0 100644
--- a/libcxx/test/libcxx/odr_signature.exceptions.sh.cpp
+++ b/libcxx/test/libcxx/odr_signature.exceptions.sh.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-// TODO: Investigate
+// ABI tags have no effect in MSVC mode.
 // XFAIL: msvc
 
 // Test that we encode whether exceptions are supported in an ABI tag to avoid
@@ -18,17 +18,19 @@
 // RUN: %{cxx} %t.tu1.o %t.tu2.o %t.main.o %{flags} %{link_flags} -o %t.exe
 // RUN: %{exec} %t.exe
 
+#include "test_macros.h"
+
 // -fno-exceptions
 #ifdef TU1
 #  include <__config>
-_LIBCPP_HIDE_FROM_ABI inline int f() { return 1; }
+_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 1; }
 int tu1() { return f(); }
 #endif // TU1
 
 // -fexceptions
 #ifdef TU2
 #  include <__config>
-_LIBCPP_HIDE_FROM_ABI inline int f() { return 2; }
+_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 2; }
 int tu2() { return f(); }
 #endif // TU2
 
diff --git a/libcxx/test/libcxx/odr_signature.hardening.sh.cpp b/libcxx/test/libcxx/odr_signature.hardening.sh.cpp
index 0dc280bf28182..da969a7bec8f1 100644
--- a/libcxx/test/libcxx/odr_signature.hardening.sh.cpp
+++ b/libcxx/test/libcxx/odr_signature.hardening.sh.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-// TODO: Investigate
+// ABI tags have no effect in MSVC mode.
 // XFAIL: msvc
 
 // Test that we encode the hardening mode in an ABI tag to avoid ODR violations
@@ -21,31 +21,33 @@
 // RUN: %{cxx} %t.tu1.o %t.tu2.o %t.tu3.o %t.tu4.o %t.main.o %{flags} %{link_flags} -o %t.exe
 // RUN: %{exec} %t.exe
 
+#include "test_macros.h"
+
 // fast hardening mode
 #ifdef TU1
 #  include <__config>
-_LIBCPP_HIDE_FROM_ABI inline int f() { return 1; }
+_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 1; }
 int tu1() { return f(); }
 #endif // TU1
 
 // extensive hardening mode
 #ifdef TU2
 #  include <__config>
-_LIBCPP_HIDE_FROM_ABI inline int f() { return 2; }
+_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 2; }
 int tu2() { return f(); }
 #endif // TU2
 
 // debug hardening mode
 #ifdef TU3
 #  include <__config>
-_LIBCPP_HIDE_FROM_ABI inline int f() { return 3; }
+_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 3; }
 int tu3() { return f(); }
 #endif // TU3
 
 // No hardening
 #ifdef TU4
 #  include <__config>
-_LIBCPP_HIDE_FROM_ABI inline int f() { return 4; }
+_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 4; }
 int tu4() { return f(); }
 #endif // TU4
 



More information about the libcxx-commits mailing list