]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: modules & -fpreprocessed [PR 99072]
authorNathan Sidwell <nathan@acm.org>
Wed, 24 Feb 2021 13:50:12 +0000 (05:50 -0800)
committerNathan Sidwell <nathan@acm.org>
Wed, 24 Feb 2021 17:14:34 +0000 (09:14 -0800)
When we read preprocessed source, we deal with a couple of special
location lines at the start of the file.  These provide information
about the original filename of the source and the current directory,
so we can process the source in the same manner.  When updating that
code, I had a somewhat philosophical question: Should the line table
contain evidence of the filename the user provided to the compiler?  I
figured to leave it there, as it did no harm.  But this defect shows
an issue.  It's in the line table and our (non optimizing) line table
serializer emits that filename.  Which means if one re-preprocesses
the original source to a differently-named intermediate file, the
resultant CMI is different.  Boo.  That's a difference that doesn't
matter, except the CRC matching then fails.  We should elide the
filename, so that one can preprocess to mktemp intermediate filenames
for whatever reason.

This patch takes the approach of expunging it from the line table --
so the line table will end up with exactly the same form.  That seems
a better bet than trying to fix up mismatching line tables in CMI
emission.

PR c++/99072
libcpp/
* init.c (read_original_filename): Expunge all evidence of the
original filename.
gcc/testsuite/
* g++.dg/modules/pr99072.H: New.

gcc/testsuite/g++.dg/modules/pr99072.H [new file with mode: 0644]
libcpp/init.c

diff --git a/gcc/testsuite/g++.dg/modules/pr99072.H b/gcc/testsuite/g++.dg/modules/pr99072.H
new file mode 100644 (file)
index 0000000..eda0c07
--- /dev/null
@@ -0,0 +1,10 @@
+# 0 "REALNAME"
+# 0 "<built-in>"
+# 0 "<command-line>"
+# 0 "<command-line>"
+# 1 "/usr/include/stdc-predef.h" 1 3 4
+# 0 "<command-line>" 2
+# 1 "REALNAME"
+
+// { dg-additional-options {-fmodule-header -fpreprocessed -fdump-lang-module-lineno} }
+// { dg-final { scan-lang-dump { 4 source file names\n Source file\[0\]=REALNAME\n Source file\[1\]=<built-in>\n Source file\[2\]=<command-line>\n Source file\[3\]=/usr/include/stdc-predef.h\n} module } }
index 17b0d251cda9d7120f09a4bd169377d51110170d..68ed2c761b90c22f66505a48052f82976d25a93e 100644 (file)
@@ -752,6 +752,23 @@ read_original_filename (cpp_reader *pfile)
       if (_cpp_handle_directive (pfile, token->flags & PREV_WHITE))
        {
          read_original_directory (pfile);
+
+         auto *penult = &linemap_check_ordinary
+           (LINEMAPS_LAST_MAP (pfile->line_table, false))[-1];
+         if (penult[1].reason == LC_RENAME_VERBATIM)
+           {
+             /* Expunge any evidence of the original linemap.  */
+             pfile->line_table->highest_location
+               = pfile->line_table->highest_line
+               = penult[0].start_location;
+
+             penult[1].start_location = penult[0].start_location;
+             penult[1].reason = penult[0].reason;
+             penult[0] = penult[1];
+             pfile->line_table->info_ordinary.used--;
+             pfile->line_table->info_ordinary.cache = 0;
+           }
+
          return true;
        }
     }