| 1 |
/* This plugin verifies the source-code location ranges of |
| 2 |
expressions, at the pre-gimplification tree stage. */ |
| 3 |
/* { dg-options "-O" } */ |
| 4 |
|
| 5 |
#include "gcc-plugin.h" |
| 6 |
#include "config.h" |
| 7 |
#include "system.h" |
| 8 |
#include "coretypes.h" |
| 9 |
#include "tm.h" |
| 10 |
#include "tree.h" |
| 11 |
#include "stringpool.h" |
| 12 |
#include "toplev.h" |
| 13 |
#include "basic-block.h" |
| 14 |
#include "hash-table.h" |
| 15 |
#include "vec.h" |
| 16 |
#include "ggc.h" |
| 17 |
#include "basic-block.h" |
| 18 |
#include "tree-ssa-alias.h" |
| 19 |
#include "internal-fn.h" |
| 20 |
#include "gimple.h" |
| 21 |
#include "gimple-iterator.h" |
| 22 |
#include "gimple-fold.h" |
| 23 |
#include "tree-eh.h" |
| 24 |
#include "gimple-expr.h" |
| 25 |
#include "is-a.h" |
| 26 |
#include "tree.h" |
| 27 |
#include "tree-pass.h" |
| 28 |
#include "intl.h" |
| 29 |
#include "plugin-version.h" |
| 30 |
#include "diagnostic.h" |
| 31 |
#include "context.h" |
| 32 |
#include "print-tree.h" |
| 33 |
|
| 34 |
int plugin_is_GPL_compatible; |
| 35 |
|
| 36 |
static void |
| 37 |
emit_warning (location_t loc) |
| 38 |
{ |
| 39 |
source_range src_range = get_range_from_loc (line_table, loc); |
| 40 |
warning_at (loc, 0, |
| 41 |
"tree range %i:%i-%i:%i", |
| 42 |
LOCATION_LINE (src_range.m_start), |
| 43 |
LOCATION_COLUMN (src_range.m_start), |
| 44 |
LOCATION_LINE (src_range.m_finish), |
| 45 |
LOCATION_COLUMN (src_range.m_finish)); |
| 46 |
} |
| 47 |
|
| 48 |
tree |
| 49 |
cb_walk_tree_fn (tree * tp, int * walk_subtrees, |
| 50 |
void * data ATTRIBUTE_UNUSED) |
| 51 |
{ |
| 52 |
if (TREE_CODE (*tp) != CALL_EXPR) |
| 53 |
return NULL_TREE; |
| 54 |
|
| 55 |
tree call_expr = *tp; |
| 56 |
tree fn = CALL_EXPR_FN (call_expr); |
| 57 |
if (TREE_CODE (fn) != ADDR_EXPR) |
| 58 |
return NULL_TREE; |
| 59 |
fn = TREE_OPERAND (fn, 0); |
| 60 |
if (TREE_CODE (fn) != FUNCTION_DECL) |
| 61 |
return NULL_TREE; |
| 62 |
if (strcmp (IDENTIFIER_POINTER (DECL_NAME (fn)), "__emit_expression_range")) |
| 63 |
return NULL_TREE; |
| 64 |
|
| 65 |
/* Get arg 1; print it! */ |
| 66 |
tree arg = CALL_EXPR_ARG (call_expr, 1); |
| 67 |
|
| 68 |
emit_warning (EXPR_LOCATION (arg)); |
| 69 |
|
| 70 |
return NULL_TREE; |
| 71 |
} |
| 72 |
|
| 73 |
static void |
| 74 |
callback (void *gcc_data, void *user_data) |
| 75 |
{ |
| 76 |
tree fndecl = (tree)gcc_data; |
| 77 |
walk_tree (&DECL_SAVED_TREE (fndecl), cb_walk_tree_fn, NULL, NULL); |
| 78 |
} |
| 79 |
|
| 80 |
int |
| 81 |
plugin_init (struct plugin_name_args *plugin_info, |
| 82 |
struct plugin_gcc_version *version) |
| 83 |
{ |
| 84 |
struct register_pass_info pass_info; |
| 85 |
const char *plugin_name = plugin_info->base_name; |
| 86 |
int argc = plugin_info->argc; |
| 87 |
struct plugin_argument *argv = plugin_info->argv; |
| 88 |
|
| 89 |
if (!plugin_default_version_check (version, &gcc_version)) |
| 90 |
return 1; |
| 91 |
|
| 92 |
global_dc->m_source_printing.max_width = 130; |
| 93 |
|
| 94 |
register_callback (plugin_name, |
| 95 |
PLUGIN_PRE_GENERICIZE, |
| 96 |
callback, |
| 97 |
NULL); |
| 98 |
|
| 99 |
return 0; |
| 100 |
} |