diff options
author | Andrzej Warzynski <andrzej.warzynski@arm.com> | 2021-04-07 13:10:35 +0000 |
---|---|---|
committer | Andrzej Warzynski <andrzej.warzynski@arm.com> | 2021-04-07 13:15:09 +0000 |
commit | 85b86c6f43ab50ba70571ed49da7e81f7d52ffd2 (patch) | |
tree | 176c625b120ff6d925e458dfc9564e4b3d566a97 /flang | |
parent | [AMDGPU] SIFoldOperands: don't dump extra '\n' after MachineInstr. NFC. (diff) | |
download | llvm-project-85b86c6f43ab50ba70571ed49da7e81f7d52ffd2.tar.gz llvm-project-85b86c6f43ab50ba70571ed49da7e81f7d52ffd2.tar.bz2 llvm-project-85b86c6f43ab50ba70571ed49da7e81f7d52ffd2.zip |
[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
Diffstat (limited to 'flang')
-rw-r--r-- | flang/include/flang/Frontend/FrontendOptions.h | 9 | ||||
-rw-r--r-- | flang/lib/Frontend/CompilerInvocation.cpp | 6 | ||||
-rw-r--r-- | flang/test/Driver/debug-provenance.f90 | 42 |
3 files changed, 36 insertions, 21 deletions
diff --git a/flang/include/flang/Frontend/FrontendOptions.h b/flang/include/flang/Frontend/FrontendOptions.h index 4e5fa0a476af..b58ca9ce8770 100644 --- a/flang/include/flang/Frontend/FrontendOptions.h +++ b/flang/include/flang/Frontend/FrontendOptions.h @@ -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. diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 6c6277c5a56a..43d9d41bd8d4 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -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(); } diff --git a/flang/test/Driver/debug-provenance.f90 b/flang/test/Driver/debug-provenance.f90 index 1d1d5cac3e70..c7e79e76ade1 100644 --- 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 |