Skip to content

[CPU] Wrong codegen when passing struct with interface-typed field by value to a function #10394

@jvepsalainen-nv

Description

@jvepsalainen-nv

Issue Description

Passing a struct that contains an interface-typed field by value to a function generates incorrect code on the CPU backend. The generated C++ code attempts to call an interface method on a Vector<uint32_t, 2> (the witness table ID) instead of on the unpacked existential value.

Reproducer Code

[anyValueSize(8)]
interface IFoo
{
    int getValue();
}

struct ImplA : IFoo
{
    int v;
    int getValue() { return v; }
}

struct Params
{
    IFoo foo;
    int scale;
}

int dispatch(Params p)
{
    return p.foo.getValue() * p.scale;
}

ConstantBuffer<Params> gParams;
RWStructuredBuffer<int> outputBuffer;

[numthreads(1, 1, 1)]
void computeMain()
{
    outputBuffer[0] = dispatch(gParams);
}

Command:

slangc -target cpp -stage compute -entry computeMain -conformance "ImplA:IFoo=0" test.slang

Expected Behavior

The function dispatch(Params p) should correctly unpack the existential field p.foo, dispatch getValue(), and return the scaled result.

Actual Behavior

The generated C++ code produces compilation errors:

error: member reference type 'Vector<uint32_t, 2>' is not a pointer; did you mean to use '.'?
error: no member named 'IFoo_getValue_0' in 'Vector<unsigned int, 2>'

Accessing gParams.foo.getValue() directly (without passing through a function) works correctly.

Test Plan

Enable the DISABLED tests in #10393 once this is fixed.

Metadata

Metadata

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions