[llvm] [PlaceSafepoints] Report usage error instead of asserting on invalid gc.safepoint_poll (PR #205520)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 24 03:05:24 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Gustas Rove (TheMixas)

<details>
<summary>Changes</summary>

When opt runs place-safepoints on valid IR that needs a safepoint poll but does not define a valid gc.safepoint_poll, InsertSafepointPoll asserted and crashed. Since this is reachable from user input, replace the precondition asserts with reportFatalUsageError so the tool reports a clean error and exits instead of crashing. These now report in all builds, not only assertions-enabled builds.

The missing-function path has a regression test; the wrong-type and empty-function paths are handled the same way.

Fixes #<!-- -->191975

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


2 Files Affected:

- (modified) llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp (+8-5) 
- (added) llvm/test/Transforms/PlaceSafepoints/missing-safepoint-poll.ll (+7) 


``````````diff
diff --git a/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp b/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp
index 44600acf5b418..85ab765d7b737 100644
--- a/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp
+++ b/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp
@@ -629,11 +629,14 @@ InsertSafepointPoll(BasicBlock::iterator InsertBefore,
   // path call - where we need to insert a safepoint (parsepoint).
 
   auto *F = M->getFunction(GCSafepointPollName);
-  assert(F && "gc.safepoint_poll function is missing");
-  assert(F->getFunctionType() ==
-             FunctionType::get(Type::getVoidTy(M->getContext()), false) &&
-         "gc.safepoint_poll declared with wrong type");
-  assert(!F->empty() && "gc.safepoint_poll must be a non-empty function");
+  if (!F) {
+    reportFatalUsageError("gc.safepoint_poll function is missing");
+  } else if (F->getFunctionType() !=
+             FunctionType::get(Type::getVoidTy(M->getContext()), false)) {
+    reportFatalUsageError("gc.safepoint_poll declared with wrong type");
+  } else if (F->empty()) {
+    reportFatalUsageError("gc.safepoint_poll must be a non-empty function");
+  }
   CallInst *PollCall = CallInst::Create(F, "", InsertBefore);
 
   // Record some information about the call site we're replacing
diff --git a/llvm/test/Transforms/PlaceSafepoints/missing-safepoint-poll.ll b/llvm/test/Transforms/PlaceSafepoints/missing-safepoint-poll.ll
new file mode 100644
index 0000000000000..5a7d5d4cc5b58
--- /dev/null
+++ b/llvm/test/Transforms/PlaceSafepoints/missing-safepoint-poll.ll
@@ -0,0 +1,7 @@
+; RUN: not opt < %s -S -passes=place-safepoints 2>&1 | FileCheck %s
+; CHECK: LLVM ERROR: gc.safepoint_poll function is missing
+
+define void @test_libcall() gc "statepoint-example" {
+entry:
+  ret void
+}
\ No newline at end of file

``````````

</details>


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


More information about the llvm-commits mailing list