Skip to content

Commit 27a1fd3

Browse files
committed
Merge branch 'rustup'
2 parents d82b696 + 887ca1f commit 27a1fd3

File tree

9 files changed

+111
-105
lines changed

9 files changed

+111
-105
lines changed

build_sysroot/Cargo.lock

+18-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build_system/build_sysroot.rs

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ fn build_clif_sysroot_for_triple(
188188
let mut build_cmd = cargo_command("cargo", "build", Some(triple), Path::new("build_sysroot"));
189189
let mut rustflags = "-Zforce-unstable-if-unmarked -Cpanic=abort".to_string();
190190
rustflags.push_str(&format!(" -Zcodegen-backend={}", cg_clif_dylib_path.to_str().unwrap()));
191+
rustflags.push_str(&format!(" --sysroot={}", target_dir.to_str().unwrap()));
191192
if channel == "release" {
192193
build_cmd.arg("--release");
193194
rustflags.push_str(" -Zmir-opt-level=3");

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2022-09-15"
2+
channel = "nightly-2022-09-25"
33
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

scripts/setup_rust_fork.sh

+15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ index d95b5b7f17f..00b6f0e3635 100644
2727
[dev-dependencies]
2828
rand = "0.7"
2929
rand_xorshift = "0.2"
30+
diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs
31+
index a6333976f2a..c9a872e876c 100644
32+
--- a/src/bootstrap/config.rs
33+
+++ b/src/bootstrap/config.rs
34+
@@ -917,6 +917,10 @@ pub fn parse(args: &[String]) -> Config {
35+
config.initial_cargo = config.out.join(config.build.triple).join("stage0/bin/cargo");
36+
}
37+
38+
+ // Workaround for rustbuild bug
39+
+ config.initial_rustc = PathBuf::from("$(pwd)/../build/rustc-clif");
40+
+ config.initial_cargo = PathBuf::from("$(rustup which cargo)");
41+
+
42+
// NOTE: it's important this comes *after* we set \`initial_rustc\` just above.
43+
if config.dry_run {
44+
let dir = config.out.join("tmp-dry-run");
3045
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
3146
index 8431aa7b818..a3ff7e68ce5 100644
3247
--- a/src/tools/compiletest/src/runtest.rs

scripts/test_rustc_tests.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ rm src/test/incremental/issue-80691-bad-eval-cache.rs # -Cpanic=abort causes abo
3030

3131
# requires compiling with -Cpanic=unwind
3232
rm src/test/ui/test-attrs/test-fn-signature-verification-for-explicit-return-type.rs # "Cannot run dynamic test fn out-of-process"
33-
rm src/test/ui/async-await/async-fn-size-moved-locals.rs # -Cpanic=abort shrinks some generator by one byte
34-
rm src/test/ui/async-await/async-fn-size-uninit-locals.rs # same
35-
rm src/test/ui/generator/size-moved-locals.rs # same
3633
rm -r src/test/ui/macros/rfc-2011-nicer-assert-messages/
3734

3835
# vendor intrinsics
@@ -67,6 +64,7 @@ rm src/test/ui/target-feature/missing-plusminus.rs # error not implemented
6764
rm src/test/ui/fn/dyn-fn-alignment.rs # wants a 256 byte alignment
6865
rm -r src/test/run-make/emit-named-files # requires full --emit support
6966
rm src/test/ui/abi/stack-probes.rs # stack probes not yet implemented
67+
rm src/test/ui/simd/intrinsic/ptr-cast.rs # simd_expose_addr intrinsic unimplemented
7068

7169
# optimization tests
7270
# ==================

src/base.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ pub(crate) fn codegen_place<'tcx>(
850850
PlaceElem::Deref => {
851851
cplace = cplace.place_deref(fx);
852852
}
853+
PlaceElem::OpaqueCast(ty) => cplace = cplace.place_opaque_cast(fx, ty),
853854
PlaceElem::Field(field, _ty) => {
854855
cplace = cplace.place_field(fx, field);
855856
}
@@ -916,7 +917,7 @@ pub(crate) fn codegen_operand<'tcx>(
916917
let cplace = codegen_place(fx, *place);
917918
cplace.to_cvalue(fx)
918919
}
919-
Operand::Constant(const_) => crate::constant::codegen_constant(fx, const_),
920+
Operand::Constant(const_) => crate::constant::codegen_constant_operand(fx, const_),
920921
}
921922
}
922923

src/constant.rs

+53-82
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
55
use rustc_middle::mir::interpret::{
66
read_target_uint, AllocId, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar,
77
};
8-
use rustc_middle::ty::ConstKind;
98
use rustc_span::DUMMY_SP;
109

11-
use cranelift_codegen::ir::GlobalValueData;
1210
use cranelift_module::*;
1311

1412
use crate::prelude::*;
@@ -41,36 +39,22 @@ impl ConstantCx {
4139
pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool {
4240
let mut all_constants_ok = true;
4341
for constant in &fx.mir.required_consts {
44-
let const_ = match fx.monomorphize(constant.literal) {
45-
ConstantKind::Ty(ct) => ct,
42+
let unevaluated = match fx.monomorphize(constant.literal) {
43+
ConstantKind::Ty(_) => unreachable!(),
44+
ConstantKind::Unevaluated(uv, _) => uv,
4645
ConstantKind::Val(..) => continue,
4746
};
48-
match const_.kind() {
49-
ConstKind::Value(_) => {}
50-
ConstKind::Unevaluated(unevaluated) => {
51-
if let Err(err) =
52-
fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None)
53-
{
54-
all_constants_ok = false;
55-
match err {
56-
ErrorHandled::Reported(_) | ErrorHandled::Linted => {
57-
fx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
58-
}
59-
ErrorHandled::TooGeneric => {
60-
span_bug!(
61-
constant.span,
62-
"codegen encountered polymorphic constant: {:?}",
63-
err
64-
);
65-
}
66-
}
47+
48+
if let Err(err) = fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) {
49+
all_constants_ok = false;
50+
match err {
51+
ErrorHandled::Reported(_) | ErrorHandled::Linted => {
52+
fx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
53+
}
54+
ErrorHandled::TooGeneric => {
55+
span_bug!(constant.span, "codegen encountered polymorphic constant: {:?}", err);
6756
}
6857
}
69-
ConstKind::Param(_)
70-
| ConstKind::Infer(_)
71-
| ConstKind::Bound(_, _)
72-
| ConstKind::Placeholder(_)
73-
| ConstKind::Error(_) => unreachable!("{:?}", const_),
7458
}
7559
}
7660
all_constants_ok
@@ -96,62 +80,47 @@ pub(crate) fn codegen_tls_ref<'tcx>(
9680
CValue::by_val(tls_ptr, layout)
9781
}
9882

99-
fn codegen_static_ref<'tcx>(
100-
fx: &mut FunctionCx<'_, '_, 'tcx>,
101-
def_id: DefId,
102-
layout: TyAndLayout<'tcx>,
103-
) -> CPlace<'tcx> {
104-
let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false);
105-
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
106-
if fx.clif_comments.enabled() {
107-
fx.add_comment(local_data_id, format!("{:?}", def_id));
108-
}
109-
let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);
110-
assert!(!layout.is_unsized(), "unsized statics aren't supported");
111-
assert!(
112-
matches!(
113-
fx.bcx.func.global_values[local_data_id],
114-
GlobalValueData::Symbol { tls: false, .. }
115-
),
116-
"tls static referenced without Rvalue::ThreadLocalRef"
117-
);
118-
CPlace::for_ptr(crate::pointer::Pointer::new(global_ptr), layout)
119-
}
120-
121-
pub(crate) fn codegen_constant<'tcx>(
83+
pub(crate) fn eval_mir_constant<'tcx>(
12284
fx: &mut FunctionCx<'_, '_, 'tcx>,
12385
constant: &Constant<'tcx>,
124-
) -> CValue<'tcx> {
125-
let const_ = match fx.monomorphize(constant.literal) {
126-
ConstantKind::Ty(ct) => ct,
127-
ConstantKind::Val(val, ty) => return codegen_const_value(fx, val, ty),
128-
};
129-
let const_val = match const_.kind() {
130-
ConstKind::Value(valtree) => fx.tcx.valtree_to_const_val((const_.ty(), valtree)),
131-
ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted })
86+
) -> (ConstValue<'tcx>, Ty<'tcx>) {
87+
let constant_kind = fx.monomorphize(constant.literal);
88+
let uv = match constant_kind {
89+
ConstantKind::Ty(const_) => match const_.kind() {
90+
ty::ConstKind::Unevaluated(uv) => uv.expand(),
91+
ty::ConstKind::Value(val) => {
92+
return (fx.tcx.valtree_to_const_val((const_.ty(), val)), const_.ty());
93+
}
94+
err => span_bug!(
95+
constant.span,
96+
"encountered bad ConstKind after monomorphizing: {:?}",
97+
err
98+
),
99+
},
100+
ConstantKind::Unevaluated(mir::UnevaluatedConst { def, .. }, _)
132101
if fx.tcx.is_static(def.did) =>
133102
{
134-
assert!(substs.is_empty());
135-
assert!(promoted.is_none());
136-
137-
return codegen_static_ref(fx, def.did, fx.layout_of(const_.ty())).to_cvalue(fx);
138-
}
139-
ConstKind::Unevaluated(unevaluated) => {
140-
match fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) {
141-
Ok(const_val) => const_val,
142-
Err(_) => {
143-
span_bug!(constant.span, "erroneous constant not captured by required_consts");
144-
}
145-
}
103+
span_bug!(constant.span, "MIR constant refers to static");
146104
}
147-
ConstKind::Param(_)
148-
| ConstKind::Infer(_)
149-
| ConstKind::Bound(_, _)
150-
| ConstKind::Placeholder(_)
151-
| ConstKind::Error(_) => unreachable!("{:?}", const_),
105+
ConstantKind::Unevaluated(uv, _) => uv,
106+
ConstantKind::Val(val, _) => return (val, constant_kind.ty()),
152107
};
153108

154-
codegen_const_value(fx, const_val, const_.ty())
109+
(
110+
fx.tcx.const_eval_resolve(ty::ParamEnv::reveal_all(), uv, None).unwrap_or_else(|_err| {
111+
span_bug!(constant.span, "erroneous constant not captured by required_consts");
112+
}),
113+
constant_kind.ty(),
114+
)
115+
}
116+
117+
pub(crate) fn codegen_constant_operand<'tcx>(
118+
fx: &mut FunctionCx<'_, '_, 'tcx>,
119+
constant: &Constant<'tcx>,
120+
) -> CValue<'tcx> {
121+
let (const_val, ty) = eval_mir_constant(fx, constant);
122+
123+
codegen_const_value(fx, const_val, ty)
155124
}
156125

157126
pub(crate) fn codegen_const_value<'tcx>(
@@ -490,12 +459,14 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
490459
operand: &Operand<'tcx>,
491460
) -> Option<ConstValue<'tcx>> {
492461
match operand {
493-
Operand::Constant(const_) => match const_.literal {
494-
ConstantKind::Ty(const_) => fx
495-
.monomorphize(const_)
496-
.eval_for_mir(fx.tcx, ParamEnv::reveal_all())
497-
.try_to_value(fx.tcx),
462+
Operand::Constant(const_) => match fx.monomorphize(const_.literal) {
463+
ConstantKind::Ty(const_) => Some(
464+
const_.eval_for_mir(fx.tcx, ParamEnv::reveal_all()).try_to_value(fx.tcx).unwrap(),
465+
),
498466
ConstantKind::Val(val, _) => Some(val),
467+
ConstantKind::Unevaluated(uv, _) => {
468+
Some(fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), uv, None).unwrap())
469+
}
499470
},
500471
// FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored
501472
// inside a temporary before being passed to the intrinsic requiring the const argument.

src/inline_asm.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) fn codegen_inline_asm<'tcx>(
2727
}
2828

2929
// Used by stdarch
30-
if template[0] == InlineAsmTemplatePiece::String("movq %rbx, ".to_string())
30+
if template[0] == InlineAsmTemplatePiece::String("mov ".to_string())
3131
&& matches!(
3232
template[1],
3333
InlineAsmTemplatePiece::Placeholder {
@@ -36,24 +36,26 @@ pub(crate) fn codegen_inline_asm<'tcx>(
3636
span: _
3737
}
3838
)
39-
&& template[2] == InlineAsmTemplatePiece::String("\n".to_string())
40-
&& template[3] == InlineAsmTemplatePiece::String("cpuid".to_string())
41-
&& template[4] == InlineAsmTemplatePiece::String("\n".to_string())
42-
&& template[5] == InlineAsmTemplatePiece::String("xchgq %rbx, ".to_string())
39+
&& template[2] == InlineAsmTemplatePiece::String(", rbx".to_string())
40+
&& template[3] == InlineAsmTemplatePiece::String("\n".to_string())
41+
&& template[4] == InlineAsmTemplatePiece::String("cpuid".to_string())
42+
&& template[5] == InlineAsmTemplatePiece::String("\n".to_string())
43+
&& template[6] == InlineAsmTemplatePiece::String("xchg ".to_string())
4344
&& matches!(
44-
template[6],
45+
template[7],
4546
InlineAsmTemplatePiece::Placeholder {
4647
operand_idx: 0,
4748
modifier: Some('r'),
4849
span: _
4950
}
5051
)
52+
&& template[8] == InlineAsmTemplatePiece::String(", rbx".to_string())
5153
{
5254
assert_eq!(operands.len(), 4);
5355
let (leaf, eax_place) = match operands[1] {
5456
InlineAsmOperand::InOut {
5557
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)),
56-
late: true,
58+
late: _,
5759
ref in_value,
5860
out_place: Some(out_place),
5961
} => (
@@ -68,15 +70,15 @@ pub(crate) fn codegen_inline_asm<'tcx>(
6870
InlineAsmRegOrRegClass::RegClass(InlineAsmRegClass::X86(
6971
X86InlineAsmRegClass::reg,
7072
)),
71-
late: true,
73+
late: _,
7274
place: Some(place),
7375
} => crate::base::codegen_place(fx, place),
7476
_ => unreachable!(),
7577
};
7678
let (sub_leaf, ecx_place) = match operands[2] {
7779
InlineAsmOperand::InOut {
7880
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::cx)),
79-
late: true,
81+
late: _,
8082
ref in_value,
8183
out_place: Some(out_place),
8284
} => (
@@ -88,7 +90,7 @@ pub(crate) fn codegen_inline_asm<'tcx>(
8890
let edx_place = match operands[3] {
8991
InlineAsmOperand::Out {
9092
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::dx)),
91-
late: true,
93+
late: _,
9294
place: Some(place),
9395
} => crate::base::codegen_place(fx, place),
9496
_ => unreachable!(),

0 commit comments

Comments
 (0)