Skip to content

Commit 907ba1b

Browse files
committed
Add global_asm tests
1 parent 4d46f54 commit 907ba1b

File tree

10 files changed

+307
-2
lines changed

10 files changed

+307
-2
lines changed

src/doc/unstable-book/src/global_asm.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ A simple usage looks like this:
2727
```rust,ignore
2828
# #![feature(global_asm)]
2929
# you also need relevant target_arch cfgs
30-
global_asm!(include_str("something_neato.s"));
30+
global_asm!(include_str!("something_neato.s"));
3131
```
3232

3333
And a more complicated usage looks like this:

src/librustc_driver/test.rs

+1
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
233233
hir::ItemStatic(..) |
234234
hir::ItemFn(..) |
235235
hir::ItemForeignMod(..) |
236+
hir::ItemGlobalAsm(..) |
236237
hir::ItemTy(..) => None,
237238

238239
hir::ItemEnum(..) |

src/libsyntax/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ pub const EXPLAIN_ASM: &'static str =
986986
"inline assembly is not stable enough for use and is subject to change";
987987

988988
pub const EXPLAIN_GLOBAL_ASM: &'static str =
989-
"module-level inline assembly is experimental and subject to change";
989+
"`global_asm!` is not stable enough for use and is subject to change";
990990

991991
pub const EXPLAIN_LOG_SYNTAX: &'static str =
992992
"`log_syntax!` is not stable enough for use and is subject to change";

src/test/codegen/foo.s

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.global foo
2+
foo:
3+
jmp baz

src/test/codegen/global_asm.rs

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-aarch64
12+
// ignore-aarch64_be
13+
// ignore-arm
14+
// ignore-armeb
15+
// ignore-avr
16+
// ignore-bpfel
17+
// ignore-bpfeb
18+
// ignore-hexagon
19+
// ignore-mips
20+
// ignore-mipsel
21+
// ignore-mips64
22+
// ignore-mips64el
23+
// ignore-msp430
24+
// ignore-powerpc64
25+
// ignore-powerpc64le
26+
// ignore-powerpc
27+
// ignore-r600
28+
// ignore-amdgcn
29+
// ignore-sparc
30+
// ignore-sparcv9
31+
// ignore-sparcel
32+
// ignore-s390x
33+
// ignore-tce
34+
// ignore-thumb
35+
// ignore-thumbeb
36+
// ignore-xcore
37+
// ignore-nvptx
38+
// ignore-nvptx64
39+
// ignore-le32
40+
// ignore-le64
41+
// ignore-amdil
42+
// ignore-amdil64
43+
// ignore-hsail
44+
// ignore-hsail64
45+
// ignore-spir
46+
// ignore-spir64
47+
// ignore-kalimba
48+
// ignore-shave
49+
// ignore-wasm32
50+
// ignore-wasm64
51+
// ignore-emscripten
52+
// compile-flags: -C no-prepopulate-passes
53+
54+
#![feature(global_asm)]
55+
#![crate_type = "lib"]
56+
57+
// CHECK-LABEL: foo
58+
// CHECK: module asm
59+
// this regex will capture the correct unconditional branch inst.
60+
// CHECK: module asm "{{[[:space:]]+}}jmp baz"
61+
global_asm!(r#"
62+
.global foo
63+
foo:
64+
jmp baz
65+
"#);
66+
67+
extern "C" {
68+
fn foo();
69+
}
70+
71+
// CHECK-LABEL: @baz
72+
#[no_mangle]
73+
pub unsafe extern "C" fn baz() {}
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-aarch64
12+
// ignore-aarch64_be
13+
// ignore-arm
14+
// ignore-armeb
15+
// ignore-avr
16+
// ignore-bpfel
17+
// ignore-bpfeb
18+
// ignore-hexagon
19+
// ignore-mips
20+
// ignore-mipsel
21+
// ignore-mips64
22+
// ignore-mips64el
23+
// ignore-msp430
24+
// ignore-powerpc64
25+
// ignore-powerpc64le
26+
// ignore-powerpc
27+
// ignore-r600
28+
// ignore-amdgcn
29+
// ignore-sparc
30+
// ignore-sparcv9
31+
// ignore-sparcel
32+
// ignore-s390x
33+
// ignore-tce
34+
// ignore-thumb
35+
// ignore-thumbeb
36+
// ignore-xcore
37+
// ignore-nvptx
38+
// ignore-nvptx64
39+
// ignore-le32
40+
// ignore-le64
41+
// ignore-amdil
42+
// ignore-amdil64
43+
// ignore-hsail
44+
// ignore-hsail64
45+
// ignore-spir
46+
// ignore-spir64
47+
// ignore-kalimba
48+
// ignore-shave
49+
// ignore-wasm32
50+
// ignore-wasm64
51+
// ignore-emscripten
52+
// compile-flags: -C no-prepopulate-passes
53+
54+
#![feature(global_asm)]
55+
#![crate_type = "lib"]
56+
57+
// CHECK-LABEL: foo
58+
// CHECK: module asm
59+
// CHECK: module asm "{{[[:space:]]+}}jmp baz"
60+
global_asm!(include_str!("foo.s"));
61+
62+
extern "C" {
63+
fn foo();
64+
}
65+
66+
// CHECK-LABEL: @baz
67+
#[no_mangle]
68+
pub unsafe extern "C" fn baz() {}

src/test/codegen/global_asm_x2.rs

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-aarch64
12+
// ignore-aarch64_be
13+
// ignore-arm
14+
// ignore-armeb
15+
// ignore-avr
16+
// ignore-bpfel
17+
// ignore-bpfeb
18+
// ignore-hexagon
19+
// ignore-mips
20+
// ignore-mipsel
21+
// ignore-mips64
22+
// ignore-mips64el
23+
// ignore-msp430
24+
// ignore-powerpc64
25+
// ignore-powerpc64le
26+
// ignore-powerpc
27+
// ignore-r600
28+
// ignore-amdgcn
29+
// ignore-sparc
30+
// ignore-sparcv9
31+
// ignore-sparcel
32+
// ignore-s390x
33+
// ignore-tce
34+
// ignore-thumb
35+
// ignore-thumbeb
36+
// ignore-xcore
37+
// ignore-nvptx
38+
// ignore-nvptx64
39+
// ignore-le32
40+
// ignore-le64
41+
// ignore-amdil
42+
// ignore-amdil64
43+
// ignore-hsail
44+
// ignore-hsail64
45+
// ignore-spir
46+
// ignore-spir64
47+
// ignore-kalimba
48+
// ignore-shave
49+
// ignore-wasm32
50+
// ignore-wasm64
51+
// ignore-emscripten
52+
// compile-flags: -C no-prepopulate-passes
53+
54+
#![feature(global_asm)]
55+
#![crate_type = "lib"]
56+
#[no_std]
57+
58+
// CHECK-LABEL: foo
59+
// CHECK: module asm
60+
// CHECK: module asm "{{[[:space:]]+}}jmp baz"
61+
// any other global_asm will be appended to this first block, so:
62+
// CHECK-LABEL: bar
63+
// CHECK: module asm "{{[[:space:]]+}}jmp quux"
64+
global_asm!(r#"
65+
.global foo
66+
foo:
67+
jmp baz
68+
"#);
69+
70+
extern "C" {
71+
fn foo();
72+
}
73+
74+
// CHECK-LABEL: @baz
75+
#[no_mangle]
76+
pub unsafe extern "C" fn baz() {}
77+
78+
// no checks here; this has been appended to the first occurrence
79+
global_asm!(r#"
80+
.global bar
81+
bar:
82+
jmp quux
83+
"#);
84+
85+
extern "C" {
86+
fn bar();
87+
}
88+
89+
#[no_mangle]
90+
pub unsafe extern "C" fn quux() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// gate-test-global_asm
12+
13+
global_asm!(""); //~ ERROR `global_asm!` is not stable
14+
15+
fn main() {}

src/test/run-pass/empty_global_asm.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(global_asm)]
12+
13+
#[cfg(target_arch = "x86")]
14+
global_asm!("");
15+
16+
#[cfg(target_arch = "x86_64")]
17+
global_asm!("");
18+
19+
#[cfg(target_arch = "arm")]
20+
global_asm!("");
21+
22+
#[cfg(target_arch = "aarch64")]
23+
global_asm!("");
24+
25+
#[cfg(target_arch = "mips")]
26+
global_asm!("");
27+
28+
fn main() {}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(global_asm)]
12+
13+
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
14+
global_asm!(r#"
15+
.global foo
16+
foo:
17+
jmp baz
18+
"#);
19+
20+
extern {
21+
fn foo();
22+
}
23+
24+
#[no_mangle]
25+
pub extern fn baz() {}
26+
27+
fn main() {}

0 commit comments

Comments
 (0)