Skip to content

Properly apply LLVM sret attribute #28320

@jabraham17

Description

@jabraham17

When codegening for LLVM, we do not add the sret attribute (Struct Return) to functions that return structs by ref. While LLVM seems to just handle what we give it, I have found sret is important for debug info generation. In #28318, I add the ability to call functions/methods in the debugger. However, it only works with simple types like int. When trying to return something like a string, it just doesn't work. Since we rely pretty heavily on C/C++ semantics to make the debugger work, I suspect this is due to sret being missing (AFAICT, its the last difference between Chapel debug info and C++ debug info).

While working on #28318, I tried to add sret handling. However, LLVM requires that sret only be applied to the first or second function formal, and it can only be applied once. It must either be first for a function call or for a method call where the second formal is this. It must be second for a method call where the first formal is this. For Chapels purposes, this means we cannot codegen _retArg as the last formal, it must be first or second. We can adjust return-by-ref to insert _retArg as the first formal, or maybe the second formal if we want it to come after the method token. This is going to require a bit of work, as the compiler assumes _retArg can only be the last formal in quite a few cases. Or we need to adjust --denormalize to re-order function formals after resolution and all the other passes in prep for codegen.

Another important note: Since we can only apply sret to one formal, we cannot use it on out formals. This may become relevant in the future, and I am not sure what we need to do when we get there.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions