diff --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h --- a/flang/include/flang/Frontend/FrontendOptions.h +++ b/flang/include/flang/Frontend/FrontendOptions.h @@ -178,6 +178,11 @@ /// 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 inputs_; @@ -201,7 +206,9 @@ 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. diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -92,6 +92,9 @@ if (opts.programAction_ == DebugDumpParsingLog) opts.instrumentedParse_ = true; + + if (opts.programAction_ == DebugDumpProvenance) + opts.needProvenanceRangeToCharBlockMappings_ = true; } static InputKind ParseFrontendArgs(FrontendOptions &opts, @@ -508,6 +511,9 @@ if (frontendOptions.instrumentedParse_) fortranOptions.instrumentedParse = true; + + if (frontendOptions.needProvenanceRangeToCharBlockMappings_) + fortranOptions.needProvenanceRangeToCharBlockMappings = true; } void CompilerInvocation::setSemanticsOpts( diff --git a/flang/test/Driver/debug-provenance.f90 b/flang/test/Driver/debug-provenance.f90 --- a/flang/test/Driver/debug-provenance.f90 +++ b/flang/test/Driver/debug-provenance.f90 @@ -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