From f90a7631a10d7dcc1427bfda85f66c539c50af5d Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Mon, 24 Feb 2025 16:25:19 -0800 Subject: 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 --- source/slang/slang-ir-ssa.cpp | 2 ++ ...nitialized-variable-name-in-error-message.slang | 37 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/diagnostics/uninitialized-variable-name-in-error-message.slang diff --git a/source/slang/slang-ir-ssa.cpp b/source/slang/slang-ir-ssa.cpp index d57d8548e..789ca4796 100644 --- a/source/slang/slang-ir-ssa.cpp +++ b/source/slang/slang-ir-ssa.cpp @@ -694,6 +694,7 @@ IRInst* readVarRec(ConstructSSAContext* context, SSABlockInfo* blockInfo, IRVar* auto type = var->getDataType()->getValueType(); val = blockInfo->builder.emitUndefined(type); + cloneRelevantDecorations(var, val); } else if (!multiplePreds) { @@ -776,6 +777,7 @@ IRInst* readVar(ConstructSSAContext* context, SSABlockInfo* blockInfo, IRVar* va // auto type = var->getDataType()->getValueType(); val = blockInfo->builder.emitUndefined(type); + cloneRelevantDecorations(var, val); writeVar(context, blockInfo, var, val); return val; } diff --git a/tests/diagnostics/uninitialized-variable-name-in-error-message.slang b/tests/diagnostics/uninitialized-variable-name-in-error-message.slang new file mode 100644 index 000000000..6e356e793 --- /dev/null +++ b/tests/diagnostics/uninitialized-variable-name-in-error-message.slang @@ -0,0 +1,37 @@ +//TEST:SIMPLE(filecheck=CHK): + +// Test if the variable name is a part of the error message +// when it is used inside of for-loop + +RWStructuredBuffer gInput; +RWStructuredBuffer outputBuffer; + +//CHK-DAG: ([[#@LINE+1]]): warning 41016: use of uninitialized variable 'a' +float func1() { float a; return a; } + +//CHK-DAG: ([[#@LINE+1]]): warning 41016: use of uninitialized variable 'b' +float func2() { float b; return b; } + +int test(int inVal) +{ + return inVal; +} + +[Shader("compute")] +[NumThreads(4, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + int tid = dispatchThreadID.x; + int inVal1; // intentionally uninitialized + int inVal2; // intentionally uninitialized + + for (int i = 0; i <2; ++i) + { + // CHK-DAG: ([[#@LINE+1]]): warning 41016: use of uninitialized variable 'inVal1' + int outVal = test(inVal1); + + // CHK-DAG: ([[#@LINE+1]]): warning 41016: use of uninitialized variable 'inVal2' + outVal += test(inVal2); + outputBuffer[tid] = outVal; + } +} -- cgit v1.2.3