[llvm] [SPIRV] Fix compilation error 'use of parameter from containing function' when building PR #106429 with gcc (PR #109924)
Vyacheslav Levytskyy via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 25 01:13:14 PDT 2024
https://github.com/VyacheslavLevytskyy created https://github.com/llvm/llvm-project/pull/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 use static const variables.
>From 15f0ef13a59e131724d907b00b2e1a4930ae009b Mon Sep 17 00:00:00 2001
From: "Levytskyy, Vyacheslav" <vyacheslav.levytskyy at intel.com>
Date: Wed, 25 Sep 2024 01:07:28 -0700
Subject: [PATCH 1/2] fix compilation error 'use of parameter from containing
function' when building with gcc
---
llvm/lib/Target/SPIRV/SPIRVUtils.cpp | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
index aec144f6f05861..ddcc183072e0f5 100644
--- a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
@@ -254,26 +254,24 @@ 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()).
+ llvm::SyncScope::ID SubGroup = Ctx.getOrInsertSyncScopeID("subgroup");
+ llvm::SyncScope::ID WorkGroup = Ctx.getOrInsertSyncScopeID("workgroup");
+ 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;
}
>From de8acf86db6ea1254731bea8f3d516bad7821bdd Mon Sep 17 00:00:00 2001
From: "Levytskyy, Vyacheslav" <vyacheslav.levytskyy at intel.com>
Date: Wed, 25 Sep 2024 01:12:48 -0700
Subject: [PATCH 2/2] static const
---
llvm/lib/Target/SPIRV/SPIRVUtils.cpp | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
index ddcc183072e0f5..a8016d42b0154f 100644
--- a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
@@ -259,9 +259,12 @@ SPIRV::Scope::Scope getMemScope(LLVMContext &Ctx, SyncScope::ID 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");
+ 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;
More information about the llvm-commits
mailing list