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

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 25 02:06:20 PDT 2024


Author: Vyacheslav Levytskyy
Date: 2024-09-25T11:06:17+02:00
New Revision: bbb3679ad8e5a6d2ed6432a8171465eadf9f73f8

URL: https://github.com/llvm/llvm-project/commit/bbb3679ad8e5a6d2ed6432a8171465eadf9f73f8
DIFF: https://github.com/llvm/llvm-project/commit/bbb3679ad8e5a6d2ed6432a8171465eadf9f73f8.diff

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

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 using static const variables
instead.

Added: 
    

Modified: 
    llvm/lib/Target/SPIRV/SPIRVUtils.cpp

Removed: 
    


################################################################################
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;
 }


        


More information about the llvm-commits mailing list