also release-validate return value before a call

This commit is contained in:
Ralf Jung 2017-08-01 21:06:33 -07:00
parent 321a72c1c1
commit 7d8dc7a979
4 changed files with 16 additions and 11 deletions

View File

@ -248,18 +248,23 @@ fn run_pass<'a, 'tcx>(&self,
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);
}

View File

@ -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;
// }
//

View File

@ -38,7 +38,7 @@ fn _unused2(x: *const i32) -> i32 { unsafe { *x }}
// 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: {

View File

@ -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;
// }
// }