Skip to content

Commit adb2dc7

Browse files
authored
[SPIR-V] Remove incorrect assert from Decl mapper (microsoft#5884)
Fixes microsoft#5859
1 parent a56078a commit adb2dc7

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,12 @@ SpirvDebugGlobalVariable *DeclResultIdMapper::createDebugGlobalVariable(
10151015
SpirvVariable *
10161016
DeclResultIdMapper::createFileVar(const VarDecl *var,
10171017
llvm::Optional<SpirvInstruction *> init) {
1018+
// In the case of template specialization, the same VarDecl node in the AST
1019+
// may be traversed more than once.
1020+
if (astDecls[var].instr != nullptr) {
1021+
return cast<SpirvVariable>(astDecls[var].instr);
1022+
}
1023+
10181024
const auto type = getTypeOrFnRetType(var);
10191025
const auto loc = var->getLocation();
10201026
const auto name = var->getName();
@@ -1025,8 +1031,6 @@ DeclResultIdMapper::createFileVar(const VarDecl *var,
10251031
bool isAlias = false;
10261032
(void)getTypeAndCreateCounterForPotentialAliasVar(var, &isAlias);
10271033
varInstr->setContainsAliasComponent(isAlias);
1028-
1029-
assert(astDecls[var].instr == nullptr);
10301034
astDecls[var].instr = varInstr;
10311035

10321036
createDebugGlobalVariable(varInstr, type, loc, name);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %dxc -T cs_6_7 -E main -fcgl %s -spirv | FileCheck %s
2+
3+
// CHECK: %bool_type = OpTypeStruct
4+
template<bool val>
5+
struct bool_type
6+
{
7+
static const bool value = val;
8+
};
9+
10+
template<>
11+
struct bool_type<false>
12+
{
13+
static const bool value = false;
14+
};
15+
16+
[numthreads(1, 1, 1)]
17+
void main(uint3 invocationID : SV_DispatchThreadID)
18+
{
19+
// CHECK: OpStore %truthVal %true
20+
bool_type<true> trueType;
21+
bool truthVal = trueType.value;
22+
23+
// CHECK: OpStore %falseVal %false
24+
bool_type<false> falseType;
25+
bool falseVal = falseType.value;
26+
}

0 commit comments

Comments
 (0)