[llvm] [SPIRV] Fix compilation error 'use of parameter from containing function' when building PR #106429 with gcc (PR #109924)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 25 01:13:49 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-spir-v

Author: Vyacheslav Levytskyy (VyacheslavLevytskyy)

<details>
<summary>Changes</summary>

It appears that PR https://github.com/llvm/llvm-project/pull/106429 introduced an issue for builds with SPIRV Backend target when building with gcc, e.g.:
```
/llvm-project/llvm/lib/Target/SPIRV/SPIRVUtils.cpp:263:36: error: use of parameter from containing function
  263 |     llvm::SyncScope::ID SubGroup = Ctx.getOrInsertSyncScopeID("subgroup");
      |                                    ^~~
/llvm-project/llvm/lib/Target/SPIRV/SPIRVUtils.cpp:256:46: note: ‘llvm::LLVMContext& Ctx’ declared here
  256 | SPIRV::Scope::Scope getMemScope(LLVMContext &Ctx, SyncScope::ID Id) {
```
This PR fixes this by removing struct and use static const variables.



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


1 Files Affected:

- (modified) llvm/lib/Target/SPIRV/SPIRVUtils.cpp (+14-13) 


``````````diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
index aec144f6f05861..a8016d42b0154f 100644
--- a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
@@ -254,26 +254,27 @@ SPIRV::MemorySemantics::MemorySemantics getMemSemantics(AtomicOrdering Ord) {
 }
 
 SPIRV::Scope::Scope getMemScope(LLVMContext &Ctx, SyncScope::ID Id) {
-  static const struct {
-    // Named by
-    // https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_scope_id.
-    // We don't need aliases for Invocation and CrossDevice, as we already have
-    // them covered by "singlethread" and "" strings respectively (see
-    // implementation of LLVMContext::LLVMContext()).
-    llvm::SyncScope::ID SubGroup = Ctx.getOrInsertSyncScopeID("subgroup");
-    llvm::SyncScope::ID WorkGroup = Ctx.getOrInsertSyncScopeID("workgroup");
-    llvm::SyncScope::ID Device = Ctx.getOrInsertSyncScopeID("device");
-  } SSIDs{};
+  // Named by
+  // https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_scope_id.
+  // We don't need aliases for Invocation and CrossDevice, as we already have
+  // them covered by "singlethread" and "" strings respectively (see
+  // implementation of LLVMContext::LLVMContext()).
+  static const llvm::SyncScope::ID SubGroup =
+      Ctx.getOrInsertSyncScopeID("subgroup");
+  static const llvm::SyncScope::ID WorkGroup =
+      Ctx.getOrInsertSyncScopeID("workgroup");
+  static const llvm::SyncScope::ID Device =
+      Ctx.getOrInsertSyncScopeID("device");
 
   if (Id == llvm::SyncScope::SingleThread)
     return SPIRV::Scope::Invocation;
   else if (Id == llvm::SyncScope::System)
     return SPIRV::Scope::CrossDevice;
-  else if (Id == SSIDs.SubGroup)
+  else if (Id == SubGroup)
     return SPIRV::Scope::Subgroup;
-  else if (Id == SSIDs.WorkGroup)
+  else if (Id == WorkGroup)
     return SPIRV::Scope::Workgroup;
-  else if (Id == SSIDs.Device)
+  else if (Id == Device)
     return SPIRV::Scope::Device;
   return SPIRV::Scope::CrossDevice;
 }

``````````

</details>


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


More information about the llvm-commits mailing list