Skip to content

Commit 4c6e809

Browse files
committed
Auto merge of rust-lang#128698 - tgross35:rollup-oan6ari, r=tgross35
Rollup of 8 pull requests Successful merges: - rust-lang#122049 (Promote riscv64gc-unknown-linux-musl to tier 2) - rust-lang#125558 (Tweak type inference for `const` operands in inline asm) - rust-lang#128638 (run-make: enable msvc for `link-dedup`) - rust-lang#128647 (Enable msvc for link-args-order) - rust-lang#128649 (run-make: Enable msvc for `no-duplicate-libs` and `zero-extend-abi-param-passing`) - rust-lang#128656 (Enable msvc for run-make/rust-lld) - rust-lang#128688 (custom MIR: add support for tail calls) - rust-lang#128691 (Update `compiler-builtins` to 0.1.115) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f7eefec + e6cdde2 commit 4c6e809

File tree

37 files changed

+496
-319
lines changed

37 files changed

+496
-319
lines changed

compiler/rustc_hir_analysis/src/check/intrinsicck.rs

+15-25
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_ast::InlineAsmTemplatePiece;
22
use rustc_data_structures::fx::FxIndexSet;
33
use rustc_hir::{self as hir, LangItem};
44
use rustc_middle::bug;
5-
use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitableExt, UintTy};
5+
use rustc_middle::ty::{self, FloatTy, IntTy, Ty, TyCtxt, TypeVisitableExt, UintTy};
66
use rustc_session::lint;
77
use rustc_span::def_id::LocalDefId;
88
use rustc_span::Symbol;
@@ -455,32 +455,22 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
455455
);
456456
}
457457
}
458-
// No special checking is needed for these:
459-
// - Typeck has checked that Const operands are integers.
460-
// - AST lowering guarantees that SymStatic points to a static.
461-
hir::InlineAsmOperand::Const { .. } | hir::InlineAsmOperand::SymStatic { .. } => {}
462-
// Check that sym actually points to a function. Later passes
463-
// depend on this.
458+
// Typeck has checked that Const operands are integers.
459+
hir::InlineAsmOperand::Const { anon_const } => {
460+
debug_assert!(matches!(
461+
self.tcx.type_of(anon_const.def_id).instantiate_identity().kind(),
462+
ty::Error(_) | ty::Int(_) | ty::Uint(_)
463+
));
464+
}
465+
// Typeck has checked that SymFn refers to a function.
464466
hir::InlineAsmOperand::SymFn { anon_const } => {
465-
let ty = self.tcx.type_of(anon_const.def_id).instantiate_identity();
466-
match ty.kind() {
467-
ty::Never | ty::Error(_) => {}
468-
ty::FnDef(..) => {}
469-
_ => {
470-
self.tcx
471-
.dcx()
472-
.struct_span_err(*op_sp, "invalid `sym` operand")
473-
.with_span_label(
474-
self.tcx.def_span(anon_const.def_id),
475-
format!("is {} `{}`", ty.kind().article(), ty),
476-
)
477-
.with_help(
478-
"`sym` operands must refer to either a function or a static",
479-
)
480-
.emit();
481-
}
482-
};
467+
debug_assert!(matches!(
468+
self.tcx.type_of(anon_const.def_id).instantiate_identity().kind(),
469+
ty::Error(_) | ty::FnDef(..)
470+
));
483471
}
472+
// AST lowering guarantees that SymStatic points to a static.
473+
hir::InlineAsmOperand::SymStatic { .. } => {}
484474
// No special checking is needed for labels.
485475
hir::InlineAsmOperand::Label { .. } => {}
486476
}

compiler/rustc_hir_analysis/src/collect/type_of.rs

+59-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::HirId;
77
use rustc_middle::query::plumbing::CyclePlaceholder;
88
use rustc_middle::ty::print::with_forced_trimmed_paths;
99
use rustc_middle::ty::util::IntTypeExt;
10-
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
10+
use rustc_middle::ty::{self, Article, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
1111
use rustc_middle::{bug, span_bug};
1212
use rustc_span::symbol::Ident;
1313
use rustc_span::{Span, DUMMY_SP};
@@ -34,6 +34,20 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
3434
let parent_node_id = tcx.parent_hir_id(hir_id);
3535
let parent_node = tcx.hir_node(parent_node_id);
3636

37+
let find_sym_fn = |&(op, op_sp)| match op {
38+
hir::InlineAsmOperand::SymFn { anon_const } if anon_const.hir_id == hir_id => {
39+
Some((anon_const, op_sp))
40+
}
41+
_ => None,
42+
};
43+
44+
let find_const = |&(op, op_sp)| match op {
45+
hir::InlineAsmOperand::Const { anon_const } if anon_const.hir_id == hir_id => {
46+
Some((anon_const, op_sp))
47+
}
48+
_ => None,
49+
};
50+
3751
match parent_node {
3852
// Anon consts "inside" the type system.
3953
Node::ConstArg(&ConstArg {
@@ -45,13 +59,51 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
4559
// Anon consts outside the type system.
4660
Node::Expr(&Expr { kind: ExprKind::InlineAsm(asm), .. })
4761
| Node::Item(&Item { kind: ItemKind::GlobalAsm(asm), .. })
48-
if asm.operands.iter().any(|(op, _op_sp)| match op {
49-
hir::InlineAsmOperand::Const { anon_const }
50-
| hir::InlineAsmOperand::SymFn { anon_const } => anon_const.hir_id == hir_id,
51-
_ => false,
52-
}) =>
62+
if let Some((anon_const, op_sp)) = asm.operands.iter().find_map(find_sym_fn) =>
5363
{
54-
tcx.typeck(def_id).node_type(hir_id)
64+
let ty = tcx.typeck(def_id).node_type(hir_id);
65+
66+
match ty.kind() {
67+
ty::Error(_) => ty,
68+
ty::FnDef(..) => ty,
69+
_ => {
70+
let guar = tcx
71+
.dcx()
72+
.struct_span_err(op_sp, "invalid `sym` operand")
73+
.with_span_label(
74+
tcx.def_span(anon_const.def_id),
75+
format!("is {} `{}`", ty.kind().article(), ty),
76+
)
77+
.with_help("`sym` operands must refer to either a function or a static")
78+
.emit();
79+
80+
Ty::new_error(tcx, guar)
81+
}
82+
}
83+
}
84+
Node::Expr(&Expr { kind: ExprKind::InlineAsm(asm), .. })
85+
| Node::Item(&Item { kind: ItemKind::GlobalAsm(asm), .. })
86+
if let Some((anon_const, op_sp)) = asm.operands.iter().find_map(find_const) =>
87+
{
88+
let ty = tcx.typeck(def_id).node_type(hir_id);
89+
90+
match ty.kind() {
91+
ty::Error(_) => ty,
92+
ty::Int(_) | ty::Uint(_) => ty,
93+
_ => {
94+
let guar = tcx
95+
.dcx()
96+
.struct_span_err(op_sp, "invalid type for `const` operand")
97+
.with_span_label(
98+
tcx.def_span(anon_const.def_id),
99+
format!("is {} `{}`", ty.kind().article(), ty),
100+
)
101+
.with_help("`const` operands must be of an integer type")
102+
.emit();
103+
104+
Ty::new_error(tcx, guar)
105+
}
106+
}
55107
}
56108
Node::Variant(Variant { disr_expr: Some(ref e), .. }) if e.hir_id == hir_id => {
57109
tcx.adt_def(tcx.hir().get_parent_item(hir_id)).repr().discr_type().to_ty(tcx)

compiler/rustc_hir_typeck/src/lib.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,10 @@ fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Opti
265265
Node::Expr(&hir::Expr { kind: hir::ExprKind::InlineAsm(asm), span, .. })
266266
| Node::Item(&hir::Item { kind: hir::ItemKind::GlobalAsm(asm), span, .. }) => {
267267
asm.operands.iter().find_map(|(op, _op_sp)| match op {
268-
hir::InlineAsmOperand::Const { anon_const } if anon_const.hir_id == id => {
269-
// Inline assembly constants must be integers.
270-
Some(fcx.next_int_var())
271-
}
272-
hir::InlineAsmOperand::SymFn { anon_const } if anon_const.hir_id == id => {
268+
hir::InlineAsmOperand::Const { anon_const }
269+
| hir::InlineAsmOperand::SymFn { anon_const }
270+
if anon_const.hir_id == id =>
271+
{
273272
Some(fcx.next_ty_var(span))
274273
}
275274
_ => None,

compiler/rustc_mir_build/src/build/custom/parse/instruction.rs

+22
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
7575
@call(mir_call, args) => {
7676
self.parse_call(args)
7777
},
78+
@call(mir_tail_call, args) => {
79+
self.parse_tail_call(args)
80+
},
7881
ExprKind::Match { scrutinee, arms, .. } => {
7982
let discr = self.parse_operand(*scrutinee)?;
8083
self.parse_match(arms, expr.span).map(|t| TerminatorKind::SwitchInt { discr, targets: t })
@@ -187,6 +190,25 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
187190
)
188191
}
189192

193+
fn parse_tail_call(&self, args: &[ExprId]) -> PResult<TerminatorKind<'tcx>> {
194+
parse_by_kind!(self, args[0], _, "tail call",
195+
ExprKind::Call { fun, args, fn_span, .. } => {
196+
let fun = self.parse_operand(*fun)?;
197+
let args = args
198+
.iter()
199+
.map(|arg|
200+
Ok(Spanned { node: self.parse_operand(*arg)?, span: self.thir.exprs[*arg].span } )
201+
)
202+
.collect::<PResult<Box<[_]>>>()?;
203+
Ok(TerminatorKind::TailCall {
204+
func: fun,
205+
args,
206+
fn_span: *fn_span,
207+
})
208+
},
209+
)
210+
}
211+
190212
fn parse_rvalue(&self, expr_id: ExprId) -> PResult<Rvalue<'tcx>> {
191213
parse_by_kind!(self, expr_id, expr, "rvalue",
192214
@call(mir_discriminant, args) => self.parse_place(args[0]).map(Rvalue::Discriminant),

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,7 @@ symbols! {
12161216
mir_static_mut,
12171217
mir_storage_dead,
12181218
mir_storage_live,
1219+
mir_tail_call,
12191220
mir_unreachable,
12201221
mir_unwind_cleanup,
12211222
mir_unwind_continue,

compiler/rustc_target/src/spec/targets/riscv64gc_unknown_linux_musl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub fn target() -> Target {
2121
llvm_abiname: "lp64d".into(),
2222
max_atomic_width: Some(64),
2323
supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),
24+
crt_static_default: false,
2425
..base::linux_musl::opts()
2526
},
2627
}

library/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ dependencies = [
5858

5959
[[package]]
6060
name = "compiler_builtins"
61-
version = "0.1.114"
61+
version = "0.1.115"
6262
source = "registry+https://github.com/rust-lang/crates.io-index"
63-
checksum = "eb58b199190fcfe0846f55a3b545cd6b07a34bdd5930a476ff856f3ebcc5558a"
63+
checksum = "3358508f8fe5c43b1d59deef1c190287490a00cce3d7b4a3744e4a35e3f220d0"
6464
dependencies = [
6565
"cc",
6666
"rustc-std-workspace-core",

library/alloc/Cargo.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ edition = "2021"
1010

1111
[dependencies]
1212
core = { path = "../core" }
13-
compiler_builtins = { version = "0.1.114", features = ['rustc-dep-of-std'] }
14-
15-
[target.'cfg(not(any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")))'.dependencies]
16-
compiler_builtins = { version = "0.1.114", features = ["no-f16-f128"] }
13+
compiler_builtins = { version = "0.1.115", features = ['rustc-dep-of-std'] }
1714

1815
[dev-dependencies]
1916
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

library/core/src/intrinsics/mir.rs

+8
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@
247247
//! otherwise branch.
248248
//! - [`Call`] has an associated function as well, with special syntax:
249249
//! `Call(ret_val = function(arg1, arg2, ...), ReturnTo(next_block), UnwindContinue())`.
250+
//! - [`TailCall`] does not have a return destination or next block, so its syntax is just
251+
//! `TailCall(function(arg1, arg2, ...))`.
250252
251253
#![unstable(
252254
feature = "custom_mir",
@@ -350,6 +352,12 @@ define!("mir_call",
350352
/// - [`UnwindCleanup`]
351353
fn Call(call: (), goto: ReturnToArg, unwind_action: UnwindActionArg)
352354
);
355+
define!("mir_tail_call",
356+
/// Call a function.
357+
///
358+
/// The argument must be of the form `fun(arg1, arg2, ...)`.
359+
fn TailCall<T>(call: T)
360+
);
353361
define!("mir_unwind_resume",
354362
/// A terminator that resumes the unwinding.
355363
fn UnwindResume()

library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
1717
panic_unwind = { path = "../panic_unwind", optional = true }
1818
panic_abort = { path = "../panic_abort" }
1919
core = { path = "../core", public = true }
20-
compiler_builtins = { version = "0.1.114" }
20+
compiler_builtins = { version = "0.1.115" }
2121
profiler_builtins = { path = "../profiler_builtins", optional = true }
2222
unwind = { path = "../unwind" }
2323
hashbrown = { version = "0.14", default-features = false, features = [

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ RUN apt-get update && apt-get build-dep -y clang llvm && apt-get install -y --no
2424
# Needed for apt-key to work:
2525
dirmngr \
2626
gpg-agent \
27-
g++-9-arm-linux-gnueabi
27+
g++-9-arm-linux-gnueabi \
28+
g++-11-riscv64-linux-gnu
2829

2930
RUN apt-key adv --batch --yes --keyserver keyserver.ubuntu.com --recv-keys 74DA7924C5513486
3031
RUN add-apt-repository -y 'deb https://apt.dilos.org/dilos dilos2 main'
@@ -73,6 +74,10 @@ RUN env \
7374
CC=arm-linux-gnueabi-gcc-9 CFLAGS="-march=armv7-a" \
7475
CXX=arm-linux-gnueabi-g++-9 CXXFLAGS="-march=armv7-a" \
7576
bash musl.sh armv7 && \
77+
env \
78+
CC=riscv64-linux-gnu-gcc-11 \
79+
CXX=riscv64-linux-gnu-g++-11 \
80+
bash musl.sh riscv64gc && \
7681
rm -rf /build/*
7782

7883
WORKDIR /tmp
@@ -125,14 +130,19 @@ ENV TARGETS=$TARGETS,x86_64-unknown-none
125130
ENV TARGETS=$TARGETS,aarch64-unknown-uefi
126131
ENV TARGETS=$TARGETS,i686-unknown-uefi
127132
ENV TARGETS=$TARGETS,x86_64-unknown-uefi
133+
ENV TARGETS=$TARGETS,riscv64gc-unknown-linux-musl
128134

129135
# As per https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1300211
130136
# we need asm in the search path for gcc-9 (for gnux32) but not in the search path of the
131137
# cross compilers.
132138
# Luckily one of the folders is /usr/local/include so symlink /usr/include/x86_64-linux-gnu/asm there
133139
RUN ln -s /usr/include/x86_64-linux-gnu/asm /usr/local/include/asm
134140

141+
# musl-gcc can't find libgcc_s.so.1 since it doesn't use the standard search paths.
142+
RUN ln -s /usr/riscv64-linux-gnu/lib/libgcc_s.so.1 /usr/lib/gcc-cross/riscv64-linux-gnu/11/
143+
135144
ENV RUST_CONFIGURE_ARGS --enable-extended --enable-lld --enable-llvm-bitcode-linker --disable-docs \
136-
--musl-root-armv7=/musl-armv7
145+
--musl-root-armv7=/musl-armv7 \
146+
--musl-root-riscv64gc=/musl-riscv64gc
137147

138148
ENV SCRIPT python3 ../x.py dist --host='' --target $TARGETS

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
- [riscv32imac-unknown-xous-elf](platform-support/riscv32imac-unknown-xous-elf.md)
6767
- [riscv32*-unknown-none-elf](platform-support/riscv32-unknown-none-elf.md)
6868
- [riscv64gc-unknown-linux-gnu](platform-support/riscv64gc-unknown-linux-gnu.md)
69+
- [riscv64gc-unknown-linux-musl](platform-support/riscv64gc-unknown-linux-musl.md)
6970
- [sparc-unknown-none-elf](./platform-support/sparc-unknown-none-elf.md)
7071
- [*-pc-windows-gnullvm](platform-support/pc-windows-gnullvm.md)
7172
- [\*-nto-qnx-\*](platform-support/nto-qnx.md)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ target | notes
9898
`powerpc64-unknown-linux-gnu` | PPC64 Linux (kernel 3.2, glibc 2.17)
9999
`powerpc64le-unknown-linux-gnu` | PPC64LE Linux (kernel 3.10, glibc 2.17)
100100
[`riscv64gc-unknown-linux-gnu`](platform-support/riscv64gc-unknown-linux-gnu.md) | RISC-V Linux (kernel 4.20, glibc 2.29)
101+
[`riscv64gc-unknown-linux-musl`](platform-support/riscv64gc-unknown-linux-musl.md) | RISC-V Linux (kernel 4.20, musl 1.2.3)
101102
`s390x-unknown-linux-gnu` | S390x Linux (kernel 3.2, glibc 2.17)
102103
`x86_64-unknown-freebsd` | 64-bit FreeBSD
103104
`x86_64-unknown-illumos` | illumos
@@ -354,7 +355,6 @@ target | std | host | notes
354355
[`riscv64gc-unknown-hermit`](platform-support/hermit.md) | ✓ | | RISC-V Hermit
355356
`riscv64gc-unknown-freebsd` | | | RISC-V FreeBSD
356357
`riscv64gc-unknown-fuchsia` | | | RISC-V Fuchsia
357-
`riscv64gc-unknown-linux-musl` | | | RISC-V Linux (kernel 4.20, musl 1.2.3)
358358
[`riscv64gc-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | RISC-V NetBSD
359359
[`riscv64gc-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | OpenBSD/riscv64
360360
[`riscv64-linux-android`](platform-support/android.md) | | | RISC-V 64-bit Android
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# riscv64gc-unknown-linux-musl
2+
3+
**Tier: 2**
4+
5+
Target for RISC-V Linux programs using musl libc.
6+
7+
## Target maintainers
8+
9+
- [@Amanieu](https://github.com/Amanieu)
10+
- [@kraj](https://github.com/kraj)
11+
12+
## Requirements
13+
14+
Building the target itself requires a RISC-V compiler that is supported by `cc-rs`.
15+
16+
## Building the target
17+
18+
The target can be built by enabling it for a `rustc` build.
19+
20+
```toml
21+
[build]
22+
target = ["riscv64gc-unknown-linux-musl"]
23+
```
24+
25+
Make sure your C compiler is included in `$PATH`, then add it to the `config.toml`:
26+
27+
```toml
28+
[target.riscv64gc-unknown-linux-musl]
29+
cc = "riscv64-linux-gnu-gcc"
30+
cxx = "riscv64-linux-gnu-g++"
31+
ar = "riscv64-linux-gnu-ar"
32+
linker = "riscv64-linux-gnu-gcc"
33+
```
34+
35+
## Building Rust programs
36+
37+
This target are distributed through `rustup`, and otherwise require no
38+
special configuration.
39+
40+
## Cross-compilation
41+
42+
This target can be cross-compiled from any host.
43+
44+
## Testing
45+
46+
This target can be tested as normal with `x.py` on a RISC-V host or via QEMU
47+
emulation.

src/tools/build-manifest/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ static TARGETS: &[&str] = &[
141141
"riscv64gc-unknown-hermit",
142142
"riscv64gc-unknown-none-elf",
143143
"riscv64gc-unknown-linux-gnu",
144+
"riscv64gc-unknown-linux-musl",
144145
"s390x-unknown-linux-gnu",
145146
"sparc64-unknown-linux-gnu",
146147
"sparcv9-sun-solaris",

0 commit comments

Comments
 (0)