[flang-commits] [flang] 0eeb157 - [flang][driver] Make the driver report diagnostics from the prescanner

Andrzej Warzynski via flang-commits flang-commits at lists.llvm.org
Thu Jan 21 07:18:05 PST 2021


Author: Andrzej Warzynski
Date: 2021-01-21T15:06:32Z
New Revision: 0eeb15741bdaa6740c3bfcbed981b9d19d5348fb

URL: https://github.com/llvm/llvm-project/commit/0eeb15741bdaa6740c3bfcbed981b9d19d5348fb
DIFF: https://github.com/llvm/llvm-project/commit/0eeb15741bdaa6740c3bfcbed981b9d19d5348fb.diff

LOG: [flang][driver] Make the driver report diagnostics from the prescanner

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.

Differential Revision: https://reviews.llvm.org/D94782

Added: 
    flang/test/Frontend/Inputs/empty.h
    flang/test/Frontend/preprocessor-diag.f90

Modified: 
    flang/lib/Frontend/FrontendActions.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index a15793571bfb..ee6f71cfc5af 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -61,6 +61,9 @@ void PrintPreprocessedAction::ExecuteAction() {
     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())}) {

diff  --git a/flang/test/Frontend/Inputs/empty.h b/flang/test/Frontend/Inputs/empty.h
new file mode 100644
index 000000000000..e69de29bb2d1

diff  --git a/flang/test/Frontend/preprocessor-diag.f90 b/flang/test/Frontend/preprocessor-diag.f90
new file mode 100644
index 000000000000..2a16aa443c7f
--- /dev/null
+++ b/flang/test/Frontend/preprocessor-diag.f90
@@ -0,0 +1,11 @@
+! RUN: %f18 -E -I %S/Inputs/ %s 2>&1 | FileCheck %s
+! RUN: %flang-new -E -I %S/Inputs/ %s 2>&1 | FileCheck %s
+! RUN: %flang-new -fc1 -E -I %S/Inputs/ %s 2>&1 | FileCheck %s
+
+! Test that the driver correctly reports diagnostics from the prescanner. The contents of the include file are irrelevant here.
+
+! CHECK: preprocessor-diag.f90:8:20: #include: extra stuff ignored after file name
+#include <empty.h> comment
+! CHECK: preprocessor-diag.f90:10:20: #include: extra stuff ignored after file name
+#include "empty.h" comment
+end


        


More information about the flang-commits mailing list