[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
This commit is contained in:
Andrzej Warzynski 2021-01-21 15:02:22 +00:00
parent e4eaf9d820
commit 0eeb15741b
3 changed files with 14 additions and 0 deletions

View File

@ -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())}) {

View File

View File

@ -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