Skip to content

Commit 2421964

Browse files
authored
[SPIRV] Add warning for initialized globals (#7448)
To be consistent with DXIL, we will start emitting a warning for extenally visible variables that have an initializer. Until now, there were silently ignored. Fixes #3950
1 parent 2a6bacd commit 2421964

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,10 @@ void SpirvEmitter::doVarDecl(const VarDecl *decl) {
20212021
// variables) belongs to the Function storage class.
20222022
if (isExternalVar(decl)) {
20232023
var = declIdMapper.createExternVar(decl);
2024+
if (decl->hasInit()) {
2025+
emitWarning("Initializer of external global will be ignored",
2026+
decl->getLocation());
2027+
}
20242028
} else {
20252029
// We already know the variable is not externally visible here. If it does
20262030
// not have local storage, it should be file scope variable.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %dxc -T cs_6_0 -E main -spirv %s 2>&1 | FileCheck %s
2+
3+
groupshared uint testing = 0;
4+
5+
[numthreads(64, 1, 1)]
6+
void main(uint local_thread_id_flat : SV_GroupIndex) {
7+
8+
InterlockedAdd(testing, 1);
9+
GroupMemoryBarrierWithGroupSync();
10+
11+
if (local_thread_id_flat == 0) {
12+
if (testing > 64) {
13+
printf("testing is %u wtf", testing);
14+
}
15+
}
16+
}
17+
18+
// CHECK: warning: Initializer of external global will be ignored
19+
// CHECK-NEXT: groupshared uint testing = 0;

0 commit comments

Comments
 (0)