Skip to content

Commit

Permalink
Fix a bug on default initialization of interface typed value. (#4249)
Browse files Browse the repository at this point in the history
* Fix a bug on default initialization of interface typed value.

* Fix.
  • Loading branch information
csyonghe authored Jun 1, 2024
1 parent febbeb1 commit a5cdb57
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions source/slang/slang-lower-to-ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4413,6 +4413,10 @@ struct ExprLoweringVisitorBase : public ExprVisitor<Derived, LoweredValInfo>
{
return LoweredValInfo::simple(getBuilder()->getIntValue(irType, 0));
}
else if (declRef.as<InterfaceDecl>())
{
return LoweredValInfo::simple(getBuilder()->emitDefaultConstruct(irType));
}
else if (auto aggTypeDeclRef = declRef.as<AggTypeDecl>())
{
List<IRInst*> args;
Expand Down
32 changes: 32 additions & 0 deletions tests/language-feature/interfaces/zero-init-interface.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Test that we can zero-init a struct with interface typed member.

//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUFFER): -shaderobj

//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<int> outputBuffer;

interface IFoo
{
int method();
}

//TEST_INPUT: type_conformance Impl1:IFoo = 0
struct Impl1 : IFoo
{
int data;
int method() { return data + 1; }
}

struct MyType
{
IFoo foo;
}


[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
{
MyType t = {};
// BUFFER: 1
outputBuffer[0] = t.foo.method();
}

0 comments on commit a5cdb57

Please sign in to comment.