[libc-commits] [libc] [libc][test] Fix death test timeouts and dead-code elimination in math tests. (PR #227966)

via libc-commits libc-commits at lists.llvm.org
Wed Sep 30 23:05:25 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: lntue

<details>
<summary>Changes</summary>

- In `ExecuteFunctionUnix.cpp`, call `prctl(PR_SET_DUMPABLE, 0)` in child processes to prevent external core dump handlers (such as apport) from intercepting expected crashes during death tests, eliminating 10s poll timeouts under parallel lit runs.
- Close `pipe_fds[0]` properly in `invoke_in_subprocess` to avoid leaking file descriptors.
- In math smoke test templates (`AddTest.h`, `SubTest.h`, `MulTest.h`, `DivTest.h`), assign test function results to `[[maybe_unused]] volatile OutType res` to prevent GCC from dead-code eliminating floating point operations in `test_inexact_results` when FMA optimization is disabled.

Assisted-by: Gemini

---
Full diff: https://github.com/llvm/llvm-project/pull/227966.diff


6 Files Affected:

- (modified) libc/test/UnitTest/CMakeLists.txt (+5) 
- (modified) libc/test/UnitTest/ExecuteFunctionUnix.cpp (+14) 
- (modified) libc/test/src/math/smoke/AddTest.h (+1-1) 
- (modified) libc/test/src/math/smoke/DivTest.h (+1-1) 
- (modified) libc/test/src/math/smoke/MulTest.h (+1-1) 
- (modified) libc/test/src/math/smoke/SubTest.h (+1-1) 


``````````diff
diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt
index 99350d4415b39..1dd3f411f5842 100644
--- a/libc/test/UnitTest/CMakeLists.txt
+++ b/libc/test/UnitTest/CMakeLists.txt
@@ -142,6 +142,11 @@ if(LIBC_TEST_SUBPROCESS_TESTS)
       libc.include.llvm-libc-types.pid_t
       libc.include.llvm-libc-types.struct_pollfd
     )
+    if(TARGET libc.src.sys.prctl.prctl)
+      list(APPEND libc_death_test_deps
+        libc.src.sys.prctl.prctl
+      )
+    endif()
   endif()
   add_unittest_framework_library(
     LibcDeathTestExecutors
diff --git a/libc/test/UnitTest/ExecuteFunctionUnix.cpp b/libc/test/UnitTest/ExecuteFunctionUnix.cpp
index a07c92f61225c..0bc16ab672f14 100644
--- a/libc/test/UnitTest/ExecuteFunctionUnix.cpp
+++ b/libc/test/UnitTest/ExecuteFunctionUnix.cpp
@@ -27,6 +27,10 @@
 #include "src/unistd/close.h"
 #include "src/unistd/fork.h"
 #include "src/unistd/pipe.h"
+#ifdef __linux__
+#include <linux/prctl.h>
+#include "src/sys/prctl/prctl.h"
+#endif
 
 #define LIBC_IMPL LIBC_NAMESPACE
 
@@ -38,6 +42,9 @@
 #include <string.h>
 #include <sys/wait.h>
 #include <unistd.h>
+#ifdef __linux__
+#include <sys/prctl.h>
+#endif
 
 #define LIBC_IMPL
 #endif
@@ -75,6 +82,10 @@ ProcessStatus invoke_in_subprocess(FunctionCaller *func, int timeout_ms) {
   }
 
   if (!pid) {
+    LIBC_IMPL::close(pipe_fds[0]);
+#if defined(__linux__) && defined(PR_SET_DUMPABLE)
+    LIBC_IMPL::prctl(PR_SET_DUMPABLE, 0);
+#endif
     (*func)();
     delete func;
     LIBC_IMPL::exit(0);
@@ -85,15 +96,18 @@ ProcessStatus invoke_in_subprocess(FunctionCaller *func, int timeout_ms) {
   // No events requested so this call will only return after the timeout or if
   // the pipes peer was closed, signaling the process exited.
   if (LIBC_IMPL::poll(&poll_fd, 1, timeout_ms) == -1) {
+    LIBC_IMPL::close(pipe_fds[0]);
     delete func;
     return ProcessStatus::error("poll(2) failed");
   }
   // If the pipe wasn't closed by the child yet then timeout has expired.
   if (!(poll_fd.revents & POLLHUP)) {
+    LIBC_IMPL::close(pipe_fds[0]);
     LIBC_IMPL::kill(pid, SIGKILL);
     delete func;
     return ProcessStatus::timed_out_ps();
   }
+  LIBC_IMPL::close(pipe_fds[0]);
 
   int wstatus = 0;
   // Wait on the pid of the subprocess here so it gets collected by the system
diff --git a/libc/test/src/math/smoke/AddTest.h b/libc/test/src/math/smoke/AddTest.h
index 99cb025538f7d..8b2a241a9596e 100644
--- a/libc/test/src/math/smoke/AddTest.h
+++ b/libc/test/src/math/smoke/AddTest.h
@@ -135,7 +135,7 @@ class AddTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
   }
 
   void test_inexact_results(AddFunc func) {
-    func(InType(1.0), in.min_denormal);
+    [[maybe_unused]] volatile OutType res = func(InType(1.0), in.min_denormal);
     EXPECT_FP_EXCEPTION(FE_INEXACT);
   }
 
diff --git a/libc/test/src/math/smoke/DivTest.h b/libc/test/src/math/smoke/DivTest.h
index ebce775d9eabd..b1303bf2815fb 100644
--- a/libc/test/src/math/smoke/DivTest.h
+++ b/libc/test/src/math/smoke/DivTest.h
@@ -147,7 +147,7 @@ class DivTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
   }
 
   void test_inexact_results(DivFunc func) {
-    func(InType(1.0), InType(3.0));
+    [[maybe_unused]] volatile OutType res = func(InType(1.0), InType(3.0));
     EXPECT_FP_EXCEPTION(FE_INEXACT);
   }
 };
diff --git a/libc/test/src/math/smoke/MulTest.h b/libc/test/src/math/smoke/MulTest.h
index c9327b3c6e285..25a0949147a8c 100644
--- a/libc/test/src/math/smoke/MulTest.h
+++ b/libc/test/src/math/smoke/MulTest.h
@@ -137,7 +137,7 @@ class MulTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
     InFPBits x_bits = InFPBits::one();
     x_bits.set_mantissa(InFPBits::SIG_MASK);
     InType x = x_bits.get_val();
-    func(x, x);
+    [[maybe_unused]] volatile OutType res = func(x, x);
     EXPECT_FP_EXCEPTION(FE_INEXACT);
   }
 };
diff --git a/libc/test/src/math/smoke/SubTest.h b/libc/test/src/math/smoke/SubTest.h
index b1ead64e71f1c..72f596d13381e 100644
--- a/libc/test/src/math/smoke/SubTest.h
+++ b/libc/test/src/math/smoke/SubTest.h
@@ -131,7 +131,7 @@ class SubTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
   }
 
   void test_inexact_results(SubFunc func) {
-    func(InType(1.0), in.min_denormal);
+    [[maybe_unused]] volatile OutType res = func(InType(1.0), in.min_denormal);
     EXPECT_FP_EXCEPTION(FE_INEXACT);
   }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/227966


More information about the libc-commits mailing list