diff options
| author | Yong He <yonghe@outlook.com> | 2024-05-31 22:08:27 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-31 22:08:27 -0700 |
| commit | a5cdb574b391e8adce1ce71e1e7ab3a20ce15818 (patch) | |
| tree | f853363b68186888d7478da0e89cb38ee1daab2e | |
| parent | febbeb140bea65180ff4be9b164207c582235d4d (diff) | |
Fix a bug on default initialization of interface typed value. (#4249)
* Fix a bug on default initialization of interface typed value.
* Fix.
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 4 | ||||
| -rw-r--r-- | tests/language-feature/interfaces/zero-init-interface.slang | 32 |
2 files changed, 36 insertions, 0 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 8a8d235f5..80e73fe2b 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -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; diff --git a/tests/language-feature/interfaces/zero-init-interface.slang b/tests/language-feature/interfaces/zero-init-interface.slang new file mode 100644 index 000000000..ee38f4d83 --- /dev/null +++ b/tests/language-feature/interfaces/zero-init-interface.slang @@ -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(); +} |
