From 0f9aa35c79a0fe195d5076375b5794246cf44819 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 26 Mar 2021 13:26:15 -0400 Subject: 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. --- gcc/analyzer/sm-sensitive.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'gcc/analyzer/sm-sensitive.cc') diff --git a/gcc/analyzer/sm-sensitive.cc b/gcc/analyzer/sm-sensitive.cc index 95172f0..9703f7e 100644 --- a/gcc/analyzer/sm-sensitive.cc +++ b/gcc/analyzer/sm-sensitive.cc @@ -174,10 +174,12 @@ sensitive_state_machine::warn_for_any_exposure (sm_context *sm_ctxt, const gimple *stmt, tree arg) const { - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); if (sm_ctxt->get_state (stmt, arg) == m_sensitive) - sm_ctxt->warn (node, stmt, arg, - new exposure_through_output_file (*this, diag_arg)); + { + tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); + sm_ctxt->warn (node, stmt, arg, + new exposure_through_output_file (*this, diag_arg)); + } } /* Implementation of state_machine::on_stmt vfunc for -- cgit v1.1