aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2021-02-16 12:23:12 -0800
committerNathan Sidwell <nathan@acm.org>2021-02-16 12:26:51 -0800
commitb37695c9bf101a3a30a231cfeb6da7a6c17657d6 (patch)
tree20733ade4d65e611ce39800abc5ac2403c440bfd
parent30a4d95bf76b0a0fdb66ac0211589a4434c83af3 (diff)
downloadgcc-b37695c9bf101a3a30a231cfeb6da7a6c17657d6.zip
gcc-b37695c9bf101a3a30a231cfeb6da7a6c17657d6.tar.gz
gcc-b37695c9bf101a3a30a231cfeb6da7a6c17657d6.tar.bz2
c++: directives-only preprocessing and include translation [PR 99050]
We make sure files end in \n by placing one at the limit of the buffer (just past the end of what is read). We need to do the same for buffers generated via include-translation. Fortunately they have space. libcpp/ * files.c (_cpp_stack_file): Make buffers end in unread \n. gcc/testsuite/ * g++.dg/modules/pr99050_a.H: New. * g++.dg/modules/pr99050_b.C: New.
-rw-r--r--gcc/testsuite/g++.dg/modules/pr99050_a.H4
-rw-r--r--gcc/testsuite/g++.dg/modules/pr99050_b.C7
-rw-r--r--libcpp/files.c10
3 files changed, 18 insertions, 3 deletions
diff --git a/gcc/testsuite/g++.dg/modules/pr99050_a.H b/gcc/testsuite/g++.dg/modules/pr99050_a.H
new file mode 100644
index 0000000..137e37f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr99050_a.H
@@ -0,0 +1,4 @@
+// PR c++/99050 ICE with directives only
+// { dg-additional-options -fmodule-header }
+// { dg-module-cmi {} }
+void f ();
diff --git a/gcc/testsuite/g++.dg/modules/pr99050_b.C b/gcc/testsuite/g++.dg/modules/pr99050_b.C
new file mode 100644
index 0000000..439e216
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr99050_b.C
@@ -0,0 +1,7 @@
+// { dg-do preprocess }
+// { dg-additional-options {-fdirectives-only -fmodules-ts} }
+#include "pr99050_a.H"
+
+int main () {}
+
+// { dg-final { scan-file pr99050_b.i {import "[^\n]*99050_a.H" \[\[__translated\]\];\n} } }
diff --git a/libcpp/files.c b/libcpp/files.c
index 5ea3f8e..3a35f7c 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -918,13 +918,17 @@ _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, include_type type,
because we don't usually need that location (we're popping an
include file). However in this case we do want to do the
increment. So push a writable buffer of two newlines to acheive
- that. */
- static uchar newlines[] = "\n\n";
+ 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);
+ size_t len = strlen (buf);
+ buf[len] = '\n'; /* See above */
cpp_buffer *buffer
= cpp_push_buffer (pfile, reinterpret_cast<unsigned char *> (buf),
- strlen (buf), true);
+ len, true);
buffer->to_free = buffer->buf;
file->header_unit = +1;