[preprocessor] Popping "" file names
authorNathan Sidwell <nathan@acm.org>
Fri, 6 Sep 2019 12:54:19 +0000 (12:54 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Fri, 6 Sep 2019 12:54:19 +0000 (12:54 +0000)
https://gcc.gnu.org/ml/gcc-patches/2019-08/msg02069.html
New # semantics for popping to "" name.
libcpp/
* directives.c (do_linemarker): Popping to "" name means get the
name from the include stack..

From-SVN: r275457

gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/cpp/line-1.c [new file with mode: 0644]
libcpp/ChangeLog
libcpp/directives.c

index 9a544bc27a63ab33129e792d250b5de547eb4e03..b999a79a466a6e7ef9bb38d07d78cde108a922a5 100644 (file)
@@ -1,3 +1,7 @@
+2019-09-06  Nathan Sidwell  <nathan@acm.org>
+
+       * c-c++-common/cpp/line-1.c: New.
+
 2019-09-06  Martin Liska  <mliska@suse.cz>
 
        PR c++/91125
diff --git a/gcc/testsuite/c-c++-common/cpp/line-1.c b/gcc/testsuite/c-c++-common/cpp/line-1.c
new file mode 100644 (file)
index 0000000..8e9c941
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do preprocess } */
+/* { dg-additional-options -Wno-pedantic } */
+
+main-1 __FILE__
+
+# 7 "inner.h" 1
+inner-1 __FILE__
+# 9 "inside.h" 1
+inside-1 __FILE__
+# 11 "" 2
+inner-2 __FILE__
+#13 "" 2
+main-2 __FILE__
+
+
+/* { dg-final { scan-file line-1.i "main-1 \"\[^\n]*line-1.c\"\n" } } */
+/* { dg-final { scan-file line-1.i "main-2 \"\[^\n]*line-1.c\"\n" } } */
+/* { dg-final { scan-file line-1.i "inner-1 \"inner.h\"\n" } } */
+/* { dg-final { scan-file line-1.i "inner-2 \"inner.h\"\n" } } */
+/* { dg-final { scan-file line-1.i "inside-1 \"inside.h\"\n" } } */
index c418d75c950abf6bd1fcf7f736a41ae6396f9fc8..1ec8541a54ced8cdbd4bc321fcbd32644ab3e1ea 100644 (file)
@@ -1,3 +1,10 @@
+2019-08-30  Nathan Sidwell  <nathan@acm.org>
+
+       New # semantics for popping to "" name.
+       libcpp/
+       * directives.c (do_linemarker): Popping to "" name means get the
+       name from the include stack..
+
 2019-09-05  Nathan Sidwell  <nathan@acm.org>
 
        PR preprocessor/91639
index 1c6b31e143bb6768454c9df2dc8dbe96a19757c1..61f1fef94892511a6b25473e179b8a0420926a6a 100644 (file)
@@ -1088,9 +1088,17 @@ do_linemarker (cpp_reader *pfile)
       map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
       const line_map_ordinary *from
        = linemap_included_from_linemap (line_table, map);
-      if (MAIN_FILE_P (map)
-         || (from
-             && filename_cmp (ORDINARY_MAP_FILE_NAME (from), new_file) != 0))
+
+      if (!from)
+       /* Not nested.  */;
+      else if (!new_file[0])
+       /* Leaving to "" means fill in the popped-to name.  */
+       new_file = ORDINARY_MAP_FILE_NAME (from);
+      else if (filename_cmp (ORDINARY_MAP_FILE_NAME (from), new_file) != 0)
+       /* It's the wrong name, Grommit!  */
+       from = NULL;
+
+      if (!from)
        {
          cpp_warning (pfile, CPP_W_NONE,
                       "file \"%s\" linemarker ignored due to "
@@ -1098,6 +1106,7 @@ do_linemarker (cpp_reader *pfile)
          return;
        }
     }
+
   /* Compensate for the increment in linemap_add that occurs in
      _cpp_do_file_change.  We're currently at the start of the line
      *following* the #line directive.  A separate location_t for this