Skip to content

Commit

Permalink
also release-validate return value before a call
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 2, 2017
1 parent 321a72c commit 7d8dc7a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
21 changes: 13 additions & 8 deletions src/librustc_mir/transform/add_validation.rs
Expand Up @@ -248,18 +248,23 @@ impl MirPass for AddValidation {
match block_data.terminator {
Some(Terminator { kind: TerminatorKind::Call { ref args, ref destination, .. },
source_info }) => {
// Before the call: Release all arguments
// Before the call: Release all arguments *and* the return value.
// The callee may write into the return value! Note that this relies
// on "release of uninitialized" to be a NOP.
if !restricted_validation {
let release_stmt = Statement {
source_info,
kind: StatementKind::Validate(ValidationOp::Release,
args.iter().filter_map(|op| {
match op {
&Operand::Consume(ref lval) =>
Some(lval_to_operand(lval.clone())),
&Operand::Constant(..) => { None },
}
}).collect())
destination.iter().map(|dest| lval_to_operand(dest.0.clone()))
.chain(
args.iter().filter_map(|op| {
match op {
&Operand::Consume(ref lval) =>
Some(lval_to_operand(lval.clone())),
&Operand::Constant(..) => { None },
}
})
).collect())
};
block_data.statements.push(release_stmt);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/validate_1.rs
Expand Up @@ -46,7 +46,7 @@ fn main() {
// Validate(Suspend(ReScope(Misc(NodeId(34)))), [(*_6): i32/ReScope(Misc(NodeId(34)))]);
// _5 = &ReErased mut (*_6);
// Validate(Acquire, [(*_5): i32/ReScope(Misc(NodeId(34)))]);
// Validate(Release, [_3: &ReScope(Misc(NodeId(34))) Test, _5: &ReScope(Misc(NodeId(34))) mut i32]);
// Validate(Release, [_2: (), _3: &ReScope(Misc(NodeId(34))) Test, _5: &ReScope(Misc(NodeId(34))) mut i32]);
// _2 = const Test::foo(_3, _5) -> bb1;
// }
//
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/validate_3.rs
Expand Up @@ -38,7 +38,7 @@ fn main() {
// Validate(Suspend(ReScope(Misc(NodeId(46)))), [(*_5): i32/ReScope(Misc(NodeId(46))) (imm)]);
// _4 = &ReErased (*_5);
// Validate(Acquire, [(*_4): i32/ReScope(Misc(NodeId(46))) (imm)]);
// Validate(Release, [_4: &ReScope(Misc(NodeId(46))) i32]);
// Validate(Release, [_3: (), _4: &ReScope(Misc(NodeId(46))) i32]);
// _3 = const foo(_4) -> bb1;
// }
// bb1: {
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/validate_5.rs
Expand Up @@ -37,7 +37,7 @@ fn main() {
// fn test(_1: &ReErased mut i32) -> () {
// bb0: {
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(4) => validate_5/8cd878b::test[0] }, BrAnon(0)) mut i32]);
// Validate(Release, [_4: *mut i32]);
// Validate(Release, [_3: bool, _4: *mut i32]);
// _3 = const write_42(_4) -> bb1;
// }
// }
Expand Down

0 comments on commit 7d8dc7a

Please sign in to comment.