Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic support for memory initialization checks for unions #3444

Merged
merged 22 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d77365d
Avoid corner-cases by grouping instrumentation into basic blocks
artemagvanian Aug 14, 2024
63f29b6
Implement memory initialization state copy functionality
artemagvanian Aug 14, 2024
3105997
Support for basic intra-body memory initialization checks for unions
artemagvanian Aug 15, 2024
50c1114
Formatting + error message changes
artemagvanian Aug 16, 2024
e7b81bc
Merge branch 'main' into uninit-unions
artemagvanian Aug 16, 2024
5649ad8
Remove accidentally added files
artemagvanian Aug 16, 2024
f6c0b05
Add annotations to union tests
artemagvanian Aug 22, 2024
2f9acc5
Merge branch 'main' into uninit-unions
artemagvanian Aug 22, 2024
acf6d91
Merge branch 'main' into uninit-unions
artemagvanian Aug 22, 2024
8ef14f0
More tests and test fixes
artemagvanian Aug 22, 2024
0f2ed21
Ensure that intermediate union field accesses are instrumented
artemagvanian Aug 22, 2024
9831c1a
Merge branch 'main' into uninit-unions
artemagvanian Aug 22, 2024
188930f
Minor changes
artemagvanian Aug 22, 2024
7d37197
Disable pointer checks for new instrumentation
artemagvanian Aug 24, 2024
bd9d4f8
Address comments from code review
artemagvanian Aug 24, 2024
0ced823
Merge branch 'main' into uninit-unions
artemagvanian Aug 24, 2024
64e21a3
Revert intermediate place checking since uninitialized intermediate p…
artemagvanian Aug 26, 2024
1cbb813
Merge branch 'main' into uninit-unions
artemagvanian Aug 26, 2024
22ba6cf
Fail if dereference is detected in union field projection
artemagvanian Aug 26, 2024
825bd37
Fix comment typo
artemagvanian Aug 27, 2024
d351eb9
Add const str's for diagnostic functions
artemagvanian Aug 27, 2024
405a1ad
Merge branch 'main' into uninit-unions
artemagvanian Aug 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions kani-compiler/src/kani_middle/transform/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,16 +310,16 @@ impl MutableBody {
// Update the source to point at the terminator.
*source = SourceInstruction::Terminator { bb: orig_bb };
}
// Make the terminator at `source` point at the new block,
// the terminator of which is a simple Goto instruction.
// Make the terminator at `source` point at the new block, the terminator of which is
// provided by the caller.
SourceInstruction::Terminator { bb } => {
let current_term = &mut self.blocks.get_mut(*bb).unwrap().terminator;
let target_bb = get_mut_target_ref(current_term);
let new_target_bb = get_mut_target_ref(&mut new_term);
// Set the new terminator to point where previous terminator pointed.
*new_target_bb = *target_bb;
// Point the current terminator to the new terminator's basic block.
*target_bb = new_bb_idx;
// Swap the targets of the newly inserted terminator and the original one. This is
// an easy way to make the original terminator point to the new basic block with the
// new terminator.
std::mem::swap(new_target_bb, target_bb);
// Update the source to point at the terminator.
*bb = new_bb_idx;
self.blocks.push(BasicBlock { statements: vec![], terminator: new_term });
Expand Down Expand Up @@ -503,6 +503,10 @@ impl SourceInstruction {
SourceInstruction::Statement { bb, .. } | SourceInstruction::Terminator { bb } => bb,
}
}

pub fn is_terminator(&self) -> bool {
matches!(self, SourceInstruction::Terminator { .. })
}
}

fn find_instance(tcx: TyCtxt, diagnostic: &str) -> Option<Instance> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use crate::kani_middle::{
points_to::{run_points_to_analysis, MemLoc, PointsToGraph},
reachability::CallGraph,
transform::{
body::{CheckType, MutableBody},
check_uninit::UninitInstrumenter,
BodyTransformation, GlobalPass, TransformationResult,
body::CheckType, check_uninit::UninitInstrumenter, BodyTransformation, GlobalPass,
TransformationResult,
},
};
use crate::kani_queries::QueryDb;
Expand Down Expand Up @@ -112,25 +111,27 @@ impl GlobalPass for DelayedUbPass {

// Instrument each instance based on the final targets we found.
for instance in instances {
let mut instrumenter = UninitInstrumenter {
check_type: self.check_type.clone(),
mem_init_fn_cache: &mut self.mem_init_fn_cache,
};
// Retrieve the body with all local instrumentation passes applied.
let body = MutableBody::from(transformer.body(tcx, instance));
let body = transformer.body(tcx, instance);
// Instrument for delayed UB.
let target_finder = InstrumentationVisitor::new(
&global_points_to_graph,
&analysis_targets,
instance,
tcx,
);
let (instrumentation_added, body) =
instrumenter.instrument(tcx, body, instance, target_finder);
let (instrumentation_added, body) = UninitInstrumenter::run(
body,
tcx,
instance,
self.check_type.clone(),
&mut self.mem_init_fn_cache,
target_finder,
);
// If some instrumentation has been performed, update the cached body in the local transformer.
if instrumentation_added {
transformer.cache.entry(instance).and_modify(|transformation_result| {
*transformation_result = TransformationResult::Modified(body.into());
*transformation_result = TransformationResult::Modified(body);
});
}
}
Expand Down
Loading
Loading