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

No error when using params in @naked functions #4689

Open
MrSmith33 opened this issue Jun 21, 2024 · 4 comments
Open

No error when using params in @naked functions #4689

MrSmith33 opened this issue Jun 21, 2024 · 4 comments

Comments

@MrSmith33
Copy link
Contributor

On x86_64: https://godbolt.org/z/dEaaqPh7v

import ldc.attributes;
import ldc.llvmasm;

@naked long spawnLinuxThread1(void* data) {
    return __asm!long("syscall",
        "={eax}, {rax}, {rdi}, {rsi}",
        56, 0x50f00, data);
}

produces:

mov     rsi, qword ptr [rdi]
mov     eax, 56
mov     edi, 331520
syscall
ret

instead of

mov     rsi, rdi
mov     eax, 56
mov     edi, 331520
syscall
ret

Changing void* to ulong causes LLVM ERROR:

Invalid bitcast
  %2 = bitcast i64 %0 to ptr, !dbg !7
LLVM ERROR: Broken module found, compilation aborted!

Same happens on arm64: https://godbolt.org/z/7Eb3Pqabd

@JohanEngelen
Copy link
Member

JohanEngelen commented Jun 22, 2024

This bug is due to using @naked and the resulting IR generation not dealing with that properly. With @naked we load from passed parameter address instead of the usual loading from the temp storage address (where the passed parameter is stored).

Compare the output of this code with/without @naked:

//@naked
size_t foo(void* data) {
    return cast(size_t) data;
}

@MrSmith33
Copy link
Contributor Author

I see. Should I expect this to be fixed?

@JohanEngelen
Copy link
Member

Not sure how much we want/should support with @naked.

@JohanEngelen
Copy link
Member

I do consider it a bug. If we don't support this usage / it's buggy, then it's better to emit a compile error for it than to leave it unfixed.

@kinke kinke changed the title Unexpected dereference produced for inline assembly for pointer input No error when using params in @naked functions Jul 1, 2024
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

No branches or pull requests

2 participants