diff options
author | David Malcolm <dmalcolm@redhat.com> | 2021-03-26 13:26:15 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2021-03-30 17:51:21 -0400 |
commit | 0f9aa35c79a0fe195d5076375b5794246cf44819 (patch) | |
tree | b6811f24977b7776b2a2077116ab64242e1ffd85 /gcc/analyzer/sm-malloc.cc | |
parent | a01f5fd71031bb34fd9d2792e6ec42d982c68a8e (diff) | |
download | gcc-0f9aa35c79a0fe195d5076375b5794246cf44819.zip gcc-0f9aa35c79a0fe195d5076375b5794246cf44819.tar.gz gcc-0f9aa35c79a0fe195d5076375b5794246cf44819.tar.bz2 |
analyzer: only call get_diagnostic_tree when it's needed
impl_sm_context::get_diagnostic_tree could be expensive, and
I find myself needing to put a breakpoint on it to debug
PR analyzer/99771, so only call it if we're about to use
the result.
gcc/analyzer/ChangeLog:
* sm-file.cc (fileptr_state_machine::on_stmt): Only call
get_diagnostic_tree if the result will be used.
* sm-malloc.cc (malloc_state_machine::on_stmt): Likewise.
(malloc_state_machine::on_deallocator_call): Likewise.
(malloc_state_machine::on_realloc_call): Likewise.
(malloc_state_machine::on_realloc_call): Likewise.
* sm-sensitive.cc
(sensitive_state_machine::warn_for_any_exposure): Likewise.
* sm-taint.cc (taint_state_machine::on_stmt): Likewise.
Diffstat (limited to 'gcc/analyzer/sm-malloc.cc')
-rw-r--r-- | gcc/analyzer/sm-malloc.cc | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc index ef250c8..ae03b06 100644 --- a/gcc/analyzer/sm-malloc.cc +++ b/gcc/analyzer/sm-malloc.cc @@ -1674,11 +1674,11 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, if (TREE_CODE (op) == MEM_REF) { tree arg = TREE_OPERAND (op, 0); - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); state_t state = sm_ctxt->get_state (stmt, arg); if (unchecked_p (state)) { + tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, stmt, arg, new possible_null_deref (*this, diag_arg)); const allocation_state *astate = as_a_allocation_state (state); @@ -1686,12 +1686,14 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, } else if (state == m_null) { + tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, stmt, arg, new null_deref (*this, diag_arg)); sm_ctxt->set_next_state (stmt, arg, m_stop); } else if (freed_p (state)) { + tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); const allocation_state *astate = as_a_allocation_state (state); sm_ctxt->warn (node, stmt, arg, new use_after_free (*this, diag_arg, @@ -1738,7 +1740,6 @@ malloc_state_machine::on_deallocator_call (sm_context *sm_ctxt, if (argno >= gimple_call_num_args (call)) return; tree arg = gimple_call_arg (call, argno); - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); state_t state = sm_ctxt->get_state (call, arg); @@ -1752,6 +1753,7 @@ malloc_state_machine::on_deallocator_call (sm_context *sm_ctxt, if (!astate->m_deallocators->contains_p (d)) { /* Wrong allocator. */ + tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); pending_diagnostic *pd = new mismatching_deallocation (*this, diag_arg, astate->m_deallocators, @@ -1766,6 +1768,7 @@ malloc_state_machine::on_deallocator_call (sm_context *sm_ctxt, else if (state == d->m_freed) { /* freed -> stop, with warning. */ + tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, call, arg, new double_free (*this, diag_arg, d->m_name)); sm_ctxt->set_next_state (call, arg, m_stop); @@ -1773,6 +1776,7 @@ malloc_state_machine::on_deallocator_call (sm_context *sm_ctxt, else if (state == m_non_heap) { /* non-heap -> stop, with warning. */ + tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, call, arg, new free_of_non_heap (*this, diag_arg, d->m_name)); @@ -1806,7 +1810,6 @@ malloc_state_machine::on_realloc_call (sm_context *sm_ctxt, const gcall *call) const { tree ptr = gimple_call_arg (call, 0); - tree diag_ptr = sm_ctxt->get_diagnostic_tree (ptr); state_t state = sm_ctxt->get_state (call, ptr); @@ -1818,6 +1821,7 @@ malloc_state_machine::on_realloc_call (sm_context *sm_ctxt, if (astate->m_deallocators != &m_free) { /* Wrong allocator. */ + tree diag_ptr = sm_ctxt->get_diagnostic_tree (ptr); pending_diagnostic *pd = new mismatching_deallocation (*this, diag_ptr, astate->m_deallocators, |