Skip to content

Commit 7d8dc7a

Browse files
committed
also release-validate return value before a call
1 parent 321a72c commit 7d8dc7a

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

src/librustc_mir/transform/add_validation.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,23 @@ impl MirPass for AddValidation {
248248
match block_data.terminator {
249249
Some(Terminator { kind: TerminatorKind::Call { ref args, ref destination, .. },
250250
source_info }) => {
251-
// Before the call: Release all arguments
251+
// Before the call: Release all arguments *and* the return value.
252+
// The callee may write into the return value! Note that this relies
253+
// on "release of uninitialized" to be a NOP.
252254
if !restricted_validation {
253255
let release_stmt = Statement {
254256
source_info,
255257
kind: StatementKind::Validate(ValidationOp::Release,
256-
args.iter().filter_map(|op| {
257-
match op {
258-
&Operand::Consume(ref lval) =>
259-
Some(lval_to_operand(lval.clone())),
260-
&Operand::Constant(..) => { None },
261-
}
262-
}).collect())
258+
destination.iter().map(|dest| lval_to_operand(dest.0.clone()))
259+
.chain(
260+
args.iter().filter_map(|op| {
261+
match op {
262+
&Operand::Consume(ref lval) =>
263+
Some(lval_to_operand(lval.clone())),
264+
&Operand::Constant(..) => { None },
265+
}
266+
})
267+
).collect())
263268
};
264269
block_data.statements.push(release_stmt);
265270
}

src/test/mir-opt/validate_1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn main() {
4646
// Validate(Suspend(ReScope(Misc(NodeId(34)))), [(*_6): i32/ReScope(Misc(NodeId(34)))]);
4747
// _5 = &ReErased mut (*_6);
4848
// Validate(Acquire, [(*_5): i32/ReScope(Misc(NodeId(34)))]);
49-
// Validate(Release, [_3: &ReScope(Misc(NodeId(34))) Test, _5: &ReScope(Misc(NodeId(34))) mut i32]);
49+
// Validate(Release, [_2: (), _3: &ReScope(Misc(NodeId(34))) Test, _5: &ReScope(Misc(NodeId(34))) mut i32]);
5050
// _2 = const Test::foo(_3, _5) -> bb1;
5151
// }
5252
//

src/test/mir-opt/validate_3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn main() {
3838
// Validate(Suspend(ReScope(Misc(NodeId(46)))), [(*_5): i32/ReScope(Misc(NodeId(46))) (imm)]);
3939
// _4 = &ReErased (*_5);
4040
// Validate(Acquire, [(*_4): i32/ReScope(Misc(NodeId(46))) (imm)]);
41-
// Validate(Release, [_4: &ReScope(Misc(NodeId(46))) i32]);
41+
// Validate(Release, [_3: (), _4: &ReScope(Misc(NodeId(46))) i32]);
4242
// _3 = const foo(_4) -> bb1;
4343
// }
4444
// bb1: {

src/test/mir-opt/validate_5.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn main() {
3737
// fn test(_1: &ReErased mut i32) -> () {
3838
// bb0: {
3939
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(4) => validate_5/8cd878b::test[0] }, BrAnon(0)) mut i32]);
40-
// Validate(Release, [_4: *mut i32]);
40+
// Validate(Release, [_3: bool, _4: *mut i32]);
4141
// _3 = const write_42(_4) -> bb1;
4242
// }
4343
// }

0 commit comments

Comments
 (0)