Skip to content

Commit

Permalink
Adding separate construct delegation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
venkataram-nv committed Aug 24, 2024
1 parent 49d8e2b commit 1744146
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 42 deletions.
1 change: 0 additions & 1 deletion source/slang/slang-ir-use-uninitialized-values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ namespace Slang
{
for (auto use = inst->firstUse; use; use = use->nextUse)
{
IRInst* user = use->getUser();
InstructionUsageType usage = getInstructionUsageType(use->getUser(), inst);
if (usage == Store || usage == StoreParent)
return true;
Expand Down
46 changes: 46 additions & 0 deletions tests/diagnostics/uninitialized-fields-delegated.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//TEST:SIMPLE(filecheck=CHK): -target spirv

// Delegated constructors
struct Impl
{
float x;

__init(float val)
{
x = val;
}

__init()
{
float val = 2.0;

// Shouldn't trigger a warning here
return Impl(val);
}
}

// Calling a method from a constructor to initialize fields
struct HitInfo
{
float3 barycentrics;
uint primitiveIndex;

[[mutating]] void init(float2 hitBarycentrics, uint hitPrimitiveIndex)
{
barycentrics = { 1.0 - hitBarycentrics.x - hitBarycentrics.y, hitBarycentrics.x, hitBarycentrics.y };
primitiveIndex = hitPrimitiveIndex;
}

__init(float2 hitBarycentrics, uint hitPrimitiveIndex)
{
init(hitBarycentrics, hitPrimitiveIndex);
}

__init(BuiltInTriangleIntersectionAttributes attr)
{
init(attr.barycentrics, PrimitiveIndex());
}
}

//CHK-NOT: warning 41020
//CHK-NOT: warning 41021
41 changes: 0 additions & 41 deletions tests/diagnostics/uninitialized-fields.slang
Original file line number Diff line number Diff line change
Expand Up @@ -86,46 +86,5 @@ struct Pass
int y = 0;
}

struct Impl
{
float x;

__init(float val)
{
x = val;
}

__init()
{
float val = 2.0;

// Shouldn't trigger a warning here
return Impl(val);
}
}

// Calling a method from a constructor to initialize fields
struct HitInfo
{
float3 barycentrics;
uint primitiveIndex;

[[mutating]] void init(float2 hitBarycentrics, uint hitPrimitiveIndex)
{
barycentrics = { 1.0 - hitBarycentrics.x - hitBarycentrics.y, hitBarycentrics.x, hitBarycentrics.y };
primitiveIndex = hitPrimitiveIndex;
}

__init(float2 hitBarycentrics, uint hitPrimitiveIndex)
{
init(hitBarycentrics, hitPrimitiveIndex);
}

__init(BuiltInTriangleIntersectionAttributes attr)
{
init(attr.barycentrics, PrimitiveIndex());
}
}

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

0 comments on commit 1744146

Please sign in to comment.