Skip to content

Conversation

@cjappl
Copy link
Contributor

@cjappl cjappl commented Jul 26, 2025

Introduce the test from #146120

For future readers of this PR, if this test causes a segfault please comment out the line indicated by the comment (or revert this entire commit).

My plan is to commit this, see if any test runners fail, then submit the fix in a follow on.

I cannot repro this bug on my machine so I need some confirmation of the bug being fixed as it is submitted.

@llvmbot
Copy link
Member

llvmbot commented Jul 26, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Chris Apple (cjappl)

Changes

Introduce the test from #146120

For future readers of this PR, if this test causes a segfault please comment out the line indicated by the comment (or revert this entire commit).

My plan is to commit this, see if any test runners fail, then submit the fix in a follow on.

I cannot repro this bug on my machine so I need some confirmation of the bug being fixed as it is submitted.


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

1 Files Affected:

  • (added) compiler-rt/test/rtsan/pthread_cond_wait.cpp (+46)
diff --git a/compiler-rt/test/rtsan/pthread_cond_wait.cpp b/compiler-rt/test/rtsan/pthread_cond_wait.cpp
new file mode 100644
index 0000000000000..915ec07228554
--- /dev/null
+++ b/compiler-rt/test/rtsan/pthread_cond_wait.cpp
@@ -0,0 +1,46 @@
+// RUN: %clangxx -fsanitize=realtime %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+
+// UNSUPPORTED: ios
+
+// Intent: Ensures that pthread_cond_signal does not segfault under rtsan
+// See issue #146120
+
+#include <condition_variable>
+#include <future>
+#include <mutex>
+#include <thread>
+
+#include <iostream>
+
+int main() {
+  std::cout << "Entry to main!" << std::endl;
+  std::mutex mut;
+  std::condition_variable cv;
+  bool go{false};
+
+  const auto fut = std::async(std::launch::async, [&] {
+    std::this_thread::sleep_for(std::chrono::milliseconds(100));
+    {
+      std::unique_lock<std::mutex> lock(mut);
+      go = true;
+    }
+    cv.notify_one();
+  });
+
+  std::unique_lock<std::mutex> lock(mut);
+  // normal wait is fine
+  // cv.wait(lock, [&] { return go; });
+  // but timed wait could segfault
+
+  // NOTE: If this test segfaults on a test runner, please comment
+  //       out this line and submit the patch.
+  //       I will follow up with a fix of the underlying problem,
+  //       but first I need to understand if it fails a test runner
+  cv.wait_for(lock, std::chrono::milliseconds(200), [&] { return go; });
+
+  std::cout << "Exit from main!" << std::endl;
+}
+
+// CHECK: Entry to main!
+// CHECK-NEXT: Exit from main!

@cjappl cjappl merged commit b60aed6 into llvm:main Jul 26, 2025
12 checks passed
@cjappl cjappl deleted the cjappl/pthread_cond_wait branch July 26, 2025 20:33
@cjappl
Copy link
Contributor Author

cjappl commented Jul 26, 2025

The good news is this DOES cause at least one test runner failure in the same mode as the reported issue:

https://lab.llvm.org/buildbot/#/builders/208/builds/3123

I will disable this test until the fix is ready.

cjappl added a commit that referenced this pull request Jul 26, 2025
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Jul 28, 2025
Introduce the test from
llvm#146120

For future readers of this PR, if this test causes a segfault please
comment out the line indicated by the comment (or revert this entire
commit).

My plan is to commit this, see if any test runners fail, then submit the
fix in a follow on.

I cannot repro this bug on my machine so I need some confirmation of the
bug being fixed as it is submitted.
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants