Skip to content

Invalid code created for String member functions #11297

Description

@skiminki-nv

Issue Description

As the topic says.

Reproducer Code

RWStructuredBuffer<int64_t> output;

void computeMain()
{
    let str : String = "123";
    output[0] = str.getLength();
}
slangc -target cpp -stage compute -entry computeMain test.slang -o test.cc
g++ test.cc

Expected Behavior

Slang should generate C++ code that writes 3 in the output buffer.

Actual Behavior

Invalid C++ code generated:

void _computeMain(void* _S1, void* entryPointParams_0, void* globalParams_0)
{

    int64_t * _S2 = (&((slang_bit_cast<GlobalParams_0*>(globalParams_0))->output_0)[int(0)]);

#line 6
    int64_t _S3 = "123".getLength();    // <<<<<<<<<<< ERROR HERE

#line 6
    *_S2 = _S3;
    return;
}

Environment

  • Slang Version: commit 7369773
  • OS: Ubuntu 24.04 LTS

Additional context

This is likely related to issue #8917. Using NativeString instead of String produces code that compiles and looks correct. Due to the lack of documentation in the user guide and the standard module reference, it is unclear whether the reproducer code is correct or not. If it should work, there is probably something missing in IR lowering.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Dev OpenedbugreproducedProvided instructions confirmed to reproduce the issue
    No fields configured for Language Maturity.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions