awarzynski created this revision.
Herald added a reviewer: sscalpone.
Herald added subscribers: jansvoboda11, dang.
awarzynski requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Note that the original spelling in `f18` is `-fget-symbols-sources`. The
new driver will only support the new spelling, which is also added to
`f18` as an alias for the existing one.

Tests are updated to use the new spelling and to use `%flang_fc1`
instead of `%f18`. This way both the new and the current driver are
tested.

As:

- both `-fsyntax-only` and `-fdebug-dump-symbols-sources` are action flags, and
- the new driver will only consider the right-most action flag,

`RUN` lines in tests are updated so that the tests work with both
`f18` (requires both flags) and `flang-new` (only considers the last
action flag).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98191

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/FrontendActions.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Semantics/getsymbols01.f90
  flang/test/Semantics/getsymbols02.f90
  flang/test/Semantics/getsymbols03-a.f90
  flang/test/Semantics/getsymbols04.f90
  flang/test/Semantics/getsymbols05.f90
  flang/tools/f18/f18.cpp

Index: flang/tools/f18/f18.cpp
===================================================================
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -628,7 +628,8 @@
         args.pop_front();
       }
       driver.getDefinitionArgs = {arguments[0], arguments[1], arguments[2]};
-    } else if (arg == "-fget-symbols-sources") {
+    } else if (arg == "-fget-symbols-sources" ||
+        arg == "-fdebug-dump-symbols-sources") {
       driver.getSymbolsSources = true;
     } else if (arg == "-byteswapio") {
       driver.byteswapio = true; // TODO: Pass to lowering, generate call
Index: flang/test/Semantics/getsymbols05.f90
===================================================================
--- flang/test/Semantics/getsymbols05.f90
+++ flang/test/Semantics/getsymbols05.f90
@@ -9,7 +9,7 @@
   x = y
 end program
 
-! RUN: %f18 -fget-symbols-sources -fsyntax-only %s 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-symbols-sources %s 2>&1 | FileCheck %s
 ! CHECK:x:{{.*}}getsymbols05.f90, 3, 14-15
 ! CHECK:x:{{.*}}getsymbols05.f90, 6, 16-17
 ! CHECK:y:{{.*}}getsymbols05.f90, 4, 14-15
Index: flang/test/Semantics/getsymbols04.f90
===================================================================
--- flang/test/Semantics/getsymbols04.f90
+++ flang/test/Semantics/getsymbols04.f90
@@ -6,7 +6,7 @@
   x = y
 end program
 
-! RUN: %f18 -fget-symbols-sources -fsyntax-only %s 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-symbols-sources %s 2>&1 | FileCheck %s
 ! CHECK:x:{{.*}}getsymbols04.f90, 3, 14-15
 ! CHECK:x:{{.*}}getsymbols04.f90, 5, 11-12
 ! CHECK:y:{{.*}}getsymbols04.f90, 4, 14-15
Index: flang/test/Semantics/getsymbols03-a.f90
===================================================================
--- flang/test/Semantics/getsymbols03-a.f90
+++ flang/test/Semantics/getsymbols03-a.f90
@@ -7,7 +7,7 @@
  x = f
 end program
 
-! RUN: %f18 -fget-symbols-sources -fsyntax-only %s 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-symbols-sources %s 2>&1 | FileCheck %s
 ! CHECK:f:{{.*}}getsymbols03-b.f90, 2, 12-13
 ! CHECK:main:{{.*}}getsymbols03-a.f90, 4, 9-13
 ! CHECK:mm3:{{.*}}getsymbols03-a.f90, 5, 6-9
Index: flang/test/Semantics/getsymbols02.f90
===================================================================
--- flang/test/Semantics/getsymbols02.f90
+++ flang/test/Semantics/getsymbols02.f90
@@ -7,8 +7,8 @@
     i = callget5()
 ENDPROGRAM
 
-! RUN: %f18 -fsyntax-only %S/Inputs/getsymbols02-a.f90
-! RUN: %f18 -fsyntax-only %S/Inputs/getsymbols02-b.f90
-! RUN: %f18 -fget-symbols-sources -fsyntax-only %s 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -fsyntax-only %S/Inputs/getsymbols02-a.f90
+! RUN: %flang_fc1 -fsyntax-only %S/Inputs/getsymbols02-b.f90
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-symbols-sources %s 2>&1 | FileCheck %s
 ! CHECK: callget5: .{{[/\\]}}mm2b.mod,
 ! CHECK: get5: .{{[/\\]}}mm2a.mod,
Index: flang/test/Semantics/getsymbols01.f90
===================================================================
--- flang/test/Semantics/getsymbols01.f90
+++ flang/test/Semantics/getsymbols01.f90
@@ -15,7 +15,7 @@
  end function
 end module
 
-! RUN: %f18 -fget-symbols-sources -fsyntax-only %s 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -fsyntax-only -fdebug-dump-symbols-sources %s 2>&1 | FileCheck %s
 ! CHECK-COUNT-1:f:{{.*}}getsymbols01.f90, 12, 26-27
 ! CHECK-COUNT-1:mm1:{{.*}}getsymbols01.f90, 2, 8-11
 ! CHECK-COUNT-1:s:{{.*}}getsymbols01.f90, 5, 18-19
Index: flang/test/Flang-Driver/driver-help.f90
===================================================================
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -63,6 +63,8 @@
 ! HELP-FC1-NEXT: -fbackslash            Specify that backslash in string introduces an escape character
 ! HELP-FC1-NEXT: -fdebug-dump-parse-tree Dump the parse tree
 ! HELP-FC1-NEXT: -fdebug-dump-provenance Dump provenance
+! HELP-FC1-NEXT: -fdebug-dump-symbols-sources
+! HELP-FC1-NEXT:      Dump symbols and their source code locations
 ! HELP-FC1-NEXT: -fdebug-dump-symbols    Dump symbols after the semantic analysis
 ! HELP-FC1-NEXT: -fdebug-measure-parse-tree
 ! HELP-FC1-NEXT:                         Measure the parse tree
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===================================================================
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -58,6 +58,9 @@
   case DebugPreFIRTree:
     return std::make_unique<DebugPreFIRTreeAction>();
     break;
+  case DebugDumpSymbolsSources:
+    return std::make_unique<DebugDumpSymbolsSourcesAction>();
+    break;
   default:
     break;
     // TODO:
Index: flang/lib/Frontend/FrontendActions.cpp
===================================================================
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -16,6 +16,7 @@
 #include "flang/Parser/provenance.h"
 #include "flang/Parser/source.h"
 #include "flang/Parser/unparse.h"
+#include "flang/Semantics/runtime-type-info.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/unparse-with-symbols.h"
 #include "llvm/ADT/StringRef.h"
@@ -307,6 +308,15 @@
   }
 }
 
+void DebugDumpSymbolsSourcesAction::ExecuteAction() {
+  // Report and exit if fatal semantic errors are present
+  if (reportFatalSemanticErrors(semantics(), this->instance().diagnostics(),
+          GetCurrentFileOrBufferName()))
+    return;
+
+  semantics().DumpSymbolsSources(llvm::outs());
+}
+
 void EmitObjAction::ExecuteAction() {
   CompilerInstance &ci = this->instance();
   unsigned DiagID = ci.diagnostics().getCustomDiagID(
Index: flang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -131,6 +131,9 @@
     case clang::driver::options::OPT_fdebug_pre_fir_tree:
       opts.programAction_ = DebugPreFIRTree;
       break;
+    case clang::driver::options::OPT_fdebug_dump_symbols_sources:
+      opts.programAction_ = DebugDumpSymbolsSources;
+      break;
 
       // TODO:
       // case calng::driver::options::OPT_emit_llvm:
Index: flang/include/flang/Frontend/FrontendOptions.h
===================================================================
--- flang/include/flang/Frontend/FrontendOptions.h
+++ flang/include/flang/Frontend/FrontendOptions.h
@@ -55,7 +55,10 @@
   DebugMeasureParseTree,
 
   /// Parse, run semantics and then output the pre-FIR tree
-  DebugPreFIRTree
+  DebugPreFIRTree,
+
+  /// Parse, run semantics and the dump symbol sources map
+  DebugDumpSymbolsSources
 
   /// TODO: RunPreprocessor, EmitLLVM, EmitLLVMOnly,
   /// EmitCodeGenOnly, EmitAssembly, (...)
@@ -172,6 +175,9 @@
   /// Show the -version text.
   unsigned showVersion_ : 1;
 
+  /// Instrument the parse to get a more verbose log
+  unsigned instrumentedParse_ : 1;
+
   /// The input files and their types.
   std::vector<FrontendInputFile> inputs_;
 
Index: flang/include/flang/Frontend/FrontendActions.h
===================================================================
--- flang/include/flang/Frontend/FrontendActions.h
+++ flang/include/flang/Frontend/FrontendActions.h
@@ -96,6 +96,10 @@
   void ExecuteAction() override;
 };
 
+class DebugDumpSymbolsSourcesAction : public PrescanAndSemaAction {
+  void ExecuteAction() override;
+};
+
 class ParseSyntaxOnlyAction : public PrescanAndSemaAction {
   void ExecuteAction() override;
 };
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -4355,6 +4355,8 @@
   HelpText<"Measure the parse tree">;
 def fdebug_pre_fir_tree : Flag<["-"], "fdebug-pre-fir-tree">, Group<Action_Group>,
   HelpText<"Dump the pre-FIR tree">;
+def fdebug_dump_symbols_sources : Flag<["-"], "fdebug-dump-symbols-sources">, Group<Action_Group>,
+  HelpText<"Dump symbols and their source code locations">;
 
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to