Skip to content

Commit bbb3679

Browse files
[SPIRV] Fix compilation error 'use of parameter from containing function' when building PR #106429 with gcc (#109924)
It appears that PR #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.
1 parent f1bbabd commit bbb3679

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

llvm/lib/Target/SPIRV/SPIRVUtils.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -254,26 +254,27 @@ SPIRV::MemorySemantics::MemorySemantics getMemSemantics(AtomicOrdering Ord) {
254254
}
255255

256256
SPIRV::Scope::Scope getMemScope(LLVMContext &Ctx, SyncScope::ID Id) {
257-
static const struct {
258-
// Named by
259-
// https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_scope_id.
260-
// We don't need aliases for Invocation and CrossDevice, as we already have
261-
// them covered by "singlethread" and "" strings respectively (see
262-
// implementation of LLVMContext::LLVMContext()).
263-
llvm::SyncScope::ID SubGroup = Ctx.getOrInsertSyncScopeID("subgroup");
264-
llvm::SyncScope::ID WorkGroup = Ctx.getOrInsertSyncScopeID("workgroup");
265-
llvm::SyncScope::ID Device = Ctx.getOrInsertSyncScopeID("device");
266-
} SSIDs{};
257+
// Named by
258+
// https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_scope_id.
259+
// We don't need aliases for Invocation and CrossDevice, as we already have
260+
// them covered by "singlethread" and "" strings respectively (see
261+
// implementation of LLVMContext::LLVMContext()).
262+
static const llvm::SyncScope::ID SubGroup =
263+
Ctx.getOrInsertSyncScopeID("subgroup");
264+
static const llvm::SyncScope::ID WorkGroup =
265+
Ctx.getOrInsertSyncScopeID("workgroup");
266+
static const llvm::SyncScope::ID Device =
267+
Ctx.getOrInsertSyncScopeID("device");
267268

268269
if (Id == llvm::SyncScope::SingleThread)
269270
return SPIRV::Scope::Invocation;
270271
else if (Id == llvm::SyncScope::System)
271272
return SPIRV::Scope::CrossDevice;
272-
else if (Id == SSIDs.SubGroup)
273+
else if (Id == SubGroup)
273274
return SPIRV::Scope::Subgroup;
274-
else if (Id == SSIDs.WorkGroup)
275+
else if (Id == WorkGroup)
275276
return SPIRV::Scope::Workgroup;
276-
else if (Id == SSIDs.Device)
277+
else if (Id == Device)
277278
return SPIRV::Scope::Device;
278279
return SPIRV::Scope::CrossDevice;
279280
}

0 commit comments

Comments
 (0)