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

Rollup of 7 pull requests #95911

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a867b8d
Add a test for issue 47384
nbdd0121 Feb 9, 2022
aa8413c
Add `SymbolExportInfo`
nbdd0121 Apr 2, 2022
08b7029
Make `#[used]` considered reachable
nbdd0121 Apr 2, 2022
c34473b
Reimplement lowering of sym operands for asm! so that it also works w…
Amanieu Mar 1, 2022
c1fa773
Add codegen for global_asm! sym operands
Amanieu Mar 1, 2022
e0ed0f4
Update tests for sym support in global_asm!
Amanieu Mar 1, 2022
fefc69a
Synthesis object file for `#[used]` and exported symbols
nbdd0121 Apr 2, 2022
3730fe3
Ignore paths in temporary dir in reproducible build test
nbdd0121 Apr 2, 2022
77f610e
Note that CI tests Windows 10
ChrisDenton Apr 9, 2022
bf3ef0d
Switch to the 'normal' basic block for writing asm outputs if needed.
luqmana Apr 9, 2022
0b2f360
Update asm-may_unwind test to handle use of asm with outputs.
luqmana Apr 9, 2022
460054c
Add a note to reachable.rs about `#[used]`
nbdd0121 Apr 9, 2022
98cd818
Refactor exported_symbols and linked_symbols for code reuse
nbdd0121 Apr 10, 2022
80152ed
use `to_string` instead of `format!`
TaKO8Ki Apr 10, 2022
386ca6a
Allow usage of sudo while not accessing root
Apr 10, 2022
dfe13db
only suggest removing semicolon when expr implements trait
compiler-errors Apr 7, 2022
0ca05f1
Rollup merge of #94468 - Amanieu:global_asm_sym, r=nagisa
Dylan-DPC Apr 10, 2022
406e171
Rollup merge of #95604 - nbdd0121:used2, r=petrochenkov
Dylan-DPC Apr 10, 2022
b51979a
Rollup merge of #95671 - gimbles:master, r=Mark-Simulacrum
Dylan-DPC Apr 10, 2022
d1d8fa4
Rollup merge of #95758 - compiler-errors:issue-54771, r=estebank
Dylan-DPC Apr 10, 2022
83fe17a
Rollup merge of #95861 - ChrisDenton:windows7-support, r=Dylan-DPC
Dylan-DPC Apr 10, 2022
6d93832
Rollup merge of #95864 - luqmana:inline-asm-unwind-store-miscompile, …
Dylan-DPC Apr 10, 2022
82f9f57
Rollup merge of #95881 - TaKO8Ki:use-to-string-instead-of-format, r=c…
Dylan-DPC Apr 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update tests for sym support in global_asm!
  • Loading branch information
Amanieu committed Apr 4, 2022
commit e0ed0f4371265a6ab41a20d4d1b70b4b29e9d238
12 changes: 11 additions & 1 deletion src/test/assembly/asm/global_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@
// assembly-output: emit-asm
// compile-flags: -C llvm-args=--x86-asm-syntax=intel

#![feature(asm_const)]
#![feature(asm_const, asm_sym)]
#![crate_type = "rlib"]

use std::arch::global_asm;

#[no_mangle]
fn my_func() {}

#[no_mangle]
static MY_STATIC: i32 = 0;

// CHECK: mov eax, eax
global_asm!("mov eax, eax");
// CHECK: mov ebx, 5
global_asm!("mov ebx, {}", const 5);
// CHECK: mov ecx, 5
global_asm!("movl ${}, %ecx", const 5, options(att_syntax));
// CHECK: call my_func
global_asm!("call {}", sym my_func);
// CHECK: lea rax, [rip + MY_STATIC]
global_asm!("lea rax, [rip + {}]", sym MY_STATIC);
2 changes: 1 addition & 1 deletion src/test/ui/asm/aarch64/parse-error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() {
asm!("{}", in(reg) foo => bar);
//~^ ERROR expected one of `!`, `,`, `.`, `::`, `?`, `{`, or an operator, found `=>`
asm!("{}", sym foo + bar);
//~^ ERROR argument to `sym` must be a path expression
//~^ ERROR expected a path for argument to `sym`
asm!("", options(foo));
//~^ ERROR expected one of
asm!("", options(nomem foo));
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/asm/aarch64/parse-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ error: expected one of `!`, `,`, `.`, `::`, `?`, `{`, or an operator, found `=>`
LL | asm!("{}", in(reg) foo => bar);
| ^^ expected one of 7 possible tokens

error: argument to `sym` must be a path expression
error: expected a path for argument to `sym`
--> $DIR/parse-error.rs:31:24
|
LL | asm!("{}", sym foo + bar);
Expand Down Expand Up @@ -350,17 +350,17 @@ LL | global_asm!("{a}", a = const FOO, a = const BAR);
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {1} */"`

error: expected one of `clobber_abi`, `const`, or `options`, found `""`
error: expected one of `clobber_abi`, `const`, `options`, or `sym`, found `""`
--> $DIR/parse-error.rs:126:28
|
LL | global_asm!("", options(), "");
| ^^ expected one of `clobber_abi`, `const`, or `options`
| ^^ expected one of `clobber_abi`, `const`, `options`, or `sym`

error: expected one of `clobber_abi`, `const`, or `options`, found `"{}"`
error: expected one of `clobber_abi`, `const`, `options`, or `sym`, found `"{}"`
--> $DIR/parse-error.rs:128:30
|
LL | global_asm!("{}", const FOO, "{}", const FOO);
| ^^^^ expected one of `clobber_abi`, `const`, or `options`
| ^^^^ expected one of `clobber_abi`, `const`, `options`, or `sym`

error: asm template must be a string literal
--> $DIR/parse-error.rs:130:13
Expand Down
15 changes: 11 additions & 4 deletions src/test/ui/asm/aarch64/type-check-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#![feature(repr_simd, never_type, asm_sym)]

use std::arch::asm;
use std::arch::{asm, global_asm};

#[repr(simd)]
#[derive(Clone, Copy)]
Expand Down Expand Up @@ -39,9 +39,7 @@ fn main() {
asm!("{}", sym S);
asm!("{}", sym main);
asm!("{}", sym C);
//~^ ERROR asm `sym` operand must point to a fn or static
asm!("{}", sym x);
//~^ ERROR asm `sym` operand must point to a fn or static
//~^ ERROR invalid `sym` operand

// Register operands must be Copy

Expand Down Expand Up @@ -84,3 +82,12 @@ fn main() {
asm!("{}", in(reg) u);
}
}

// Sym operands must point to a function or static

const C: i32 = 0;
static S: i32 = 0;
global_asm!("{}", sym S);
global_asm!("{}", sym main);
global_asm!("{}", sym C);
//~^ ERROR invalid `sym` operand
34 changes: 19 additions & 15 deletions src/test/ui/asm/aarch64/type-check-2.stderr
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
error: arguments for inline assembly must be copyable
--> $DIR/type-check-2.rs:48:31
--> $DIR/type-check-2.rs:46:31
|
LL | asm!("{:v}", in(vreg) SimdNonCopy(0.0, 0.0, 0.0, 0.0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `SimdNonCopy` does not implement the Copy trait

error: cannot use value of type `[closure@$DIR/type-check-2.rs:60:28: 60:38]` for inline assembly
--> $DIR/type-check-2.rs:60:28
error: cannot use value of type `[closure@$DIR/type-check-2.rs:58:28: 58:38]` for inline assembly
--> $DIR/type-check-2.rs:58:28
|
LL | asm!("{}", in(reg) |x: i32| x);
| ^^^^^^^^^^
|
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly

error: cannot use value of type `Vec<i32>` for inline assembly
--> $DIR/type-check-2.rs:62:28
--> $DIR/type-check-2.rs:60:28
|
LL | asm!("{}", in(reg) vec![0]);
| ^^^^^^^
Expand All @@ -24,48 +24,52 @@ LL | asm!("{}", in(reg) vec![0]);
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)

error: cannot use value of type `(i32, i32, i32)` for inline assembly
--> $DIR/type-check-2.rs:64:28
--> $DIR/type-check-2.rs:62:28
|
LL | asm!("{}", in(reg) (1, 2, 3));
| ^^^^^^^^^
|
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly

error: cannot use value of type `[i32; 3]` for inline assembly
--> $DIR/type-check-2.rs:66:28
--> $DIR/type-check-2.rs:64:28
|
LL | asm!("{}", in(reg) [1, 2, 3]);
| ^^^^^^^^^
|
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly

error: cannot use value of type `fn() {main}` for inline assembly
--> $DIR/type-check-2.rs:74:31
--> $DIR/type-check-2.rs:72:31
|
LL | asm!("{}", inout(reg) f);
| ^
|
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly

error: cannot use value of type `&mut i32` for inline assembly
--> $DIR/type-check-2.rs:77:31
--> $DIR/type-check-2.rs:75:31
|
LL | asm!("{}", inout(reg) r);
| ^
|
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly

error: asm `sym` operand must point to a fn or static
--> $DIR/type-check-2.rs:41:24
error: invalid `sym` operand
--> $DIR/type-check-2.rs:41:20
|
LL | asm!("{}", sym C);
| ^
| ^^^^^ is an `i32`
|
= help: `sym` operands must refer to either a function or a static

error: asm `sym` operand must point to a fn or static
--> $DIR/type-check-2.rs:43:24
error: invalid `sym` operand
--> $DIR/type-check-2.rs:92:19
|
LL | global_asm!("{}", sym C);
| ^^^^^ is an `i32`
|
LL | asm!("{}", sym x);
| ^
= help: `sym` operands must refer to either a function or a static

error[E0381]: use of possibly-uninitialized variable: `x`
--> $DIR/type-check-2.rs:19:28
Expand Down
9 changes: 8 additions & 1 deletion src/test/ui/asm/type-check-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ignore-spirv
// ignore-wasm32

#![feature(asm_const)]
#![feature(asm_const, asm_sym)]

use std::arch::{asm, global_asm};

Expand Down Expand Up @@ -44,6 +44,8 @@ fn main() {
asm!("{}", const const_bar(0));
asm!("{}", const const_bar(x));
//~^ ERROR attempt to use a non-constant value in a constant
asm!("{}", sym x);
//~^ ERROR invalid `sym` operand

// Const operands must be integers and must be constants.

Expand All @@ -59,6 +61,11 @@ fn main() {
}
}

unsafe fn generic<T>() {
asm!("{}", sym generic::<T>);
//~^ generic parameters may not be used in const operations
}

// Const operands must be integers and must be constants.

global_asm!("{}", const 0);
Expand Down
29 changes: 23 additions & 6 deletions src/test/ui/asm/type-check-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,31 @@ LL | let x = 0;
LL | asm!("{}", const const_bar(x));
| ^ non-constant value

error: invalid `sym` operand
--> $DIR/type-check-1.rs:47:24
|
LL | asm!("{}", sym x);
| ^ is a local variable
|
= help: `sym` operands must refer to either a function or a static

error: generic parameters may not be used in const operations
--> $DIR/type-check-1.rs:65:30
|
LL | asm!("{}", sym generic::<T>);
| ^ cannot perform const operation using `T`
|
= note: type parameters may not be used in const expressions
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions

error[E0308]: mismatched types
--> $DIR/type-check-1.rs:53:26
--> $DIR/type-check-1.rs:55:26
|
LL | asm!("{}", const 0f32);
| ^^^^ expected integer, found `f32`

error[E0308]: mismatched types
--> $DIR/type-check-1.rs:55:26
--> $DIR/type-check-1.rs:57:26
|
LL | asm!("{}", const 0 as *mut u8);
| ^^^^^^^^^^^^ expected integer, found *-ptr
Expand All @@ -41,7 +58,7 @@ LL | asm!("{}", const 0 as *mut u8);
found raw pointer `*mut u8`

error[E0308]: mismatched types
--> $DIR/type-check-1.rs:57:26
--> $DIR/type-check-1.rs:59:26
|
LL | asm!("{}", const &0);
| ^^ expected integer, found `&{integer}`
Expand Down Expand Up @@ -92,21 +109,21 @@ LL | asm!("{}", inout(reg) v[..]);
= note: all inline asm arguments must have a statically known size

error[E0308]: mismatched types
--> $DIR/type-check-1.rs:67:25
--> $DIR/type-check-1.rs:74:25
|
LL | global_asm!("{}", const 0f32);
| ^^^^ expected integer, found `f32`

error[E0308]: mismatched types
--> $DIR/type-check-1.rs:69:25
--> $DIR/type-check-1.rs:76:25
|
LL | global_asm!("{}", const 0 as *mut u8);
| ^^^^^^^^^^^^ expected integer, found *-ptr
|
= note: expected type `{integer}`
found raw pointer `*mut u8`

error: aborting due to 13 previous errors
error: aborting due to 15 previous errors

Some errors have detailed explanations: E0277, E0308, E0435.
For more information about an error, try `rustc --explain E0277`.
2 changes: 1 addition & 1 deletion src/test/ui/asm/x86_64/parse-error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() {
asm!("{}", in(reg) foo => bar);
//~^ ERROR expected one of `!`, `,`, `.`, `::`, `?`, `{`, or an operator, found `=>`
asm!("{}", sym foo + bar);
//~^ ERROR argument to `sym` must be a path expression
//~^ ERROR expected a path for argument to `sym`
asm!("", options(foo));
//~^ ERROR expected one of
asm!("", options(nomem foo));
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/asm/x86_64/parse-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ error: expected one of `!`, `,`, `.`, `::`, `?`, `{`, or an operator, found `=>`
LL | asm!("{}", in(reg) foo => bar);
| ^^ expected one of 7 possible tokens

error: argument to `sym` must be a path expression
error: expected a path for argument to `sym`
--> $DIR/parse-error.rs:31:24
|
LL | asm!("{}", sym foo + bar);
Expand Down Expand Up @@ -362,17 +362,17 @@ LL | global_asm!("{a}", a = const FOO, a = const BAR);
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {1} */"`

error: expected one of `clobber_abi`, `const`, or `options`, found `""`
error: expected one of `clobber_abi`, `const`, `options`, or `sym`, found `""`
--> $DIR/parse-error.rs:130:28
|
LL | global_asm!("", options(), "");
| ^^ expected one of `clobber_abi`, `const`, or `options`
| ^^ expected one of `clobber_abi`, `const`, `options`, or `sym`

error: expected one of `clobber_abi`, `const`, or `options`, found `"{}"`
error: expected one of `clobber_abi`, `const`, `options`, or `sym`, found `"{}"`
--> $DIR/parse-error.rs:132:30
|
LL | global_asm!("{}", const FOO, "{}", const FOO);
| ^^^^ expected one of `clobber_abi`, `const`, or `options`
| ^^^^ expected one of `clobber_abi`, `const`, `options`, or `sym`

error: asm template must be a string literal
--> $DIR/parse-error.rs:134:13
Expand Down
15 changes: 11 additions & 4 deletions src/test/ui/asm/x86_64/type-check-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#![feature(repr_simd, never_type, asm_sym)]

use std::arch::asm;
use std::arch::{asm, global_asm};

#[repr(simd)]
struct SimdNonCopy(f32, f32, f32, f32);
Expand Down Expand Up @@ -35,9 +35,7 @@ fn main() {
asm!("{}", sym S);
asm!("{}", sym main);
asm!("{}", sym C);
//~^ ERROR asm `sym` operand must point to a fn or static
asm!("{}", sym x);
//~^ ERROR asm `sym` operand must point to a fn or static
//~^ ERROR invalid `sym` operand

// Register operands must be Copy

Expand Down Expand Up @@ -80,3 +78,12 @@ fn main() {
asm!("{}", in(reg) u);
}
}

// Sym operands must point to a function or static

const C: i32 = 0;
static S: i32 = 0;
global_asm!("{}", sym S);
global_asm!("{}", sym main);
global_asm!("{}", sym C);
//~^ ERROR invalid `sym` operand
Loading