Skip to content

Commit 8fee3f6

Browse files
committed
Auto merge of #121940 - veera-sivarajan:bugfix-121593, r=fmease
Mention Register Size in `#[warn(asm_sub_register)]` Fixes #121593 Displays the register size information obtained from `suggest_modifier()` and `default_modifier()`.
2 parents 548e14b + afc99cc commit 8fee3f6

23 files changed

+132
-124
lines changed

compiler/rustc_hir_analysis/src/check/intrinsicck.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use rustc_session::lint;
66
use rustc_span::def_id::LocalDefId;
77
use rustc_span::Symbol;
88
use rustc_target::abi::FieldIdx;
9-
use rustc_target::asm::{InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass, InlineAsmType};
9+
use rustc_target::asm::{
10+
InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass, InlineAsmType, ModifierInfo,
11+
};
1012

1113
pub struct InlineAsmCtxt<'a, 'tcx> {
1214
tcx: TyCtxt<'tcx>,
@@ -251,8 +253,11 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
251253
}
252254

253255
// Check whether a modifier is suggested for using this type.
254-
if let Some((suggested_modifier, suggested_result)) =
255-
reg_class.suggest_modifier(asm_arch, asm_ty)
256+
if let Some(ModifierInfo {
257+
modifier: suggested_modifier,
258+
result: suggested_result,
259+
size: suggested_size,
260+
}) = reg_class.suggest_modifier(asm_arch, asm_ty)
256261
{
257262
// Search for any use of this operand without a modifier and emit
258263
// the suggestion for them.
@@ -266,8 +271,11 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
266271
}
267272
}
268273
if !spans.is_empty() {
269-
let (default_modifier, default_result) =
270-
reg_class.default_modifier(asm_arch).unwrap();
274+
let ModifierInfo {
275+
modifier: default_modifier,
276+
result: default_result,
277+
size: default_size,
278+
} = reg_class.default_modifier(asm_arch).unwrap();
271279
self.tcx.node_span_lint(
272280
lint::builtin::ASM_SUB_REGISTER,
273281
expr.hir_id,
@@ -276,10 +284,10 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
276284
|lint| {
277285
lint.span_label(expr.span, "for this argument");
278286
lint.help(format!(
279-
"use `{{{idx}:{suggested_modifier}}}` to have the register formatted as `{suggested_result}`",
287+
"use `{{{idx}:{suggested_modifier}}}` to have the register formatted as `{suggested_result}` (for {suggested_size}-bit values)",
280288
));
281289
lint.help(format!(
282-
"or use `{{{idx}:{default_modifier}}}` to keep the default formatting of `{default_result}`",
290+
"or use `{{{idx}:{default_modifier}}}` to keep the default formatting of `{default_result}` (for {default_size}-bit values)",
283291
));
284292
},
285293
);

compiler/rustc_target/src/asm/aarch64.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{InlineAsmArch, InlineAsmType};
1+
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
22
use crate::spec::{RelocModel, Target};
33
use rustc_data_structures::fx::FxIndexSet;
44
use rustc_macros::HashStable_Generic;
@@ -27,32 +27,28 @@ impl AArch64InlineAsmRegClass {
2727
None
2828
}
2929

30-
pub fn suggest_modifier(
31-
self,
32-
_arch: InlineAsmArch,
33-
ty: InlineAsmType,
34-
) -> Option<(char, &'static str)> {
30+
pub fn suggest_modifier(self, _arch: InlineAsmArch, ty: InlineAsmType) -> Option<ModifierInfo> {
3531
match self {
3632
Self::reg => match ty.size().bits() {
3733
64 => None,
38-
_ => Some(('w', "w0")),
34+
_ => Some(('w', "w0", 32).into()),
3935
},
4036
Self::vreg | Self::vreg_low16 => match ty.size().bits() {
41-
8 => Some(('b', "b0")),
42-
16 => Some(('h', "h0")),
43-
32 => Some(('s', "s0")),
44-
64 => Some(('d', "d0")),
45-
128 => Some(('q', "q0")),
37+
8 => Some(('b', "b0", 8).into()),
38+
16 => Some(('h', "h0", 16).into()),
39+
32 => Some(('s', "s0", 32).into()),
40+
64 => Some(('d', "d0", 64).into()),
41+
128 => Some(('q', "q0", 128).into()),
4642
_ => None,
4743
},
4844
Self::preg => None,
4945
}
5046
}
5147

52-
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> {
48+
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<ModifierInfo> {
5349
match self {
54-
Self::reg => Some(('x', "x0")),
55-
Self::vreg | Self::vreg_low16 => Some(('v', "v0")),
50+
Self::reg => Some(('x', "x0", 64).into()),
51+
Self::vreg | Self::vreg_low16 => Some(('v', "v0", 128).into()),
5652
Self::preg => None,
5753
}
5854
}

compiler/rustc_target/src/asm/arm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{InlineAsmArch, InlineAsmType};
1+
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
22
use crate::spec::{RelocModel, Target};
33
use rustc_data_structures::fx::FxIndexSet;
44
use rustc_macros::HashStable_Generic;
@@ -35,11 +35,11 @@ impl ArmInlineAsmRegClass {
3535
self,
3636
_arch: InlineAsmArch,
3737
_ty: InlineAsmType,
38-
) -> Option<(char, &'static str)> {
38+
) -> Option<ModifierInfo> {
3939
None
4040
}
4141

42-
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> {
42+
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<ModifierInfo> {
4343
None
4444
}
4545

compiler/rustc_target/src/asm/avr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{InlineAsmArch, InlineAsmType};
1+
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
22
use rustc_macros::HashStable_Generic;
33
use rustc_span::Symbol;
44
use std::fmt;
@@ -29,11 +29,11 @@ impl AvrInlineAsmRegClass {
2929
self,
3030
_arch: InlineAsmArch,
3131
_ty: InlineAsmType,
32-
) -> Option<(char, &'static str)> {
32+
) -> Option<ModifierInfo> {
3333
None
3434
}
3535

36-
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> {
36+
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<ModifierInfo> {
3737
None
3838
}
3939

compiler/rustc_target/src/asm/bpf.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{InlineAsmArch, InlineAsmType};
1+
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
22
use rustc_macros::HashStable_Generic;
33
use rustc_span::Symbol;
44
use std::fmt;
@@ -23,11 +23,11 @@ impl BpfInlineAsmRegClass {
2323
self,
2424
_arch: InlineAsmArch,
2525
_ty: InlineAsmType,
26-
) -> Option<(char, &'static str)> {
26+
) -> Option<ModifierInfo> {
2727
None
2828
}
2929

30-
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> {
30+
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<ModifierInfo> {
3131
None
3232
}
3333

compiler/rustc_target/src/asm/csky.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{InlineAsmArch, InlineAsmType};
1+
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
22
use rustc_macros::HashStable_Generic;
33
use rustc_span::Symbol;
44
use std::fmt;
@@ -23,11 +23,11 @@ impl CSKYInlineAsmRegClass {
2323
self,
2424
_arch: InlineAsmArch,
2525
_ty: InlineAsmType,
26-
) -> Option<(char, &'static str)> {
26+
) -> Option<ModifierInfo> {
2727
None
2828
}
2929

30-
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> {
30+
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<ModifierInfo> {
3131
None
3232
}
3333

compiler/rustc_target/src/asm/hexagon.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{InlineAsmArch, InlineAsmType};
1+
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
22
use rustc_macros::HashStable_Generic;
33
use rustc_span::Symbol;
44
use std::fmt;
@@ -22,11 +22,11 @@ impl HexagonInlineAsmRegClass {
2222
self,
2323
_arch: InlineAsmArch,
2424
_ty: InlineAsmType,
25-
) -> Option<(char, &'static str)> {
25+
) -> Option<ModifierInfo> {
2626
None
2727
}
2828

29-
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> {
29+
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<ModifierInfo> {
3030
None
3131
}
3232

compiler/rustc_target/src/asm/loongarch.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{InlineAsmArch, InlineAsmType};
1+
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
22
use rustc_macros::HashStable_Generic;
33
use rustc_span::Symbol;
44
use std::fmt;
@@ -23,11 +23,11 @@ impl LoongArchInlineAsmRegClass {
2323
self,
2424
_arch: InlineAsmArch,
2525
_ty: InlineAsmType,
26-
) -> Option<(char, &'static str)> {
26+
) -> Option<ModifierInfo> {
2727
None
2828
}
2929

30-
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> {
30+
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<ModifierInfo> {
3131
None
3232
}
3333

compiler/rustc_target/src/asm/m68k.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{InlineAsmArch, InlineAsmType};
1+
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
22
use rustc_macros::HashStable_Generic;
33
use rustc_span::Symbol;
44
use std::fmt;
@@ -24,11 +24,11 @@ impl M68kInlineAsmRegClass {
2424
self,
2525
_arch: InlineAsmArch,
2626
_ty: InlineAsmType,
27-
) -> Option<(char, &'static str)> {
27+
) -> Option<ModifierInfo> {
2828
None
2929
}
3030

31-
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> {
31+
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<ModifierInfo> {
3232
None
3333
}
3434

compiler/rustc_target/src/asm/mips.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{InlineAsmArch, InlineAsmType};
1+
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
22
use rustc_macros::HashStable_Generic;
33
use rustc_span::Symbol;
44
use std::fmt;
@@ -23,11 +23,11 @@ impl MipsInlineAsmRegClass {
2323
self,
2424
_arch: InlineAsmArch,
2525
_ty: InlineAsmType,
26-
) -> Option<(char, &'static str)> {
26+
) -> Option<ModifierInfo> {
2727
None
2828
}
2929

30-
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> {
30+
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<ModifierInfo> {
3131
None
3232
}
3333

compiler/rustc_target/src/asm/mod.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ use rustc_span::Symbol;
66
use std::fmt;
77
use std::str::FromStr;
88

9+
pub struct ModifierInfo {
10+
pub modifier: char,
11+
pub result: &'static str,
12+
pub size: u64,
13+
}
14+
15+
impl From<(char, &'static str, u64)> for ModifierInfo {
16+
fn from((modifier, result, size): (char, &'static str, u64)) -> Self {
17+
Self { modifier, result, size }
18+
}
19+
}
20+
921
macro_rules! def_reg_class {
1022
($arch:ident $arch_regclass:ident {
1123
$(
@@ -512,11 +524,7 @@ impl InlineAsmRegClass {
512524
/// Such suggestions are useful if a type smaller than the full register
513525
/// size is used and a modifier can be used to point to the subregister of
514526
/// the correct size.
515-
pub fn suggest_modifier(
516-
self,
517-
arch: InlineAsmArch,
518-
ty: InlineAsmType,
519-
) -> Option<(char, &'static str)> {
527+
pub fn suggest_modifier(self, arch: InlineAsmArch, ty: InlineAsmType) -> Option<ModifierInfo> {
520528
match self {
521529
Self::X86(r) => r.suggest_modifier(arch, ty),
522530
Self::Arm(r) => r.suggest_modifier(arch, ty),
@@ -545,7 +553,7 @@ impl InlineAsmRegClass {
545553
/// This is only needed when the register class can suggest a modifier, so
546554
/// that the user can be shown how to get the default behavior without a
547555
/// warning.
548-
pub fn default_modifier(self, arch: InlineAsmArch) -> Option<(char, &'static str)> {
556+
pub fn default_modifier(self, arch: InlineAsmArch) -> Option<ModifierInfo> {
549557
match self {
550558
Self::X86(r) => r.default_modifier(arch),
551559
Self::Arm(r) => r.default_modifier(arch),

compiler/rustc_target/src/asm/msp430.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{InlineAsmArch, InlineAsmType};
1+
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
22
use rustc_macros::HashStable_Generic;
33
use rustc_span::Symbol;
44
use std::fmt;
@@ -22,11 +22,11 @@ impl Msp430InlineAsmRegClass {
2222
self,
2323
_arch: InlineAsmArch,
2424
_ty: InlineAsmType,
25-
) -> Option<(char, &'static str)> {
25+
) -> Option<ModifierInfo> {
2626
None
2727
}
2828

29-
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> {
29+
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<ModifierInfo> {
3030
None
3131
}
3232

compiler/rustc_target/src/asm/nvptx.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{InlineAsmArch, InlineAsmType};
1+
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
22
use rustc_macros::HashStable_Generic;
33
use rustc_span::Symbol;
44

@@ -23,11 +23,11 @@ impl NvptxInlineAsmRegClass {
2323
self,
2424
_arch: InlineAsmArch,
2525
_ty: InlineAsmType,
26-
) -> Option<(char, &'static str)> {
26+
) -> Option<ModifierInfo> {
2727
None
2828
}
2929

30-
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> {
30+
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<ModifierInfo> {
3131
None
3232
}
3333

compiler/rustc_target/src/asm/powerpc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{InlineAsmArch, InlineAsmType};
1+
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
22
use rustc_macros::HashStable_Generic;
33
use rustc_span::Symbol;
44
use std::fmt;
@@ -26,11 +26,11 @@ impl PowerPCInlineAsmRegClass {
2626
self,
2727
_arch: InlineAsmArch,
2828
_ty: InlineAsmType,
29-
) -> Option<(char, &'static str)> {
29+
) -> Option<ModifierInfo> {
3030
None
3131
}
3232

33-
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> {
33+
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<ModifierInfo> {
3434
None
3535
}
3636

compiler/rustc_target/src/asm/riscv.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{InlineAsmArch, InlineAsmType};
1+
use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
22
use crate::spec::{RelocModel, Target};
33
use rustc_data_structures::fx::FxIndexSet;
44
use rustc_macros::HashStable_Generic;
@@ -26,11 +26,11 @@ impl RiscVInlineAsmRegClass {
2626
self,
2727
_arch: InlineAsmArch,
2828
_ty: InlineAsmType,
29-
) -> Option<(char, &'static str)> {
29+
) -> Option<ModifierInfo> {
3030
None
3131
}
3232

33-
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> {
33+
pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<ModifierInfo> {
3434
None
3535
}
3636

0 commit comments

Comments
 (0)