Skip to content

Commit cb45688

Browse files
committed
Clone name hint decoration when emiting Undefined
When emiting "Undefined", we lost the information of where it was synthasized from. This prevents us from providing more helpful error messages. The issue was the when we handle "IRLoop", the inputs parameters to the Phi didn't clone the name hint decoration. This commit clones them when emiting "Undefined".
1 parent 9580e31 commit cb45688

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

source/slang/slang-ir-ssa.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ IRInst* readVarRec(ConstructSSAContext* context, SSABlockInfo* blockInfo, IRVar*
694694

695695
auto type = var->getDataType()->getValueType();
696696
val = blockInfo->builder.emitUndefined(type);
697+
cloneRelevantDecorations(var, val);
697698
}
698699
else if (!multiplePreds)
699700
{
@@ -776,6 +777,7 @@ IRInst* readVar(ConstructSSAContext* context, SSABlockInfo* blockInfo, IRVar* va
776777
//
777778
auto type = var->getDataType()->getValueType();
778779
val = blockInfo->builder.emitUndefined(type);
780+
cloneRelevantDecorations(var, val);
779781
writeVar(context, blockInfo, var, val);
780782
return val;
781783
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//TEST:SIMPLE(filecheck=CHK):
2+
3+
// Test if the variable name is a part of the error message
4+
// when it is used inside of for-loop
5+
6+
RWStructuredBuffer<float> gInput;
7+
RWStructuredBuffer<float> outputBuffer;
8+
9+
int test(int inVal)
10+
{
11+
return inVal;
12+
}
13+
14+
[Shader("compute")]
15+
[NumThreads(4, 1, 1)]
16+
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
17+
{
18+
int tid = dispatchThreadID.x;
19+
int inVal; // = tid; // intentionally uninitialized
20+
21+
for (int i = 0; i <2; ++i)
22+
{
23+
// CHK: ([[#@LINE+1]]): warning 41016: use of uninitialized variable 'inVal'
24+
int outVal = test(inVal);
25+
outputBuffer[tid] = outVal;
26+
}
27+
}

0 commit comments

Comments
 (0)