[llvm] [NVPTX] Add more clear error message for using invalid syncscope (PR #165737)

Durgadoss R via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 30 11:28:41 PDT 2025


================
@@ -1851,11 +1851,24 @@ NVPTX::Scope NVPTXScopes::operator[](SyncScope::ID ID) const {
 
   auto S = Scopes.find(ID);
   if (S == Scopes.end()) {
-    // TODO:
-    // - Add API to LLVMContext to get the name of a single scope.
-    // - Use that API here to print an error containing the name
-    //   of this Unknown ID.
-    report_fatal_error(formatv("Could not find scope ID={}.", int(ID)));
+    // Get the actual scope name from LLVMContext for a better error message
+    std::string scopeName = "<unknown>";
+    if (auto name = Context->getSyncScopeName(ID))
+      scopeName = name->str();
+
+    // Build list of supported syncscopes programmatically
+    std::string supportedScopes;
+    for (const auto &Entry : Scopes) {
+      if (!supportedScopes.empty())
+        supportedScopes += ", ";
+      if (auto name = Context->getSyncScopeName(Entry.first))
+        supportedScopes += name->empty() ? "<empty string>" : name->str();
+    }
----------------
durga4github wrote:

The error-reporting enhancement LGTM.

Would collecting the scopes in a small-vector and then using llvm::join (with `comma` as separator) make it simpler?



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


More information about the llvm-commits mailing list