Skip to content

Commit

Permalink
Add load paths to return value check (shader-slang#5042)
Browse files Browse the repository at this point in the history
  • Loading branch information
venkataram-nv authored Sep 10, 2024
1 parent 170558c commit d9fc7bc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions source/slang/slang-ir-use-uninitialized-values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ namespace Slang
IRInst* user = use->getUser();
if (as<IRReturn>(user))
return true;

// Loading from a Ptr type should be
// treated as an aliased path to any return
IRLoad *load = as<IRLoad>(user);
if (load && isReturnedValue(load))
return true;
}
return false;
}
Expand Down
24 changes: 24 additions & 0 deletions tests/diagnostics/uninitialized-struct-from-constructor.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//TEST:SIMPLE(filecheck=CHK): -target spirv

struct TangentSpace
{
static const float3 localNormal = {0, 1, 0};

float4x4 tangentTransform;
float3 geometryNormal;

__init(in float3 normal, in float3 inRay)
{
// Should not warn here
tangentTransform = getMatrix(normal, inRay);
geometryNormal = localNormal;
}

float4x4 getMatrix(in float3 normal, in float3 inRay)
{
return float4x4(0.0f);
}
}

//CHK-NOT: warning 41020
//CHK-NOT: warning 41021

0 comments on commit d9fc7bc

Please sign in to comment.