1 /* Plugin for testing how gracefully we degrade in the face of very
5 #include "gcc-plugin.h"
8 #include "spellcheck.h"
9 #include "diagnostic.h"
11 int plugin_is_GPL_compatible
;
13 static location_t base_location
;
15 /* Callback handler for the PLUGIN_START_UNIT event; pretend
16 we parsed a very large include file. */
19 on_start_unit (void */
*gcc_data*/
, void */
*user_data*/
)
21 /* Act as if we've already parsed a large body of code;
22 so that we can simulate various fallbacks in libcpp:
24 0x50000001 > LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES:
25 this will trigger the creation of line maps with range_bits == 0
26 so that all ranges will be stored in the ad-hoc lookaside.
28 0x60000001 > LINE_MAP_MAX_LOCATION_WITH_COLS:
29 this will trigger the creation of line maps with column_bits == 0
30 and hence we will immediately degrade to having locations in which
31 column number is 0. */
32 line_table
->highest_location
= base_location
;
35 /* We add some extra testing during diagnostics by chaining up
38 static diagnostic_finalizer_fn original_finalizer
= NULL
;
41 verify_unpacked_ranges (diagnostic_context
*context
,
42 diagnostic_info
*diagnostic
)
44 /* Verify that the locations are ad-hoc, not packed. */
45 location_t loc
= diagnostic_location (diagnostic
);
46 gcc_assert (IS_ADHOC_LOC (loc
));
48 /* We're done testing; chain up to original finalizer. */
49 gcc_assert (original_finalizer
);
50 original_finalizer (context
, diagnostic
);
54 verify_no_columns (diagnostic_context
*context
,
55 diagnostic_info
*diagnostic
)
57 /* Verify that the locations have no columns. */
58 location_t loc
= diagnostic_location (diagnostic
);
59 gcc_assert (LOCATION_COLUMN (loc
) == 0);
61 /* We're done testing; chain up to original finalizer. */
62 gcc_assert (original_finalizer
);
63 original_finalizer (context
, diagnostic
);
67 plugin_init (struct plugin_name_args
*plugin_info
,
68 struct plugin_gcc_version */
*version*/
)
70 /* Read VALUE from -fplugin-arg-location_overflow_plugin-value=<VALUE>
71 in hexadecimal form into base_location. */
72 for (int i
= 0; i
< plugin_info
->argc
; i
++)
74 if (0 == strcmp (plugin_info
->argv
[i
].key
, "value"))
75 base_location
= strtol (plugin_info
->argv
[i
].value
, NULL
, 16);
79 error_at (UNKNOWN_LOCATION
, "missing plugin argument");
81 register_callback (plugin_info
->base_name
,
84 NULL
); /* void *user_data */
86 /* Hack in additional testing, based on the exact value supplied. */
87 original_finalizer
= diagnostic_finalizer (global_dc
);
88 switch (base_location
)
90 case LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES
+ 1:
91 diagnostic_finalizer (global_dc
) = verify_unpacked_ranges
;
94 case LINE_MAP_MAX_LOCATION_WITH_COLS
+ 1:
95 diagnostic_finalizer (global_dc
) = verify_no_columns
;
99 error_at (UNKNOWN_LOCATION
, "unrecognized value for plugin argument");