[flang][driver] Fix -fdebug-dump-provenance

The -fdebug-dump-provenance flag is meant to be used with
needProvenanceRangeToCharBlockMappings set to true. This way, extra
mapping is generated that allows e.g. IDEs to retrieve symbol's scope
(offset into cooked character stream) based on symbol's source code
location. This patch makes sure that this option is set when using
-fdebug-dump-provenance.

With this patch, the implementation of  -fdebug-dump-provenance in
`flang-new -fc1` becomes consistent with `f18`. The corresponding LIT
test is updated so that it can be shared with `f18`. I refined it a bit
so that:
  * it becomes a frontend-only test
  * it's stricter about the expected output

Differential Revision: https://reviews.llvm.org/D98847
This commit is contained in:
Andrzej Warzynski 2021-04-07 13:10:35 +00:00
parent bf6cab6f07
commit 85b86c6f43
3 changed files with 36 additions and 21 deletions

View File

@ -194,6 +194,11 @@ public:
/// Instrument the parse to get a more verbose log
unsigned instrumentedParse_ : 1;
/// Enable Provenance to character-stream mapping. Allows e.g. IDEs to find
/// symbols based on source-code location. This is not needed in regular
/// compilation.
unsigned needProvenanceRangeToCharBlockMappings_ : 1;
/// The input files and their types.
std::vector<FrontendInputFile> inputs_;
@ -217,7 +222,9 @@ public:
Fortran::parser::Encoding encoding_{Fortran::parser::Encoding::UTF_8};
public:
FrontendOptions() : showHelp_(false), showVersion_(false) {}
FrontendOptions()
: showHelp_(false), showVersion_(false), instrumentedParse_(false),
needProvenanceRangeToCharBlockMappings_(false) {}
// Return the appropriate input kind for a file extension. For example,
/// "*.f" would return Language::Fortran.

View File

@ -94,6 +94,9 @@ static void setUpFrontendBasedOnAction(FrontendOptions &opts) {
if (opts.programAction_ == DebugDumpParsingLog)
opts.instrumentedParse_ = true;
if (opts.programAction_ == DebugDumpProvenance)
opts.needProvenanceRangeToCharBlockMappings_ = true;
}
static InputKind ParseFrontendArgs(FrontendOptions &opts,
@ -584,6 +587,9 @@ void CompilerInvocation::setFortranOpts() {
if (frontendOptions.instrumentedParse_)
fortranOptions.instrumentedParse = true;
if (frontendOptions.needProvenanceRangeToCharBlockMappings_)
fortranOptions.needProvenanceRangeToCharBlockMappings = true;
if (enableConformanceChecks()) {
fortranOptions.features.WarnOnAllNonstandard();
}

View File

@ -1,26 +1,28 @@
! Ensure argument -fdebug-dump-provenance works as expected.
! REQUIRES: new-flang-driver
!----------
! RUN LINE
!----------
! RUN: %flang_fc1 -fdebug-dump-provenance %s 2>&1 | FileCheck %s
!--------------------------
! FLANG DRIVER (flang-new)
!--------------------------
! RUN: not %flang-new -fdebug-dump-provenance %s 2>&1 | FileCheck %s --check-prefix=FLANG
!----------------
! EXPECTED OUTPUT
!----------------
! CHECK: AllSources:
! CHECK-NEXT: AllSources range_ [{{[0-9]*}}..{{[0-9]*}}] ({{[0-9]*}} bytes)
! CHECK-NEXT: [1..1] (1 bytes) -> compiler '?'(0x3f)
! CHECK-NEXT: [2..2] (1 bytes) -> compiler ' '(0x20)
! CHECK-NEXT: [3..3] (1 bytes) -> compiler '\'(0x5c)
! CHECK-NEXT: [{{[0-9]*}}..{{[0-9]*}}] ({{[0-9]*}} bytes) -> file {{.*}}/debug-provenance.f90
! CHECK-NEXT: [{{[0-9]*}}..{{[0-9]*}}] ({{[0-9]*}} bytes) -> compiler '(after end of source)'
! CHECK-NEXT: CookedSource::provenanceMap_:
! CHECK-NEXT: offsets [{{[0-9]*}}..{{[0-9]*}}] -> provenances [{{[0-9]*}}..{{[0-9]*}}] ({{[0-9]*}} bytes)
! CHECK-NEXT: CookedSource::invertedMap_:
! CHECK-NEXT: provenances [{{[0-9]*}}..{{[0-9]*}}] ({{[0-9]*}} bytes) -> offsets [{{[0-9]*}}..{{[0-9]*}}]
! CHECK-EMPTY:
!----------------------------------------
! FRONTEND FLANG DRIVER (flang-new -fc1)
!----------------------------------------
! RUN: %flang-new -fc1 -fdebug-dump-provenance %s 2>&1 | FileCheck %s --check-prefix=FRONTEND
!----------------------------------
! EXPECTED OUTPUT WITH `flang-new`
!----------------------------------
! FLANG:warning: argument unused during compilation: '-fdebug-dump-provenance'
!---------------------------------------
! EXPECTED OUTPUT WITH `flang-new -fc1`
!---------------------------------------
! FRONTEND:AllSources:
! FRONTEND:CookedSource::provenanceMap_:
!-------------
! TEST INPUT
!------------
program A
end