Skip to content

Commit 0eeb157

Browse files
committed
[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
1 parent e4eaf9d commit 0eeb157

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ void PrintPreprocessedAction::ExecuteAction() {
6161
return;
6262
}
6363

64+
// Print diagnostics from the preprocessor
65+
ci.parsing().messages().Emit(llvm::errs(), ci.allCookedSources());
66+
6467
// Create a file and save the preprocessed output there
6568
if (auto os{ci.CreateDefaultOutputFile(
6669
/*Binary=*/true, /*InFile=*/GetCurrentFileOrBufferName())}) {

flang/test/Frontend/Inputs/empty.h

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
! RUN: %f18 -E -I %S/Inputs/ %s 2>&1 | FileCheck %s
2+
! RUN: %flang-new -E -I %S/Inputs/ %s 2>&1 | FileCheck %s
3+
! RUN: %flang-new -fc1 -E -I %S/Inputs/ %s 2>&1 | FileCheck %s
4+
5+
! Test that the driver correctly reports diagnostics from the prescanner. The contents of the include file are irrelevant here.
6+
7+
! CHECK: preprocessor-diag.f90:8:20: #include: extra stuff ignored after file name
8+
#include <empty.h> comment
9+
! CHECK: preprocessor-diag.f90:10:20: #include: extra stuff ignored after file name
10+
#include "empty.h" comment
11+
end

0 commit comments

Comments
 (0)