Skip to content

Commit 5efa045

Browse files
authored
Rollup merge of rust-lang#46852 - scottmcm:asm-placecontext, r=arielb1
Split PlaceContext::Store into Store & AsmOutput Outputs in InlineAsm can be read-write, so splitting it out is useful for things like Store-Store folding, as that's unsound for a Store-AsmOutput. This PR is intended to make no changes, just be the mechanical split of the enum. Future changes can use the split, like a MIR pass I'm working on and perhaps two-phase borrows (see this FIXME: https://github.com/rust-lang/rust/pull/46852/files#diff-74dcd7740ab2104cd2b9a3b68dd4f208R543)
2 parents 0c29c7b + fb245e0 commit 5efa045

File tree

6 files changed

+18
-2
lines changed

6 files changed

+18
-2
lines changed

src/librustc/mir/visit.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ macro_rules! make_mir_visitor {
376376
ref $($mutability)* inputs,
377377
asm: _ } => {
378378
for output in & $($mutability)* outputs[..] {
379-
self.visit_place(output, PlaceContext::Store, location);
379+
self.visit_place(output, PlaceContext::AsmOutput, location);
380380
}
381381
for input in & $($mutability)* inputs[..] {
382382
self.visit_operand(input, location);
@@ -835,6 +835,11 @@ pub enum PlaceContext<'tcx> {
835835
// Appears as LHS of an assignment
836836
Store,
837837

838+
// Can often be treated as a Store, but needs to be separate because
839+
// ASM is allowed to read outputs as well, so a Store-AsmOutput sequence
840+
// cannot be simplified the way a Store-Store can be.
841+
AsmOutput,
842+
838843
// Dest of a call
839844
Call,
840845

@@ -910,7 +915,7 @@ impl<'tcx> PlaceContext<'tcx> {
910915
/// Returns true if this place context represents a use that potentially changes the value.
911916
pub fn is_mutating_use(&self) -> bool {
912917
match *self {
913-
PlaceContext::Store | PlaceContext::Call |
918+
PlaceContext::Store | PlaceContext::AsmOutput | PlaceContext::Call |
914919
PlaceContext::Borrow { kind: BorrowKind::Mut, .. } |
915920
PlaceContext::Projection(Mutability::Mut) |
916921
PlaceContext::Drop => true,
@@ -932,6 +937,7 @@ impl<'tcx> PlaceContext<'tcx> {
932937
PlaceContext::Projection(Mutability::Not) |
933938
PlaceContext::Copy | PlaceContext::Move => true,
934939
PlaceContext::Borrow { kind: BorrowKind::Mut, .. } | PlaceContext::Store |
940+
PlaceContext::AsmOutput |
935941
PlaceContext::Call | PlaceContext::Projection(Mutability::Mut) |
936942
PlaceContext::Drop | PlaceContext::StorageLive | PlaceContext::StorageDead |
937943
PlaceContext::Validate => false,

src/librustc_mir/dataflow/impls/borrows.rs

+4
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,10 @@ impl<'a, 'b, 'tcx> FindPlaceUses<'a, 'b, 'tcx> {
540540
// "deep" does validation go?
541541
PlaceContext::Validate => false,
542542

543+
// FIXME: This is here to not change behaviour from before
544+
// AsmOutput existed, but it's not necessarily a pure overwrite.
545+
// so it's possible this should activate the place.
546+
PlaceContext::AsmOutput |
543547
// pure overwrites of an place do not activate it. (note
544548
// PlaceContext::Call is solely about dest place)
545549
PlaceContext::Store | PlaceContext::Call => false,

src/librustc_mir/transform/check_unsafety.rs

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
173173
ty::TyAdt(adt, _) => {
174174
if adt.is_union() {
175175
if context == PlaceContext::Store ||
176+
context == PlaceContext::AsmOutput ||
176177
context == PlaceContext::Drop
177178
{
178179
let elem_ty = match elem {

src/librustc_mir/transform/promote_consts.rs

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl<'tcx> Visitor<'tcx> for TempCollector<'tcx> {
103103
if *temp == TempState::Undefined {
104104
match context {
105105
PlaceContext::Store |
106+
PlaceContext::AsmOutput |
106107
PlaceContext::Call => {
107108
*temp = TempState::Defined {
108109
location,

src/librustc_mir/util/liveness.rs

+3
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ impl<'tcx> Visitor<'tcx> for DefsUsesVisitor {
273273

274274
PlaceContext::Store |
275275

276+
// This is potentially both a def and a use...
277+
PlaceContext::AsmOutput |
278+
276279
// We let Call define the result in both the success and
277280
// unwind cases. This is not really correct, however it
278281
// does not seem to be observable due to the way that we

src/librustc_trans/mir/analyze.rs

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {
193193

194194
PlaceContext::Inspect |
195195
PlaceContext::Store |
196+
PlaceContext::AsmOutput |
196197
PlaceContext::Borrow { .. } |
197198
PlaceContext::Projection(..) => {
198199
self.mark_as_memory(index);

0 commit comments

Comments
 (0)