Skip to content

Commit c367798

Browse files
committed
Auto merge of #74746 - wesleywiser:stable_backport_73669, r=Mark-Simulacrum
Stable backport of #73613 This is the backport of #73613 to stable. r? @ghost cc @Mark-Simulacrum In addition the tests added in the original PR passing, I've also confirmed that the test case in #74739 works correctly.
2 parents 14485ee + 41895ca commit c367798

File tree

14 files changed

+207
-108
lines changed

14 files changed

+207
-108
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ jobs:
101101
- name: install MSYS2
102102
run: src/ci/scripts/install-msys2.sh
103103
if: success() && !env.SKIP_JOB
104-
- name: install MSYS2 packages
105-
run: src/ci/scripts/install-msys2-packages.sh
106-
if: success() && !env.SKIP_JOB
107104
- name: install MinGW
108105
run: src/ci/scripts/install-mingw.sh
109106
if: success() && !env.SKIP_JOB
@@ -210,9 +207,6 @@ jobs:
210207
- name: install MSYS2
211208
run: src/ci/scripts/install-msys2.sh
212209
if: success() && !env.SKIP_JOB
213-
- name: install MSYS2 packages
214-
run: src/ci/scripts/install-msys2-packages.sh
215-
if: success() && !env.SKIP_JOB
216210
- name: install MinGW
217211
run: src/ci/scripts/install-mingw.sh
218212
if: success() && !env.SKIP_JOB
@@ -561,9 +555,6 @@ jobs:
561555
- name: install MSYS2
562556
run: src/ci/scripts/install-msys2.sh
563557
if: success() && !env.SKIP_JOB
564-
- name: install MSYS2 packages
565-
run: src/ci/scripts/install-msys2-packages.sh
566-
if: success() && !env.SKIP_JOB
567558
- name: install MinGW
568559
run: src/ci/scripts/install-mingw.sh
569560
if: success() && !env.SKIP_JOB

RELEASES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
Version 1.45.1 (2020-07-30)
22
==========================
33

4+
* [Fix const propagation with references.][73613]
45
* [rustfmt accepts rustfmt_skip in cfg_attr again.][73078]
56
* [Avoid spurious implicit region bound.][74509]
67
* [Install clippy on x.py install][74457]
78

9+
[73613]: https://github.com/rust-lang/rust/pull/73613
810
[73078]: https://github.com/rust-lang/rust/issues/73078
911
[74509]: https://github.com/rust-lang/rust/pull/74509
1012
[74457]: https://github.com/rust-lang/rust/pull/74457

src/ci/azure-pipelines/steps/run.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ steps:
8282
displayName: Install msys2
8383
condition: and(succeeded(), not(variables.SKIP_JOB))
8484

85-
- bash: src/ci/scripts/install-msys2-packages.sh
86-
displayName: Install msys2 packages
87-
condition: and(succeeded(), not(variables.SKIP_JOB))
88-
8985
- bash: src/ci/scripts/install-mingw.sh
9086
displayName: Install MinGW
9187
condition: and(succeeded(), not(variables.SKIP_JOB))

src/ci/github-actions/ci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ x--expand-yaml-anchors--remove:
146146
run: src/ci/scripts/install-msys2.sh
147147
<<: *step
148148

149-
- name: install MSYS2 packages
150-
run: src/ci/scripts/install-msys2-packages.sh
151-
<<: *step
152-
153149
- name: install MinGW
154150
run: src/ci/scripts/install-mingw.sh
155151
<<: *step

src/ci/scripts/install-msys2-packages.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/ci/scripts/install-msys2.sh

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
#!/bin/bash
22
# Download and install MSYS2, needed primarily for the test suite (run-make) but
33
# also used by the MinGW toolchain for assembling things.
4-
#
5-
# FIXME: we should probe the default azure image and see if we can use the MSYS2
6-
# toolchain there. (if there's even one there). For now though this gets the job
7-
# done.
84

95
set -euo pipefail
106
IFS=$'\n\t'
117

128
source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
139

1410
if isWindows; then
15-
# Pre-followed the api/v2 URL to the CDN since the API can be a bit flakey
16-
curl -sSL https://packages.chocolatey.org/msys2.20190524.0.0.20191030.nupkg > \
17-
msys2.nupkg
18-
curl -sSL https://packages.chocolatey.org/chocolatey-core.extension.1.3.5.1.nupkg > \
19-
chocolatey-core.extension.nupkg
20-
choco install -s . msys2 \
21-
--params="/InstallDir:$(ciCheckoutPath)/msys2 /NoPath" -y --no-progress
22-
rm msys2.nupkg chocolatey-core.extension.nupkg
23-
mkdir -p "$(ciCheckoutPath)/msys2/home/${USERNAME}"
24-
ciCommandAddPath "$(ciCheckoutPath)/msys2/usr/bin"
11+
msys2Path="c:/msys64"
12+
mkdir -p "${msys2Path}/home/${USERNAME}"
13+
ciCommandAddPath "${msys2Path}/usr/bin"
2514

2615
# Detect the native Python version installed on the agent. On GitHub
2716
# Actions, the C:\hostedtoolcache\windows\Python directory contains a

src/librustc_mir/transform/const_prop.rs

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,16 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
580580
}
581581

582582
// Do not try creating references (#67862)
583-
Rvalue::Ref(_, _, place_ref) => {
584-
trace!("skipping Ref({:?})", place_ref);
583+
Rvalue::AddressOf(_, place) | Rvalue::Ref(_, _, place) => {
584+
trace!("skipping AddressOf | Ref for {:?}", place);
585+
586+
// This may be creating mutable references or immutable references to cells.
587+
// If that happens, the pointed to value could be mutated via that reference.
588+
// Since we aren't tracking references, the const propagator loses track of what
589+
// value the local has right now.
590+
// Thus, all locals that have their reference taken
591+
// must not take part in propagation.
592+
Self::remove_const(&mut self.ecx, place.local);
585593

586594
return None;
587595
}
@@ -726,7 +734,8 @@ enum ConstPropMode {
726734
OnlyInsideOwnBlock,
727735
/// The `Local` can be propagated into but reads cannot be propagated.
728736
OnlyPropagateInto,
729-
/// No propagation is allowed at all.
737+
/// The `Local` cannot be part of propagation at all. Any statement
738+
/// referencing it either for reading or writing will not get propagated.
730739
NoPropagation,
731740
}
732741

@@ -793,7 +802,9 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
793802
// end of the block anyway, and inside the block we overwrite previous
794803
// states as applicable.
795804
ConstPropMode::OnlyInsideOwnBlock => {}
796-
other => {
805+
ConstPropMode::NoPropagation => {}
806+
ConstPropMode::OnlyPropagateInto => {}
807+
other @ ConstPropMode::FullConstProp => {
797808
trace!(
798809
"local {:?} can't be propagated because of multiple assignments",
799810
local,
@@ -880,13 +891,22 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
880891
}
881892
}
882893
}
883-
if can_const_prop == ConstPropMode::OnlyPropagateInto
884-
|| can_const_prop == ConstPropMode::NoPropagation
885-
{
886-
trace!("can't propagate into {:?}", place);
887-
if place.local != RETURN_PLACE {
888-
Self::remove_const(&mut self.ecx, place.local);
894+
match can_const_prop {
895+
ConstPropMode::OnlyInsideOwnBlock => {
896+
trace!(
897+
"found local restricted to its block. \
898+
Will remove it from const-prop after block is finished. Local: {:?}",
899+
place.local
900+
);
901+
self.locals_of_current_block.insert(place.local);
902+
}
903+
ConstPropMode::OnlyPropagateInto | ConstPropMode::NoPropagation => {
904+
trace!("can't propagate into {:?}", place);
905+
if place.local != RETURN_PLACE {
906+
Self::remove_const(&mut self.ecx, place.local);
907+
}
889908
}
909+
ConstPropMode::FullConstProp => {}
890910
}
891911
} else {
892912
// Const prop failed, so erase the destination, ensuring that whatever happens
@@ -906,6 +926,12 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
906926
);
907927
Self::remove_const(&mut self.ecx, place.local);
908928
}
929+
} else {
930+
trace!(
931+
"cannot propagate into {:?}, because the type of the local is generic.",
932+
place,
933+
);
934+
Self::remove_const(&mut self.ecx, place.local);
909935
}
910936
} else {
911937
match statement.kind {

src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/32bit/rustc.main.ConstProp.diff

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,8 @@
4646
// mir::Constant
4747
// + span: $DIR/bad_op_unsafe_oob_for_slices.rs:7:23: 7:24
4848
// + literal: Const { ty: usize, val: Value(Scalar(0x00000003)) }
49-
- _7 = Len((*_1)); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
50-
- _8 = Lt(_6, _7); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
51-
+ _7 = const 3usize; // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
52-
+ // ty::Const
53-
+ // + ty: usize
54-
+ // + val: Value(Scalar(0x00000003))
55-
+ // mir::Constant
56-
+ // + span: $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
57-
+ // + literal: Const { ty: usize, val: Value(Scalar(0x00000003)) }
58-
+ _8 = const false; // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
59-
+ // ty::Const
60-
+ // + ty: bool
61-
+ // + val: Value(Scalar(0x00))
62-
+ // mir::Constant
63-
+ // + span: $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
64-
+ // + literal: Const { ty: bool, val: Value(Scalar(0x00)) }
49+
_7 = Len((*_1)); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
50+
_8 = Lt(_6, _7); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
6551
assert(move _8, "index out of bounds: the len is {} but the index is {}", move _7, _6) -> bb1; // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
6652
}
6753

src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/64bit/rustc.main.ConstProp.diff

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,8 @@
4646
// mir::Constant
4747
// + span: $DIR/bad_op_unsafe_oob_for_slices.rs:7:23: 7:24
4848
// + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000003)) }
49-
- _7 = Len((*_1)); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
50-
- _8 = Lt(_6, _7); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
51-
+ _7 = const 3usize; // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
52-
+ // ty::Const
53-
+ // + ty: usize
54-
+ // + val: Value(Scalar(0x0000000000000003))
55-
+ // mir::Constant
56-
+ // + span: $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
57-
+ // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000003)) }
58-
+ _8 = const false; // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
59-
+ // ty::Const
60-
+ // + ty: bool
61-
+ // + val: Value(Scalar(0x00))
62-
+ // mir::Constant
63-
+ // + span: $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
64-
+ // + literal: Const { ty: bool, val: Value(Scalar(0x00)) }
49+
_7 = Len((*_1)); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
50+
_8 = Lt(_6, _7); // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
6551
assert(move _8, "index out of bounds: the len is {} but the index is {}", move _7, _6) -> bb1; // scope 2 at $DIR/bad_op_unsafe_oob_for_slices.rs:7:18: 7:25
6652
}
6753

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![feature(raw_ref_op)]
2+
3+
// EMIT_MIR rustc.foo.ConstProp.diff
4+
fn foo() {
5+
let mut u = (1,);
6+
*&mut u.0 = 5;
7+
let y = { u.0 } == 5;
8+
}
9+
10+
// EMIT_MIR rustc.bar.ConstProp.diff
11+
fn bar() {
12+
let mut v = (1,);
13+
unsafe {
14+
*&raw mut v.0 = 5;
15+
}
16+
let y = { v.0 } == 5;
17+
}
18+
19+
fn main() {
20+
foo();
21+
bar();
22+
}

0 commit comments

Comments
 (0)