]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libcpp: modules and -include again
authorJason Merrill <jason@redhat.com>
Tue, 26 Nov 2024 21:19:05 +0000 (16:19 -0500)
committerJason Merrill <jason@redhat.com>
Wed, 27 Nov 2024 04:53:37 +0000 (23:53 -0500)
I enabled include translation to header units in r15-1104-ga29f481bbcaf2b,
but it seems that patch wasn't sufficient, as any diagnostics in the main
source file would show up as coming from the header instead.

Fixed by setting buffer->file for leaving the file transition that my
previous patch made us enter.  And don't push a buffer of newlines, in this
case that messes up line numbers instead of aligning them.

libcpp/ChangeLog:

* files.cc (_cpp_stack_file): Handle -include of header unit more
specially.

gcc/testsuite/ChangeLog:

* g++.dg/modules/dashinclude-1_b.C: Add an #error.
* g++.dg/modules/dashinclude-1_a.H: Remove dg-module-do run.

gcc/testsuite/g++.dg/modules/dashinclude-1_a.H
gcc/testsuite/g++.dg/modules/dashinclude-1_b.C
libcpp/files.cc

index c1b40a5392432efef045f5957df7bdad2a7e67ce..82ee340798f6fea7de68513c0a482aa3d6bbea31 100644 (file)
@@ -1,4 +1,3 @@
-// { dg-module-do run }
 // { dg-additional-options "-fmodule-header" }
 // { dg-module-cmi {} }
 
index 6e6a33407a46b506074107ab6697746d6c17b4b0..f257a1d658e3397c9815ba34ef1b0cc0a5f35fa4 100644 (file)
@@ -6,4 +6,6 @@ int main ()
   return f();
 }
 
+#error foo                     // { dg-error "foo" }
+
 // { dg-final { scan-lang-dump {Translating include to import} module } }
index 1cbce4947ee19b4351cae9d53d569b6d1d13582c..a60fe1fb6eac0b031a7158baa6dee22535c598f3 100644 (file)
@@ -977,8 +977,11 @@ _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, include_type type,
         that.  (We also need an extra newline, so this looks like a regular
         file, which we do that to to make sure we don't fall off the end in the
         middle of a line.  */
-      static uchar newlines[] = "\n\n\n";
-      cpp_push_buffer (pfile, newlines, 2, true);
+      if (type != IT_CMDLINE)
+       {
+         static uchar newlines[] = "\n\n\n";
+         cpp_push_buffer (pfile, newlines, 2, true);
+       }
 
       size_t len = strlen (buf);
       buf[len] = '\n'; /* See above  */
@@ -986,6 +989,9 @@ _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, include_type type,
        = cpp_push_buffer (pfile, reinterpret_cast<unsigned char *> (buf),
                           len, true);
       buffer->to_free = buffer->buf;
+      if (type == IT_CMDLINE)
+       /* Tell _cpp_pop_buffer to change files.  */
+       buffer->file = file;
 
       file->header_unit = +1;
       _cpp_mark_file_once_only (pfile, file);