Skip to content

Inline assembly clobber formatting mismatch #34458

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

Closed
CensoredUsername opened this issue Jun 24, 2016 · 0 comments · Fixed by #34682
Closed

Inline assembly clobber formatting mismatch #34458

CensoredUsername opened this issue Jun 24, 2016 · 0 comments · Fixed by #34682
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`)

Comments

@CensoredUsername
Copy link
Contributor

CensoredUsername commented Jun 24, 2016

The rust book states that asm! clobbers should be written as "{rdx}" but when you use them as such the clobbers will be silently ignored making for some nasty bugs.

Relevant part of the book

testcase

rustc --version:

rustc 1.11.0-nightly (6dcc2c1de 2016-06-22)

rustc output

$ rustc -g main.rs -C opt-level=2
$

Relevant part of objdump:

   140001070:   48 c7 c2 01 00 00 00    mov    $0x1,%rdx
   140001077:   48 89 f0                mov    %rsi,%rax
   14000107a:   ff d0                   callq  *%rax
   14000107c:   48 89 c1                mov    %rax,%rcx
   14000107f:   48 89 d0                mov    %rdx,%rax

Relevant LLVM IR:

  %13 = tail call i64 asm sideeffect inteldialect "mov rdx, 1", "={rdx},~{dirflag},~{fpsr},~{flags}"() #8, !dbg !718, !srcloc !720
  %14 = tail call i64 asm sideeffect inteldialect "call rax", "={rax},{rax},{rcx},~{{rdx}},~{{memory}},~{{cc}},~{dirflag},~{fpsr},~{flags}"(i8* %2, i8 %12) #8, !dbg !739, !srcloc 
  %15 = tail call i64 asm sideeffect inteldialect "mov rax, rdx", "={rax},{rdx},~{dirflag},~{fpsr},~{flags}"(i64 %13) #8, !dbg !742, !srcloc !744

As we can seen in the emitted LLVM IR, the given clobbers are surrounded by {{}}. I'm not sure what effect this has, but it seems like LLVM just silently ignores them. A fix would either be to not send the extra {}'s to LLVM or to edit the documentation to reflect that clobbers should be given without surrounding {}'s. Either way, this should probably not generate invalid code silently.

@bstrie bstrie added A-docs A-inline-assembly Area: Inline assembly (`asm!(…)`) labels Jun 24, 2016
bors added a commit that referenced this issue Jul 8, 2016
Correct inline assembly clobber formatting.

Fixes the formatting for inline assembly clobbers used in the book.
As this causes llvm to silently ignore the clobber an error is also
added to catch cases in which the wrong formatting was used.
Additionally a test case is added to confirm that this error works.

This fixes #34458

Note: this is only one out of a few possible ways to fix the issue
depending on how the asm! macro formatting is wanted.

Additionally, it'd be nicer to have some kind of test or feedback
from llvm if the clobber constraints are valid, but I do not know
enough about llvm to say if or how this is possible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants