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

Alex MacLean via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 30 13:33:00 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();
+    }
----------------
AlexMaclean wrote:

Agreed, better yet use StringRefs as well and just comma join the list as part of formatv https://llvm.org/docs/ProgrammersManual.html#formatv-examples

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


More information about the llvm-commits mailing list