Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 77ea82b

Browse files
committedMar 7, 2025·
Pass InferCtxt to InlineAsmCtxt to properly taint on error
Split up some of the tests bc tainting causes some errors to become suppressed
1 parent ded9ca7 commit 77ea82b

File tree

9 files changed

+110
-80
lines changed

9 files changed

+110
-80
lines changed
 

‎compiler/rustc_hir_analysis/src/check/intrinsicck.rs

+58-52
Large diffs are not rendered by default.

‎compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
101101
debug!("FnCtxt::check_asm: {} deferred checks", deferred_asm_checks.len());
102102
for (asm, hir_id) in deferred_asm_checks.drain(..) {
103103
let enclosing_id = self.tcx.hir_enclosing_body_owner(hir_id);
104-
let expr_ty = |expr: &hir::Expr<'tcx>| {
105-
let ty = self.typeck_results.borrow().expr_ty_adjusted(expr);
106-
let ty = self.resolve_vars_if_possible(ty);
107-
if ty.has_non_region_infer() {
108-
Ty::new_misc_error(self.tcx)
109-
} else {
110-
self.tcx.erase_regions(ty)
111-
}
112-
};
113-
let node_ty = |hir_id: HirId| self.typeck_results.borrow().node_type(hir_id);
114104
InlineAsmCtxt::new(
115-
self.tcx,
116105
enclosing_id,
106+
&self.infcx,
117107
self.typing_env(self.param_env),
118-
expr_ty,
119-
node_ty,
108+
&*self.typeck_results.borrow(),
120109
)
121110
.check_asm(asm);
122111
}

‎tests/ui/asm/global-asm-with-error.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0425]: cannot find value `a` in this scope
2-
--> $DIR/global-asm-with-error.rs:6:29
2+
--> $DIR/global-asm-with-error.rs:8:29
33
|
44
LL | global_asm!("/* {} */", sym a);
55
| ^ not found in this scope

‎tests/ui/asm/invalid-const-operand.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ global_asm!("{}", const 0f32);
1414
global_asm!("{}", const 0 as *mut u8);
1515
//~^ ERROR invalid type for `const` operand
1616

17-
fn main() {
17+
fn test1() {
1818
unsafe {
1919
// Const operands must be integers and must be constants.
2020

@@ -27,7 +27,11 @@ fn main() {
2727
//~^ ERROR invalid type for `const` operand
2828
asm!("{}", const &0);
2929
//~^ ERROR invalid type for `const` operand
30+
}
31+
}
3032

33+
fn test2() {
34+
unsafe {
3135
// Constants must be... constant
3236

3337
let x = 0;
@@ -47,3 +51,5 @@ fn main() {
4751
//~^ ERROR attempt to use a non-constant value in a constant
4852
}
4953
}
54+
55+
fn main() {}

‎tests/ui/asm/invalid-const-operand.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0435]: attempt to use a non-constant value in a constant
2-
--> $DIR/invalid-const-operand.rs:40:26
2+
--> $DIR/invalid-const-operand.rs:44:26
33
|
44
LL | asm!("{}", const x);
55
| ^ non-constant value
@@ -11,7 +11,7 @@ LL + const x: /* Type */ = 0;
1111
|
1212

1313
error[E0435]: attempt to use a non-constant value in a constant
14-
--> $DIR/invalid-const-operand.rs:43:36
14+
--> $DIR/invalid-const-operand.rs:47:36
1515
|
1616
LL | asm!("{}", const const_foo(x));
1717
| ^ non-constant value
@@ -23,7 +23,7 @@ LL + const x: /* Type */ = 0;
2323
|
2424

2525
error[E0435]: attempt to use a non-constant value in a constant
26-
--> $DIR/invalid-const-operand.rs:46:36
26+
--> $DIR/invalid-const-operand.rs:50:36
2727
|
2828
LL | asm!("{}", const const_bar(x));
2929
| ^ non-constant value
@@ -80,7 +80,7 @@ error: invalid type for `const` operand
8080
LL | asm!("{}", const &0);
8181
| ^^^^^^--
8282
| |
83-
| is a `&{integer}`
83+
| is a `&i32`
8484
|
8585
= help: `const` operands must be of an integer type
8686

‎tests/ui/asm/tainting-on-error.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ needs-asm-support
2+
3+
use std::arch::asm;
4+
5+
fn main() {
6+
unsafe {
7+
asm!(
8+
"/* {} */",
9+
sym None::<()>,
10+
//~^ ERROR invalid `sym` operand
11+
);
12+
}
13+
}

‎tests/ui/asm/tainting-on-error.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: invalid `sym` operand
2+
--> $DIR/tainting-on-error.rs:9:13
3+
|
4+
LL | sym None::<()>,
5+
| ^^^^^^^^^^^^^^ is an `Option<()>`
6+
|
7+
= help: `sym` operands must refer to either a function or a static
8+
9+
error: aborting due to 1 previous error
10+

‎tests/ui/asm/x86_64/type-check-2.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::arch::{asm, global_asm};
77
#[repr(simd)]
88
struct SimdNonCopy([f32; 4]);
99

10-
fn main() {
10+
fn test1() {
1111
unsafe {
1212
// Inputs must be initialized
1313

@@ -26,7 +26,11 @@ fn main() {
2626
asm!("{}", in(reg) v[0]);
2727
asm!("{}", out(reg) v[0]);
2828
asm!("{}", inout(reg) v[0]);
29+
}
30+
}
2931

32+
fn test2() {
33+
unsafe {
3034
// Register operands must be Copy
3135

3236
asm!("{}", in(xmm_reg) SimdNonCopy([0.0, 0.0, 0.0, 0.0]));
@@ -68,3 +72,5 @@ fn main() {
6872
asm!("{}", in(reg) u);
6973
}
7074
}
75+
76+
fn main() {}

‎tests/ui/asm/x86_64/type-check-2.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
error: arguments for inline assembly must be copyable
2-
--> $DIR/type-check-2.rs:32:32
2+
--> $DIR/type-check-2.rs:36:32
33
|
44
LL | asm!("{}", in(xmm_reg) SimdNonCopy([0.0, 0.0, 0.0, 0.0]));
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `SimdNonCopy` does not implement the Copy trait
88

9-
error: cannot use value of type `{closure@$DIR/type-check-2.rs:44:28: 44:36}` for inline assembly
10-
--> $DIR/type-check-2.rs:44:28
9+
error: cannot use value of type `{closure@$DIR/type-check-2.rs:48:28: 48:36}` for inline assembly
10+
--> $DIR/type-check-2.rs:48:28
1111
|
1212
LL | asm!("{}", in(reg) |x: i32| x);
1313
| ^^^^^^^^^^
1414
|
1515
= note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
1616

1717
error: cannot use value of type `Vec<i32>` for inline assembly
18-
--> $DIR/type-check-2.rs:46:28
18+
--> $DIR/type-check-2.rs:50:28
1919
|
2020
LL | asm!("{}", in(reg) vec![0]);
2121
| ^^^^^^^
@@ -24,31 +24,31 @@ LL | asm!("{}", in(reg) vec![0]);
2424
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
2525

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

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

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

5050
error: cannot use value of type `&mut i32` for inline assembly
51-
--> $DIR/type-check-2.rs:61:31
51+
--> $DIR/type-check-2.rs:65:31
5252
|
5353
LL | asm!("{}", inout(reg) r);
5454
| ^

0 commit comments

Comments
 (0)
Please sign in to comment.