From d9fc7bc9b9b12e0d7c24d9159e501271161aedeb Mon Sep 17 00:00:00 2001 From: venkataram-nv Date: Mon, 9 Sep 2024 22:03:27 -0700 Subject: Add load paths to return value check (#5042) --- source/slang/slang-ir-use-uninitialized-values.cpp | 6 ++++++ .../uninitialized-struct-from-constructor.slang | 24 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/diagnostics/uninitialized-struct-from-constructor.slang diff --git a/source/slang/slang-ir-use-uninitialized-values.cpp b/source/slang/slang-ir-use-uninitialized-values.cpp index b48dadf8d..8661ba0dc 100644 --- a/source/slang/slang-ir-use-uninitialized-values.cpp +++ b/source/slang/slang-ir-use-uninitialized-values.cpp @@ -438,6 +438,12 @@ namespace Slang IRInst* user = use->getUser(); if (as(user)) return true; + + // Loading from a Ptr type should be + // treated as an aliased path to any return + IRLoad *load = as(user); + if (load && isReturnedValue(load)) + return true; } return false; } diff --git a/tests/diagnostics/uninitialized-struct-from-constructor.slang b/tests/diagnostics/uninitialized-struct-from-constructor.slang new file mode 100644 index 000000000..e3c44dca1 --- /dev/null +++ b/tests/diagnostics/uninitialized-struct-from-constructor.slang @@ -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 \ No newline at end of file -- cgit v1.2.3