Skip to content

Commit f90a763

Browse files
jkwak-workcsyonghe
andauthored
Clone name hint decoration when emiting Undefined (#6415)
* 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". * Adding more test case --------- Co-authored-by: Yong He <[email protected]>
1 parent 73a8d74 commit f90a763

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-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,37 @@
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+
//CHK-DAG: ([[#@LINE+1]]): warning 41016: use of uninitialized variable 'a'
10+
float func1() { float a; return a; }
11+
12+
//CHK-DAG: ([[#@LINE+1]]): warning 41016: use of uninitialized variable 'b'
13+
float func2() { float b; return b; }
14+
15+
int test(int inVal)
16+
{
17+
return inVal;
18+
}
19+
20+
[Shader("compute")]
21+
[NumThreads(4, 1, 1)]
22+
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
23+
{
24+
int tid = dispatchThreadID.x;
25+
int inVal1; // intentionally uninitialized
26+
int inVal2; // intentionally uninitialized
27+
28+
for (int i = 0; i <2; ++i)
29+
{
30+
// CHK-DAG: ([[#@LINE+1]]): warning 41016: use of uninitialized variable 'inVal1'
31+
int outVal = test(inVal1);
32+
33+
// CHK-DAG: ([[#@LINE+1]]): warning 41016: use of uninitialized variable 'inVal2'
34+
outVal += test(inVal2);
35+
outputBuffer[tid] = outVal;
36+
}
37+
}

0 commit comments

Comments
 (0)