gcc/libcpp
Lewis Hyatt cb05acdcea libcpp: Improve the diagnostic for poisoned identifiers [PR36887]
The PR requests an enhancement to the diagnostic issued for the use of a
poisoned identifier. Currently, we show the location of the usage, but not
the location which requested the poisoning, which would be helpful for the
user if the decision to poison an identifier was made externally, such as
in a library header.

In order to output this information, we need to remember a location_t for
each identifier that has been poisoned, and that data needs to be preserved
as well in a PCH. One option would be to add a field to struct cpp_hashnode,
but there is no convenient place to add it without increasing the size of
the struct for all identifiers. Given this facility will be needed rarely,
it seemed better to add a second hash map, which is handled PCH-wise the
same as the current one in gcc/stringpool.cc. This hash map associates a new
struct cpp_hashnode_extra with each identifier that needs one. Currently
that struct only contains the new location_t, but it could be extended in
the future if there is other ancillary data that may be convenient to put
there for other purposes.

libcpp/ChangeLog:

	PR preprocessor/36887
	* directives.cc (do_pragma_poison): Store in the extra hash map the
	location from which an identifier has been poisoned.
	* lex.cc (identifier_diagnostics_on_lex): When issuing a diagnostic
	for the use of a poisoned identifier, also add a note indicating the
	location from which it was poisoned.
	* identifiers.cc (alloc_node): Convert to template function.
	(_cpp_init_hashtable): Handle the new extra hash map.
	(_cpp_destroy_hashtable): Likewise.
	* include/cpplib.h (struct cpp_hashnode_extra): New struct.
	(cpp_create_reader): Update prototype to...
	* init.cc (cpp_create_reader): ...accept an argument for the extra
	hash table and pass it to _cpp_init_hashtable.
	* include/symtab.h (ht_lookup): New overload for convenience.
	* internal.h (struct cpp_reader): Add EXTRA_HASH_TABLE member.
	(_cpp_init_hashtable): Adjust prototype.

gcc/c-family/ChangeLog:

	PR preprocessor/36887
	* c-opts.cc (c_common_init_options): Pass new extra hash map
	argument to cpp_create_reader().

gcc/ChangeLog:

	PR preprocessor/36887
	* toplev.h (ident_hash_extra): Declare...
	* stringpool.cc (ident_hash_extra): ...this new global variable.
	(init_stringpool): Handle ident_hash_extra as well as ident_hash.
	(ggc_mark_stringpool): Likewise.
	(ggc_purge_stringpool): Likewise.
	(struct string_pool_data_extra): New struct.
	(spd2): New GC root variable.
	(gt_pch_save_stringpool): Use spd2 to handle ident_hash_extra,
	analogous to how spd is used to handle ident_hash.
	(gt_pch_restore_stringpool): Likewise.

gcc/testsuite/ChangeLog:

	PR preprocessor/36887
	* c-c++-common/cpp/diagnostic-poison.c: New test.
	* g++.dg/pch/pr36887.C: New test.
	* g++.dg/pch/pr36887.Hs: New test.
2023-10-23 18:35:26 -04:00
..
include libcpp: Improve the diagnostic for poisoned identifiers [PR36887] 2023-10-23 18:35:26 -04:00
po Daily bump. 2023-05-10 00:17:49 +00:00
aclocal.m4
ChangeLog Daily bump. 2023-10-09 00:17:27 +00:00
ChangeLog.jit
charset.cc libcpp: allow UCS_LIMIT codepoints in UTF-8 strings 2023-06-23 16:04:12 -04:00
combining-chars.inc diagnostics: add support for "text art" diagrams 2023-06-21 21:49:00 -04:00
config.in build: re-configure 2 files 2022-11-21 09:03:35 +01:00
configure egrep in binutils 2023-08-07 22:59:40 +02:00
configure.ac configure: Implement --enable-host-pie 2023-06-15 16:51:27 -04:00
directives.cc libcpp: Improve the diagnostic for poisoned identifiers [PR36887] 2023-10-23 18:35:26 -04:00
errors.cc Update copyright years. 2023-01-16 11:52:17 +01:00
expr.cc C _BitInt incremental fixes [PR102989] 2023-09-06 17:39:15 +02:00
files.cc libcpp: Fix ICE on #include after a line marker directive [PR61474] 2023-09-20 16:44:24 -04:00
generated_cpp_wcwidth.h libcpp: Update cpp_wcwidth() to Unicode 15 2023-03-13 07:40:50 -04:00
identifiers.cc libcpp: Improve the diagnostic for poisoned identifiers [PR36887] 2023-10-23 18:35:26 -04:00
init.cc libcpp: Improve the diagnostic for poisoned identifiers [PR36887] 2023-10-23 18:35:26 -04:00
internal.h libcpp: Improve the diagnostic for poisoned identifiers [PR36887] 2023-10-23 18:35:26 -04:00
lex.cc libcpp: Improve the diagnostic for poisoned identifiers [PR36887] 2023-10-23 18:35:26 -04:00
line-map.cc libcpp: eliminate LINEMAPS_{ORDINARY,MACRO}_MAPS 2023-10-08 18:43:17 -04:00
location-example.txt
macro.cc libcpp: Improve location for macro names [PR66290] 2023-06-20 16:58:12 -04:00
Makefile.in Update copyright years. 2023-01-16 11:52:17 +01:00
makeucnid.cc libcpp: Update Unicode copyright years 2023-03-16 10:19:04 +01:00
makeuname2c.cc libcpp: Update Unicode copyright years 2023-03-16 10:19:04 +01:00
mkdeps.cc p1689r5: initial support 2023-09-19 17:32:23 -04:00
pch.cc libcpp: Improve location for macro names [PR66290] 2023-06-20 16:58:12 -04:00
printable-chars.inc diagnostics: add support for "text art" diagrams 2023-06-21 21:49:00 -04:00
symtab.cc Update copyright years. 2023-01-16 11:52:17 +01:00
system.h Update copyright years. 2023-01-16 11:52:17 +01:00
traditional.cc Update copyright years. 2023-01-16 11:52:17 +01:00
ucnid.h libcpp: Update Unicode copyright years 2023-03-16 10:19:04 +01:00
ucnid.tab Update copyright years. 2023-01-16 11:52:17 +01:00
uname2c.h libcpp: Update Unicode copyright years 2023-03-16 10:19:04 +01:00