From b0082b5572a79da4601f07f2eeeff9acf780c9a2 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Wed, 24 Jun 2020 18:15:13 -0400 Subject: [PATCH 251/315] FIXME: add workaround for missing clobber stmt locations --- gcc/analyzer/analyzer.cc | 30 ++++++++++++++++++++++++++++++ gcc/analyzer/analyzer.h | 2 ++ gcc/analyzer/checker-path.cc | 2 +- gcc/analyzer/diagnostic-manager.cc | 2 +- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/gcc/analyzer/analyzer.cc b/gcc/analyzer/analyzer.cc index 8bc3ce49f07..102f81a14e0 100644 --- a/gcc/analyzer/analyzer.cc +++ b/gcc/analyzer/analyzer.cc @@ -32,6 +32,36 @@ along with GCC; see the file COPYING3. If not see #if ENABLE_ANALYZER +namespace ana { + +/* Workaround for missing location information for some stmts, + which ultimately should be solved by fixing the frontends + to provide the locations (TODO). */ + +location_t +get_stmt_location (const gimple *stmt, function *fun) +{ + if (get_pure_location (stmt->location) == UNKNOWN_LOCATION) + { + /* FIXME: Workaround for missing location information for clobber + stmts, which seem to lack location information in the C frontend + at least. Created by gimplify_bind_expr, which uses the + BLOCK_SOURCE_END_LOCATION (BIND_EXPR_BLOCK (bind_expr)) + but this is never set up when the block is created in + c_end_compound_stmt's pop_scope. + TODO: fix this missing location information. + + For now, as a hackish workaround, use the location of the end of + the function. */ + if (gimple_clobber_p (stmt) && fun) + return fun->function_end_locus; + } + + return stmt->location; +} + +} // namespace ana + /* Helper function for checkers. Is the CALL to the given function name, and with the given number of arguments? diff --git a/gcc/analyzer/analyzer.h b/gcc/analyzer/analyzer.h index b2d0a9c7e49..8abead5f251 100644 --- a/gcc/analyzer/analyzer.h +++ b/gcc/analyzer/analyzer.h @@ -227,6 +227,8 @@ struct setjmp_record const gcall *m_setjmp_call; }; +extern location_t get_stmt_location (const gimple *stmt, function *fun); + } // namespace ana extern bool is_special_named_call_p (const gcall *call, const char *funcname, diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc index 4ff1494c698..bcdf4d9b4ed 100644 --- a/gcc/analyzer/checker-path.cc +++ b/gcc/analyzer/checker-path.cc @@ -1067,7 +1067,7 @@ checker_path::add_final_event (const state_machine *sm, tree var, state_machine::state_t state) { checker_event *end_of_path - = new warning_event (stmt->location, + = new warning_event (get_stmt_location (stmt, enode->get_function ()), enode->get_function ()->decl, enode->get_stack_depth (), sm, var, state); diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index ffa96825bd0..c5e57d281ed 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -571,7 +571,7 @@ diagnostic_manager::emit_saved_diagnostic (const exploded_graph &eg, emission_path.prepare_for_emission (sd.m_d); - gcc_rich_location rich_loc (stmt->location); + gcc_rich_location rich_loc (get_stmt_location (stmt, sd.m_snode->m_fun)); rich_loc.set_path (&emission_path); auto_diagnostic_group d; -- 2.26.2