common: Use strcmp to compare location file names
authorNathan Sidwell <nathan@acm.org>
Mon, 27 Jul 2020 20:05:28 +0000 (13:05 -0700)
committerNathan Sidwell <nathan@acm.org>
Mon, 27 Jul 2020 20:13:32 +0000 (13:13 -0700)
commit06aa77035c9debda88c1841dc34e188154a95963
treedac51aba497cbe52cc0602ebf2519886615791dc
parentb95eba48a1a25284ce7385bbfa0ee733124cb84b
common: Use strcmp to compare location file names

The logic to figure out where a missing #include should be inserted
uses pointer equality to check filenames -- the routine even says so.
But cpplib makes no such guarantee.  It happens to be true for input
that it preprocesses[* see line zero below], but is not true for
source that has already been preprocessed -- all those '# ...' line
directives produce disctinct filename strings.  That renders using
-fdirectives-only as a prescanning stage (as I understand some people
do), broken.

This patch changes to string comparisons, and explicitly rejects any
line-zero location map that occurs at the beginning of a file.  The
very first map of a file has a different string to the remaining maps,
and we never tripped on that because of the pointer comparison.  The
second testcase deploys -save-temps to cause an intermediate
preprocessed output that is read back.

gcc/c-family/
* c-common.c (try_to_locate_new_include_insertion_point): Use
strcmp, not pointer equality.
gcc/testsuite/
* g++.dg/lookup/missing-std-include-10.h: New.
* g++.dg/lookup/missing-std-include-10.C: New.
* g++.dg/lookup/missing-std-include-11.C: New.
gcc/c-family/c-common.c
gcc/testsuite/g++.dg/lookup/missing-std-include-10.C [new file with mode: 0644]
gcc/testsuite/g++.dg/lookup/missing-std-include-10.h [new file with mode: 0644]
gcc/testsuite/g++.dg/lookup/missing-std-include-11.C [new file with mode: 0644]