[flang-commits] [PATCH] D87638: [flang] Allow Fortran comments after #include path

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Sep 14 16:58:54 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG4706880f06fb: [flang] Allow Fortran comments after #include path (authored by klausler).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87638/new/

https://reviews.llvm.org/D87638

Files:
  flang/lib/Parser/preprocessor.cpp
  flang/test/Preprocessing/empty.h
  flang/test/Preprocessing/include-comment.F90


Index: flang/test/Preprocessing/include-comment.F90
===================================================================
--- /dev/null
+++ flang/test/Preprocessing/include-comment.F90
@@ -0,0 +1,18 @@
+! RUN: %f18 -I%S -E %s 2>&1 | FileCheck %s
+! CHECK-NOT: :3:
+#include <empty.h> ! comment
+! CHECK-NOT: :5:
+#include <empty.h> /* comment */
+! CHECK-NOT: :7:
+#include <empty.h> !comment
+! CHECK: :9:20: #include: extra stuff ignored after file name
+#include <empty.h> comment
+! CHECK-NOT: :11:
+#include "empty.h" ! comment
+! CHECK-NOT: :13:
+#include "empty.h" /* comment */
+! CHECK-NOT: :15:
+#include "empty.h" !comment
+! CHECK: :17:20: #include: extra stuff ignored after file name
+#include "empty.h" comment
+end
Index: flang/lib/Parser/preprocessor.cpp
===================================================================
--- flang/lib/Parser/preprocessor.cpp
+++ flang/lib/Parser/preprocessor.cpp
@@ -540,7 +540,7 @@
       return;
     }
     std::string include;
-    if (dir.TokenAt(j).ToString() == "<") {
+    if (dir.TokenAt(j).ToString() == "<") { // #include <foo>
       std::size_t k{j + 1};
       if (k >= tokens) {
         prescanner->Say(dir.GetIntervalProvenanceRange(j, tokens - j),
@@ -553,15 +553,12 @@
       if (k >= tokens) {
         prescanner->Say(dir.GetIntervalProvenanceRange(j, tokens - j),
             "#include: expected '>' at end of included file"_en_US);
-      } else if (k + 1 < tokens) {
-        prescanner->Say(dir.GetIntervalProvenanceRange(k + 1, tokens - k - 1),
-            "#include: extra stuff ignored after '>'"_en_US);
       }
       TokenSequence braced{dir, j + 1, k - j - 1};
       include = ReplaceMacros(braced, *prescanner).ToString();
-    } else if (j + 1 == tokens &&
-        (include = dir.TokenAt(j).ToString()).substr(0, 1) == "\"" &&
-        include.substr(include.size() - 1, 1) == "\"") {
+      j = k;
+    } else if ((include = dir.TokenAt(j).ToString()).substr(0, 1) == "\"" &&
+        include.substr(include.size() - 1, 1) == "\"") { // #include "foo"
       include = include.substr(1, include.size() - 2);
     } else {
       prescanner->Say(dir.GetTokenProvenanceRange(j < tokens ? j : tokens - 1),
@@ -573,6 +570,11 @@
           "#include: empty include file name"_err_en_US);
       return;
     }
+    j = dir.SkipBlanks(j + 1);
+    if (j < tokens && dir.TokenAt(j).ToString() != "!") {
+      prescanner->Say(dir.GetIntervalProvenanceRange(j, tokens - j),
+          "#include: extra stuff ignored after file name"_en_US);
+    }
     std::string buf;
     llvm::raw_string_ostream error{buf};
     const SourceFile *included{allSources_.Open(include, error)};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87638.291737.patch
Type: text/x-patch
Size: 2662 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20200914/a6dc88b2/attachment.bin>


More information about the flang-commits mailing list