| 1 |
/* Plugin for testing how gracefully we degrade in the face of very |
| 2 |
large source files. */ |
| 3 |
|
| 4 |
#include "config.h" |
| 5 |
#include "gcc-plugin.h" |
| 6 |
#include "system.h" |
| 7 |
#include "coretypes.h" |
| 8 |
#include "spellcheck.h" |
| 9 |
#include "diagnostic.h" |
| 10 |
#include "diagnostic-format-text.h" |
| 11 |
|
| 12 |
int plugin_is_GPL_compatible; |
| 13 |
|
| 14 |
static location_t base_location; |
| 15 |
|
| 16 |
/* Callback handler for the PLUGIN_PRAGMAS event; pretend we parsed a |
| 17 |
very large include file. This is used to set the initial line table |
| 18 |
offset for the preprocessor, to make it appear as if we had parsed a |
| 19 |
very large file. PRAGMA_START_UNIT is not suitable here as is not |
| 20 |
invoked during the preprocessor stage. */ |
| 21 |
|
| 22 |
static void |
| 23 |
on_pragma_registration (void */*gcc_data*/, void */*user_data*/) |
| 24 |
{ |
| 25 |
/* Act as if we've already parsed a large body of code; |
| 26 |
so that we can simulate various fallbacks in libcpp: |
| 27 |
|
| 28 |
0x50000001 > LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES: |
| 29 |
this will trigger the creation of line maps with range_bits == 0 |
| 30 |
so that all ranges will be stored in the ad-hoc lookaside. |
| 31 |
|
| 32 |
0x60000001 > LINE_MAP_MAX_LOCATION_WITH_COLS: |
| 33 |
this will trigger the creation of line maps with column_bits == 0 |
| 34 |
and hence we will immediately degrade to having locations in which |
| 35 |
column number is 0. */ |
| 36 |
line_table->highest_location = base_location; |
| 37 |
} |
| 38 |
|
| 39 |
/* We add some extra testing during diagnostics by chaining up |
| 40 |
to the text finalizer. */ |
| 41 |
|
| 42 |
static diagnostic_text_finalizer_fn original_text_finalizer = NULL; |
| 43 |
|
| 44 |
static void |
| 45 |
verify_unpacked_ranges (diagnostic_text_output_format &text_output, |
| 46 |
const diagnostic_info *diagnostic, |
| 47 |
diagnostic_t orig_diag_kind) |
| 48 |
{ |
| 49 |
/* Verify that the locations are ad-hoc, not packed. */ |
| 50 |
location_t loc = diagnostic_location (diagnostic); |
| 51 |
gcc_assert (IS_ADHOC_LOC (loc)); |
| 52 |
|
| 53 |
/* We're done testing; chain up to original text finalizer. */ |
| 54 |
gcc_assert (original_text_finalizer); |
| 55 |
original_text_finalizer (text_output, diagnostic, orig_diag_kind); |
| 56 |
} |
| 57 |
|
| 58 |
static void |
| 59 |
verify_no_columns (diagnostic_text_output_format &text_output, |
| 60 |
const diagnostic_info *diagnostic, |
| 61 |
diagnostic_t orig_diag_kind) |
| 62 |
{ |
| 63 |
/* Verify that the locations have no columns. */ |
| 64 |
location_t loc = diagnostic_location (diagnostic); |
| 65 |
gcc_assert (LOCATION_COLUMN (loc) == 0); |
| 66 |
|
| 67 |
/* We're done testing; chain up to original text finalizer. */ |
| 68 |
gcc_assert (original_text_finalizer); |
| 69 |
original_text_finalizer (text_output, diagnostic, orig_diag_kind); |
| 70 |
} |
| 71 |
|
| 72 |
int |
| 73 |
plugin_init (struct plugin_name_args *plugin_info, |
| 74 |
struct plugin_gcc_version */*version*/) |
| 75 |
{ |
| 76 |
/* Read VALUE from -fplugin-arg-location_overflow_plugin-value=<VALUE> |
| 77 |
in hexadecimal form into base_location. */ |
| 78 |
for (int i = 0; i < plugin_info->argc; i++) |
| 79 |
{ |
| 80 |
if (0 == strcmp (plugin_info->argv[i].key, "value")) |
| 81 |
base_location = strtol (plugin_info->argv[i].value, NULL, 16); |
| 82 |
} |
| 83 |
|
| 84 |
if (!base_location) |
| 85 |
error_at (UNKNOWN_LOCATION, "missing plugin argument"); |
| 86 |
|
| 87 |
/* With 64-bit locations, the thresholds are larger, so shift the base |
| 88 |
location argument accordingly, basically remap the GCC 14 32-bit |
| 89 |
location_t argument values to 64-bit location_t counterparts. There |
| 90 |
is one exception for values slightly before the 32-bit location_t |
| 91 |
LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES (0x50000000). In that case |
| 92 |
remap them to the same amount before the 64-bit location_t |
| 93 |
LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES - |
| 94 |
((location_t) 0x50000000) << 31. */ |
| 95 |
gcc_assert (sizeof (location_t) == sizeof (uint64_t)); |
| 96 |
if (base_location >= 0x4f000000 && base_location <= 0x4fffffff) |
| 97 |
base_location += (((location_t) 0x50000000) << 31) - 0x50000000; |
| 98 |
else |
| 99 |
base_location = 1 + ((base_location - 1) << 31); |
| 100 |
|
| 101 |
register_callback (plugin_info->base_name, |
| 102 |
PLUGIN_PRAGMAS, |
| 103 |
on_pragma_registration, |
| 104 |
NULL); /* void *user_data */ |
| 105 |
|
| 106 |
/* Hack in additional testing, based on the exact value supplied. */ |
| 107 |
original_text_finalizer = diagnostic_text_finalizer (global_dc); |
| 108 |
switch (base_location) |
| 109 |
{ |
| 110 |
case LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES + 1: |
| 111 |
diagnostic_text_finalizer (global_dc) = verify_unpacked_ranges; |
| 112 |
break; |
| 113 |
|
| 114 |
case LINE_MAP_MAX_LOCATION_WITH_COLS + 1: |
| 115 |
diagnostic_text_finalizer (global_dc) = verify_no_columns; |
| 116 |
break; |
| 117 |
|
| 118 |
default: |
| 119 |
break; |
| 120 |
} |
| 121 |
|
| 122 |
return 0; |
| 123 |
} |