File tree Expand file tree Collapse file tree 2 files changed +89
-9
lines changed
compiler/rustc_codegen_llvm/src Expand file tree Collapse file tree 2 files changed +89
-9
lines changed Original file line number Diff line number Diff line change @@ -384,15 +384,19 @@ impl<'tcx> AsmCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
384
384
) {
385
385
let asm_arch = self . tcx . sess . asm_arch . unwrap ( ) ;
386
386
387
- // Default to Intel syntax on x86
388
- let intel_syntax = matches ! ( asm_arch, InlineAsmArch :: X86 | InlineAsmArch :: X86_64 )
389
- && !options. contains ( InlineAsmOptions :: ATT_SYNTAX ) ;
390
-
391
387
// Build the template string
392
388
let mut template_str = String :: new ( ) ;
393
- if intel_syntax {
394
- template_str. push_str ( ".intel_syntax\n " ) ;
389
+
390
+ // Select the assembly syntax. On non-X86 platforms att is used by default, on X86 we use
391
+ // intel by default, unless `att_syntax` is explicitly specified.
392
+ if matches ! ( asm_arch, InlineAsmArch :: X86 | InlineAsmArch :: X86_64 ) {
393
+ if options. contains ( InlineAsmOptions :: ATT_SYNTAX ) {
394
+ template_str. push_str ( ".att_syntax\n " )
395
+ } else {
396
+ template_str. push_str ( ".intel_syntax\n " )
397
+ }
395
398
}
399
+
396
400
for piece in template {
397
401
match * piece {
398
402
InlineAsmTemplatePiece :: String ( ref s) => template_str. push_str ( s) ,
@@ -431,9 +435,8 @@ impl<'tcx> AsmCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
431
435
}
432
436
}
433
437
}
434
- if intel_syntax {
435
- template_str. push_str ( "\n .att_syntax\n " ) ;
436
- }
438
+
439
+ // For LLVM we don't need to reset the assembly syntax here.
437
440
438
441
llvm:: append_module_inline_asm ( self . llmod , template_str. as_bytes ( ) ) ;
439
442
}
Original file line number Diff line number Diff line change
1
+ //@ assembly-output: emit-asm
2
+ //@ revisions: att intel
3
+ //@ [att] compile-flags: -Cllvm-args=-x86-asm-syntax=att
4
+ //@ [intel] compile-flags: -Cllvm-args=-x86-asm-syntax=intel
5
+ //@ only-x86_64
6
+
7
+ #![ crate_type = "lib" ]
8
+
9
+ // CHECK-LABEL: naked_att:
10
+ // intel-CHECK: mov rax, qword ptr [rdi]
11
+ // intel-CHECK: ret
12
+ // att-CHECK: movq (%rdi), %rax
13
+ // att-CHECK: retq
14
+
15
+ #[ unsafe( naked) ]
16
+ #[ unsafe( no_mangle) ]
17
+ extern "sysv64" fn naked_att ( ) {
18
+ std:: arch:: naked_asm!(
19
+ "
20
+ movq (%rdi), %rax
21
+ retq
22
+ " ,
23
+ options( att_syntax) ,
24
+ ) ;
25
+ }
26
+
27
+ // CHECK-LABEL: naked_intel:
28
+ // intel-CHECK: mov rax, rdi
29
+ // intel-CHECK: ret
30
+ // att-CHECK: movq (%rdi), %rax
31
+ // att-CHECK: retq
32
+
33
+ #[ unsafe( naked) ]
34
+ #[ unsafe( no_mangle) ]
35
+ extern "sysv64" fn naked_intel ( ) {
36
+ std:: arch:: naked_asm!(
37
+ "
38
+ mov rax, rdi
39
+ ret
40
+ " ,
41
+ options( ) ,
42
+ ) ;
43
+ }
44
+
45
+ // CHECK-LABEL: global_att:
46
+ // intel-CHECK: mov rax, rdi
47
+ // intel-CHECK: ret
48
+ // att-CHECK: movq (%rdi), %rax
49
+ // att-CHECK: retq
50
+
51
+ core:: arch:: global_asm!(
52
+ "
53
+ .att_syntax
54
+ .globl global_att
55
+ global_att:
56
+ movq (%rdi), %rax
57
+ retq
58
+ " ,
59
+ options( att_syntax) ,
60
+ ) ;
61
+
62
+ // CHECK-LABEL: global_intel:
63
+ // intel-CHECK: mov rax, rdi
64
+ // intel-CHECK: ret
65
+ // att-CHECK: movq (%rdi), %rax
66
+ // att-CHECK: retq
67
+
68
+ core:: arch:: global_asm!(
69
+ "
70
+ .intel_syntax
71
+ .globl global_intel
72
+ global_intel:
73
+ mov rax, rdi
74
+ ret
75
+ " ,
76
+ options( ) ,
77
+ ) ;
You can’t perform that action at this time.
0 commit comments