Unverified Commit 1fcc30cb by Enkelmann Committed by GitHub

Prevent panic on non-converging globals propagation (#409)

parent d84f5170
...@@ -10,6 +10,7 @@ use crate::analysis::callgraph::get_program_callgraph; ...@@ -10,6 +10,7 @@ use crate::analysis::callgraph::get_program_callgraph;
use crate::analysis::callgraph::CallGraph; use crate::analysis::callgraph::CallGraph;
use crate::analysis::fixpoint::{Computation, Context}; use crate::analysis::fixpoint::{Computation, Context};
use crate::intermediate_representation::*; use crate::intermediate_representation::*;
use crate::utils::log::LogMessage;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::collections::HashSet; use std::collections::HashSet;
...@@ -162,6 +163,7 @@ fn propagate_globals_bottom_up( ...@@ -162,6 +163,7 @@ fn propagate_globals_bottom_up(
project: &Project, project: &Project,
known_globals: &BTreeMap<Tid, HashSet<u64>>, known_globals: &BTreeMap<Tid, HashSet<u64>>,
fn_sigs: &mut BTreeMap<Tid, FunctionSignature>, fn_sigs: &mut BTreeMap<Tid, FunctionSignature>,
logs: &mut Vec<LogMessage>,
) { ) {
// To propagate bottom-up, we have to reverse the edges in the callgraph // To propagate bottom-up, we have to reverse the edges in the callgraph
let mut graph = get_program_callgraph(&project.program); let mut graph = get_program_callgraph(&project.program);
...@@ -183,7 +185,11 @@ fn propagate_globals_bottom_up( ...@@ -183,7 +185,11 @@ fn propagate_globals_bottom_up(
// Compute the fixpoint // Compute the fixpoint
computation.compute_with_max_steps(100); computation.compute_with_max_steps(100);
if !computation.has_stabilized() { if !computation.has_stabilized() {
panic!("Global parameter propagation algorithm did not stabilize.") let error_msg = format!(
"Global parameter propagation algorithm did not stabilize. Remaining worklist size: {}",
computation.get_worklist().len()
);
logs.push(LogMessage::new_error(error_msg).source("Function Signature Analysis"));
} }
// Add the propagated globals to the function signatures // Add the propagated globals to the function signatures
for node in graph.node_indices() { for node in graph.node_indices() {
...@@ -217,9 +223,13 @@ fn propagate_globals_bottom_up( ...@@ -217,9 +223,13 @@ fn propagate_globals_bottom_up(
/// But if the function itself (or any of its callers) do not access the global variable, /// But if the function itself (or any of its callers) do not access the global variable,
/// then there is no benefit in tracking its value for the function itself. /// then there is no benefit in tracking its value for the function itself.
/// Thus, the global variable should not be propagated to the function in such a case. /// Thus, the global variable should not be propagated to the function in such a case.
pub fn propagate_globals(project: &Project, fn_sigs: &mut BTreeMap<Tid, FunctionSignature>) { pub fn propagate_globals(
project: &Project,
fn_sigs: &mut BTreeMap<Tid, FunctionSignature>,
logs: &mut Vec<LogMessage>,
) {
let known_globals = propagate_known_globals_top_down(project, fn_sigs); let known_globals = propagate_known_globals_top_down(project, fn_sigs);
propagate_globals_bottom_up(project, &known_globals, fn_sigs); propagate_globals_bottom_up(project, &known_globals, fn_sigs, logs);
} }
#[cfg(test)] #[cfg(test)]
...@@ -271,7 +281,7 @@ pub mod tests { ...@@ -271,7 +281,7 @@ pub mod tests {
]); ]);
// Propagate globals // Propagate globals
propagate_globals(&project, &mut fn_sigs); propagate_globals(&project, &mut fn_sigs, &mut Vec::new());
// Check propagation results // Check propagation results
assert_eq!( assert_eq!(
&fn_sigs[&Tid::new("main")].global_parameters, &fn_sigs[&Tid::new("main")].global_parameters,
......
...@@ -168,7 +168,7 @@ pub fn compute_function_signatures<'a>( ...@@ -168,7 +168,7 @@ pub fn compute_function_signatures<'a>(
} }
} }
// Propagate globals in bottom-up direction in the call graph // Propagate globals in bottom-up direction in the call graph
propagate_globals(project, &mut fn_sig_map); propagate_globals(project, &mut fn_sig_map, &mut logs);
(fn_sig_map, logs) (fn_sig_map, logs)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment