[PATCH] D94782: [flang][driver] Make the driver report diagnostics from the prescanner

Andrzej Warzynski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 15 07:40:03 PST 2021


awarzynski created this revision.
Herald added a reviewer: sscalpone.
awarzynski requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch makes sure that diagnostics from the prescanner are reported
when running `flang-new -E` (i.e. only the preprocessor phase is
requested). More specifically, the `PrintPreprocessedAction` action is
updated.

With this patch we make sure that the `f18` and `flang-new` provide
identical output when running the preprocessor and the prescanner
generates diagnostics.

Depends on: D93453 <https://reviews.llvm.org/D93453>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94782

Files:
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Frontend/Inputs/empty.h
  flang/test/Frontend/preprocessor-diag.f90


Index: flang/test/Frontend/preprocessor-diag.f90
===================================================================
--- /dev/null
+++ flang/test/Frontend/preprocessor-diag.f90
@@ -0,0 +1,11 @@
+! RUN: %f18 -E -I %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=ERROR
+! RUN: %flang-new -E -I %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=ERROR
+! RUN: %flang-new -fc1 -E -I %S/Inputs/ %s 2>&1 | FileCheck %s --check-prefix=ERROR
+
+! Test that the driver correctly reports diagnostics from the prescanner. The contents of the include file are irrelevant here.
+
+! ERROR: :8:20: #include: extra stuff ignored after file name
+#include <empty.h> comment
+! ERROR: :10:20: #include: extra stuff ignored after file name
+#include "empty.h" comment
+end
Index: flang/lib/Frontend/FrontendActions.cpp
===================================================================
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -61,6 +61,9 @@
     return;
   }
 
+  // Print diagnostics from the preprocessor
+  ci.parsing().messages().Emit(llvm::errs(), ci.allCookedSources());
+
   // Create a file and save the preprocessed output there
   if (auto os{ci.CreateDefaultOutputFile(
           /*Binary=*/true, /*InFile=*/GetCurrentFileOrBufferName())}) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94782.316949.patch
Type: text/x-patch
Size: 1285 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210115/1449f482/attachment.bin>


More information about the llvm-commits mailing list