Closed
Description
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.
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.