Skip to content

Commit 23903d0

Browse files
committed
Auto merge of rust-lang#154423 - JonathanBrouwer:rollup-CxbclzF, r=JonathanBrouwer
Rollup of 5 pull requests Successful merges: - rust-lang#152757 (Add x86_64-unknown-linux-gnu{m,t}san target which enables {M,T}San by default) - rust-lang#154354 (Add more tests for the parallel frontend) - rust-lang#154088 (Reorder inline asm operands in pretty printer to satisfy grammar constraints) - rust-lang#154407 (Link from `assert_matches` to `debug_assert_matches`) - rust-lang#154420 (Use extended regex syntax)
2 parents f58bd5c + 90bebc0 commit 23903d0

35 files changed

Lines changed: 1943 additions & 6 deletions

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,85 @@ impl<'a> State<'a> {
16491649
);
16501650
}
16511651

1652+
fn inline_asm_template_and_operands<'asm>(
1653+
asm: &'asm ast::InlineAsm,
1654+
) -> (String, Vec<&'asm InlineAsmOperand>) {
1655+
fn is_explicit_reg(op: &InlineAsmOperand) -> bool {
1656+
match op {
1657+
InlineAsmOperand::In { reg, .. }
1658+
| InlineAsmOperand::Out { reg, .. }
1659+
| InlineAsmOperand::InOut { reg, .. }
1660+
| InlineAsmOperand::SplitInOut { reg, .. } => {
1661+
matches!(reg, InlineAsmRegOrRegClass::Reg(_))
1662+
}
1663+
InlineAsmOperand::Const { .. }
1664+
| InlineAsmOperand::Sym { .. }
1665+
| InlineAsmOperand::Label { .. } => false,
1666+
}
1667+
}
1668+
1669+
// After macro expansion, named operands become positional. The grammar
1670+
// requires positional operands to precede explicit register operands,
1671+
// so we must reorder when any non-explicit operand follows an explicit
1672+
// one. When no reordering is needed, we use the original template
1673+
// string and operand order to avoid duplicating the Display logic in
1674+
// InlineAsmTemplatePiece.
1675+
let needs_reorder = {
1676+
let mut seen_explicit = false;
1677+
asm.operands.iter().any(|(op, _)| {
1678+
if is_explicit_reg(op) {
1679+
seen_explicit = true;
1680+
false
1681+
} else {
1682+
seen_explicit
1683+
}
1684+
})
1685+
};
1686+
1687+
if !needs_reorder {
1688+
let template = InlineAsmTemplatePiece::to_string(&asm.template);
1689+
let operands = asm.operands.iter().map(|(op, _)| op).collect();
1690+
return (template, operands);
1691+
}
1692+
1693+
let mut non_explicit = Vec::new();
1694+
let mut explicit = Vec::new();
1695+
for (i, (op, _)) in asm.operands.iter().enumerate() {
1696+
if is_explicit_reg(op) {
1697+
explicit.push(i);
1698+
} else {
1699+
non_explicit.push(i);
1700+
}
1701+
}
1702+
let order = non_explicit.into_iter().chain(explicit).collect::<Vec<_>>();
1703+
1704+
// Build old-index -> new-index mapping for template renumbering.
1705+
let mut old_to_new = vec![0usize; asm.operands.len()];
1706+
for (new_idx, old_idx) in order.iter().copied().enumerate() {
1707+
old_to_new[old_idx] = new_idx;
1708+
}
1709+
1710+
// Remap template placeholder indices and reuse the existing Display
1711+
// impl to build the template string.
1712+
let remapped = asm
1713+
.template
1714+
.iter()
1715+
.map(|piece| match piece {
1716+
InlineAsmTemplatePiece::Placeholder { operand_idx, modifier, span } => {
1717+
InlineAsmTemplatePiece::Placeholder {
1718+
operand_idx: old_to_new[*operand_idx],
1719+
modifier: *modifier,
1720+
span: *span,
1721+
}
1722+
}
1723+
other => other.clone(),
1724+
})
1725+
.collect::<Vec<_>>();
1726+
let template = InlineAsmTemplatePiece::to_string(&remapped);
1727+
let operands = order.iter().map(|&idx| &asm.operands[idx].0).collect();
1728+
(template, operands)
1729+
}
1730+
16521731
fn print_inline_asm(&mut self, asm: &ast::InlineAsm) {
16531732
enum AsmArg<'a> {
16541733
Template(String),
@@ -1657,8 +1736,9 @@ impl<'a> State<'a> {
16571736
Options(InlineAsmOptions),
16581737
}
16591738

1660-
let mut args = vec![AsmArg::Template(InlineAsmTemplatePiece::to_string(&asm.template))];
1661-
args.extend(asm.operands.iter().map(|(o, _)| AsmArg::Operand(o)));
1739+
let (template, operands) = Self::inline_asm_template_and_operands(asm);
1740+
let mut args = vec![AsmArg::Template(template)];
1741+
args.extend(operands.into_iter().map(AsmArg::Operand));
16621742
for (abi, _) in &asm.clobber_abis {
16631743
args.push(AsmArg::ClobberAbi(*abi));
16641744
}

compiler/rustc_target/src/spec/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,8 @@ supported_targets! {
18261826
("x86_64-pc-cygwin", x86_64_pc_cygwin),
18271827

18281828
("x86_64-unknown-linux-gnuasan", x86_64_unknown_linux_gnuasan),
1829+
("x86_64-unknown-linux-gnumsan", x86_64_unknown_linux_gnumsan),
1830+
("x86_64-unknown-linux-gnutsan", x86_64_unknown_linux_gnutsan),
18291831
}
18301832

18311833
/// Cow-Vec-Str: Cow<'static, [Cow<'static, str>]>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use crate::spec::{SanitizerSet, Target, TargetMetadata};
2+
3+
pub(crate) fn target() -> Target {
4+
let mut base = super::x86_64_unknown_linux_gnu::target();
5+
base.metadata = TargetMetadata {
6+
description: Some(
7+
"64-bit Linux (kernel 3.2+, glibc 2.17+) with MSAN enabled by default".into(),
8+
),
9+
tier: Some(2),
10+
host_tools: Some(false),
11+
std: Some(true),
12+
};
13+
base.supported_sanitizers = SanitizerSet::MEMORY;
14+
base.default_sanitizers = SanitizerSet::MEMORY;
15+
base
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use crate::spec::{SanitizerSet, Target, TargetMetadata};
2+
3+
pub(crate) fn target() -> Target {
4+
let mut base = super::x86_64_unknown_linux_gnu::target();
5+
base.metadata = TargetMetadata {
6+
description: Some(
7+
"64-bit Linux (kernel 3.2+, glibc 2.17+) with TSAN enabled by default".into(),
8+
),
9+
tier: Some(2),
10+
host_tools: Some(false),
11+
std: Some(true),
12+
};
13+
base.supported_sanitizers = SanitizerSet::THREAD;
14+
base.default_sanitizers = SanitizerSet::THREAD;
15+
base
16+
}

library/core/src/macros/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ macro_rules! assert_ne {
124124
};
125125
}
126126

127-
// FIXME add back debug_assert_matches doc link after bootstrap.
128-
129127
/// Asserts that an expression matches the provided pattern.
130128
///
131129
/// This macro is generally preferable to `assert!(matches!(value, pattern))`, because it can print
@@ -137,9 +135,11 @@ macro_rules! assert_ne {
137135
/// otherwise this macro will panic.
138136
///
139137
/// Assertions are always checked in both debug and release builds, and cannot
140-
/// be disabled. See `debug_assert_matches!` for assertions that are disabled in
138+
/// be disabled. See [`debug_assert_matches!`] for assertions that are disabled in
141139
/// release builds by default.
142140
///
141+
/// [`debug_assert_matches!`]: crate::debug_assert_matches
142+
///
143143
/// On panic, this macro will print the value of the expression with its debug representation.
144144
///
145145
/// Like [`assert!`], this macro has a second form, where a custom panic message can be provided.

src/bootstrap/src/core/build_steps/llvm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,8 @@ fn supported_sanitizers(
15581558
&["asan", "dfsan", "lsan", "msan", "safestack", "tsan", "rtsan"],
15591559
),
15601560
"x86_64-unknown-linux-gnuasan" => common_libs("linux", "x86_64", &["asan"]),
1561+
"x86_64-unknown-linux-gnumsan" => common_libs("linux", "x86_64", &["msan"]),
1562+
"x86_64-unknown-linux-gnutsan" => common_libs("linux", "x86_64", &["tsan"]),
15611563
"x86_64-unknown-linux-musl" => {
15621564
common_libs("linux", "x86_64", &["asan", "lsan", "msan", "tsan"])
15631565
}

src/bootstrap/src/core/sanity.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub struct Finder {
3737
/// when the newly-bumped stage 0 compiler now knows about the formerly-missing targets.
3838
const STAGE0_MISSING_TARGETS: &[&str] = &[
3939
// just a dummy comment so the list doesn't get onelined
40+
"x86_64-unknown-linux-gnumsan",
41+
"x86_64-unknown-linux-gnutsan",
4042
];
4143

4244
/// Minimum version threshold for libstdc++ required when using prebuilt LLVM

src/ci/docker/host-x86_64/dist-various-2/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ ENV TARGETS=$TARGETS,x86_64-unknown-uefi
124124
ENV TARGETS=$TARGETS,riscv64gc-unknown-linux-musl
125125

126126
ENV TARGETS_SANITIZERS=x86_64-unknown-linux-gnuasan
127+
ENV TARGETS_SANITIZERS=$TARGETS_SANITIZERS,x86_64-unknown-linux-gnumsan
128+
ENV TARGETS_SANITIZERS=$TARGETS_SANITIZERS,x86_64-unknown-linux-gnutsan
127129

128130
# As per https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1300211
129131
# we need asm in the search path for gcc-9 (for gnux32) but not in the search path of the

src/doc/rustc/src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,7 @@
155155
- [x86_64-unknown-linux-none](platform-support/x86_64-unknown-linux-none.md)
156156
- [x86_64-unknown-none](platform-support/x86_64-unknown-none.md)
157157
- [x86_64-unknown-linux-gnuasan](platform-support/x86_64-unknown-linux-gnuasan.md)
158+
- [x86_64-unknown-linux-gnumsan](platform-support/x86_64-unknown-linux-gnumsan.md)
159+
- [x86_64-unknown-linux-gnutsan](platform-support/x86_64-unknown-linux-gnutsan.md)
158160
- [xtensa-\*-none-elf](platform-support/xtensa.md)
159161
- [\*-nuttx-\*](platform-support/nuttx.md)

src/doc/rustc/src/platform-support.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ target | std | notes
216216
[`x86_64-fortanix-unknown-sgx`](platform-support/x86_64-fortanix-unknown-sgx.md) | ✓ | [Fortanix ABI] for 64-bit Intel SGX
217217
[`x86_64-linux-android`](platform-support/android.md) | ✓ | 64-bit x86 Android
218218
[`x86_64-unknown-linux-gnuasan`](platform-support/x86_64-unknown-linux-gnuasan.md) | ✓ | 64-bit Linux (kernel 3.2+, glibc 2.17+) with ASAN enabled by default
219+
[`x86_64-unknown-linux-gnumsan`](platform-support/x86_64-unknown-linux-gnumsan.md) | ✓ | 64-bit Linux (kernel 3.2+, glibc 2.17+) with MSAN enabled by default
220+
[`x86_64-unknown-linux-gnutsan`](platform-support/x86_64-unknown-linux-gnutsan.md) | ✓ | 64-bit Linux (kernel 3.2+, glibc 2.17+) with TSAN enabled by default
219221
[`x86_64-unknown-fuchsia`](platform-support/fuchsia.md) | ✓ | 64-bit x86 Fuchsia
220222
`x86_64-unknown-linux-gnux32` | ✓ | 64-bit Linux (x32 ABI) (kernel 4.15+, glibc 2.27)
221223
[`x86_64-unknown-none`](platform-support/x86_64-unknown-none.md) | * | Freestanding/bare-metal x86_64, softfloat

0 commit comments

Comments
 (0)