Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String -> NativeString conversion incorrectly omitted #6034

Open
juliusikkala opened this issue Jan 8, 2025 · 0 comments · May be fixed by #6035
Open

String -> NativeString conversion incorrectly omitted #6034

juliusikkala opened this issue Jan 8, 2025 · 0 comments · May be fixed by #6035

Comments

@juliusikkala
Copy link
Contributor

NativeStrings are incorrectly assumed to be equivalent to Strings, without going through the proper constructors. This causes compilation errors in e.g. the following program:

void string_conversion(String title)
{
    NativeString c_title = NativeString(title);
    printf(c_title);
}

export __extern_cpp int main(int argc, int8_t** argv)
{
    string_conversion("asdf");
    return 0;
}

Compiled with slangc -target exe test.slang -o test:

gcc 13.3: testi.slang(3): error :  cannot convert ‘Slang::String’ to ‘const char*’
    3 | void string_conversion(String title)
      |            ^~~~~~~
      |            |
      |            Slang::String
gcc 13.3: /usr/include/x86_64-linux-gnu/bits/stdio2.h(84): note :    initializing argument 1 of ‘int printf(const char*, ...)’
   84 | printf (const char *__restrict __fmt, ...)
      |         ~~~~~~~~~~~~~~~~~~~~~~~^~~~~

The generated code looks like this:

#line 1 "test.slang"
static void string_conversion_0(String title_0)
{

#line 1
    printf(title_0);



    return;
}


#line 7
int32_t main(int32_t argc_0, int8_t * * argv_0)
{
    string_conversion_0(Slang::toTerminatedSlice("asdf"));
    return int(0);
}

I have a PR lined up for this, but I'm not 100% sure if it's the correct solution, so I made this issue to keep track of this in case the PR isn't the right way to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant