[clang] ef875c2 - [clang][NFC] Removed unused parameters in InitializeSourceManager

2020-07-03 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2020-07-03T16:16:20+01:00
New Revision: ef875c228ae7484f7bc42511c9fb1e643fa7550d

URL: 
https://github.com/llvm/llvm-project/commit/ef875c228ae7484f7bc42511c9fb1e643fa7550d
DIFF: 
https://github.com/llvm/llvm-project/commit/ef875c228ae7484f7bc42511c9fb1e643fa7550d.diff

LOG: [clang][NFC] Removed unused parameters in InitializeSourceManager

Added: 


Modified: 
clang/include/clang/Frontend/CompilerInstance.h
clang/lib/Frontend/CompilerInstance.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/CompilerInstance.h 
b/clang/include/clang/Frontend/CompilerInstance.h
index ba9bd439c4a3..cb935becaef1 100644
--- a/clang/include/clang/Frontend/CompilerInstance.h
+++ b/clang/include/clang/Frontend/CompilerInstance.h
@@ -764,10 +764,7 @@ class CompilerInstance : public ModuleLoader {
   static bool InitializeSourceManager(const FrontendInputFile &Input,
   DiagnosticsEngine &Diags,
   FileManager &FileMgr,
-  SourceManager &SourceMgr,
-  HeaderSearch *HS,
-  DependencyOutputOptions &DepOpts,
-  const FrontendOptions &Opts);
+  SourceManager &SourceMgr);
 
   /// }
 

diff  --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 0140a756b7dd..9dc9c42297ed 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -815,17 +815,15 @@ std::unique_ptr 
CompilerInstance::createOutputFile(
 // Initialization Utilities
 
 bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input){
-  return InitializeSourceManager(
-  Input, getDiagnostics(), getFileManager(), getSourceManager(),
-  hasPreprocessor() ? &getPreprocessor().getHeaderSearchInfo() : nullptr,
-  getDependencyOutputOpts(), getFrontendOpts());
+  return InitializeSourceManager(Input, getDiagnostics(), getFileManager(),
+ getSourceManager());
 }
 
 // static
-bool CompilerInstance::InitializeSourceManager(
-const FrontendInputFile &Input, DiagnosticsEngine &Diags,
-FileManager &FileMgr, SourceManager &SourceMgr, HeaderSearch *HS,
-DependencyOutputOptions &DepOpts, const FrontendOptions &Opts) {
+bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
+   DiagnosticsEngine &Diags,
+   FileManager &FileMgr,
+   SourceManager &SourceMgr) {
   SrcMgr::CharacteristicKind Kind =
   Input.getKind().getFormat() == InputKind::ModuleMap
   ? Input.isSystem() ? SrcMgr::C_System_ModuleMap



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 869385b - [flang][driver] Add support for `-O{0|1|2|3}`

2022-06-27 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-06-27T10:06:14Z
New Revision: 869385b11c32032d02f5f24fcd21c694fb073850

URL: 
https://github.com/llvm/llvm-project/commit/869385b11c32032d02f5f24fcd21c694fb073850
DIFF: 
https://github.com/llvm/llvm-project/commit/869385b11c32032d02f5f24fcd21c694fb073850.diff

LOG: [flang][driver] Add support for `-O{0|1|2|3}`

This patch adds support for most common optimisation compiler flags:
`-O{0|1|2|3}`. This is implemented in both the compiler and frontend
drivers. At this point, these options are only used to configure the
LLVM optimisation pipelines (aka middle-end). LLVM backend or MLIR/FIR
optimisations are not supported yet.

Previously, the middle-end pass manager was only required when
generating LLVM bitcode (i.e. for `flang-new -c -emit-llvm ` or
`flang-new -fc1 -emit-llvm-bc `). With this change, it becomes
required for all frontend actions that are represented as
`CodeGenAction` and `CodeGenAction::executeAction` is refactored
accordingly (in the spirit of better code re-use).

Additionally, the `-fdebug-pass-manager` option is enabled to facilitate
testing. This flag can be used to configure the pass manager to print
the middle-end passes that are being run. Similar option exists in Clang
and the semantics in Flang are identical. This option translates to
extra configuration when setting up the pass manager. This is
implemented in `CodeGenAction::runOptimizationPipeline`.

This patch also adds some bolier plate code to manage code-gen options
("code-gen" refers to generating machine code in LLVM in this context).
This was extracted from Clang. In Clang, it simplifies defining code-gen
options and enables option marshalling. In Flang, option marshalling is
not yet supported (we might do at some point), but being able to
auto-generate some code with macros is beneficial. This will become
particularly apparent when we start adding more options (at least in
Clang, the list of code-gen options is rather long).

Differential Revision: https://reviews.llvm.org/D128043

Added: 
flang/include/flang/Frontend/CodeGenOptions.def
flang/include/flang/Frontend/CodeGenOptions.h
flang/lib/Frontend/CodeGenOptions.cpp
flang/test/Driver/default-optimization-pipelines.f90
flang/test/Driver/flang_f_opts.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/CompilerInvocation.h
flang/include/flang/Frontend/FrontendActions.h
flang/lib/Frontend/CMakeLists.txt
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 5d5f886ea7534..06c7e415384cd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -721,14 +721,14 @@ def MV : Flag<["-"], "MV">, Group, 
Flags<[CC1Option]>,
 MarshallingInfoFlag, 
"DependencyOutputFormat::Make">,
 Normalizer<"makeFlagToValueNormalizer(DependencyOutputFormat::NMake)">;
 def Mach : Flag<["-"], "Mach">, Group;
-def O0 : Flag<["-"], "O0">, Group, Flags<[CC1Option, HelpHidden]>;
-def O4 : Flag<["-"], "O4">, Group, Flags<[CC1Option, HelpHidden]>;
+def O0 : Flag<["-"], "O0">, Group, Flags<[CC1Option, FC1Option, 
HelpHidden]>;
+def O4 : Flag<["-"], "O4">, Group, Flags<[CC1Option, FC1Option, 
HelpHidden]>;
 def ObjCXX : Flag<["-"], "ObjC++">, Flags<[NoXarchOption]>,
   HelpText<"Treat source input files as Objective-C++ inputs">;
 def ObjC : Flag<["-"], "ObjC">, Flags<[NoXarchOption]>,
   HelpText<"Treat source input files as Objective-C inputs">;
-def O : Joined<["-"], "O">, Group, Flags<[CC1Option]>;
-def O_flag : Flag<["-"], "O">, Flags<[CC1Option]>, Alias, AliasArgs<["1"]>;
+def O : Joined<["-"], "O">, Group, Flags<[CC1Option,FC1Option]>;
+def O_flag : Flag<["-"], "O">, Flags<[CC1Option,FC1Option]>, Alias, 
AliasArgs<["1"]>;
 def Ofast : Joined<["-"], "Ofast">, Group, Flags<[CC1Option]>;
 def P : Flag<["-"], "P">, Flags<[CC1Option,FlangOption,FC1Option]>, 
Group,
   HelpText<"Disable linemarker output in -E mode">,
@@ -5473,10 +5473,6 @@ defm lto_unit : BoolOption<"f", "lto-unit",
   CodeGenOpts<"LTOUnit">, DefaultFalse,
   PosFlag,
   NegFlag>;
-defm debug_pass_manager : BoolOption<"f", "debug-pass-manager",
-  CodeGenOpts<"DebugPassManager">, DefaultFalse,
-  PosFlag,
-  NegFlag>;
 def fverify_debuginfo_preserve
 : Flag<["-"], "fverify-debuginfo-preserve">,
   HelpText<"Enable Debug Info Metadata preservation testing in "
@@ -6280,6 +6276,10 @@ def load : Separate<["-"], "load">, 
MetaVarName<"">,
   HelpText<"Load the named plugin (dynamic shared object)">;
 def plugin : Separate<["-"], "plugin">, MetaVarName<"">,
   HelpText<"Use the named plugin action instead of the default action (use 
\"help\" to list available options)">;
+defm debu

[clang] b405407 - [clang][flang] Disable defaulting to `-fpie` for LLVM Flang

2022-06-29 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-06-29T07:53:06Z
New Revision: b405407a489902c0acfcf936bfda9821a1deb170

URL: 
https://github.com/llvm/llvm-project/commit/b405407a489902c0acfcf936bfda9821a1deb170
DIFF: 
https://github.com/llvm/llvm-project/commit/b405407a489902c0acfcf936bfda9821a1deb170.diff

LOG: [clang][flang] Disable defaulting to `-fpie` for LLVM Flang

In, https://reviews.llvm.org/D120305, CLANG_DEFAULT_PIE_ON_LINUX was set
to `On` by default. However, neither `-fpie` nor `-fpic` are currently
supported in LLVM Flang. Hence, in this patch the behaviour controlled
with CLANG_DEFAULT_PIE_ON_LINUX is refined not to apply to Flang.

Another way to look at this is that CLANG_DEFAULT_PIE_ON_LINUX is
currently affecting both Clang and Flang. IIUC, the intention for this
CMake variable has always been to only affect Clang. This patch makes
sure that that's the case.

Without this change, you might see errors like this on X86_64:
```
/usr/bin/ld: main.o: relocation R_X86_64_32 against `.bss' can not be used when 
making a PIE object; recompile with -fPIC
```
I've not experienced any issues on AArch64. That's probably because on
AArch64 some object files happen to be position independent without
needing -fpie or -fpic.

Differential Revision: https://reviews.llvm.org/D128333

Added: 
flang/test/Driver/pic-flags.f90

Modified: 
clang/lib/Driver/ToolChains/Linux.cpp
flang/docs/ReleaseNotes.md

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Linux.cpp 
b/clang/lib/Driver/ToolChains/Linux.cpp
index 4309b10603465..ceb1a982c3a4c 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -699,8 +699,11 @@ void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs,
 }
 
 bool Linux::isPIEDefault(const llvm::opt::ArgList &Args) const {
-  return CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid() ||
- getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE();
+  // TODO: Remove the special treatment for Flang once its frontend driver can
+  // generate position independent code.
+  return !getDriver().IsFlangMode() &&
+ (CLANG_DEFAULT_PIE_ON_LINUX || getTriple().isAndroid() ||
+  getTriple().isMusl() || getSanitizerArgs(Args).requiresPIE());
 }
 
 bool Linux::IsAArch64OutlineAtomicsDefault(const ArgList &Args) const {

diff  --git a/flang/docs/ReleaseNotes.md b/flang/docs/ReleaseNotes.md
index b41a2aabb9733..38d5c3f0706dc 100644
--- a/flang/docs/ReleaseNotes.md
+++ b/flang/docs/ReleaseNotes.md
@@ -28,6 +28,13 @@ page](https://llvm.org/releases/).
 
 ## Non-comprehensive list of changes in this release
 * The bash wrapper script, `flang`, is renamed as `flang-to-external-fc`.
+* In contrast to Clang, Flang will not default to using `-fpie` when linking
+  executables. This is only a temporary solution and the goal is to align with
+  Clang in the near future. First, however, the frontend driver needs to be
+  extended so that it can generate position independent code (that requires
+  adding support for e.g. `-fpic` and `-mrelocation-model` in `flang-new
+  -fc1`). Once that is available, support for the `-fpie` can officially be
+  added and the default behaviour updated.
 
 ## New Compiler Flags
 * Refined how `-f{no-}color-diagnostics` is treated to better align with Clang.

diff  --git a/flang/test/Driver/pic-flags.f90 b/flang/test/Driver/pic-flags.f90
new file mode 100644
index 0..4e6b9796cb4a1
--- /dev/null
+++ b/flang/test/Driver/pic-flags.f90
@@ -0,0 +1,24 @@
+! Verify that in contrast to Clang, Flang does not default to generating 
position independent executables/code
+
+!-
+! RUN COMMANDS
+!-
+! RUN: %flang -### %s --target=aarch64-linux-gnu 2>&1 | FileCheck %s 
--check-prefix=CHECK-NOPIE
+! RUN: %flang -### %s --target=aarch64-linux-gnu -fno-pie 2>&1 | FileCheck %s 
--check-prefix=CHECK-NOPIE
+
+! RUN: %flang -### %s --target=aarch64-linux-gnu -fpie 2>&1 | FileCheck %s 
--check-prefix=CHECK-PIE
+
+!
+! EXPECTED OUTPUT
+!
+! CHECK-NOPIE: "-fc1"
+! CHECk-NOPIE-NOT: "-fpic"
+! CHECK-NOPIE: "{{.*}}ld"
+! CHECK-NOPIE-NOT: "-pie"
+
+! CHECK-PIE: "-fc1"
+!! TODO Once Flang supports `-fpie`, it //should// use -fpic when invoking 
`flang -fc1`. Update the following line once `-fpie` is
+! available.
+! CHECk-PIE-NOT: "-fpic"
+! CHECK-PIE: "{{.*}}ld"
+! CHECK-PIE-NOT: "-pie"



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 38101b4 - [flang][driver] Add support for -S and implement -c/-emit-obj

2022-03-09 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-03-09T15:48:09Z
New Revision: 38101b4e95aa4983b7acf1e6351309db9ce5761b

URL: 
https://github.com/llvm/llvm-project/commit/38101b4e95aa4983b7acf1e6351309db9ce5761b
DIFF: 
https://github.com/llvm/llvm-project/commit/38101b4e95aa4983b7acf1e6351309db9ce5761b.diff

LOG: [flang][driver] Add support for -S and implement -c/-emit-obj

This patch adds support for:
  * `-S` in Flang's compiler and frontend drivers,
and implements:
  * `-emit-obj` in Flang's frontend driver and `-c` in Flang's compiler
driver (this is consistent with Clang).
(these options were already available before, but only as placeholders).
The semantics of these options in Clang and Flang are identical.

The `EmitObjAction` frontend action is renamed as `BackendAction`. This
new name more accurately reflects the fact that this action will
primarily run the code-gen/backend pipeline in LLVM. It also makes more
sense as an action implementing both `-emit-obj` and `-S` (originally,
it was just `-emit-obj`).

`tripleName` from FirContext.cpp is deleted and, when a target triple is
required, `mlir::LLVM::LLVMDialect::getTargetTripleAttrName()` is used
instead. In practice, this means that `fir.triple` is replaced with
`llvm.target_triple`. The former was effectively ignored. The latter is
used when lowering from the LLVM dialect in MLIR to LLVM IR (i.e. it's
embedded in the generated LLVM IR module). The driver can then re-use
it when configuring the backend. With this change, the LLVM IR files
generated by e.g. `tco` will from now on contain the correct target
triple.

The code-gen.f90 test is replaced with code-gen-x86.f90 and
code-gen-aarch64.f90. With 2 seperate files we can verify that
`--target` is correctly taken into account. LIT configuration is updated
to enable e.g.:
```
! REQUIRES: aarch64-registered-target
```

Differential Revision: https://reviews.llvm.org/D120568

Added: 
flang/test/Driver/code-gen-aarch64.f90
flang/test/Driver/code-gen-x86.f90
flang/test/Driver/emit-asm-aarch64.f90
flang/test/Driver/emit-asm-x86.f90

Modified: 
clang/include/clang/Driver/Options.td
flang/include/flang/Frontend/FrontendActions.h
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CMakeLists.txt
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/lib/Optimizer/Support/FIRContext.cpp
flang/test/CMakeLists.txt
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
flang/test/Driver/syntax-only.f90
flang/test/Fir/target-rewrite-triple.fir
flang/test/lit.cfg.py
flang/test/lit.site.cfg.py.in
flang/tools/flang-driver/fc1_main.cpp
flang/unittests/Frontend/CMakeLists.txt
flang/unittests/Frontend/FrontendActionTest.cpp

Removed: 
flang/test/Driver/code-gen.f90



diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3d49e6b165b38..fa54d4a7689cd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -750,7 +750,7 @@ def Rpass_analysis_EQ : Joined<["-"], "Rpass-analysis=">, 
Group,
"name matches the given POSIX regular expression">;
 def R_Joined : Joined<["-"], "R">, Group, Flags<[CC1Option, 
CoreOption]>,
   MetaVarName<"">, HelpText<"Enable the specified remark">;
-def S : Flag<["-"], "S">, Flags<[NoXarchOption,CC1Option]>, 
Group,
+def S : Flag<["-"], "S">, 
Flags<[NoXarchOption,CC1Option,FlangOption,FC1Option]>, Group,
   HelpText<"Only run preprocess and compilation steps">;
 def Tbss : JoinedOrSeparate<["-"], "Tbss">, Group,
   MetaVarName<"">, HelpText<"Set starting address of BSS to ">;

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index 0cb6d6301c066..34cabea590485 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -192,8 +192,19 @@ class EmitLLVMAction : public CodeGenAction {
   void ExecuteAction() override;
 };
 
-class EmitObjAction : public CodeGenAction {
+class BackendAction : public CodeGenAction {
+public:
+  enum class BackendActionTy {
+Backend_EmitAssembly, ///< Emit native assembly files
+Backend_EmitObj ///< Emit native object files
+  };
+
+  BackendAction(BackendActionTy act) : action{act} {};
+
+private:
   void ExecuteAction() override;
+
+  BackendActionTy action;
 };
 
 } // namespace Fortran::frontend

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index c396822819ac6..b299c87ef15f1 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -40,6 +40,9 @@ enum ActionKind {
   /// Emit a .o file.
   EmitObj,
 
+  /// Emit a .s file.
+  EmitAssembly

[clang] a7c08bc - [flang][driver] Add support for `-mllvm`

2022-03-16 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-03-16T10:41:04Z
New Revision: a7c08bcf777ee0712c140052d0814f55a02dd27b

URL: 
https://github.com/llvm/llvm-project/commit/a7c08bcf777ee0712c140052d0814f55a02dd27b
DIFF: 
https://github.com/llvm/llvm-project/commit/a7c08bcf777ee0712c140052d0814f55a02dd27b.diff

LOG: [flang][driver] Add support for `-mllvm`

This option is added in both `flang-new` (the compiler driver) and
`flang-new -fc1` (the frontend driver). The semantics are consistent
with `clang` and `clang -cc1`.

As Flang does not run any LLVM passes when invoked with `-emit-llvm`
(i.e. `flang-new -S -emit-llvm `), the tests use
`-S`/`-c`/`-emit-obj` instead. These options require an LLVM backend to
be run by the driver to generate the output (this makese `-mllvm`
relevant here).

Differential Revision: https://reviews.llvm.org/D121374

Added: 
flang/test/Driver/mllvm.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index fa54d4a7689cd..2a23695c149fa 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3254,7 +3254,7 @@ def miphonesimulator_version_min_EQ : Joined<["-"], 
"miphonesimulator-version-mi
 def mkernel : Flag<["-"], "mkernel">, Group;
 def mlinker_version_EQ : Joined<["-"], "mlinker-version=">,
   Flags<[NoXarchOption]>;
-def mllvm : Separate<["-"], "mllvm">, 
Flags<[CC1Option,CC1AsOption,CoreOption]>,
+def mllvm : Separate<["-"], 
"mllvm">,Flags<[CC1Option,CC1AsOption,CoreOption,FC1Option,FlangOption]>,
   HelpText<"Additional arguments to forward to LLVM's option processing">,
   MarshallingInfoStringVector>;
 def ffuchsia_api_level_EQ : Joined<["-"], "ffuchsia-api-level=">,

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index c77aa68257a67..283b5ca80b28c 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -106,6 +106,13 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // Forward -Xflang arguments to -fc1
   Args.AddAllArgValues(CmdArgs, options::OPT_Xflang);
 
+  // Forward -mllvm options to the LLVM option parser. In practice, this means
+  // forwarding to `-fc1` as that's where the LLVM parser is run.
+  for (const Arg *A : Args.filtered(options::OPT_mllvm)) {
+A->claim();
+A->render(Args, CmdArgs);
+  }
+
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index b299c87ef15f1..5d97580af5a56 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -266,6 +266,10 @@ struct FrontendOptions {
   /// The name of the action to run when using a plugin action.
   std::string ActionName;
 
+  /// A list of arguments to forward to LLVM's option processing; this
+  /// should only be used for debugging and experimental features.
+  std::vector llvmArgs;
+
   // 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 d1b0d0e532cd9..cf92e71c755d2 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -584,6 +584,8 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation 
&res,
   success &= parseSemaArgs(res, args, diags);
   success &= parseDialectArgs(res, args, diags);
   success &= parseDiagArgs(res, args, diags);
+  res.frontendOpts_.llvmArgs =
+  args.getAllArgValues(clang::driver::options::OPT_mllvm);
 
   return success;
 }

diff  --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp 
b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index 4e8c22550c406..0f91d6e1a44b0 100644
--- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -135,6 +135,19 @@ bool ExecuteCompilerInvocation(CompilerInstance *flang) {
 }
   }
 
+  // Honor -mllvm. This should happen AFTER plugins have been loaded!
+  if (!flang->frontendOpts().llvmArgs.empty()) {
+unsigned numArgs = flang->frontendOpts().llvmArgs.size();
+auto args = std::make_unique(numArgs + 2);
+args[0] = "flang (LLVM option parsing)";
+
+for (unsigned i = 0; i != numArgs; ++i)
+  args[i + 1] = flang->frontendOpts().llvmArgs[i].c_str();
+
+args[numArgs + 1] = nullptr;

[clang] dd56939 - [flang][driver] Add support for generating LLVM bytecode files

2022-04-13 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-04-13T10:19:56Z
New Revision: dd56939a4b04072a449a05701373e95d00cc494f

URL: 
https://github.com/llvm/llvm-project/commit/dd56939a4b04072a449a05701373e95d00cc494f
DIFF: 
https://github.com/llvm/llvm-project/commit/dd56939a4b04072a449a05701373e95d00cc494f.diff

LOG: [flang][driver] Add support for generating LLVM bytecode files

Support for generating LLVM BC files is added in Flang's compiler and
frontend drivers. This requires the `BitcodeWriterPass` pass to be run
on the input LLVM IR module and is implemented as a dedicated frontend
aciton. The new functionality as seen by the user (compiler driver):
```
flang-new -c -emit-llvm file.90
```
or (frontend driver):
```
flang-new -fc1 -emit-llvm-bc file.f90
```

The new behaviour is consistent with `clang` and `clang -cc1`.

Differential Revision: https://reviews.llvm.org/D123211

Added: 
flang/test/Driver/emit-llvm-bc.f90

Modified: 
clang/include/clang/Driver/Options.td
flang/include/flang/Frontend/FrontendActions.h
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CMakeLists.txt
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/test/CMakeLists.txt
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9ffc79a52b0ed..483f0cc549ab4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5678,8 +5678,6 @@ def emit_header_unit : Flag<["-"], "emit-header-unit">,
   HelpText<"Generate C++20 header units from header files">;
 def emit_pch : Flag<["-"], "emit-pch">,
   HelpText<"Generate pre-compiled header file">;
-def emit_llvm_bc : Flag<["-"], "emit-llvm-bc">,
-  HelpText<"Build ASTs then convert to LLVM, emit .bc file">;
 def emit_llvm_only : Flag<["-"], "emit-llvm-only">,
   HelpText<"Build ASTs and convert to LLVM, discarding output">;
 def emit_codegen_only : Flag<["-"], "emit-codegen-only">,
@@ -6143,6 +6141,8 @@ def emit_obj : Flag<["-"], "emit-obj">,
   HelpText<"Emit native object files">;
 def init_only : Flag<["-"], "init-only">,
   HelpText<"Only execute frontend initialization">;
+def emit_llvm_bc : Flag<["-"], "emit-llvm-bc">,
+  HelpText<"Build ASTs then convert to LLVM, emit .bc file">;
 
 } // let Group = Action_Group
 

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index 34cabea590485..48836c6d41e21 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -192,6 +192,10 @@ class EmitLLVMAction : public CodeGenAction {
   void ExecuteAction() override;
 };
 
+class EmitLLVMBitcodeAction : public CodeGenAction {
+  void ExecuteAction() override;
+};
+
 class BackendAction : public CodeGenAction {
 public:
   enum class BackendActionTy {

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index 5d97580af5a56..d0459e4bf06ff 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -37,6 +37,9 @@ enum ActionKind {
   /// Emit an .ll file
   EmitLLVM,
 
+  /// Emit a .bc file
+  EmitLLVMBitcode,
+
   /// Emit a .o file.
   EmitObj,
 

diff  --git a/flang/lib/Frontend/CMakeLists.txt 
b/flang/lib/Frontend/CMakeLists.txt
index d6520e705dc9f..45692a5342094 100644
--- a/flang/lib/Frontend/CMakeLists.txt
+++ b/flang/lib/Frontend/CMakeLists.txt
@@ -32,6 +32,7 @@ add_flang_library(flangFrontend
   FIRBuilder
   FIRCodeGen
   FIRTransforms
+  LLVMPasses
   MLIRTransforms
   MLIRLLVMToLLVMIRTranslation
   MLIRSCFToControlFlow

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index d1f427a15005f..ea5accd76bca2 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -148,6 +148,9 @@ static bool ParseFrontendArgs(FrontendOptions &opts, 
llvm::opt::ArgList &args,
 case clang::driver::options::OPT_emit_llvm:
   opts.programAction = EmitLLVM;
   break;
+case clang::driver::options::OPT_emit_llvm_bc:
+  opts.programAction = EmitLLVMBitcode;
+  break;
 case clang::driver::options::OPT_emit_obj:
   opts.programAction = EmitObj;
   break;

diff  --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index e30f6af7d489a..e93781e87fe00 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -33,6 +33,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
+#include "llvm/Bitcode/BitcodeWriterPass.h"
 #include "llvm/IR/LegacyPassManager.h"
 #include "l

[clang] 6c93e1d - [flang][driver] Add support for `-mmlir`

2022-04-14 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-04-14T09:40:31Z
New Revision: 6c93e1d329e6c6ef828ec63c66f4cb39ee9cb9ce

URL: 
https://github.com/llvm/llvm-project/commit/6c93e1d329e6c6ef828ec63c66f4cb39ee9cb9ce
DIFF: 
https://github.com/llvm/llvm-project/commit/6c93e1d329e6c6ef828ec63c66f4cb39ee9cb9ce.diff

LOG: [flang][driver] Add support for `-mmlir`

The semantics of `-mmlir` are identical to `-mllvm`. The only notable
difference is that `-mmlir` options should be forwarded to MLIR rather
than LLVM.

Note that MLIR llvm::cl options are lazily constructed on demand (see
the definition of options in PassManagerOptions.cpp). This means that:
  * MLIR global options are only visible when explicitly initialised and
displayed only when using `-mmlir --help`,
  * Flang and LLVM global options are always visible and displayed when
using either `-mllvm -help` or `-mmlir --help`.

In other words, `-mmlir --help` is a superset of `-mllvm --help`. This is not
ideal, but we'd need to refactor all option definitions in Flang and
LLVM to improve this. I suggesting leaving this for later.

Differential Revision: https://reviews.llvm.org/D123297

Added: 
flang/test/Driver/mllvm_vs_mmlir.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/FrontendTool/CMakeLists.txt
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 87b5ef2d39c33..104c8ea8483d1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3264,6 +3264,8 @@ def mlinker_version_EQ : Joined<["-"], 
"mlinker-version=">,
 def mllvm : Separate<["-"], 
"mllvm">,Flags<[CC1Option,CC1AsOption,CoreOption,FC1Option,FlangOption]>,
   HelpText<"Additional arguments to forward to LLVM's option processing">,
   MarshallingInfoStringVector>;
+def mmlir : Separate<["-"], "mmlir">, 
Flags<[CoreOption,FC1Option,FlangOption]>,
+  HelpText<"Additional arguments to forward to MLIR's option processing">;
 def ffuchsia_api_level_EQ : Joined<["-"], "ffuchsia-api-level=">,
   Group, Flags<[CC1Option]>, HelpText<"Set Fuchsia API level">,
   MarshallingInfoInt>;

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 283b5ca80b28c..63e3c080a7e7f 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -113,6 +113,11 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 A->render(Args, CmdArgs);
   }
 
+  for (const Arg *A : Args.filtered(options::OPT_mmlir)) {
+A->claim();
+A->render(Args, CmdArgs);
+  }
+
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index d0459e4bf06ff..ab085172e6d9f 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -273,6 +273,10 @@ struct FrontendOptions {
   /// should only be used for debugging and experimental features.
   std::vector llvmArgs;
 
+  /// A list of arguments to forward to MLIR's option processing; this
+  /// should only be used for debugging and experimental features.
+  std::vector mlirArgs;
+
   // 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 ea5accd76bca2..0f0db576a4fed 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -597,6 +597,9 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation 
&res,
   res.frontendOpts_.llvmArgs =
   args.getAllArgValues(clang::driver::options::OPT_mllvm);
 
+  res.frontendOpts_.mlirArgs =
+  args.getAllArgValues(clang::driver::options::OPT_mmlir);
+
   return success;
 }
 

diff  --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index a05c2e27a34b4..83e795c16906f 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -427,6 +427,7 @@ void CodeGenAction::GenerateLLVMIR() {
 
   // Create the pass pipeline
   fir::createMLIRToLLVMPassPipeline(pm);
+  mlir::applyPassManagerCLOptions(pm);
 
   // Run the pass manager
   if (!mlir::succeeded(pm.run(*mlirModule))) {

diff  --git a/flang/lib/FrontendTool/CMakeLists.txt 
b/flang/lib/FrontendTool/CMakeLists.txt
index 1a29f4acd9ae7..0753313d73427 100644
--- a/flang/lib/FrontendToo

[clang] 69c3309 - [flang][driver] Add support for `-emit-mlir`

2022-02-09 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-02-09T08:35:48Z
New Revision: 69c3309d4545cd729c41b102303686e19c92f55c

URL: 
https://github.com/llvm/llvm-project/commit/69c3309d4545cd729c41b102303686e19c92f55c
DIFF: 
https://github.com/llvm/llvm-project/commit/69c3309d4545cd729c41b102303686e19c92f55c.diff

LOG: [flang][driver] Add support for `-emit-mlir`

This patch adds support for generating MLIR files in Flang's frontend
driver (i.e. `flang-new -fc1`). `-emit-fir` is added as an alias for
`-emit-mlir`. We may want to decide to split the two in the future.

A new parent class for code-gen frontend actions is introduced:
`CodeGenAction`. We will be using this class to encapsulate logic shared
between all code-generation actions, but not required otherwise. For
now, it will:
 * run prescanning, parsing and semantic checks,
 * lower the input to MLIR.
`EmitObjAction` is updated to inherit from this class. This means that
the behaviour of `flang-new -fc1 -emit-obj` is also updated (previously,
it would just exit immediately). This change required
`flang/test/Driver/syntax-only.f90` to be updated.

For `-emit-fir`, a specialisation of `CodeGenAction` is introduced:
`EmitMLIRAction`. The key logic for this class is implemented in
`EmitMLIRAction::ExecuteAction`.

Differential Revision: https://reviews.llvm.org/D118985

Added: 
flang/test/Driver/emit-mlir.f90

Modified: 
clang/include/clang/Driver/Options.td
flang/include/flang/Frontend/CompilerInstance.h
flang/include/flang/Frontend/FrontendActions.h
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CMakeLists.txt
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/FrontendTool/CMakeLists.txt
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/test/Driver/driver-help.f90
flang/test/Driver/syntax-only.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1900d0f782de6..a64a6766e1645 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4759,6 +4759,10 @@ def fno_reformat : Flag<["-"], "fno-reformat">, 
Group,
   HelpText<"Dump the cooked character stream in -E mode">;
 defm analyzed_objects_for_unparse : 
OptOutFC1FFlag<"analyzed-objects-for-unparse", "", "Do not use the analyzed 
objects when unparsing">;
 
+def emit_mlir : Flag<["-"], "emit-mlir">, Group,
+  HelpText<"Build the parse tree, then lower it to MLIR">;
+def emit_fir : Flag<["-"], "emit-fir">, Alias;
+
 }
 
 
//===--===//

diff  --git a/flang/include/flang/Frontend/CompilerInstance.h 
b/flang/include/flang/Frontend/CompilerInstance.h
index ce1e46cab3147..29a1bc7b9a5c7 100644
--- a/flang/include/flang/Frontend/CompilerInstance.h
+++ b/flang/include/flang/Frontend/CompilerInstance.h
@@ -250,6 +250,13 @@ class CompilerInstance {
   void WriteOutputStream(const std::string &message) {
 *outputStream_ << message;
   }
+
+  /// Get the user specified output stream.
+  llvm::raw_pwrite_stream &GetOutputStream() {
+assert(outputStream_ &&
+"Compiler instance has no user-specified output stream!");
+return *outputStream_;
+  }
 };
 
 } // end namespace Fortran::frontend

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index 1e17f194ba5f2..e3def74e0f417 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -11,6 +11,8 @@
 
 #include "flang/Frontend/FrontendAction.h"
 #include "flang/Semantics/semantics.h"
+
+#include "mlir/IR/BuiltinOps.h"
 #include 
 
 namespace Fortran::frontend {
@@ -34,10 +36,6 @@ class InputOutputTestAction : public FrontendAction {
   void ExecuteAction() override;
 };
 
-class EmitObjAction : public FrontendAction {
-  void ExecuteAction() override;
-};
-
 class InitOnlyAction : public FrontendAction {
   void ExecuteAction() override;
 };
@@ -146,6 +144,35 @@ class DebugDumpAllAction : public 
PrescanAndSemaDebugAction {
   void ExecuteAction() override;
 };
 
+//===--===//
+// CodeGen Actions
+//===--===//
+/// Abstract base class for actions that generate code (MLIR, LLVM IR, assembly
+/// and machine code). Every action that inherits from this class will at
+/// least run the prescanning, parsing, semantic checks and lower the parse
+/// tree to an MLIR module.
+class CodeGenAction : public FrontendAction {
+
+  void ExecuteAction() override = 0;
+  /// Runs prescan, parsing, sema and lowers to MLIR.
+  bool BeginSourceFileAction() override;
+
+protected:
+  /// @name MLIR
+  /// {
+  std::unique_ptr mlirModule;
+  std::unique_ptr mlirCtx;
+  /// }

[clang] e993b20 - [flang][driver] Add support for `-emit-llvm`

2022-02-17 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-02-17T12:13:03Z
New Revision: e993b20c049d2f933831c26139f024e022f3d7fe

URL: 
https://github.com/llvm/llvm-project/commit/e993b20c049d2f933831c26139f024e022f3d7fe
DIFF: 
https://github.com/llvm/llvm-project/commit/e993b20c049d2f933831c26139f024e022f3d7fe.diff

LOG: [flang][driver] Add support for `-emit-llvm`

This patch adds support for the `-emit-llvm` option in the frontend
driver (i.e. `flang-new -fc1`). Similarly to Clang, `flang-new -fc1
-emit-llvm file.f` will generate a textual LLVM IR file.

Depends on D118985

Differential Revision: https://reviews.llvm.org/D119012

Added: 
flang/test/Driver/emit-llvm.f90

Modified: 
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/Driver/driver-help.f90
flang/unittests/Frontend/FrontendActionTest.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b81973155cae6..37a8e9b77bbfb 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1071,7 +1071,7 @@ def d_Flag : Flag<["-"], "d">, Group;
 def d_Joined : Joined<["-"], "d">, Group;
 def emit_ast : Flag<["-"], "emit-ast">,
   HelpText<"Emit Clang AST files for source inputs">;
-def emit_llvm : Flag<["-"], "emit-llvm">, Flags<[CC1Option]>, 
Group,
+def emit_llvm : Flag<["-"], "emit-llvm">, Flags<[CC1Option, FC1Option]>, 
Group,
   HelpText<"Use the LLVM representation for assembler and object files">;
 def emit_interface_stubs : Flag<["-"], "emit-interface-stubs">, 
Flags<[CC1Option]>, Group,
   HelpText<"Generate Interface Stub Files.">;

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index e3def74e0f417..6a9afd1afc5c0 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -13,6 +13,7 @@
 #include "flang/Semantics/semantics.h"
 
 #include "mlir/IR/BuiltinOps.h"
+#include "llvm/IR/Module.h"
 #include 
 
 namespace Fortran::frontend {
@@ -163,12 +164,25 @@ class CodeGenAction : public FrontendAction {
   std::unique_ptr mlirModule;
   std::unique_ptr mlirCtx;
   /// }
+
+  /// @name LLVM IR
+  std::unique_ptr llvmCtx;
+  std::unique_ptr llvmModule;
+
+  /// Generates an LLVM IR module from CodeGenAction::mlirModule and saves it
+  /// in CodeGenAction::llvmModule.
+  void GenerateLLVMIR();
+  /// }
 };
 
 class EmitMLIRAction : public CodeGenAction {
   void ExecuteAction() override;
 };
 
+class EmitLLVMAction : public CodeGenAction {
+  void ExecuteAction() override;
+};
+
 class EmitObjAction : public CodeGenAction {
   void ExecuteAction() override;
 };

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index 0ff8d0a758873..060910e3d67cd 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -34,6 +34,9 @@ enum ActionKind {
   /// Emit a .mlir file
   EmitMLIR,
 
+  /// Emit an .ll file
+  EmitLLVM,
+
   /// Emit a .o file.
   EmitObj,
 
@@ -84,9 +87,6 @@ enum ActionKind {
 
   /// Run a plugin action
   PluginAction
-
-  /// TODO: RunPreprocessor, EmitLLVM, EmitLLVMOnly,
-  /// EmitCodeGenOnly, EmitAssembly, (...)
 };
 
 /// \param suffix The file extension

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index af59cb6636b3a..7507b0091e13c 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -137,6 +137,9 @@ static bool ParseFrontendArgs(FrontendOptions &opts, 
llvm::opt::ArgList &args,
 case clang::driver::options::OPT_emit_mlir:
   opts.programAction = EmitMLIR;
   break;
+case clang::driver::options::OPT_emit_llvm:
+  opts.programAction = EmitLLVM;
+  break;
 case clang::driver::options::OPT_emit_obj:
   opts.programAction = EmitObj;
   break;

diff  --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index d981faaa84980..43ab3f689522d 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -14,6 +14,7 @@
 #include "flang/Lower/Bridge.h"
 #include "flang/Lower/PFTBuilder.h"
 #include "flang/Lower/Support/Verifier.h"
+#include "flang/Optimizer/Support/FIRContext.h"
 #include "flang/Optimizer/Support/InitFIR.h"
 #include "flang/Optimizer/Support/KindMapping.h"
 #include "flang/Optimizer/Support/Utils.h"
@@ -28,6 +29,7 @@
 
 #include "mlir/IR/Dialect.h"
 #include "mlir/Pass/PassManager.h"
+#include "mlir/Target/LLVMIR/ModuleTranslation.h"
 #include "llvm/ADT/StringRef

[clang] 97a32d3 - [flang][driver] Add support for generating executables

2022-04-25 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-04-25T12:00:23Z
New Revision: 97a32d3e43fec35ea424e77c2940ee7e801a

URL: 
https://github.com/llvm/llvm-project/commit/97a32d3e43fec35ea424e77c2940ee7e801a
DIFF: 
https://github.com/llvm/llvm-project/commit/97a32d3e43fec35ea424e77c2940ee7e801a.diff

LOG: [flang][driver] Add support for generating executables

This patch adds 2 missing items required for `flang-new` to be able to
generate executables:

1. The Fortran_main runtime library, which implements the main entry
   point into Fortran's `PROGRAM` in Flang,

2. Extra linker flags to include Fortran runtime libraries (e.g.
   Fortran_main).

Fortran_main is the bridge between object files generated by Flang and
the C runtime that takes care of program set-up at system-level. For
every Fortran `PROGRAM`, Flang generates the `_QQmain` function.
Fortran_main implements the C `main` function that simply calls
`_QQmain`.

Additionally, "/../lib" directory is added to the list of
search directories for libraries. This is where the required runtime
libraries are currently located. Note that this the case for the build
directory. We haven't considered installation directories/targets yet.

With this change, you can generate an executable that will print `hello,
world!` as follows:

```bash
$ cat hello.f95
PROGRAM HELLO
  write(*, *) "hello, world!"
END PROGRAM HELLO
$ flang-new -flang-experimental-exec hello.f95
./a.out
hello, world!
```

NOTE 1: Fortran_main has to be a static library at all times. It invokes
`_QQmain`, which is the main entry point generated by Flang for the
given input file (you can check this with `flang-new -S hello.f95 -o - |
grep "Qmain"`). This means that Fortran_main has an unresolved
dependency at build time. The linker will allow this for a static
library. However, if Fortran_main was a shared object, then the linker
will produce an error: `undefined symbol: `_QQmain`.

NOTE 2: When Fortran runtime libraries are generated as shared libraries
(excluding Fortran_main, which is always static), you will need to
tell the dynamic linker (by e.g. tweaking LD_LIBRARY_PATH) where to look
for them when invoking the executables. For example:
```bash
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib/ ./a.out
```

NOTE 3: This feature is considered experimental and currently guarded
with a flag: `-flang-experimental-exec`.

Differential Revision: https://reviews.llvm.org/D122008

[1] https://github.com/flang-compiler/f18-llvm-project

CREDITS: Fortran_main was originally written by Eric Schweitz, Jean
Perier, Peter Klausler and Steve Scalpone in the fir-dev` branch in [1].

Co-authored-by: Eric Schweitz 
Co-authored-by: Peter Klausler 
Co-authored-by: Jean Perier 
Co-authored-by: Steve Scalpone , Flags<[NoXarchOption, 
CoreOption]>,
 def fno_sycl : Flag<["-"], "fno-sycl">, Flags<[NoXarchOption, CoreOption]>,
   Group, HelpText<"Disables SYCL kernels compilation for device">;
 
+//===--===//
+// FLangOption + NoXarchOption
+//===--===//
+
+def flang_experimental_exec : Flag<["-"], "flang-experimental-exec">,
+  Flags<[FlangOption, FlangOnlyOption, NoXarchOption, HelpHidden]>,
+  HelpText<"Enable support for generating executables (experimental)">;
+
 
//===--===//
 // FLangOption + CoreOption + NoXarchOption
 
//===--===//

diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 5816b91994102..e0fcabc3e250a 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -382,6 +382,28 @@ void tools::gnutools::StaticLibTool::ConstructJob(
  Exec, CmdArgs, Inputs, Output));
 }
 
+static void addFortranRuntimeLibraryPath(const ToolChain &TC,
+ const ArgList &Args,
+ ArgStringList &CmdArgs) {
+  // Default to the /../lib directory. This works fine on the
+  // platforms that we have tested so far. We will probably have to re-fine
+  // this in the future. In particular:
+  //* on some platforms, we may need to use lib64 instead of lib
+  //* this logic should also work on other similar platforms too, so we
+  //should move it to one of Gnu's parent tool{chain} classes
+  SmallString<256> DefaultLibPath =
+  llvm::sys::path::parent_path(TC.getDriver().Dir);
+  llvm::sys::path::append(DefaultLibPath, "lib");
+  CmdArgs.push_back(Args.MakeArgString("-L" + DefaultLibPath));
+}
+
+static void addFortranLinkerFlags(ArgStringList &CmdArgs) {
+  CmdArgs.push_back("-lFortran_main");
+  CmdArgs.push_back("-lFortranRuntime");
+  CmdArgs.push_back("-lFortranDecimal");
+  CmdArgs.push_back("-lm");
+}
+
 void tools::gnutools::Linker::ConstructJob(Compilation &

[clang] b9f3b7f - [flang][driver] Add support for consuming LLVM IR/BC files

2022-05-05 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-05-05T15:11:50Z
New Revision: b9f3b7f89a4cb4cf541b7116d9389c73690f78fa

URL: 
https://github.com/llvm/llvm-project/commit/b9f3b7f89a4cb4cf541b7116d9389c73690f78fa
DIFF: 
https://github.com/llvm/llvm-project/commit/b9f3b7f89a4cb4cf541b7116d9389c73690f78fa.diff

LOG: [flang][driver] Add support for consuming LLVM IR/BC files

This change makes sure that Flang's driver recognises LLVM IR and BC as
supported file formats. To this end, `isFortran` is extended and renamed
as `isSupportedByFlang` (the latter better reflects the new
functionality).

New tests are added to verify that the target triple is correctly
overridden by the frontend driver's default value or the value specified
with `-triple`. Strictly speaking, this is not a functionality that's
new in this patch (it was added in D124664). This patch simply enables
us to write such tests and hence I'm including them here.

Differential Revision: https://reviews.llvm.org/D124667

Added: 
flang/test/Driver/emit-asm-from-llvm-bc.ll
flang/test/Driver/emit-asm-from-llvm.ll
flang/test/Driver/missing-triple.ll
flang/test/Driver/override-triple.ll

Modified: 
clang/include/clang/Driver/Types.h
clang/lib/Driver/Driver.cpp
clang/lib/Driver/Types.cpp
flang/lib/Frontend/CMakeLists.txt
flang/lib/Frontend/FrontendActions.cpp
flang/lib/Frontend/FrontendOptions.cpp
flang/test/lit.cfg.py

Removed: 




diff  --git a/clang/include/clang/Driver/Types.h 
b/clang/include/clang/Driver/Types.h
index 4aecf7ee1e5286..fc5dd7bbfd6f55 100644
--- a/clang/include/clang/Driver/Types.h
+++ b/clang/include/clang/Driver/Types.h
@@ -66,6 +66,9 @@ namespace types {
   /// isAcceptedByClang - Can clang handle this input type.
   bool isAcceptedByClang(ID Id);
 
+  /// isAcceptedByFlang - Can flang handle this input type.
+  bool isAcceptedByFlang(ID Id);
+
   /// isDerivedFromC - Is the input derived from C.
   ///
   /// That is, does the lexer follow the rules of
@@ -92,9 +95,6 @@ namespace types {
   /// isOpenCL - Is this an "OpenCL" input.
   bool isOpenCL(ID Id);
 
-  /// isFortran - Is this a Fortran input.
-  bool isFortran(ID Id);
-
   /// isSrcFile - Is this a source file, i.e. something that still has to be
   /// preprocessed. The logic behind this is the same that decides if the first
   /// compilation phase is a preprocessing one.

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 8f71634a7fc03c..5bba896d8c3784 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6050,11 +6050,12 @@ bool Driver::ShouldUseClangCompiler(const JobAction 
&JA) const {
 bool Driver::ShouldUseFlangCompiler(const JobAction &JA) const {
   // Say "no" if there is not exactly one input of a type flang understands.
   if (JA.size() != 1 ||
-  !types::isFortran((*JA.input_begin())->getType()))
+  !types::isAcceptedByFlang((*JA.input_begin())->getType()))
 return false;
 
   // And say "no" if this is not a kind of action flang understands.
-  if (!isa(JA) && !isa(JA) && 
!isa(JA))
+  if (!isa(JA) && !isa(JA) &&
+  !isa(JA))
 return false;
 
   return true;

diff  --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp
index 1115e8c7710cf2..66da6fe97059a0 100644
--- a/clang/lib/Driver/Types.cpp
+++ b/clang/lib/Driver/Types.cpp
@@ -159,6 +159,20 @@ bool types::isAcceptedByClang(ID Id) {
   }
 }
 
+bool types::isAcceptedByFlang(ID Id) {
+  switch (Id) {
+  default:
+return false;
+
+  case TY_Fortran:
+  case TY_PP_Fortran:
+return true;
+  case TY_LLVM_IR:
+  case TY_LLVM_BC:
+return true;
+  }
+}
+
 bool types::isDerivedFromC(ID Id) {
   switch (Id) {
   default:
@@ -272,16 +286,6 @@ bool types::isHIP(ID Id) {
   }
 }
 
-bool types::isFortran(ID Id) {
-  switch (Id) {
-  default:
-return false;
-
-  case TY_Fortran: case TY_PP_Fortran:
-return true;
-  }
-}
-
 bool types::isSrcFile(ID Id) {
   return Id != TY_Object && getPreprocessedType(Id) != TY_INVALID;
 }

diff  --git a/flang/lib/Frontend/CMakeLists.txt 
b/flang/lib/Frontend/CMakeLists.txt
index 8e186616fb8180..476dff0a76cfac 100644
--- a/flang/lib/Frontend/CMakeLists.txt
+++ b/flang/lib/Frontend/CMakeLists.txt
@@ -40,6 +40,7 @@ add_flang_library(flangFrontend
   LINK_COMPONENTS
   Passes
   Analysis
+  IRReader
   Option
   Support
   Target

diff  --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index 3965c490227164..2ff121d2a241cb 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -73,6 +73,19 @@ bool PrescanAndSemaDebugAction::BeginSourceFileAction() {
 }
 
 bool CodeGenAction::BeginSourceFileAction() {
+  llvmCtx = std::make_unique();
+
+  // If the input is an LLVM file, just parse it and return.
+  if (this->currentInput().kind().GetLanguage() == Language::LLVM_IR) {
+llvm::SMDiagnostic er

[clang] a65afce - [flang][driver] Add support for -save-temps

2022-05-06 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-05-06T08:41:29Z
New Revision: a65afce731c2fa91effcfa5d4917d6ad90a28bf0

URL: 
https://github.com/llvm/llvm-project/commit/a65afce731c2fa91effcfa5d4917d6ad90a28bf0
DIFF: 
https://github.com/llvm/llvm-project/commit/a65afce731c2fa91effcfa5d4917d6ad90a28bf0.diff

LOG: [flang][driver] Add support for -save-temps

This patch adds support for `-save-temps` in `flang-new`, Flang's
compiler driver. The semantics of this option are inherited from Clang.

The file extension for temporary Fortran preprocessed files is set to
`i`. This is identical to what Clang uses for C (or C++) preprocessed
files. I have tried researching what other compilers do here, but I
couldn't find any definitive answers. One GFortran thread [1] suggests
that indeed it is not clear what the right approach should be.

Normally, various phases in Clang/Flang are combined. The `-save-temps`
option works by forcing the compiler to run every phase separately. As
there is no integrated assembler driver in Flang, user will have to use
`-save-temps` together with `-fno-integrated-as`. Otherwise, an
invocation to the integrated assembler would be generated generated,
which is going to fail (i.e. something equivalent to `clang -cc1as` from
Clang).

There are no specific plans for implementing an integrated assembler for
Flang for now. One possible solution would be to share it entirely with
Clang.

Note that on Windows you will get the following error when using
`-fno-integrated-as`:
```bash
  flang-new: error: there is no external assembler that can be used on this 
platform
```
Unfortunately, I don't have access to a Windows machine to investigate
this. Instead, I marked the tests in this patch as unsupported on
Windows.

[1] https://gcc.gnu.org/bugzilla//show_bug.cgi?id=81615

Differential Revision: https://reviews.llvm.org/D124669

Added: 
flang/test/Driver/fno-integrated-as.f90
flang/test/Driver/save-temps.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/include/clang/Driver/Types.def
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f4c34bcf5dea5..d9a4cb23a0934 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3995,9 +3995,9 @@ defm openmp_implicit_rpath: 
BoolFOption<"openmp-implicit-rpath",
   NegFlag>;
 def r : Flag<["-"], "r">, Flags<[LinkerInput,NoArgumentUnused]>,
 Group;
-def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[CC1Option, 
NoXarchOption]>,
+def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[CC1Option, 
FlangOption, NoXarchOption]>,
   HelpText<"Save intermediate compilation results.">;
-def save_temps : Flag<["-", "--"], "save-temps">, Flags<[NoXarchOption]>,
+def save_temps : Flag<["-", "--"], "save-temps">, Flags<[FlangOption, 
NoXarchOption]>,
   Alias, AliasArgs<["cwd"]>,
   HelpText<"Save intermediate compilation results">;
 def save_stats_EQ : Joined<["-", "--"], "save-stats=">, Flags<[NoXarchOption]>,
@@ -4125,7 +4125,7 @@ def y : Joined<["-"], "y">;
 
 defm integrated_as : BoolFOption<"integrated-as",
   CodeGenOpts<"DisableIntegratedAS">, DefaultFalse,
-  NegFlag, PosFlag,
+  NegFlag, PosFlag,
   BothFlags<[], " the integrated assembler">>;
 
 def fintegrated_cc1 : Flag<["-"], "fintegrated-cc1">,
@@ -4137,7 +4137,7 @@ def fno_integrated_cc1 : Flag<["-"], 
"fno-integrated-cc1">,
 
 def : Flag<["-"], "integrated-as">, Alias, 
Flags<[NoXarchOption]>;
 def : Flag<["-"], "no-integrated-as">, Alias,
-  Flags<[CC1Option, NoXarchOption]>;
+  Flags<[CC1Option, FlangOption, NoXarchOption]>;
 
 def working_directory : JoinedOrSeparate<["-"], "working-directory">, 
Flags<[CC1Option]>,
   HelpText<"Resolve file paths relative to the specified directory">,

diff  --git a/clang/include/clang/Driver/Types.def 
b/clang/include/clang/Driver/Types.def
index 0cf265e05fedc..d00d520d7514c 100644
--- a/clang/include/clang/Driver/Types.def
+++ b/clang/include/clang/Driver/Types.def
@@ -77,7 +77,7 @@ TYPE("c++-module-cpp-output",PP_CXXModule, INVALID,   
  "iim",phases
 TYPE("ada",  Ada,  INVALID, nullptr,  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("assembler",PP_Asm,   INVALID, "s",  
phases::Assemble, phases::Link)
 TYPE("assembler-with-cpp",   Asm,  PP_Asm,  "S",  
phases::Preprocess, phases::Assemble, phases::Link)
-TYPE("f95",  PP_Fortran,   INVALID, nullptr,  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("f95",  PP_Fortran,   INVALID, "i",  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("f95-cpp-input",Fo

[clang] ce82407 - Revert "[Flang] Generate documentation for compiler flags"

2022-07-21 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-07-21T11:54:49Z
New Revision: ce824078de2fbd46e8514e7f6e8b8dde6f201259

URL: 
https://github.com/llvm/llvm-project/commit/ce824078de2fbd46e8514e7f6e8b8dde6f201259
DIFF: 
https://github.com/llvm/llvm-project/commit/ce824078de2fbd46e8514e7f6e8b8dde6f201259.diff

LOG: Revert "[Flang] Generate documentation for compiler flags"

This reverts commit 396e944d82f3e212746cd241e4caba445523aff6.

Failing bot: https://lab.llvm.org/buildbot/#/builders/89/builds/30096

Added: 


Modified: 
clang/utils/TableGen/ClangOptionDocEmitter.cpp
flang/docs/CMakeLists.txt
flang/docs/index.md

Removed: 
flang/include/flang/FlangOptionsDocs.td



diff  --git a/clang/utils/TableGen/ClangOptionDocEmitter.cpp 
b/clang/utils/TableGen/ClangOptionDocEmitter.cpp
index 75f5d057c33a5..6c24ad2bdcc53 100644
--- a/clang/utils/TableGen/ClangOptionDocEmitter.cpp
+++ b/clang/utils/TableGen/ClangOptionDocEmitter.cpp
@@ -168,29 +168,6 @@ bool hasFlag(const Record *OptionOrGroup, StringRef 
OptionFlag) {
   return false;
 }
 
-bool isIncluded(const Record *OptionOrGroup, const Record *DocInfo) {
-  assert(DocInfo->getValue("IncludedFlags") && "Missing includeFlags");
-  for (StringRef Inclusion : DocInfo->getValueAsListOfStrings("IncludedFlags"))
-if (hasFlag(OptionOrGroup, Inclusion))
-  return true;
-  return false;
-}
-
-bool isGroupIncluded(const DocumentedGroup &Group, const Record *DocInfo) {
-  if (isIncluded(Group.Group, DocInfo))
-return true;
-  for (auto &O : Group.Options)
-if (isIncluded(O.Option, DocInfo))
-  return true;
-  for (auto &G : Group.Groups) {
-if (isIncluded(G.Group, DocInfo))
-  return true;
-if (isGroupIncluded(G, DocInfo))
-  return true;
-  }
-  return false;
-}
-
 bool isExcluded(const Record *OptionOrGroup, const Record *DocInfo) {
   // FIXME: Provide a flag to specify the set of exclusions.
   for (StringRef Exclusion : DocInfo->getValueAsListOfStrings("ExcludedFlags"))
@@ -327,8 +304,6 @@ void emitOption(const DocumentedOption &Option, const 
Record *DocInfo,
 raw_ostream &OS) {
   if (isExcluded(Option.Option, DocInfo))
 return;
-  if (DocInfo->getValue("IncludedFlags") && !isIncluded(Option.Option, 
DocInfo))
-return;
   if (Option.Option->getValueAsDef("Kind")->getName() == "KIND_UNKNOWN" ||
   Option.Option->getValueAsDef("Kind")->getName() == "KIND_INPUT")
 return;
@@ -404,9 +379,6 @@ void emitGroup(int Depth, const DocumentedGroup &Group, 
const Record *DocInfo,
   if (isExcluded(Group.Group, DocInfo))
 return;
 
-  if (DocInfo->getValue("IncludedFlags") && !isGroupIncluded(Group, DocInfo))
-return;
-
   emitHeading(Depth,
   getRSTStringWithTextFallback(Group.Group, "DocName", "Name"), 
OS);
 

diff  --git a/flang/docs/CMakeLists.txt b/flang/docs/CMakeLists.txt
index 077c01d3310ff..044697a104507 100644
--- a/flang/docs/CMakeLists.txt
+++ b/flang/docs/CMakeLists.txt
@@ -91,16 +91,6 @@ if (LLVM_ENABLE_DOXYGEN)
 endif()
 endif()
 
-function (gen_rst_file_from_td output_file td_option source docs_target)
-  if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${source}")
-message(FATAL_ERROR "Cannot find source file: ${source} in 
${CMAKE_CURRENT_SOURCE_DIR}")
-  endif()
-  get_filename_component(TABLEGEN_INCLUDE_DIR 
"${CMAKE_CURRENT_SOURCE_DIR}/${source}" DIRECTORY)
-  list(APPEND LLVM_TABLEGEN_FLAGS "-I${TABLEGEN_INCLUDE_DIR}")
-  clang_tablegen(Source/${output_file} ${td_option} SOURCE ${source} TARGET 
"gen-${output_file}")
-  add_dependencies(${docs_target} "gen-${output_file}")
-endfunction()
-
 if (LLVM_ENABLE_SPHINX)
   include(AddSphinxTarget)
   if (SPHINX_FOUND)
@@ -124,7 +114,6 @@ if (LLVM_ENABLE_SPHINX)
   COMMAND "${Python3_EXECUTABLE}"
   ARGS ${CMAKE_CURRENT_BINARY_DIR}/Source/FIR/CreateFIRLangRef.py)
 
-  gen_rst_file_from_td(FlangCommandLineReference.rst -gen-opt-docs 
../include/flang/FlangOptionsDocs.td docs-flang-html)
 endif()
 if (${SPHINX_OUTPUT_MAN})
   add_sphinx_target(man flang)

diff  --git a/flang/docs/index.md b/flang/docs/index.md
index d6b05115f8611..3c3e2de2a8078 100644
--- a/flang/docs/index.md
+++ b/flang/docs/index.md
@@ -45,7 +45,6 @@ on how to get in touch with us and to learn more about the 
current status.
DoConcurrent
Extensions
FIRLangRef
-   FlangCommandLineReference
FlangDriver
FortranIR
FortranLLVMTestSuite

diff  --git a/flang/include/flang/FlangOptionsDocs.td 
b/flang/include/flang/FlangOptionsDocs.td
deleted file mode 100644
index 32054428ad3f8..0
--- a/flang/include/flang/FlangOptionsDocs.td
+++ /dev/null
@@ -1,35 +0,0 @@
-//==--- FlangOptionDocs.td - Option documentation 
-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: 

[clang] f820625 - [flang][driver] Make driver accept `-module-dir`

2022-05-19 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-05-19T11:13:35Z
New Revision: f820625503744472be8312bb70ee0da197816067

URL: 
https://github.com/llvm/llvm-project/commit/f820625503744472be8312bb70ee0da197816067
DIFF: 
https://github.com/llvm/llvm-project/commit/f820625503744472be8312bb70ee0da197816067.diff

LOG: [flang][driver] Make driver accept `-module-dir`

`-module-dir` is Flang's equivalent for `-J` from GFortran (in fact,
`-J` is an alias for `-module-dir` in Flang). Currently, only
`-module-dir ` is accepted. However, `-J` (and other options for
specifying various paths) accepts `-J` as well as `-J `.
This patch makes sure that `-module-dir` behaves consistently with other
such flags.

Differential Revision: https://reviews.llvm.org/D125957

Added: 


Modified: 
clang/include/clang/Driver/Options.td
flang/test/Driver/write-module.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e18b71ba064df..e100711516089 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4776,7 +4776,7 @@ def cpp : Flag<["-"], "cpp">, Group,
   HelpText<"Enable predefined and command line preprocessor macros">;
 def nocpp : Flag<["-"], "nocpp">, Group,
   HelpText<"Disable predefined and command line preprocessor macros">;
-def module_dir : Separate<["-"], "module-dir">, MetaVarName<"">,
+def module_dir : JoinedOrSeparate<["-"], "module-dir">, MetaVarName<"">,
   HelpText<"Put MODULE files in ">,
   DocBrief<[{This option specifies where to put .mod files for compiled 
modules.
 It is also added to the list of directories to be searched by an USE statement.

diff  --git a/flang/test/Driver/write-module.f90 
b/flang/test/Driver/write-module.f90
index baa480e055b98..0be5c5817ba90 100644
--- a/flang/test/Driver/write-module.f90
+++ b/flang/test/Driver/write-module.f90
@@ -4,21 +4,28 @@
 ! We use `-fsyntax-only` as it stops after the semantic checks (the module 
file is generated when sema checks are run)
 
 !--
-! -module-dir
+! -module-dir 
 !--
 ! RUN: rm -rf %t && mkdir -p %t/dir-flang
 ! RUN: cd %t && %flang -fsyntax-only -module-dir %t/dir-flang %s
 ! RUN: ls %t/dir-flang/testmodule.mod && not ls %t/testmodule.mod
 
+!--
+! -module-dir
+!--
+! RUN: rm -rf %t && mkdir -p %t/dir-flang
+! RUN: cd %t && %flang -fsyntax-only -module-dir%t/dir-flang %s
+! RUN: ls %t/dir-flang/testmodule.mod && not ls %t/testmodule.mod
+
 !---
-! -J  (i.e. with space)
+! -J 
 !---
 ! RUN: rm -rf %t && mkdir -p %t/dir-flang
 ! RUN: cd %t && %flang -fsyntax-only -J %t/dir-flang %s
 ! RUN: ls %t/dir-flang/testmodule.mod && not ls %t/testmodule.mod
 
 !--
-! -J (i.e. without space)
+! -J
 !--
 ! RUN: rm -rf %t && mkdir -p %t/dir-flang
 ! RUN: cd %t && %flang -fsyntax-only -J%t/dir-flang %s



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e601b2a - [flang][driver] Add support for generating executables on MacOSX/Darwin

2022-05-19 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-05-19T15:47:59+01:00
New Revision: e601b2a1542710789395ab1121b1ccc7076e39d1

URL: 
https://github.com/llvm/llvm-project/commit/e601b2a1542710789395ab1121b1ccc7076e39d1
DIFF: 
https://github.com/llvm/llvm-project/commit/e601b2a1542710789395ab1121b1ccc7076e39d1.diff

LOG: [flang][driver] Add support for generating executables on MacOSX/Darwin

This patch basically extends https://reviews.llvm.org/D122008 with
support for MacOSX/Darwin.

To facilitate this, I've added `MacOSX` to the list of supported OSes in
Target.cpp. Flang already supports `Darwin` and it doesn't really do
anything OS-specific there (it could probably safely skip checking the
OS for now).

Note that generating executables remains hidden behind the
`-flang-experimental-exec` flag. Also, we don't need to add `-lm` on
MacOSX as `libm` is effectively included in `libSystem` (which is linked
in unconditionally).

Differential Revision: https://reviews.llvm.org/D125628

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/CommonArgs.h
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
flang/lib/Optimizer/CodeGen/Target.cpp
flang/test/Driver/linker-flags.f90

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 2f342c59bda4e..33f3df80a2a2e 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -748,6 +748,25 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, const 
ToolChain &TC,
   return true;
 }
 
+void tools::addFortranRuntimeLibs(llvm::opt::ArgStringList &CmdArgs) {
+  CmdArgs.push_back("-lFortran_main");
+  CmdArgs.push_back("-lFortranRuntime");
+  CmdArgs.push_back("-lFortranDecimal");
+}
+
+void tools::addFortranRuntimeLibraryPath(const ToolChain &TC,
+ const llvm::opt::ArgList &Args,
+ ArgStringList &CmdArgs) {
+  // Default to the /../lib directory. This works fine on the
+  // platforms that we have tested so far. We will probably have to re-fine
+  // this in the future. In particular, on some platforms, we may need to use
+  // lib64 instead of lib.
+  SmallString<256> DefaultLibPath =
+  llvm::sys::path::parent_path(TC.getDriver().Dir);
+  llvm::sys::path::append(DefaultLibPath, "lib");
+  CmdArgs.push_back(Args.MakeArgString("-L" + DefaultLibPath));
+}
+
 static void addSanitizerRuntime(const ToolChain &TC, const ArgList &Args,
 ArgStringList &CmdArgs, StringRef Sanitizer,
 bool IsShared, bool IsWhole) {

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.h 
b/clang/lib/Driver/ToolChains/CommonArgs.h
index 1c43cd329b85c..b0238612234c5 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -120,6 +120,14 @@ bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, 
const ToolChain &TC,
   bool ForceStaticHostRuntime = false,
   bool IsOffloadingHost = false, bool GompNeedsRT = false);
 
+/// Adds Fortran runtime libraries to \p CmdArgs.
+void addFortranRuntimeLibs(llvm::opt::ArgStringList &CmdArgs);
+
+/// Adds the path for the Fortran runtime libraries to \p CmdArgs.
+void addFortranRuntimeLibraryPath(const ToolChain &TC,
+  const llvm::opt::ArgList &Args,
+  llvm::opt::ArgStringList &CmdArgs);
+
 void addHIPRuntimeLibArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
   llvm::opt::ArgStringList &CmdArgs);
 

diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 60346ee44e3a9..b0d72c74dcb74 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -635,6 +635,18 @@ void darwin::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 InputFileList.push_back(II.getFilename());
   }
 
+  // Additional linker set-up and flags for Fortran. This is required in order
+  // to generate executables.
+  //
+  // NOTE: Generating executables by Flang is considered an "experimental"
+  // feature and hence this is guarded with a command line option.
+  // TODO: Make this work unconditionally once Flang is mature enough.
+  if (getToolChain().getDriver().IsFlangMode() &&
+  Args.hasArg(options::OPT_flang_experimental_exec)) {
+addFortranRuntimeLibraryPath(getToolChain(), Args, CmdArgs);
+addFortranRuntimeLibs(CmdArgs);
+  }
+
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
 addOpenMPRuntime(CmdArgs, getToolChain(), Args);
 

diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index b73634bad631a..38280a2e36526 1

[clang] 4eae6fc - [clang] Fix incorrect call to TextDiagnostic::printDiagnosticMessage

2020-09-21 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2020-09-21T09:41:39+01:00
New Revision: 4eae6fc95f95563a73a510a8b09cfce01004930a

URL: 
https://github.com/llvm/llvm-project/commit/4eae6fc95f95563a73a510a8b09cfce01004930a
DIFF: 
https://github.com/llvm/llvm-project/commit/4eae6fc95f95563a73a510a8b09cfce01004930a.diff

LOG: [clang] Fix incorrect call to TextDiagnostic::printDiagnosticMessage

As per the documentation, the 2nd argument in printDiagnosticMessage
should be a bool that specifies whether the underlying message is a
continuation note diagnostic or not. More specifically, it should be:
```
Level == DiagnosticsEngine::Note
```
instead of:
```
Level
```

This change means that `no input file` in the following scenario will be
now correctly printed in bold:
```
$ bin/clang
clang: error: no input files
```
In terminals that don't support text formatting the behaviour doesn't
change.

Differential Revision: https://reviews.llvm.org/D87816

Added: 


Modified: 
clang/lib/Frontend/TextDiagnosticPrinter.cpp

Removed: 




diff  --git a/clang/lib/Frontend/TextDiagnosticPrinter.cpp 
b/clang/lib/Frontend/TextDiagnosticPrinter.cpp
index 0c0a44a1388b..9feb3c64039f 100644
--- a/clang/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/clang/lib/Frontend/TextDiagnosticPrinter.cpp
@@ -135,10 +135,10 @@ void 
TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
   if (!Info.getLocation().isValid()) {
 TextDiagnostic::printDiagnosticLevel(OS, Level, DiagOpts->ShowColors,
  DiagOpts->CLFallbackMode);
-TextDiagnostic::printDiagnosticMessage(OS, Level, DiagMessageStream.str(),
-   OS.tell() - StartOfLocationInfo,
-   DiagOpts->MessageLength,
-   DiagOpts->ShowColors);
+TextDiagnostic::printDiagnosticMessage(
+OS, /*IsSupplemental=*/Level == DiagnosticsEngine::Note,
+DiagMessageStream.str(), OS.tell() - StartOfLocationInfo,
+DiagOpts->MessageLength, DiagOpts->ShowColors);
 OS.flush();
 return;
   }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 764690b - [clang] Remove `-triple` from the invocations of `flang-new -fc1`

2020-12-10 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2020-12-10T17:54:12Z
New Revision: 764690b8a883c9466324f9c33ab1047a0661e8ef

URL: 
https://github.com/llvm/llvm-project/commit/764690b8a883c9466324f9c33ab1047a0661e8ef
DIFF: 
https://github.com/llvm/llvm-project/commit/764690b8a883c9466324f9c33ab1047a0661e8ef.diff

LOG: [clang] Remove `-triple` from the invocations of `flang-new -fc1`

This is just a small change in the Flang tool within libclangDriver.
Currently it passes `-triple` when calling `flang-new -fc1` for various
driver Jobs. As there is no support for code-generation, `-triple` is
not required and should remain unsupported. It is safe to remove it.

This hasn't been a problem as the affected driver Jobs are not yet
implemented or used. However, we will be adding support for them in the
near future and the fact `-triple` is added will become a problem.

Differential Revision: https://reviews.llvm.org/D93027

Added: 


Modified: 
clang/lib/Driver/ToolChains/Flang.cpp
clang/test/Driver/flang/flang.f90
clang/test/Driver/flang/flang_ucase.F90

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 6d79fbe6aa8f..d7dee9594e45 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -40,8 +40,6 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
 else
   CmdArgs.push_back("-E");
   } else if (isa(JA) || isa(JA)) {
-CmdArgs.push_back("-triple");
-CmdArgs.push_back(Args.MakeArgString(TripleStr));
 if (JA.getType() == types::TY_Nothing) {
   CmdArgs.push_back("-fsyntax-only");
 } else if (JA.getType() == types::TY_AST) {

diff  --git a/clang/test/Driver/flang/flang.f90 
b/clang/test/Driver/flang/flang.f90
index e4629d527d18..9b16f233b231 100644
--- a/clang/test/Driver/flang/flang.f90
+++ b/clang/test/Driver/flang/flang.f90
@@ -23,7 +23,6 @@
 ! CHECK-E-DAG: "-o" "-"
 
 ! RUN: %clang --driver-mode=flang -### -emit-ast   %s 2>&1 | FileCheck 
--check-prefixes=ALL,CHECK-EMIT-AST %s
-! CHECK-EMIT-AST-DAG: "-triple"
 ! CHECK-EMIT-AST-DAG: "-emit-ast"
 ! CHECK-EMIT-AST-DAG: "-o" "{{[^"]*}}.ast"
 

diff  --git a/clang/test/Driver/flang/flang_ucase.F90 
b/clang/test/Driver/flang/flang_ucase.F90
index 4da09e138b59..113ef75f45b8 100644
--- a/clang/test/Driver/flang/flang_ucase.F90
+++ b/clang/test/Driver/flang/flang_ucase.F90
@@ -23,7 +23,6 @@
 ! CHECK-E-DAG: "-o" "-"
 
 ! RUN: %clang --driver-mode=flang -### -emit-ast   %s 2>&1 | FileCheck 
--check-prefixes=ALL,CHECK-EMIT-AST %s
-! CHECK-EMIT-AST-DAG: "-triple"
 ! CHECK-EMIT-AST-DAG: "-emit-ast"
 ! CHECK-EMIT-AST-DAG: "-o" "{{[^"]*}}.ast"
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7f19712 - [clang][nfc] Update comment to match the opening `{`

2020-12-17 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2020-12-17T09:04:41Z
New Revision: 7f19712a6a9e65bdc9a9843ea488030bc12f3acc

URL: 
https://github.com/llvm/llvm-project/commit/7f19712a6a9e65bdc9a9843ea488030bc12f3acc
DIFF: 
https://github.com/llvm/llvm-project/commit/7f19712a6a9e65bdc9a9843ea488030bc12f3acc.diff

LOG: [clang][nfc] Update comment to match the opening `{`

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index dd23d810e388..f384e0d993c2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5081,7 +5081,7 @@ def fopenmp_host_ir_file_path : Separate<["-"], 
"fopenmp-host-ir-file-path">,
 def fsycl_is_device : Flag<["-"], "fsycl-is-device">,
   HelpText<"Generate code for SYCL device.">;
 
-} // let Flags = [CC1Option]
+} // let Flags = [CC1Option, NoDriverOption]
 
 
//===--===//
 // cc1as-only Options



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7d246cb - [flang][driver] Add support for `-fsyntax-only`

2020-12-18 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2020-12-18T09:35:02Z
New Revision: 7d246cb19db9fce65946fb4bac6e570787dbe78a

URL: 
https://github.com/llvm/llvm-project/commit/7d246cb19db9fce65946fb4bac6e570787dbe78a
DIFF: 
https://github.com/llvm/llvm-project/commit/7d246cb19db9fce65946fb4bac6e570787dbe78a.diff

LOG: [flang][driver] Add support for `-fsyntax-only`

The behaviour triggered with this flag is consistent with `-fparse-only`
in `flang` (i.e. the throwaway driver). This new spelling is consistent
with Clang and gfortran, and was proposed and agreed on for the new
driver in [1].

This patch also adds some minimal logic to communicate whether the
semantic checks have failed or not. When semantic checks fail, a
frontend driver error is generated. The return code from the frontend
driver is then determined by checking the driver diagnostics - the
presence of driver errors means that the compilation has failed. This
logic is consistent with `clang -cc1`.

[1] http://lists.llvm.org/pipermail/flang-dev/2020-November/000588.html

Differential Revision: https://reviews.llvm.org/D92854

Added: 
flang/test/Flang-Driver/syntax-only.f90

Modified: 
clang/include/clang/Driver/Options.td
flang/include/flang/Frontend/CompilerInstance.h
flang/include/flang/Frontend/FrontendActions.h
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CMakeLists.txt
flang/lib/Frontend/CompilerInstance.cpp
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/unittests/Frontend/PrintPreprocessedTest.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3e4fbf1fbb8f..63a5b5484f0f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2287,7 +2287,7 @@ defm strict_vtable_pointers : 
BoolFOption<"strict-vtable-pointers",
   ResetBy>;
 def fstrict_overflow : Flag<["-"], "fstrict-overflow">, Group;
 def fsyntax_only : Flag<["-"], "fsyntax-only">,
-  Flags<[NoXarchOption,CoreOption,CC1Option]>, Group;
+  Flags<[NoXarchOption,CoreOption,CC1Option,FC1Option]>, Group;
 def ftabstop_EQ : Joined<["-"], "ftabstop=">, Group;
 def ftemplate_depth_EQ : Joined<["-"], "ftemplate-depth=">, Group;
 def ftemplate_depth_ : Joined<["-"], "ftemplate-depth-">, Group;

diff  --git a/flang/include/flang/Frontend/CompilerInstance.h 
b/flang/include/flang/Frontend/CompilerInstance.h
index 21ef9f0dcd47..b00b5cd4479a 100644
--- a/flang/include/flang/Frontend/CompilerInstance.h
+++ b/flang/include/flang/Frontend/CompilerInstance.h
@@ -12,6 +12,7 @@
 #include "flang/Frontend/FrontendAction.h"
 #include "flang/Parser/parsing.h"
 #include "flang/Parser/provenance.h"
+#include "flang/Semantics/semantics.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace Fortran::frontend {
@@ -28,6 +29,12 @@ class CompilerInstance {
 
   std::shared_ptr parsing_;
 
+  /// The stream for diagnostics from Semantics
+  llvm::raw_ostream *semaOutputStream_ = &llvm::errs();
+
+  /// The stream for diagnostics from Semantics if owned, otherwise nullptr.
+  std::unique_ptr ownedSemaOutputStream_;
+
   /// The diagnostics engine instance.
   llvm::IntrusiveRefCntPtr diagnostics_;
 
@@ -77,6 +84,11 @@ class CompilerInstance {
 
   bool HasAllSources() const { return allSources_ != nullptr; }
 
+  parser::AllCookedSources &allCookedSources() {
+assert(allCookedSources_ && "Compiler instance has no AllCookedSources!");
+return *allCookedSources_;
+  };
+
   /// }
   /// @name Parser Operations
   /// {
@@ -84,6 +96,19 @@ class CompilerInstance {
   /// Return parsing to be used by Actions.
   Fortran::parser::Parsing &parsing() const { return *parsing_; }
 
+  /// }
+  /// @name Semantic analysis
+  /// {
+
+  /// Replace the current stream for verbose output.
+  void set_semaOutputStream(llvm::raw_ostream &Value);
+
+  /// Replace the current stream for verbose output.
+  void set_semaOutputStream(std::unique_ptr Value);
+
+  /// Get the current stream for verbose output.
+  llvm::raw_ostream &semaOutputStream() { return *semaOutputStream_; }
+
   /// }
   /// @name High-Level Operations
   /// {

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index db5afe4da7eb..3eea94b60bf5 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -25,6 +25,10 @@ class PrintPreprocessedAction : public FrontendAction {
   void ExecuteAction() override;
 };
 
+class ParseSyntaxOnlyAction : public FrontendAction {
+  void ExecuteAction() override;
+};
+
 } // namespace Fortran::frontend
 
 #endif // LLVM_FLANG_FRONTEND_FRONTENDACTIONS_H

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index ac8f01d2a1

[clang] fdbc7e5 - [flang][driver] Make sure that `-###` is marked as supported (NFC)

2020-11-11 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2020-11-11T13:12:51Z
New Revision: fdbc7e505c0cb424bf629a0d6901bc6812302dcc

URL: 
https://github.com/llvm/llvm-project/commit/fdbc7e505c0cb424bf629a0d6901bc6812302dcc
DIFF: 
https://github.com/llvm/llvm-project/commit/fdbc7e505c0cb424bf629a0d6901bc6812302dcc.diff

LOG: [flang][driver] Make sure that `-###` is marked as supported (NFC)

`-###` has always been supported in the new flang driver. This patch
merely makes sure that it's included when printing the help screen (i.e.
`flang-new -help`).

Added: 


Modified: 
clang/include/clang/Driver/Options.td
flang/test/Flang-Driver/driver-help-hidden.f90
flang/test/Flang-Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 75b63d49bb24..867b47857295 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -398,7 +398,7 @@ def ccc_ : Joined<["-"], "ccc-">, Group, 
Flags<[Unsupported]>;
 
 // Standard Options
 
-def _HASH_HASH_HASH : Flag<["-"], "###">, Flags<[NoXarchOption, CoreOption]>,
+def _HASH_HASH_HASH : Flag<["-"], "###">, Flags<[NoXarchOption, CoreOption, 
FlangOption]>,
 HelpText<"Print (but do not run) the commands to run for this 
compilation">;
 def _DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>,
 Flags<[NoXarchOption, CoreOption]>;

diff  --git a/flang/test/Flang-Driver/driver-help-hidden.f90 
b/flang/test/Flang-Driver/driver-help-hidden.f90
index 3d4a237a2aa9..3143cfd3d715 100644
--- a/flang/test/Flang-Driver/driver-help-hidden.f90
+++ b/flang/test/Flang-Driver/driver-help-hidden.f90
@@ -18,6 +18,7 @@
 ! CHECK:USAGE: flang-new
 ! CHECK-EMPTY:
 ! CHECK-NEXT:OPTIONS:
+! CHECK-NEXT: -###  Print (but do not run) the commands to run for this 
compilation
 ! CHECK-NEXT: -EOnly run the preprocessor
 ! CHECK-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics

diff  --git a/flang/test/Flang-Driver/driver-help.f90 
b/flang/test/Flang-Driver/driver-help.f90
index 2fc19f3830cf..58fa8fc79aca 100644
--- a/flang/test/Flang-Driver/driver-help.f90
+++ b/flang/test/Flang-Driver/driver-help.f90
@@ -18,6 +18,7 @@
 ! HELP:USAGE: flang-new
 ! HELP-EMPTY:
 ! HELP-NEXT:OPTIONS:
+! HELP-NEXT: -###   Print (but do not run) the commands to run 
for this compilation
 ! HELP-NEXT: -E Only run the preprocessor
 ! HELP-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8d51d37 - [flang] Introduce DiagnosticConsumer classes in libflangFrontend

2020-10-05 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2020-10-05T17:46:44+01:00
New Revision: 8d51d37e0628bde3eb5a3200507ba7135dfc2751

URL: 
https://github.com/llvm/llvm-project/commit/8d51d37e0628bde3eb5a3200507ba7135dfc2751
DIFF: 
https://github.com/llvm/llvm-project/commit/8d51d37e0628bde3eb5a3200507ba7135dfc2751.diff

LOG: [flang] Introduce DiagnosticConsumer classes in libflangFrontend

Currently Flang uses TextDiagnostic, TextDiagnosticPrinter &
TestDiagnosticBuffer classes from Clang (more specifically, from
libclangFrontend). This patch introduces simplified equivalents of these
classes in Flang (i.e. it removes the dependency on libclangFrontend).

Flang only needs these diagnostics classes for the compiler driver
diagnostics. This is unlike in Clang in which similar diagnostic classes
are used for e.g. Lexing/Parsing/Sema diagnostics. For this reason, the
implementations introduced here are relatively basic. We can extend them
in the future if this is required.

This patch also enhances how the diagnostics are printed. In particular,
this is the diagnostic that you'd get _before_  the changes introduced here
(no text formatting):

```
$ bin/flang-new
error: no input files
```

This is the diagnostic that you get _after_ the changes introduced here
(in terminals that support it, the text is formatted - bold + red):

```
$ bin/flang-new
flang-new: error: no input files
```

Tests are updated accordingly and options related to enabling/disabling
color diagnostics are flagged as supported by Flang.

Reviewed By: sameeranjoshi, CarolineConcatto

Differential Revision: https://reviews.llvm.org/D87774

Added: 
flang/include/flang/Frontend/TextDiagnostic.h
flang/include/flang/Frontend/TextDiagnosticBuffer.h
flang/include/flang/Frontend/TextDiagnosticPrinter.h
flang/lib/Frontend/TextDiagnostic.cpp
flang/lib/Frontend/TextDiagnosticBuffer.cpp
flang/lib/Frontend/TextDiagnosticPrinter.cpp

Modified: 
clang/include/clang/Driver/Options.td
flang/include/flang/Frontend/CompilerInvocation.h
flang/lib/Frontend/CMakeLists.txt
flang/lib/Frontend/CompilerInstance.cpp
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Flang-Driver/driver-error-cc1.c
flang/test/Flang-Driver/driver-error-cc1.cpp
flang/test/Flang-Driver/driver-help.f90
flang/test/Flang-Driver/driver-version.f90
flang/test/Flang-Driver/missing-input.f90
flang/tools/flang-driver/driver.cpp
flang/tools/flang-driver/fc1_main.cpp
flang/unittests/Frontend/CompilerInstanceTest.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 18a123476253..e65a68c0deaa 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -876,7 +876,8 @@ def fclang_abi_compat_EQ : Joined<["-"], 
"fclang-abi-compat=">, Group, MetaVarName<"">, 
Values<".,latest">,
   HelpText<"Attempt to match the ABI of Clang ">;
 def fclasspath_EQ : Joined<["-"], "fclasspath=">, Group;
-defm color_diagnostics : OptInFFlag<"color-diagnostics", "Enable", "Disable", 
" colors in diagnostics", [CoreOption]>;
+defm color_diagnostics : OptInFFlag<"color-diagnostics", "Enable", "Disable", 
" colors in diagnostics",
+  [CoreOption, FlangOption]>;
 def fdiagnostics_color : Flag<["-"], "fdiagnostics-color">, Group,
   Flags<[CoreOption, DriverOption]>;
 def fdiagnostics_color_EQ : Joined<["-"], "fdiagnostics-color=">, 
Group;

diff  --git a/flang/include/flang/Frontend/CompilerInvocation.h 
b/flang/include/flang/Frontend/CompilerInvocation.h
index 0fa169fd1620..05f93293d0a5 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -11,8 +11,17 @@
 #include "flang/Frontend/FrontendOptions.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticOptions.h"
+#include "llvm/Option/ArgList.h"
 
 namespace Fortran::frontend {
+
+/// Fill out Opts based on the options given in Args.
+///
+/// When errors are encountered, return false and, if Diags is non-null,
+/// report the error(s).
+bool ParseDiagnosticArgs(clang::DiagnosticOptions &opts,
+llvm::opt::ArgList &args, bool defaultDiagColor = true);
+
 class CompilerInvocationBase {
 public:
   /// Options controlling the diagnostic engine.$

diff  --git a/flang/include/flang/Frontend/TextDiagnostic.h 
b/flang/include/flang/Frontend/TextDiagnostic.h
new file mode 100644
index ..f803058c88c5
--- /dev/null
+++ b/flang/include/flang/Frontend/TextDiagnostic.h
@@ -0,0 +1,70 @@
+//===--- TextDiagnostic.h - Text Diagnostic Pretty-Printing -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--

Re: [cfe-dev] Upcoming upgrade of LLVM buildbot

2020-10-08 Thread Andrzej Warzynski via cfe-commits
Our Flang-aarch64 buildbots just won't connect to the main Buildbot 
master anymore. I switched them to the staging buildbot master instead 
and it seems fine for now. Is there anything that we can/should tweak at 
our end?


http://lab.llvm.org:8014/#/waterfall?tags=flang

-Andrzej

On 08/10/2020 00:31, Galina Kistanova via cfe-dev wrote:

They are online now - http://lab.llvm.org:8011/#/waterfall?tags=sanitizer

AnnotatedCommand has severe design conflict with the new buildbot.
We have changed it to be safe and still do something useful, but it will 
need more love and care.


Please let me know if you have some spare time to work on porting 
AnnotatedCommand.


Thanks

Galina

On Wed, Oct 7, 2020 at 2:57 PM Vitaly Buka > wrote:


It looks like all sanitizer builder are still offline
http://lab.llvm.org:8011/#/builders

On Tue, 6 Oct 2020 at 00:34, Galina Kistanova via cfe-commits
mailto:cfe-commits@lists.llvm.org>> wrote:

Hello everyone,

The staging buildbot was up and running for 6 days now, and
looks good.

Tomorrow at 12:00 PM PDT we will switch the production buildbot
to the new version.

If you are a bot owner, you do not need to do anything at this
point, unless I'll ask you to help.
The buildbot will go down for a short period of time, and then a
new version will come up and will accept connections from your bots.

Please note that the new version has a bit different URL
structure. You will need to update the bookmarks or scripts if
you have stored direct URLs to inside the buldbot.

We will be watching the production and staging bots and will be
improving zorg for the next week or so.

I will need your feedback about blame e-mails delivery, IRC
reporting issues, and anything you could spot wrong with the new
bot. I  hope the transition will go smoothly and we will handle
issues quickly if any would come up.

After production is good and we have about a week of running
history, I'll ask the bot owners to upgrade buildbots on their
side. Please do not upgrade your buildbots unless I'll ask you
to. We are trying to limit a number of moving parts at this
stage. We will start accepting change to zorg at this point.
Please feel free to talk to me if you will have a special
situation and if you would absolutely have to make changes.

Thanks for your support and help. And please feel free to ask if
you have questions.

Galina


On Thu, Sep 10, 2020 at 9:35 PM Galina Kistanova
mailto:gkistan...@gmail.com>> wrote:

Hello everyone,

The buildbot upgrade is entering the phase when the results
to become visible.

No change is required at this time on any of the builders.
The bot owners could upgrade the buildbot on build computers
later, at their convenience, as this is not on the critical
path.

We are going to upgrade the staging bot first. Then, once
that is stable and all detected issues are resolved, we will
upgrade the production bot.

I will need some help with testing, and will be asking to
move some of the builders temporarily to the staging. LLVM
buildbot is a piece of critical infrastructure, so more eyes
and hands in making sure it works properly the better.

I'll be posting updates and ETA of particular changes in
this thread.

Please feel free to ask if you have any questions or concerns.

Thanks

Galina

___
cfe-commits mailing list
cfe-commits@lists.llvm.org 
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


___
cfe-dev mailing list
cfe-...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [llvm-dev] [cfe-dev] Upcoming upgrade of LLVM buildbot

2020-10-09 Thread Andrzej Warzynski via cfe-commits
I switched one of our workers to the main Buildbot and everything seems 
fine #fingers-crossed. I guess that that was a temporary glitch?


We haven't updated our local Buildbot installations - still on 0.8.5. 
Should we update?


-Andrzej

On 09/10/2020 00:44, Galina Kistanova wrote:

Hi Paula,

This error is fine. The buildbot has tested the worker version. 0.8.x 
apparently does not have that method.
The error gets handled gracefully on the server side. At least it seems 
so so far.


That should not prevent your bot from connecting.

Thanks

Galina

On Thu, Oct 8, 2020 at 2:11 PM Paula Askar > wrote:


Hey Andrzej,

What are you seeing in your buildbot logs? Is it this error?
`twisted.spread.flavors.NoSuchMethod: No such method:
remote_getWorkerInfo`

If so, you might want to try updating your buildbot worker.
I updated llvmlibc's to 2.8.4 and that seemed to solve the connection
problem:

https://github.com/llvm/llvm-project/commit/f60686f35cc89504f3411f49cf16a651a74be6eb

Best,
Paula Askar


On Thu, Oct 8, 2020 at 5:43 AM Andrzej Warzynski via llvm-dev
mailto:llvm-...@lists.llvm.org>> wrote:
 >
 > Our Flang-aarch64 buildbots just won't connect to the main Buildbot
 > master anymore. I switched them to the staging buildbot master
instead
 > and it seems fine for now. Is there anything that we can/should
tweak at
 > our end?
 >
 > http://lab.llvm.org:8014/#/waterfall?tags=flang
 >
 > -Andrzej
 >
 > On 08/10/2020 00:31, Galina Kistanova via cfe-dev wrote:
 > > They are online now -
http://lab.llvm.org:8011/#/waterfall?tags=sanitizer
 > >
 > > AnnotatedCommand has severe design conflict with the new buildbot.
 > > We have changed it to be safe and still do something useful,
but it will
 > > need more love and care.
 > >
 > > Please let me know if you have some spare time to work on porting
 > > AnnotatedCommand.
 > >
 > > Thanks
 > >
 > > Galina
 > >
 > > On Wed, Oct 7, 2020 at 2:57 PM Vitaly Buka
mailto:vitalyb...@google.com>
 > > >>
wrote:
 > >
 > >     It looks like all sanitizer builder are still offline
 > > http://lab.llvm.org:8011/#/builders
 > >
 > >     On Tue, 6 Oct 2020 at 00:34, Galina Kistanova via cfe-commits
 > >     mailto:cfe-commits@lists.llvm.org>
>> wrote:
 > >
 > >         Hello everyone,
 > >
 > >         The staging buildbot was up and running for 6 days now, and
 > >         looks good.
 > >
 > >         Tomorrow at 12:00 PM PDT we will switch the production
buildbot
 > >         to the new version.
 > >
 > >         If you are a bot owner, you do not need to do anything
at this
 > >         point, unless I'll ask you to help.
 > >         The buildbot will go down for a short period of time,
and then a
 > >         new version will come up and will accept connections
from your bots.
 > >
 > >         Please note that the new version has a bit different URL
 > >         structure. You will need to update the bookmarks or
scripts if
 > >         you have stored direct URLs to inside the buldbot.
 > >
 > >         We will be watching the production and staging bots and
will be
 > >         improving zorg for the next week or so.
 > >
 > >         I will need your feedback about blame e-mails delivery, IRC
 > >         reporting issues, and anything you could spot wrong
with the new
 > >         bot. I  hope the transition will go smoothly and we
will handle
 > >         issues quickly if any would come up.
 > >
 > >         After production is good and we have about a week of
running
 > >         history, I'll ask the bot owners to upgrade buildbots
on their
 > >         side. Please do not upgrade your buildbots unless I'll
ask you
 > >         to. We are trying to limit a number of moving parts at this
 > >         stage. We will start accepting change to zorg at this
point.
 > >         Please feel free to talk to me if you will have a special
 > >         situation and if you would absolutely have to make changes.
 > >
 > >         Thanks for your support and help. And please feel free
to ask if
 > >         you have questions.
 > >
 > >         Galina
 > >
 > >
 > >         On Thu, Sep 10, 2020 at 9:35 PM Galina Kistanova
 > >         mailto:gkistan...@gmail.com>
>> wrote:
 > >
 > >             Hello everyone,
 > >
 > >             The buildbot upgrade is entering the phase when the
results
 > >             to become v

[clang] 4c5906c - [Flang][Driver] Add infrastructure for basic frontend actions and file I/O

2020-10-24 Thread Andrzej Warzynski via cfe-commits

Author: Caroline Concatto
Date: 2020-10-24T14:58:32+01:00
New Revision: 4c5906cffd04202387d2f6b50a47d39c0e4f2c0e

URL: 
https://github.com/llvm/llvm-project/commit/4c5906cffd04202387d2f6b50a47d39c0e4f2c0e
DIFF: 
https://github.com/llvm/llvm-project/commit/4c5906cffd04202387d2f6b50a47d39c0e4f2c0e.diff

LOG: [Flang][Driver] Add infrastructure for basic frontend actions and file I/O

This patch introduces the dependencies required to read and manage input files
provided by the command line option. It also adds the infrastructure to create
and write to output files. The output is sent to either stdout or a file
(specified with the `-o` flag).

Separately, in order to be able to test the code for file I/O, it adds
infrastructure to create frontend actions. As a basic testable example, it adds
the `InputOutputTest` FrontendAction. The sole purpose of this action is to
read a file from the command line and print it either to stdout or the output
file.  This action is run by using the `-test-io` flag also introduced in this
patch (available for `flang-new` and `flang-new -fc1`). With this patch:
```
flang-new -test-io input-file.f90
```
will read input-file.f90 and print it in the output file.

The `InputOutputTest` frontend action has been introduced primarily to
facilitate testing. It is hidden from users (i.e. it's only displayed with
`--help-hidden`). Currently Clang doesn’t have an equivalent action.

`-test-io` is used to trigger the InputOutputTest action in the Flang frontend
driver. This patch makes sure that “flang-new” forwards it to “flang-new -fc1"
by creating a preprocessor job. However, in Flang.cpp, `-test-io` is passed to
“flang-new -fc1” without `-E`. This way we make sure that the preprocessor is
_not_ run in the frontend driver. This is the desired behaviour: `-test-io`
should only read the input file and print it to the output stream.

co-authored-by: Andrzej Warzynski 

Differential Revision: https://reviews.llvm.org/D87989

Added: 
flang/include/flang/Frontend/FrontendAction.h
flang/include/flang/Frontend/FrontendActions.h
flang/lib/Frontend/FrontendAction.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/test/Flang-Driver/driver-help-hidden.f90
flang/test/Frontend/Inputs/hello-world.f90
flang/test/Frontend/input-output-file.f90
flang/test/Frontend/multiple-input-files.f90
flang/unittests/Frontend/InputOutputTest.cpp

Modified: 
clang/include/clang/Driver/Options.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Flang.cpp
clang/lib/Driver/Types.cpp
clang/test/Driver/immediate-options.c
flang/include/flang/Frontend/CompilerInstance.h
flang/include/flang/Frontend/CompilerInvocation.h
flang/include/flang/Frontend/FrontendOptions.h
flang/include/flang/FrontendTool/Utils.h
flang/lib/Frontend/CMakeLists.txt
flang/lib/Frontend/CompilerInstance.cpp
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendOptions.cpp
flang/lib/FrontendTool/CMakeLists.txt
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/test/Flang-Driver/driver-help.f90
flang/test/Flang-Driver/emit-obj.f90
flang/test/lit.cfg.py
flang/tools/flang-driver/fc1_main.cpp
flang/unittests/Frontend/CMakeLists.txt
flang/unittests/Frontend/CompilerInstanceTest.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.h 
b/clang/include/clang/Driver/Options.h
index 06dd3652be94..ae188cec93c2 100644
--- a/clang/include/clang/Driver/Options.h
+++ b/clang/include/clang/Driver/Options.h
@@ -36,7 +36,8 @@ enum ClangFlags {
   LinkOption = (1 << 13),
   FlangOption = (1 << 14),
   FC1Option = (1 << 15),
-  Ignored = (1 << 16),
+  FlangOnlyOption = (1 << 16),
+  Ignored = (1 << 17),
 };
 
 enum ID {

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0cab3e8ecc16..0b9817a0cfd4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -60,6 +60,10 @@ def LinkOption : OptionFlag;
 // flang mode.
 def FlangOption : OptionFlag;
 
+// FlangOnlyOption - This option should only be used by Flang (i.e. it is not
+// available for Clang)
+def FlangOnlyOption : OptionFlag;
+
 // FC1Option - This option should be accepted by flang -fc1.
 def FC1Option : OptionFlag;
 
@@ -2130,8 +2134,8 @@ def gno_embed_source : Flag<["-"], "gno-embed-source">, 
Group,
 Flags<[DriverOption]>,
 HelpText<"Restore the default behavior of not embedding source text in 
DWARF debug sections">;
 def headerpad__max__install__names : Joined<["-"], 
"headerpad_max_install_names">;
-def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption, FC1Option, 
FlangOption]>,
-  HelpText<"Display available options">;
+def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption, FC1Option,
+FlangOption]>, Hel

[clang] e5699b8 - [clang][driver] Rename DriverOption as NoXarchOption (NFC)

2020-10-30 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2020-10-30T17:00:06Z
New Revision: e5699b8ff1b6ea68e77dffb037e1c5d612131580

URL: 
https://github.com/llvm/llvm-project/commit/e5699b8ff1b6ea68e77dffb037e1c5d612131580
DIFF: 
https://github.com/llvm/llvm-project/commit/e5699b8ff1b6ea68e77dffb037e1c5d612131580.diff

LOG: [clang][driver] Rename DriverOption as NoXarchOption (NFC)

As discussed in [1], ClangFlags::DriverOption is currently only used to
mark options that should not be forwarded to other tools via `-Xarch`
options. This patch renames this flag accordingly and updates the
corresponding driver diagnostic.

A comment in ToolChain::TranslateXarchArgs is also updated to reflect
the change. The original comment referred to isDriverOption(), which is
no longer available.

[1] http://lists.llvm.org/pipermail/cfe-dev/2020-October/066953.html

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D89799

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Driver.h
clang/include/clang/Driver/Options.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChain.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index a45d9e8ee788..43ee4968dafd 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -121,8 +121,6 @@ def err_drv_missing_argument : Error<
   "argument to '%0' is missing (expected %1 value%s1)">;
 def err_drv_invalid_Xarch_argument_with_args : Error<
   "invalid Xarch argument: '%0', options requiring arguments are unsupported">;
-def err_drv_invalid_Xarch_argument_isdriver : Error<
-  "invalid Xarch argument: '%0', cannot change driver behavior inside Xarch 
argument">;
 def err_drv_Xopenmp_target_missing_triple : Error<
   "cannot deduce implicit triple value for -Xopenmp-target, specify triple 
using -Xopenmp-target=">;
 def err_drv_invalid_Xopenmp_target_with_args : Error<

diff  --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 7a476199ff7f..74a9cf3dab81 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -314,7 +314,7 @@ class Driver {
 
   const llvm::opt::OptTable &getOpts() const { return getDriverOptTable(); }
 
-  const DiagnosticsEngine &getDiags() const { return Diags; }
+  DiagnosticsEngine &getDiags() const { return Diags; }
 
   llvm::vfs::FileSystem &getVFS() const { return *VFS; }
 

diff  --git a/clang/include/clang/Driver/Options.h 
b/clang/include/clang/Driver/Options.h
index ae188cec93c2..b641f64c3116 100644
--- a/clang/include/clang/Driver/Options.h
+++ b/clang/include/clang/Driver/Options.h
@@ -24,7 +24,7 @@ namespace options {
 /// Flags specifically for clang options.  Must not overlap with
 /// llvm::opt::DriverFlag.
 enum ClangFlags {
-  DriverOption = (1 << 4),
+  NoXarchOption = (1 << 4),
   LinkerInput = (1 << 5),
   NoArgumentUnused = (1 << 6),
   Unsupported = (1 << 7),

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 09996af6f91f..069e5805d999 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -16,9 +16,9 @@ include "llvm/Option/OptParser.td"
 /
 // Flags
 
-// DriverOption - The option is a "driver" option, and should not be forwarded
-// to other tools.
-def DriverOption : OptionFlag;
+// The option is a "driver"-only option, and should not be forwarded to other
+// tools via `-Xarch` options.
+def NoXarchOption : OptionFlag;
 
 // LinkerInput - The option is a linker input.
 def LinkerInput : OptionFlag;
@@ -294,19 +294,19 @@ def internal_debug_Group :
   Group, HelpText<"DEBUG/DEVELOPMENT OPTIONS">;
 
 class InternalDriverOpt : Group,
-  Flags<[DriverOption, HelpHidden]>;
+  Flags<[NoXarchOption, HelpHidden]>;
 def driver_mode : Joined<["--"], "driver-mode=">, Group,
-  Flags<[CoreOption, DriverOption, HelpHidden]>,
+  Flags<[CoreOption, NoXarchOption, HelpHidden]>,
   HelpText<"Set the driver mode to either 'gcc', 'g++', 'cpp', or 'cl'">;
 def rsp_quoting : Joined<["--"], "rsp-quoting=">, Group,
-  Flags<[CoreOption, DriverOption, HelpHidden]>,
+  Flags<[CoreOption, NoXarchOption, HelpHidden]>,
   HelpText<"Set the rsp quoting to either 'posix', or 'windows'">;
 def ccc_gcc_name : Separate<["-"], "ccc-gcc-name">, InternalDriverOpt,
   HelpText<"Name for native GCC compiler">,
   MetaVarName<"">;
 
 class InternalDebugOpt : Group,
-  Flags<[DriverOption, HelpHidden, CoreOption]>;
+  Flags<[NoXarchOption, HelpHidden, CoreOption]>;
 def ccc_install_dir : Separate<["-"], "ccc-install-dir">, InternalDebugOpt,
   HelpText<"Simulate installation in the given directory">;
 def ccc_print_phases : Flag<["-"], "ccc-print-phases">, InternalDebugOpt,
@@ -330,7 +330,7 @@ def gen

[clang] d28de0d - [Flang][Driver] Add PrintPreprocessedInput FrontendAction (`flang-new -E`)

2020-11-02 Thread Andrzej Warzynski via cfe-commits

Author: Caroline Concatto
Date: 2020-11-02T14:03:35Z
New Revision: d28de0d7f257bbe4703f3449f1672f1744cf306b

URL: 
https://github.com/llvm/llvm-project/commit/d28de0d7f257bbe4703f3449f1672f1744cf306b
DIFF: 
https://github.com/llvm/llvm-project/commit/d28de0d7f257bbe4703f3449f1672f1744cf306b.diff

LOG: [Flang][Driver] Add PrintPreprocessedInput FrontendAction (`flang-new -E`)

This patch implements the first frontend action for the Flang parser (i.e.
Fortran::parser). This action runs the preprocessor and is invoked with the
`-E` flag. (i.e. `flang-new -E ). The generated output is printed
to either stdout or the output file (specified with `-` or `-o `).

Note that currently there is no mechanism to map options for the
frontend driver (i.e. Fortran::frontend::FrontendOptions) to options for
the parser (i.e. Fortran::parser::Options). Instead,
Frotran::parser::options are hard-coded to:

```
std::vector searchDirectories{"."s};
searchDirectories = searchDirectories;
isFixedForm = false;
_encoding(Fortran::parser::Encoding::UTF_8);
```

These default settings are compatible with the current Flang driver. Further
work is required in order for CompilerInvocation to read and map
clang::driver::options to Fortran::parser::options.

Co-authored-by: Andrzej Warzynski 

Differential Revision: https://reviews.llvm.org/D88381

Added: 
flang/test/Frontend/Inputs/hello-world.c
flang/test/Frontend/print-preprocess-C-file.f90
flang/test/Frontend/print-preprocessed-file.f90
flang/unittests/Frontend/PrintPreprocessedTest.cpp

Modified: 
clang/include/clang/Driver/Options.td
flang/include/flang/Frontend/CompilerInstance.h
flang/include/flang/Frontend/CompilerInvocation.h
flang/include/flang/Frontend/FrontendActions.h
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CompilerInstance.cpp
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendAction.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/test/Flang-Driver/driver-help-hidden.f90
flang/test/Flang-Driver/driver-help.f90
flang/unittests/Frontend/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 165baf06cbb2..057c2606c69d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -391,7 +391,7 @@ def C : Flag<["-"], "C">, Flags<[CC1Option]>, 
Group,
 def D : JoinedOrSeparate<["-"], "D">, Group,
 Flags<[CC1Option]>, MetaVarName<"=">,
 HelpText<"Define  to  (or 1 if  omitted)">;
-def E : Flag<["-"], "E">, Flags<[NoXarchOption,CC1Option]>, 
Group,
+def E : Flag<["-"], "E">, Flags<[NoXarchOption,CC1Option, FlangOption, 
FC1Option]>, Group,
 HelpText<"Only run the preprocessor">;
 def F : JoinedOrSeparate<["-"], "F">, Flags<[RenderJoined,CC1Option]>,
 HelpText<"Add directory to framework include search path">;

diff  --git a/flang/include/flang/Frontend/CompilerInstance.h 
b/flang/include/flang/Frontend/CompilerInstance.h
index b3f77896b8cb..21ef9f0dcd47 100644
--- a/flang/include/flang/Frontend/CompilerInstance.h
+++ b/flang/include/flang/Frontend/CompilerInstance.h
@@ -10,12 +10,10 @@
 
 #include "flang/Frontend/CompilerInvocation.h"
 #include "flang/Frontend/FrontendAction.h"
+#include "flang/Parser/parsing.h"
 #include "flang/Parser/provenance.h"
 #include "llvm/Support/raw_ostream.h"
 
-#include 
-#include 
-
 namespace Fortran::frontend {
 
 class CompilerInstance {
@@ -26,6 +24,10 @@ class CompilerInstance {
   /// Flang file  manager.
   std::shared_ptr allSources_;
 
+  std::shared_ptr allCookedSources_;
+
+  std::shared_ptr parsing_;
+
   /// The diagnostics engine instance.
   llvm::IntrusiveRefCntPtr diagnostics_;
 
@@ -75,6 +77,13 @@ class CompilerInstance {
 
   bool HasAllSources() const { return allSources_ != nullptr; }
 
+  /// }
+  /// @name Parser Operations
+  /// {
+
+  /// Return parsing to be used by Actions.
+  Fortran::parser::Parsing &parsing() const { return *parsing_; }
+
   /// }
   /// @name High-Level Operations
   /// {

diff  --git a/flang/include/flang/Frontend/CompilerInvocation.h 
b/flang/include/flang/Frontend/CompilerInvocation.h
index 223047c2afbd..12915c7c1d9c 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -9,6 +9,7 @@
 #define LLVM_FLANG_FRONTEND_COMPILERINVOCATION_H
 
 #include "flang/Frontend/FrontendOptions.h"
+#include "flang/Parser/parsing.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "llvm/Option/ArgList.h"
@@ -40,15 +41,25 @@ class CompilerInvocationBase {
 };
 
 class CompilerInvocation : public CompilerInvocationBase {
-  /// Options controlling the frontend itself.
+  /// Options for the frontend driver
+  // TODO: Merge with or translate to

[clang] 62e4f22 - [clang] Add AddClang.cmake to the list of the CMake modules that are installed

2021-02-04 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-02-04T12:38:38Z
New Revision: 62e4f22e297ade62fd1e463e7c846df96148ffc4

URL: 
https://github.com/llvm/llvm-project/commit/62e4f22e297ade62fd1e463e7c846df96148ffc4
DIFF: 
https://github.com/llvm/llvm-project/commit/62e4f22e297ade62fd1e463e7c846df96148ffc4.diff

LOG: [clang] Add AddClang.cmake to the list of the CMake modules that are 
installed

This makes sure that AddClang.cmake is installed alongside other Clang
CMake modules. This mirrors LLVM and MLIR in this respect and is
required when building the new Flang driver out of tree (as it depends
on Clang and includes AddClang.cmake).

Reviewed By: bogner

Differential Revision: https://reviews.llvm.org/D94533

Added: 


Modified: 
clang/cmake/modules/CMakeLists.txt

Removed: 




diff  --git a/clang/cmake/modules/CMakeLists.txt 
b/clang/cmake/modules/CMakeLists.txt
index d233f552f01f..79fefa08772f 100644
--- a/clang/cmake/modules/CMakeLists.txt
+++ b/clang/cmake/modules/CMakeLists.txt
@@ -61,6 +61,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
 
   install(FILES
 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/ClangConfig.cmake
+${CMAKE_CURRENT_SOURCE_DIR}/AddClang.cmake
 DESTINATION ${CLANG_INSTALL_PACKAGE_DIR}
 COMPONENT clang-cmake-exports)
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 985a42f - [flang][driver] Add support for `-J/-module-dir`

2021-02-04 Thread Andrzej Warzynski via cfe-commits

Author: Arnamoy Bhattacharyya
Date: 2021-02-04T16:31:40Z
New Revision: 985a42fdf8ae3117442ea129b684569fa6942a71

URL: 
https://github.com/llvm/llvm-project/commit/985a42fdf8ae3117442ea129b684569fa6942a71
DIFF: 
https://github.com/llvm/llvm-project/commit/985a42fdf8ae3117442ea129b684569fa6942a71.diff

LOG: [flang][driver] Add support for `-J/-module-dir`

Add support for option -J/-module-dir in the new Flang driver.  This
will allow for including module files in other directories, as the
default search path is currently the working folder. This also provides
an option of storing the output module in the specified folder.

Differential Revision: https://reviews.llvm.org/D95448

Added: 
flang/test/Flang-Driver/write-module.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
clang/lib/Driver/ToolChains/Flang.h
flang/include/flang/Frontend/CompilerInstance.h
flang/include/flang/Frontend/CompilerInvocation.h
flang/lib/Frontend/CompilerInstance.cpp
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/test/Flang-Driver/driver-help-hidden.f90
flang/test/Flang-Driver/driver-help.f90
flang/test/Flang-Driver/include-module.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a700cab350b7..7bd9a8ab40dc 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -949,6 +949,11 @@ def dependency_dot : Separate<["-"], "dependency-dot">, 
Flags<[CC1Option]>,
 def module_dependency_dir : Separate<["-"], "module-dependency-dir">,
   Flags<[CC1Option]>, HelpText<"Directory to dump module dependencies to">,
   MarshallingInfoString>;
+def module_dir : Separate<["-"], "module-dir">, 
Flags<[FlangOption,FC1Option]>, MetaVarName<"">,
+  HelpText<"Put MODULE files in ">,
+  DocBrief<[{This option specifies where to put .mod files for compiled 
modules.
+It is also added to the list of directories to be searched by an USE statement.
+The default is the current directory.}]>;
 def dsym_dir : JoinedOrSeparate<["-"], "dsym-dir">,
   Flags<[NoXarchOption, RenderAsInput]>,
   HelpText<"Directory to output dSYM's (if any) to">, MetaVarName<"">;
@@ -4121,7 +4126,7 @@ defm devirtualize_speculatively : 
BooleanFFlag<"devirtualize-speculatively">,
 
 // Generic gfortran options.
 def A_DASH : Joined<["-"], "A-">, Group;
-def J : JoinedOrSeparate<["-"], "J">, Flags<[RenderJoined]>, 
Group;
+def J : JoinedOrSeparate<["-"], "J">, 
Flags<[RenderJoined,FlangOption,FC1Option]>, Group, 
Alias;
 def cpp : Flag<["-"], "cpp">, Group;
 def nocpp : Flag<["-"], "nocpp">, Group;
 def static_libgfortran : Flag<["-"], "static-libgfortran">, 
Group;

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 1b8d03406f30..dee2148c231c 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -30,6 +30,10 @@ void Flang::AddPreprocessingOptions(const ArgList &Args,
   Args.AddAllArgs(CmdArgs, {options::OPT_D, options::OPT_U, options::OPT_I});
 }
 
+void Flang::AddOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const 
{
+  Args.AddAllArgs(CmdArgs, options::OPT_module_dir);
+}
+
 void Flang::ConstructJob(Compilation &C, const JobAction &JA,
  const InputInfo &Output, const InputInfoList &Inputs,
  const ArgList &Args, const char *LinkingOutput) const 
{
@@ -87,6 +91,9 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
 
   AddFortranDialectOptions(Args, CmdArgs);
 
+  // Add other compile options
+  AddOtherOptions(Args, CmdArgs);
+
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());

diff  --git a/clang/lib/Driver/ToolChains/Flang.h 
b/clang/lib/Driver/ToolChains/Flang.h
index a6efa9ae9bda..efbdbe854e24 100644
--- a/clang/lib/Driver/ToolChains/Flang.h
+++ b/clang/lib/Driver/ToolChains/Flang.h
@@ -39,6 +39,13 @@ class LLVM_LIBRARY_VISIBILITY Flang : public Tool {
   /// \param [out] CmdArgs The list of output command arguments
   void AddPreprocessingOptions(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const;
+  /// Extract other compilation options from the driver arguments and add them
+  /// to the command arguments.
+  ///
+  /// \param [in] Args The list of input driver arguments
+  /// \param [out] CmdArgs The list of output command arguments
+  void AddOtherOptions(const llvm::opt::ArgList &Args,
+   llvm::opt::ArgStringList &CmdArgs) const;
 
 public:
   Flang(const ToolChain &TC);

diff  --git a/flang/include/flang/Frontend/CompilerInstance.h 
b/flang/include/flang/Frontend/CompilerInstance.h
index 79a05c0ddbbe..a6f5fa970ddb 100644
--- a/flang/include/flang/Frontend/Compile

[clang] 96d229c - [flang][driver] Add options for unparsing

2021-02-16 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-02-16T09:32:51Z
New Revision: 96d229c9abdfb2836e18a554bfb63b5d52aeebfa

URL: 
https://github.com/llvm/llvm-project/commit/96d229c9abdfb2836e18a554bfb63b5d52aeebfa
DIFF: 
https://github.com/llvm/llvm-project/commit/96d229c9abdfb2836e18a554bfb63b5d52aeebfa.diff

LOG: [flang][driver] Add options for unparsing

This patch adds the following compiler frontend driver options:
  * -fdebug-unparse (f18 spelling: -funparse)
  * -fdebug-unparse-with-symbols (f18 spelling: -funparse-with-symbols)
The new driver will only accept the new spelling. `f18` will accept both
the original and the new spelling.

A new base class for frontend actions is added: `PrescanAndSemaAction`.
This is added to reduce code duplication that otherwise these new
options would lead to. Implementation from
  * `ParseSyntaxOnlyAction::ExecutionAction`
is moved to:
  * `PrescanAndSemaAction::BeginSourceFileAction`
This implementation is now shared between:
  * PrescanAndSemaAction
  * ParseSyntaxOnlyAction
  * DebugUnparseAction
  * DebugUnparseWithSymbolsAction

All tests that don't require other yet unimplemented options are
updated. This way `flang-new -fc1` is used instead of `f18` when
`FLANG_BUILD_NEW_DRIVER` is set to `On`. In order to facilitate this,
`%flang_fc1` is added in the LIT configuration (lit.cfg.py).

`asFortran` from f18.cpp is duplicated as `getBasicAsFortran` in
FrontendOptions.cpp. At this stage it's hard to find a good place to
share this method. I suggest that we revisit this once a switch from
`f18` to `flang-new` is complete.

Differential Revision: https://reviews.llvm.org/D96483

Added: 


Modified: 
clang/include/clang/Driver/Options.td
flang/include/flang/Frontend/FrontendActions.h
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CMakeLists.txt
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/Frontend/FrontendOptions.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/lib/Parser/CMakeLists.txt
flang/test/Flang-Driver/driver-help.f90
flang/test/Parser/continuation-in-if.f
flang/test/Parser/pp-dir-comments.f90
flang/test/Semantics/canondo01.f90
flang/test/Semantics/canondo02.f90
flang/test/Semantics/canondo03.f90
flang/test/Semantics/canondo04.f90
flang/test/Semantics/canondo05.f90
flang/test/Semantics/critical04.f90
flang/test/Semantics/defined-ops.f90
flang/test/Semantics/doconcurrent02.f90
flang/test/Semantics/doconcurrent03.f90
flang/test/Semantics/doconcurrent04.f90
flang/test/Semantics/doconcurrent07.f90
flang/test/Semantics/label02.f90
flang/test/Semantics/label03.f90
flang/test/Semantics/label04.f90
flang/test/Semantics/label05.f90
flang/test/Semantics/label06.f90
flang/test/Semantics/label07.f90
flang/test/Semantics/label08.f90
flang/test/Semantics/label09.f90
flang/test/Semantics/label10.f90
flang/test/Semantics/label12.f90
flang/test/Semantics/label13.f90
flang/test/Semantics/label15.f90
flang/test/lit.cfg.py
flang/tools/f18/f18.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d22956b86c4a..04a23c59e264 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4244,6 +4244,18 @@ def fopenacc : Flag<["-"], "fopenacc">, Group,
 
 }
 
+//===--===//
+// FC1 Options
+//===--===//
+let Flags = [FC1Option, FlangOnlyOption] in {
+
+def fdebug_unparse : Flag<["-"], "fdebug-unparse">, Group,
+  HelpText<"Unparse and stop.">;
+def fdebug_unparse_with_symbols : Flag<["-"], "fdebug-unparse-with-symbols">, 
Group,
+  HelpText<"Unparse and stop.">;
+
+}
+
 
//===--===//
 // CC1 Options
 
//===--===//

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index f28e3c2bc552..4c29d0d5a641 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -37,7 +37,23 @@ class PrintPreprocessedAction : public PrescanAction {
   void ExecuteAction() override;
 };
 
-class ParseSyntaxOnlyAction : public PrescanAction {
+//===--===//
+// PrescanAndSema Actions
+//===--===//
+class PrescanAndSemaAction : public FrontendAction {
+  void ExecuteAction() override = 0;
+  bool BeginSourceFileAction(CompilerInstance &ci) override;
+};
+
+class DebugUnparseWithSymbolsAction : public 

[clang] d81f633 - [flang][driver] Add -Xflang and make -test-io a frontend-only flang

2021-02-22 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-02-22T10:11:43Z
New Revision: d81f633fe28fd23108b4dc8c25548f1653ba0cd2

URL: 
https://github.com/llvm/llvm-project/commit/d81f633fe28fd23108b4dc8c25548f1653ba0cd2
DIFF: 
https://github.com/llvm/llvm-project/commit/d81f633fe28fd23108b4dc8c25548f1653ba0cd2.diff

LOG: [flang][driver] Add -Xflang and make -test-io a frontend-only flang

This patch adds support for `-Xflang` in `flang-new`. The semantics are
identical to `-Xclang`.

With the addition of `-Xflang`, we can modify `-test-io` to be a
compiler-frontend only flag. This makes more sense, this flag is:
  * very frontend specific
  * to be used for development and testing only
  * not to be exposed to the end user
Originally we added it to the compiler driver, `flang-new`, in order to
facilitate testing. With `-Xflang` this is no longer needed. Tests are
updated accordingly.

Differential Revision: https://reviews.llvm.org/D96864

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
clang/lib/Driver/Types.cpp
flang/test/Flang-Driver/driver-help-hidden.f90
flang/test/Flang-Driver/driver-help.f90
flang/test/Frontend/input-output-file.f90
flang/test/Frontend/multiple-input-files.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index ade330bd7ba4..bbaa16658639 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4236,11 +4236,17 @@ def sycl_std_EQ : Joined<["-"], "sycl-std=">, 
Group, Flags<[CC1Optio
   MarshallingInfoString, "SYCL_None">, 
ShouldParseIf, AutoNormalizeEnum;
 
 
//===--===//
-// FlangOption and FC1 Options
+// FLangOption + CoreOption + NoXarchOption
 
//===--===//
-def test_io : Flag<["-"], "test-io">, Flags<[HelpHidden, FlangOption, 
FC1Option, FlangOnlyOption]>, Group,
-  HelpText<"Run the InputOuputTest action. Use for development and testing 
only.">;
+let Flags = [FlangOption, FlangOnlyOption, NoXarchOption, CoreOption] in {
+def Xflang : Separate<["-"], "Xflang">,
+  HelpText<"Pass  to the flang compiler">, MetaVarName<"">,
+  Flags<[NoXarchOption, CoreOption]>, Group;
+}
 
+//===--===//
+// FlangOption and FC1 Options
+//===--===//
 let Flags = [FC1Option, FlangOption, FlangOnlyOption] in {
 
 def ffixed_form : Flag<["-"], "ffixed-form">, Group,
@@ -4270,7 +4276,6 @@ def fimplicit_none : Flag<["-"], "fimplicit-none">, 
Group,
 def fno_implicit_none : Flag<["-"], "fno-implicit-none">, Group;
 def falternative_parameter_statement : Flag<["-"], 
"falternative-parameter-statement">, Group,
   HelpText<"Enable the old style PARAMETER statement">;
-
 }
 
 
//===--===//
@@ -4278,6 +4283,8 @@ def falternative_parameter_statement : Flag<["-"], 
"falternative-parameter-state
 
//===--===//
 let Flags = [FC1Option, FlangOnlyOption] in {
 
+def test_io : Flag<["-"], "test-io">, Group,
+  HelpText<"Run the InputOuputTest action. Use for development and testing 
only.">;
 def fdebug_unparse : Flag<["-"], "fdebug-unparse">, Group,
   HelpText<"Unparse and stop.">;
 def fdebug_unparse_with_symbols : Flag<["-"], "fdebug-unparse-with-symbols">, 
Group,

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 98d37eb7e692..b79b94a11956 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -63,9 +63,6 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
   // CmdArgs.push_back(Args.MakeArgString(TripleStr));
 
   if (isa(JA)) {
-if (C.getArgs().hasArg(options::OPT_test_io))
-  CmdArgs.push_back("-test-io");
-else
   CmdArgs.push_back("-E");
   } else if (isa(JA) || isa(JA)) {
 if (JA.getType() == types::TY_Nothing) {
@@ -102,6 +99,9 @@ void Flang::ConstructJob(Compilation &C, const JobAction &JA,
   // Add other compile options
   AddOtherOptions(Args, CmdArgs);
 
+  // Forward -Xflang arguments to -fc1
+  Args.AddAllArgValues(CmdArgs, options::OPT_Xflang);
+
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());

diff  --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp
index e898334c3227..2050dffa6fa0 100644
--- a/clang/lib/Driver/Types.cpp
+++ b/clang/lib/Driver/Types.cpp
@@ -325,12 +325,10 @@ types::getCompilationPhases(const clang::driver::Driver 
&Driver,
   // Filter to compiler mode. When the compiler is run as a preprocessor then
   // compilation is not an option.

[clang] baebc11 - [clang][driver] Set the input type to Fortran when reading from stdin

2021-02-25 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-02-25T13:13:42Z
New Revision: baebc1162f810f7bf5de48919054f75a2f81e180

URL: 
https://github.com/llvm/llvm-project/commit/baebc1162f810f7bf5de48919054f75a2f81e180
DIFF: 
https://github.com/llvm/llvm-project/commit/baebc1162f810f7bf5de48919054f75a2f81e180.diff

LOG: [clang][driver] Set the input type to Fortran when reading from stdin

This patch makes sure that for the following invocation of the new Flang
driver, clangDriver sets the input type to Fortran:
```
flang-new -E -
```
This change does not affect `clang`, i.e. for the following invocation
the input type is set to C:
```
clang -E -
```

This change leverages the fact that for `flang-new` the driver is in
Flang mode.

Differential Revision: https://reviews.llvm.org/D96777

Added: 


Modified: 
clang/lib/Driver/Driver.cpp
flang/test/Flang-Driver/input-from-stdin.f90

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 8c180140ae92..5aa0011d80ef 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2191,15 +2191,20 @@ void Driver::BuildInputs(const ToolChain &TC, 
DerivedArgList &Args,
 
 // stdin must be handled specially.
 if (memcmp(Value, "-", 2) == 0) {
-  // If running with -E, treat as a C input (this changes the builtin
-  // macros, for example). This may be overridden by -ObjC below.
-  //
-  // Otherwise emit an error but still use a valid type to avoid
-  // spurious errors (e.g., no inputs).
-  if (!Args.hasArgNoClaim(options::OPT_E) && !CCCIsCPP())
-Diag(IsCLMode() ? clang::diag::err_drv_unknown_stdin_type_clang_cl
-: clang::diag::err_drv_unknown_stdin_type);
-  Ty = types::TY_C;
+  if (IsFlangMode()) {
+Ty = types::TY_Fortran;
+  } else {
+// If running with -E, treat as a C input (this changes the
+// builtin macros, for example). This may be overridden by -ObjC
+// below.
+//
+// Otherwise emit an error but still use a valid type to avoid
+// spurious errors (e.g., no inputs).
+if (!Args.hasArgNoClaim(options::OPT_E) && !CCCIsCPP())
+  Diag(IsCLMode() ? 
clang::diag::err_drv_unknown_stdin_type_clang_cl
+  : clang::diag::err_drv_unknown_stdin_type);
+Ty = types::TY_C;
+  }
 } else {
   // Otherwise lookup by extension.
   // Fallback is C if invoked as C preprocessor, C++ if invoked with

diff  --git a/flang/test/Flang-Driver/input-from-stdin.f90 
b/flang/test/Flang-Driver/input-from-stdin.f90
index 05f99a300c19..d95218abe278 100644
--- a/flang/test/Flang-Driver/input-from-stdin.f90
+++ b/flang/test/Flang-Driver/input-from-stdin.f90
@@ -5,19 +5,22 @@
 !--
 ! FLANG DRIVER (flang-new)
 !--
-! TODO: Add support for `flang-new -`
-! Currently `bin/flang-new  -E -` defaults to `-x c` and e.g. F90 is not 
allowed
-! in `-x ` (see `clang::driver::types::canTypeBeUserSpecified` in
-! Types.cpp)
+! Input type is implicit
+! RUN: cat %s | flang-new -E - | FileCheck %s --check-prefix=PP-NOT-DEFINED
+! RUN: cat %s | flang-new -DNEW -E - | FileCheck %s --check-prefix=PP-DEFINED
+
+! Input type is explicit
+! RUN: cat %s | flang-new -E -x f95-cpp-input - | FileCheck %s 
--check-prefix=PP-NOT-DEFINED
+! RUN: cat %s | flang-new -DNEW -E -x f95-cpp-input - | FileCheck %s 
--check-prefix=PP-DEFINED
 
 !---
 ! FLANG FRONTEND DRIVER (flang-new -fc1)
 !---
-! Test `-E` - for the corresponding frontend actions the driver relies on the 
prescanner API to handle file I/O
+! Test `-E`: for the corresponding frontend actions the driver relies on the 
prescanner API to handle file I/O
 ! RUN: cat %s | flang-new -fc1 -E | FileCheck %s --check-prefix=PP-NOT-DEFINED
 ! RUN: cat %s | flang-new -fc1 -DNEW -E | FileCheck %s 
--check-prefix=PP-DEFINED
 
-! Test `-test-io` - for the corresponding frontend action 
(`InputOutputTestAction`) the driver handles the file I/O on its own
+! Test `-test-io`: for the corresponding frontend action 
(`InputOutputTestAction`) the driver handles the file I/O on its own
 ! the corresponding action (`PrintPreprocessedAction`)
 ! RUN: cat %s | flang-new -fc1 -test-io | FileCheck %s --check-prefix=IO 
--match-full-lines
 ! RUN: cat %s | flang-new -fc1 -DNEW -test-io | FileCheck %s --check-prefix=IO 
--match-full-lines



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 20bd214 - [flang][driver] Add support for `-module-suffix`

2021-06-04 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-06-04T13:58:04+01:00
New Revision: 20bd2142d46536f4ffd61f28a029d6bda68f1a7f

URL: 
https://github.com/llvm/llvm-project/commit/20bd2142d46536f4ffd61f28a029d6bda68f1a7f
DIFF: 
https://github.com/llvm/llvm-project/commit/20bd2142d46536f4ffd61f28a029d6bda68f1a7f.diff

LOG: [flang][driver] Add support for `-module-suffix`

This option is supported in `f18`, but not yet available in `flang-new`.
It is required in order to call `flang-new` from the `flang` bash
script.

Differential Revision: https://reviews.llvm.org/D103613

Added: 
flang/test/Driver/module-suffix.f90

Modified: 
clang/include/clang/Driver/Options.td
flang/include/flang/Frontend/CompilerInvocation.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4945538ec0f01..c2945fb0bf184 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4522,6 +4522,9 @@ def fdebug_module_writer : 
Flag<["-"],"fdebug-module-writer">,
 def fget_symbols_sources : Flag<["-"], "fget-symbols-sources">, 
Group,
   HelpText<"Dump symbols and their source code locations">;
 
+def module_suffix : Separate<["-"], "module-suffix">,  Group, 
MetaVarName<"">,
+  HelpText<"Use  as the suffix for module files (the default value is 
`.mod`)">;
+
 }
 
 
//===--===//

diff  --git a/flang/include/flang/Frontend/CompilerInvocation.h 
b/flang/include/flang/Frontend/CompilerInvocation.h
index edd32917b175c..f449a69dfa8a0 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -69,6 +69,8 @@ class CompilerInvocation : public CompilerInvocationBase {
   // of options.
   std::string moduleDir_ = ".";
 
+  std::string moduleFileSuffix_ = ".mod";
+
   bool debugModuleDir_ = false;
 
   bool warnAsErr_ = false;
@@ -97,6 +99,9 @@ class CompilerInvocation : public CompilerInvocationBase {
   std::string &moduleDir() { return moduleDir_; }
   const std::string &moduleDir() const { return moduleDir_; }
 
+  std::string &moduleFileSuffix() { return moduleFileSuffix_; }
+  const std::string &moduleFileSuffix() const { return moduleFileSuffix_; }
+
   bool &debugModuleDir() { return debugModuleDir_; }
   const bool &debugModuleDir() const { return debugModuleDir_; }
 
@@ -129,6 +134,10 @@ class CompilerInvocation : public CompilerInvocationBase {
   /// Useful setters
   void SetModuleDir(std::string &moduleDir) { moduleDir_ = moduleDir; }
 
+  void SetModuleFileSuffix(const char *moduleFileSuffix) {
+moduleFileSuffix_ = std::string(moduleFileSuffix);
+  }
+
   void SetDebugModuleDir(bool flag) { debugModuleDir_ = flag; }
 
   void SetWarnAsErr(bool flag) { warnAsErr_ = flag; }

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 1f61e0e9ff305..1d18dda5e7eea 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -392,6 +392,12 @@ static bool parseSemaArgs(CompilerInvocation &res, 
llvm::opt::ArgList &args,
 res.SetDebugModuleDir(true);
   }
 
+  // -module-suffix
+  if (const auto *moduleSuffix =
+  args.getLastArg(clang::driver::options::OPT_module_suffix)) {
+res.SetModuleFileSuffix(moduleSuffix->getValue());
+  }
+
   return diags.getNumErrors() == numErrorsBefore;
 }
 
@@ -639,5 +645,6 @@ void CompilerInvocation::setSemanticsOpts(
   semanticsContext_->set_moduleDirectory(moduleDir())
   .set_searchDirectories(fortranOptions.searchDirectories)
   .set_warnOnNonstandardUsage(enableConformanceChecks())
-  .set_warningsAreErrors(warnAsErr());
+  .set_warningsAreErrors(warnAsErr())
+  .set_moduleFileSuffix(moduleFileSuffix());
 }

diff  --git a/flang/test/Driver/driver-help.f90 
b/flang/test/Driver/driver-help.f90
index 9783751a2c9e7..696c437a574b8 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -106,6 +106,7 @@
 ! HELP-FC1-NEXT: -help  Display available options
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list 
of include search paths
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
+! HELP-FC1-NEXT: -module-suffix  Use  as the suffix for module 
files (the default value is `.mod`)
 ! HELP-FC1-NEXT: -nocpp Disable predefined and command line 
preprocessor macros
 ! HELP-FC1-NEXT: -o   Write output to 
 ! HELP-FC1-NEXT: -pedantic  Warn on language extensions

diff  --git a/flang/test/Driver/module-suffix.f90 
b/flang/test/Driver/module-suffix.f90
new file mode 100644
index 0..151688492c932
--- /dev/null
+++ b/flang/test/Driver/module-suffix.f90
@@ -0,0 +1,16 @@
+! Tes

[clang] e1da329 - [flang][driver] Add support for the "-init-only" option

2021-06-07 Thread Andrzej Warzynski via cfe-commits

Author: Stuart Ellis
Date: 2021-06-07T15:40:26+01:00
New Revision: e1da3297d253b33be1ff941cf9ed9091dd332ea5

URL: 
https://github.com/llvm/llvm-project/commit/e1da3297d253b33be1ff941cf9ed9091dd332ea5
DIFF: 
https://github.com/llvm/llvm-project/commit/e1da3297d253b33be1ff941cf9ed9091dd332ea5.diff

LOG: [flang][driver] Add support for the "-init-only" option

Adding the `-init-only` option and corresponding frontend action to
generate a diagnostic.

`-init-only` vs `-test-io`:
`-init-only` ignores the input (it never calls the prescanner)
`-test-io` is similar to `-init-only`, but does read and print the input
without calling the prescanner.

This patch also adds a Driver test to check this action.

Reviewed By: awarzynski, AMDChirag

Differential Revision: https://reviews.llvm.org/D102849

Added: 
flang/test/Driver/init-only.f90

Modified: 
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/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c2945fb0bf184..c92348d040712 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5273,8 +5273,6 @@ def analyze : Flag<["-"], "analyze">,
   HelpText<"Run static analysis engine">;
 def dump_tokens : Flag<["-"], "dump-tokens">,
   HelpText<"Run preprocessor, dump internal rep of tokens">;
-def init_only : Flag<["-"], "init-only">,
-  HelpText<"Only execute frontend initialization">;
 def fixit : Flag<["-"], "fixit">,
   HelpText<"Apply fix-it advice to the input source">;
 def fixit_EQ : Joined<["-"], "fixit=">,
@@ -5740,6 +5738,8 @@ let Group = Action_Group in {
 
 def emit_obj : Flag<["-"], "emit-obj">,
   HelpText<"Emit native object files">;
+def init_only : Flag<["-"], "init-only">,
+  HelpText<"Only execute frontend initialization">;
 
 } // let Group = Action_Group
 } // let Flags = [CC1Option, FC1Option, NoDriverOption]

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index 619e83ad88c77..7a88382075741 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -38,6 +38,10 @@ class EmitObjAction : public FrontendAction {
   void ExecuteAction() override;
 };
 
+class InitOnlyAction : public FrontendAction {
+  void ExecuteAction() override;
+};
+
 
//===--===//
 // Prescan Actions
 
//===--===//

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index e18fd961a55b0..9c34abb68f2d6 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -71,7 +71,10 @@ enum ActionKind {
   GetDefinition,
 
   /// Parse, run semantics and then dump symbol sources map
-  GetSymbolsSources
+  GetSymbolsSources,
+
+  /// Only execute frontend initialization
+  InitOnly
 
   /// TODO: RunPreprocessor, EmitLLVM, EmitLLVMOnly,
   /// EmitCodeGenOnly, EmitAssembly, (...)

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 6d9a3a7f31947..5098da42dfc0f 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -162,9 +162,12 @@ static bool ParseFrontendArgs(FrontendOptions &opts, 
llvm::opt::ArgList &args,
 case clang::driver::options::OPT_fget_definition:
   opts.programAction_ = GetDefinition;
   break;
+case clang::driver::options::OPT_init_only:
+  opts.programAction_ = InitOnly;
+  break;
 
   // TODO:
-  // case calng::driver::options::OPT_emit_llvm:
+  // case clang::driver::options::OPT_emit_llvm:
   // case clang::driver::options::OPT_emit_llvm_only:
   // case clang::driver::options::OPT_emit_codegen_only:
   // case clang::driver::options::OPT_emit_module:

diff  --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index de8a02753391b..f4ba515440d9b 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -447,3 +447,11 @@ void EmitObjAction::ExecuteAction() {
   clang::DiagnosticsEngine::Error, "code-generation is not available yet");
   ci.diagnostics().Report(DiagID);
 }
+
+void InitOnlyAction::ExecuteAction() {
+  CompilerInstance &ci = this->instance();
+  unsigned DiagID =
+  ci.diagnostics().getCustomDiagID(clang::DiagnosticsEngine::Warning,
+  "Use `-init-only` for testing purposes only");
+  ci.

[clang] a6be6e3 - [flang][driver] Add `-fdebug-dump-all`

2021-06-16 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-06-16T07:54:27Z
New Revision: a6be6e31f1810012922e50dab0d4c15cdf990d2e

URL: 
https://github.com/llvm/llvm-project/commit/a6be6e31f1810012922e50dab0d4c15cdf990d2e
DIFF: 
https://github.com/llvm/llvm-project/commit/a6be6e31f1810012922e50dab0d4c15cdf990d2e.diff

LOG: [flang][driver] Add `-fdebug-dump-all`

The new option will run the semantic checks and then dump the parse tree
and all the symbols. This is equivalent to running the driver twice,
once with `-fdebug-dump-parse-tree` and then with
the `-fdebug-dump-symbols` action flag.

Currently we wouldn't be able to achieve the same by simply running:
```
flang-new -fc1 -fdebug-dump-parse-tree -fdebug-dump-symbols 
```
That's because the new driver will only run one frontend action per
invocation (both of the flags used here are action flags). Diverging
from this design would lead to costly compromises and it's best avoided.

We may want to consider re-designing our debugging actions (and action
options) in the future so that there's more code re-use. For now, I'm
focusing on making sure that we support all the major cases requested by
our users.

Differential Revision: https://reviews.llvm.org/D104305

Added: 
flang/test/Driver/dump-all.f90

Modified: 
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/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7c6b22c029693..151968de1789e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4523,6 +4523,8 @@ def fdebug_dump_parse_tree_no_sema : Flag<["-"], 
"fdebug-dump-parse-tree-no-sema
   HelpText<"Dump the parse tree (skips the semantic checks)">,
   DocBrief<[{Run the Parser and then output the parse tree. Semantic
 checks are disabled.}]>;
+def fdebug_dump_all : Flag<["-"], "fdebug-dump-all">, Group,
+  HelpText<"Dump symbols and the parse tree after the semantic checks">;
 def fdebug_dump_provenance : Flag<["-"], "fdebug-dump-provenance">, 
Group,
   HelpText<"Dump provenance">;
 def fdebug_dump_parsing_log : Flag<["-"], "fdebug-dump-parsing-log">, 
Group,

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index 7a88382075741..72eb44223fe49 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -116,6 +116,10 @@ class DebugDumpParseTreeAction : public 
PrescanAndSemaAction {
   void ExecuteAction() override;
 };
 
+class DebugDumpAllAction : public PrescanAndSemaAction {
+  void ExecuteAction() override;
+};
+
 class DebugPreFIRTreeAction : public PrescanAndSemaAction {
   void ExecuteAction() override;
 };

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index 9c34abb68f2d6..42ce499566e9f 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -51,6 +51,9 @@ enum ActionKind {
   /// Parse, run semantics and then output the parse tree
   DebugDumpParseTree,
 
+  /// Parse, run semantics and then output the parse tree and symbols
+  DebugDumpAll,
+
   /// Parse and then output the parse tree, skip the semantic checks
   DebugDumpParseTreeNoSema,
 

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 5098da42dfc0f..dc771ecbc9a8f 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -141,6 +141,9 @@ static bool ParseFrontendArgs(FrontendOptions &opts, 
llvm::opt::ArgList &args,
 case clang::driver::options::OPT_fdebug_dump_parse_tree:
   opts.programAction_ = DebugDumpParseTree;
   break;
+case clang::driver::options::OPT_fdebug_dump_all:
+  opts.programAction_ = DebugDumpAll;
+  break;
 case clang::driver::options::OPT_fdebug_dump_parse_tree_no_sema:
   opts.programAction_ = DebugDumpParseTreeNoSema;
   break;

diff  --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index f4ba515440d9b..d3cce62681cc0 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -305,6 +305,42 @@ void DebugDumpSymbolsAction::ExecuteAction() {
   semantics.DumpSymbols(llvm::outs());
 }
 
+void DebugDumpAllAction::ExecuteAction() {
+  CompilerInstance &ci = this->instance();
+
+  // Dump parse tree
+  auto &parseTree{instance().parsing().parseTree()};
+  Fortran::parser::AnalyzedObjectsAsFortran asFortran =
+  Fortran::frontend::getBasicAsFortran();
+  llvm::outs() <

[clang] 55a9615 - [flang][driver] Refactor boolean options

2021-08-05 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-08-05T10:20:47Z
New Revision: 55a96155995465416118774add8ef09c30dbebda

URL: 
https://github.com/llvm/llvm-project/commit/55a96155995465416118774add8ef09c30dbebda
DIFF: 
https://github.com/llvm/llvm-project/commit/55a96155995465416118774add8ef09c30dbebda.diff

LOG: [flang][driver] Refactor boolean options

For boolean options, e.g. `-fxor-operator`/`-fno-xor-operator`, we ought
to be using TableGen multi-classes. This way, we only have to write one
definition to have both forms auto-generated. This patch refactors all
of Flang's boolean options to use two new multi-classes:
`OptInFC1FFOption` and `OptOutFC1FFOption`. These multi-classes are
based on `OptInFFOption`/`OptOutFFOption`, respectively. I've also
simplified the processing of the updated options in
CompilerInvocation.cpp.

With the new approach, "empty" help text (i.e. no `HelpText`) is now
replaced with an empty string (i.e. HelpText<"">). When running
flang-new --help, that's considered as non-empty help messages, which is
then printed (that's controlled by `printHelp` from
llvm/lib/Option/OptTable.cpp). This means that with this patch,
flang-new --help will start printing e.g. -fno-backslash, even though
there is no actual help text to print for this option (apart from the
empty string ""). Tests are updated accordingly.

Note that with this patch, both `-fxor-operator` and `-fno-xor-operator`
(and other boolean options refactored here) remain available in
`flang-new` and `flang-new -fc1`. In this respect, nothing changes. In a
forthcoming patch, I will refine this so that `flang-new -fc1` only
accepts `-ffoo` (`OptInFC1FFOption`) or `-fno-foo` (`OptOutCC1FFOption`).

For clarity, `OptInFFOption`/`OptOutFFOption` are renamed as
`OptInCC1FFOption`/`OptOutCC1FFOption`, respectively. Otherwise, this is
an NFC from Clang's perspective.

Differential Revision: https://reviews.llvm.org/D105881

Added: 


Modified: 
clang/include/clang/Driver/Options.td
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3715172917204..9f42072a92900 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -272,7 +272,7 @@ class MigratorOpts
 // Args.hasArg(OPT_ffoo) can be used to check that the flag is enabled.
 // This is useful if the option is usually disabled.
 // Use this only when the option cannot be declared via BoolFOption.
-multiclass OptInFFlag flags=[]> {
   def f#NAME : Flag<["-"], "f"#name>, Flags<[CC1Option] # flags>,
Group, HelpText;
@@ -283,7 +283,7 @@ multiclass OptInFFlag flags=[]> {
   def f#NAME : Flag<["-"], "f"#name>, Flags,
Group, HelpText;
@@ -291,6 +291,27 @@ multiclass OptOutFFlag, HelpText;
 }
 
+// A boolean option which is opt-in in FC1. The positive option exists in FC1 
and
+// Args.hasArg(OPT_ffoo) can be used to check that the flag is enabled.
+// This is useful if the option is usually disabled.
+multiclass OptInFC1FFlag flags=[]> {
+  def f#NAME : Flag<["-"], "f"#name>, Flags<[FC1Option] # flags>,
+   Group, HelpText;
+  def fno_#NAME : Flag<["-"], "fno-"#name>, Flags,
+  Group, HelpText;
+}
+
+// A boolean option which is opt-out in FC1. The negative option exists in FC1 
and
+// Args.hasArg(OPT_fno_foo) can be used to check that the flag is disabled.
+multiclass OptOutFC1FFlag flags=[]> {
+  def f#NAME : Flag<["-"], "f"#name>, Flags,
+   Group, HelpText;
+  def fno_#NAME : Flag<["-"], "fno-"#name>, Flags<[FC1Option] # flags>,
+  Group, HelpText;
+}
+
 // Creates a positive and negative flags where both of them are prefixed with
 // "m", have help text specified for positive and negative option, and a Group
 // optionally specified by the opt_group argument, otherwise Group.
@@ -1257,7 +1278,7 @@ defm addrsig : BoolFOption<"addrsig",
   CodeGenOpts<"Addrsig">, DefaultFalse,
   PosFlag, NegFlag,
   BothFlags<[CoreOption], " an address-significance table">>;
-defm blocks : OptInFFlag<"blocks", "Enable the 'blocks' language feature", "", 
"", [CoreOption]>;
+defm blocks : OptInCC1FFlag<"blocks", "Enable the 'blocks' language feature", 
"", "", [CoreOption]>;
 def fbootclasspath_EQ : Joined<["-"], "fbootclasspath=">, Group;
 defm borland_extensions : BoolFOption<"borland-extensions",
   LangOpts<"Borland">, DefaultFalse,
@@ -1273,7 +1294,7 @@ def fclang_abi_compat_EQ : Joined<["-"], 
"fclang-abi-compat=">, Group, MetaVarName<"">, 
Values<".,latest">,
   HelpText<"Attempt to match the ABI of Clang ">;
 def fclasspath_EQ : Joined<["-"], "fclasspath=">, Group;
-defm color_diagnostics : OptInFFlag<"color-diagnostics", "Enable", "Disable", 
" colors in diagnostics",
+defm color_diagnostics : OptInC

[clang] f52fc59 - [flang][driver] Add support for Frontend Plugins

2021-08-12 Thread Andrzej Warzynski via cfe-commits

Author: Stuart Ellis
Date: 2021-08-12T11:42:16+01:00
New Revision: f52fc591fa34a8c85577108358b3b36c42b6d364

URL: 
https://github.com/llvm/llvm-project/commit/f52fc591fa34a8c85577108358b3b36c42b6d364
DIFF: 
https://github.com/llvm/llvm-project/commit/f52fc591fa34a8c85577108358b3b36c42b6d364.diff

LOG: [flang][driver] Add support for Frontend Plugins

Introducing a plugin API and a simple HelloWorld Plugin example.
This patch adds the `-load` and `-plugin` flags to frontend driver and
the code around using custom frontend actions from within a plugin
shared library object.

It also adds to the Driver-help test to check the help option with the
updated driver flags.

Additionally, the patch creates a plugin-example test to check the
HelloWorld plugin example runs correctly. As part of this, a new CMake
flag (`FLANG_BUILD_EXAMPLES`) is added to allow the example to be built
and for the test to run.

This Plugin API has only been tested on Linux.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D106137

Added: 
flang/examples/HelloWorld/CMakeLists.txt
flang/examples/HelloWorld/HelloWorldPlugin.cpp
flang/include/flang/Frontend/FrontendPluginRegistry.h
flang/test/Driver/plugin-example.f90

Modified: 
clang/include/clang/Driver/Options.td
flang/CMakeLists.txt
flang/examples/CMakeLists.txt
flang/include/flang/Frontend/FrontendActions.h
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendAction.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/test/CMakeLists.txt
flang/test/Driver/driver-help.f90
flang/test/lit.cfg.py
flang/test/lit.site.cfg.py.in
flang/tools/flang-driver/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7525795bf9d3c..a91114f76ff07 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5266,10 +5266,6 @@ def enable_noundef_analysis : Flag<["-"], 
"enable-noundef-analysis">, Group,
   HelpText<"Discard value names in LLVM IR">,
   MarshallingInfoFlag>;
-def load : Separate<["-"], "load">, MetaVarName<"">,
-  HelpText<"Load the named plugin (dynamic shared object)">;
-def plugin : Separate<["-"], "plugin">, MetaVarName<"">,
-  HelpText<"Use the named plugin action instead of the default action (use 
\"help\" to list available options)">;
 def plugin_arg : JoinedAndSeparate<["-"], "plugin-arg-">,
 MetaVarName<" ">,
 HelpText<"Pass  to plugin ">;
@@ -5836,6 +5832,12 @@ def init_only : Flag<["-"], "init-only">,
   HelpText<"Only execute frontend initialization">;
 
 } // let Group = Action_Group
+
+def load : Separate<["-"], "load">, MetaVarName<"">,
+  HelpText<"Load the named plugin (dynamic shared object)">;
+def plugin : Separate<["-"], "plugin">, MetaVarName<"">,
+  HelpText<"Use the named plugin action instead of the default action (use 
\"help\" to list available options)">;
+
 } // let Flags = [CC1Option, FC1Option, NoDriverOption]
 
 
//===--===//

diff  --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index fc85f44513163..cf6055075c383 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -390,6 +390,8 @@ if (FLANG_BUILD_TOOLS)
   add_subdirectory(tools)
 endif()
 add_subdirectory(runtime)
+
+option(FLANG_BUILD_EXAMPLES "Build Flang example programs by default." OFF)
 add_subdirectory(examples)
 
 if (FLANG_INCLUDE_TESTS)

diff  --git a/flang/examples/CMakeLists.txt b/flang/examples/CMakeLists.txt
index 3ca9feddf33e9..c4ef3bf20d4b0 100644
--- a/flang/examples/CMakeLists.txt
+++ b/flang/examples/CMakeLists.txt
@@ -1,3 +1,7 @@
+if(NOT FLANG_BUILD_EXAMPLES)
+  set(EXCLUDE_FROM_ALL ON)
+endif()
+
 # This test is not run by default as it requires input.
 add_executable(external-hello-world
   external-hello.cpp
@@ -6,3 +10,5 @@ add_executable(external-hello-world
 target_link_libraries(external-hello-world
   FortranRuntime
 )
+
+add_subdirectory(HelloWorld)

diff  --git a/flang/examples/HelloWorld/CMakeLists.txt 
b/flang/examples/HelloWorld/CMakeLists.txt
new file mode 100644
index 0..8552284c80529
--- /dev/null
+++ b/flang/examples/HelloWorld/CMakeLists.txt
@@ -0,0 +1,7 @@
+# TODO: Note that this is currently only available on Linux.
+# On Windows, we would also have to specify e.g. `PLUGIN_TOOL`.
+add_llvm_library(
+flangHelloWorldPlugin
+MODULE
+HelloWorldPlugin.cpp
+)

diff  --git a/flang/examples/HelloWorld/HelloWorldPlugin.cpp 
b/flang/examples/HelloWorld/HelloWorldPlugin.cpp
new file mode 100644
index 0..11100384aed9f
--- /dev/null
+++ b/flang/examples/HelloWorld/HelloWorldPlugin.cpp
@@ -0,0 +1,25 @@
+//===-- HelloWorldPlugin.cpp 
---

[clang] 2a7bb84 - [flang][driver] Add `-fno-analyzed-objects-for-unparse`

2021-06-25 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-06-25T13:28:12+01:00
New Revision: 2a7bb8494e9c58b44ad7142d8d309455cd669603

URL: 
https://github.com/llvm/llvm-project/commit/2a7bb8494e9c58b44ad7142d8d309455cd669603
DIFF: 
https://github.com/llvm/llvm-project/commit/2a7bb8494e9c58b44ad7142d8d309455cd669603.diff

LOG: [flang][driver] Add `-fno-analyzed-objects-for-unparse`

This patch adds a new option for the new Flang driver:
`-fno-analyzed-objects-for-unparse`. The semantics are similar to
`-funparse-typed-exprs-to-f18-fc` from `f18`. For consistency, the
latter is replaced with `-fno-analyzed-objects-for-unparse`.

The new option controls the behaviour of the unparser (i.e. the action
corresponding to `-fdebug-unparse`). The default behaviour is to use the
analyzed objects when unparsing. The new flag can be used to turn this
off, so that the original parse-tree objects are used. The analyzed
objects are generated during the semantic checks [1].

This patch also updates the semantics of
`-fno-analyzed-objects-for-unparse`/`-funparse-typed-exprs-to-f18-fc`
in `f18`, so that this flag is always taken into account when `Unparse`
is used (this way the semantics in `f18` and `flang-new` are identical).

The added test file is based on example from Peter Steinfeld.

[1]
https://github.com/llvm/llvm-project/blob/main/flang/docs/Semantics.md

Differential Revision: https://reviews.llvm.org/D103612

Added: 
flang/test/Driver/unparse-use-analyzed.f95

Modified: 
clang/include/clang/Driver/Options.td
flang/include/flang/Frontend/CompilerInvocation.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/Frontend/FrontendOptions.cpp
flang/test/Driver/driver-help.f90
flang/tools/f18/f18.cpp
flang/tools/f18/flang

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index cddc924dacd2e..0122afd2eeada 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4536,6 +4536,11 @@ def fget_symbols_sources : Flag<["-"], 
"fget-symbols-sources">, Group,  Group, 
MetaVarName<"">,
   HelpText<"Use  as the suffix for module files (the default value is 
`.mod`)">;
+def fanalyzed_objects_for_unparse : Flag<["-"],
+  "fanalyzed-objects-for-unparse">,  Group;
+def fno_analyzed_objects_for_unparse : Flag<["-"],
+  "fno-analyzed-objects-for-unparse">,  Group,
+  HelpText<"Do not use the analyzed objects when unparsing">;
 
 }
 

diff  --git a/flang/include/flang/Frontend/CompilerInvocation.h 
b/flang/include/flang/Frontend/CompilerInvocation.h
index f449a69dfa8a0..ad25c39b48507 100644
--- a/flang/include/flang/Frontend/CompilerInvocation.h
+++ b/flang/include/flang/Frontend/CompilerInvocation.h
@@ -75,11 +75,39 @@ class CompilerInvocation : public CompilerInvocationBase {
 
   bool warnAsErr_ = false;
 
+  /// This flag controls the unparsing and is used to decide whether to print 
out
+  /// the semantically analyzed version of an object or expression or the plain
+  /// version that does not include any information from semantic analysis.
+  bool useAnalyzedObjectsForUnparse_ = true;
+
   // Fortran Dialect options
   Fortran::common::IntrinsicTypeDefaultKinds defaultKinds_;
 
   bool EnableConformanceChecks_ = false;
 
+  /// Used in e.g. unparsing to dump the analyzed rather than the original
+  /// parse-tree objects.
+  Fortran::parser::AnalyzedObjectsAsFortran AsFortran_{
+  [](llvm::raw_ostream &o, const Fortran::evaluate::GenericExprWrapper &x) 
{
+if (x.v) {
+  x.v->AsFortran(o);
+} else {
+  o << "(bad expression)";
+}
+  },
+  [](llvm::raw_ostream &o,
+  const Fortran::evaluate::GenericAssignmentWrapper &x) {
+if (x.v) {
+  x.v->AsFortran(o);
+} else {
+  o << "(bad assignment)";
+}
+  },
+  [](llvm::raw_ostream &o, const Fortran::evaluate::ProcedureRef &x) {
+x.AsFortran(o << "CALL ");
+  },
+  };
+
 public:
   CompilerInvocation() = default;
 
@@ -108,11 +136,21 @@ class CompilerInvocation : public CompilerInvocationBase {
   bool &warnAsErr() { return warnAsErr_; }
   const bool &warnAsErr() const { return warnAsErr_; }
 
+  bool &useAnalyzedObjectsForUnparse() { return useAnalyzedObjectsForUnparse_; 
}
+  const bool &useAnalyzedObjectsForUnparse() const {
+return useAnalyzedObjectsForUnparse_;
+  }
+
   bool &enableConformanceChecks() { return EnableConformanceChecks_; }
   const bool &enableConformanceChecks() const {
 return EnableConformanceChecks_;
   }
 
+  Fortran::parser::AnalyzedObjectsAsFortran &asFortran() { return AsFortran_; }
+  const Fortran::parser::AnalyzedObjectsAsFortran &asFortran() const {
+return AsFortran_;
+  }
+
   Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds() {
 return defaultKinds_;
   }
@@ -142,6 +180,10 @@ 

[clang] 788a5d4 - PoC for Flang Driver Plugins

2021-07-01 Thread Andrzej Warzynski via cfe-commits

Author: Stuart Ellis
Date: 2021-07-01T08:10:40Z
New Revision: 788a5d4afe6407e647454a9832a7b4a27fba06bf

URL: 
https://github.com/llvm/llvm-project/commit/788a5d4afe6407e647454a9832a7b4a27fba06bf
DIFF: 
https://github.com/llvm/llvm-project/commit/788a5d4afe6407e647454a9832a7b4a27fba06bf.diff

LOG: PoC for Flang Driver Plugins

Added: 
flang/examples/HelloWorld/CMakeLists.txt
flang/examples/HelloWorld/HelloWorldPlugin.cpp
flang/include/flang/Frontend/FrontendPluginRegistry.h

Modified: 
clang/include/clang/Driver/Options.td
flang/CMakeLists.txt
flang/examples/CMakeLists.txt
flang/include/flang/Frontend/FrontendActions.h
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendAction.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
llvm/include/llvm/Support/Registry.h
llvm/lib/Support/DynamicLibrary.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 41b7299b02745..1629a74ae62c9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5221,10 +5221,6 @@ def enable_noundef_analysis : Flag<["-"], 
"enable-noundef-analysis">, Group,
   HelpText<"Discard value names in LLVM IR">,
   MarshallingInfoFlag>;
-def load : Separate<["-"], "load">, MetaVarName<"">,
-  HelpText<"Load the named plugin (dynamic shared object)">;
-def plugin : Separate<["-"], "plugin">, MetaVarName<"">,
-  HelpText<"Use the named plugin action instead of the default action (use 
\"help\" to list available options)">;
 def plugin_arg : JoinedAndSeparate<["-"], "plugin-arg-">,
 MetaVarName<" ">,
 HelpText<"Pass  to plugin ">;
@@ -5788,6 +5784,12 @@ def init_only : Flag<["-"], "init-only">,
   HelpText<"Only execute frontend initialization">;
 
 } // let Group = Action_Group
+
+def load : Separate<["-"], "load">, MetaVarName<"">,
+  HelpText<"Load the named plugin (dynamic shared object)">;
+def plugin : Separate<["-"], "plugin">, MetaVarName<"">,
+  HelpText<"Use the named plugin action instead of the default action (use 
\"help\" to list available options)">;
+
 } // let Flags = [CC1Option, FC1Option, NoDriverOption]
 
 
//===--===//

diff  --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index adf3dc819dc93..d9495c4748ce5 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -390,7 +390,6 @@ endif()
 include(CMakeParseArguments)
 include(AddFlang)
 
-
 add_subdirectory(include)
 add_subdirectory(lib)
 add_subdirectory(cmake/modules)

diff  --git a/flang/examples/CMakeLists.txt b/flang/examples/CMakeLists.txt
index 3ca9feddf33e9..f896874f7f89b 100644
--- a/flang/examples/CMakeLists.txt
+++ b/flang/examples/CMakeLists.txt
@@ -6,3 +6,5 @@ add_executable(external-hello-world
 target_link_libraries(external-hello-world
   FortranRuntime
 )
+#add_subdirectory(HelloEarth)
+add_subdirectory(HelloWorld)

diff  --git a/flang/examples/HelloWorld/CMakeLists.txt 
b/flang/examples/HelloWorld/CMakeLists.txt
new file mode 100644
index 0..eb716c2f17b49
--- /dev/null
+++ b/flang/examples/HelloWorld/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_llvm_library(
+flangHelloWorldPlugin
+MODULE
+HelloWorldPlugin.cpp
+
+DEPENDS
+clangBasic
+
+LINK_COMPONENTS
+Option
+Support
+)

diff  --git a/flang/examples/HelloWorld/HelloWorldPlugin.cpp 
b/flang/examples/HelloWorld/HelloWorldPlugin.cpp
new file mode 100644
index 0..30d23ce104227
--- /dev/null
+++ b/flang/examples/HelloWorld/HelloWorldPlugin.cpp
@@ -0,0 +1,18 @@
+#include "flang/Frontend/FrontendActions.h"
+#include "flang/Frontend/FrontendPluginRegistry.h"
+
+__attribute__((constructor))
+static void printing() {
+  llvm::outs() << "  > Plugin Constructed\n";
+}
+
+using namespace Fortran::frontend;
+
+class HelloWorldFlangPlugin : public PluginParseTreeAction
+{
+void ExecuteAction() override {
+  llvm::outs() << "Hello World from your new plugin (Remote plugin)\n";
+}
+};
+
+static FrontendPluginRegistry::Add X("-hello-w", "Hello 
World Plugin example");

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index 72eb44223fe49..d30ae1dbed0ff 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -30,6 +30,10 @@ struct MeasurementVisitor {
 // Custom Consumer Actions
 
//===--===//
 
+class PluginParseTreeAction : public FrontendAction {
+  void ExecuteAction() override;
+};
+
 class InputOutputTestAction : public FrontendAction {
   void ExecuteAction() override;
 };

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/f

[clang] c1f068b - [flang] Revert "PoC for Flang Driver Plugins"

2021-07-01 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-07-01T08:27:31Z
New Revision: c1f068b8f1d5f6ca75acc07fdedf2e7416e834ec

URL: 
https://github.com/llvm/llvm-project/commit/c1f068b8f1d5f6ca75acc07fdedf2e7416e834ec
DIFF: 
https://github.com/llvm/llvm-project/commit/c1f068b8f1d5f6ca75acc07fdedf2e7416e834ec.diff

LOG: [flang] Revert "PoC for Flang Driver Plugins"

This patch has not been reviewed and was commited by accident.

This reverts commit 788a5d4afe6407e647454a9832a7b4a27fba06bf.

Added: 


Modified: 
clang/include/clang/Driver/Options.td
flang/CMakeLists.txt
flang/examples/CMakeLists.txt
flang/include/flang/Frontend/FrontendActions.h
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendAction.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
llvm/include/llvm/Support/Registry.h
llvm/lib/Support/DynamicLibrary.cpp

Removed: 
flang/examples/HelloWorld/CMakeLists.txt
flang/examples/HelloWorld/HelloWorldPlugin.cpp
flang/include/flang/Frontend/FrontendPluginRegistry.h



diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1629a74ae62c9..41b7299b02745 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5221,6 +5221,10 @@ def enable_noundef_analysis : Flag<["-"], 
"enable-noundef-analysis">, Group,
   HelpText<"Discard value names in LLVM IR">,
   MarshallingInfoFlag>;
+def load : Separate<["-"], "load">, MetaVarName<"">,
+  HelpText<"Load the named plugin (dynamic shared object)">;
+def plugin : Separate<["-"], "plugin">, MetaVarName<"">,
+  HelpText<"Use the named plugin action instead of the default action (use 
\"help\" to list available options)">;
 def plugin_arg : JoinedAndSeparate<["-"], "plugin-arg-">,
 MetaVarName<" ">,
 HelpText<"Pass  to plugin ">;
@@ -5784,12 +5788,6 @@ def init_only : Flag<["-"], "init-only">,
   HelpText<"Only execute frontend initialization">;
 
 } // let Group = Action_Group
-
-def load : Separate<["-"], "load">, MetaVarName<"">,
-  HelpText<"Load the named plugin (dynamic shared object)">;
-def plugin : Separate<["-"], "plugin">, MetaVarName<"">,
-  HelpText<"Use the named plugin action instead of the default action (use 
\"help\" to list available options)">;
-
 } // let Flags = [CC1Option, FC1Option, NoDriverOption]
 
 
//===--===//

diff  --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index d9495c4748ce5..adf3dc819dc93 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -390,6 +390,7 @@ endif()
 include(CMakeParseArguments)
 include(AddFlang)
 
+
 add_subdirectory(include)
 add_subdirectory(lib)
 add_subdirectory(cmake/modules)

diff  --git a/flang/examples/CMakeLists.txt b/flang/examples/CMakeLists.txt
index f896874f7f89b..3ca9feddf33e9 100644
--- a/flang/examples/CMakeLists.txt
+++ b/flang/examples/CMakeLists.txt
@@ -6,5 +6,3 @@ add_executable(external-hello-world
 target_link_libraries(external-hello-world
   FortranRuntime
 )
-#add_subdirectory(HelloEarth)
-add_subdirectory(HelloWorld)

diff  --git a/flang/examples/HelloWorld/CMakeLists.txt 
b/flang/examples/HelloWorld/CMakeLists.txt
deleted file mode 100644
index eb716c2f17b49..0
--- a/flang/examples/HelloWorld/CMakeLists.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-add_llvm_library(
-flangHelloWorldPlugin
-MODULE
-HelloWorldPlugin.cpp
-
-DEPENDS
-clangBasic
-
-LINK_COMPONENTS
-Option
-Support
-)

diff  --git a/flang/examples/HelloWorld/HelloWorldPlugin.cpp 
b/flang/examples/HelloWorld/HelloWorldPlugin.cpp
deleted file mode 100644
index 30d23ce104227..0
--- a/flang/examples/HelloWorld/HelloWorldPlugin.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "flang/Frontend/FrontendActions.h"
-#include "flang/Frontend/FrontendPluginRegistry.h"
-
-__attribute__((constructor))
-static void printing() {
-  llvm::outs() << "  > Plugin Constructed\n";
-}
-
-using namespace Fortran::frontend;
-
-class HelloWorldFlangPlugin : public PluginParseTreeAction
-{
-void ExecuteAction() override {
-  llvm::outs() << "Hello World from your new plugin (Remote plugin)\n";
-}
-};
-
-static FrontendPluginRegistry::Add X("-hello-w", "Hello 
World Plugin example");

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index d30ae1dbed0ff..72eb44223fe49 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -30,10 +30,6 @@ struct MeasurementVisitor {
 // Custom Consumer Actions
 
//===--===//
 
-class PluginParseTreeAction : public FrontendAction {
-  void ExecuteAction() override;
-};
-
 c

[clang] ab971c2 - [flang][driver] Add options for -fdefault* and -flarge-sizes

2021-03-04 Thread Andrzej Warzynski via cfe-commits

Author: Arnamoy Bhattacharyya
Date: 2021-03-04T13:29:07Z
New Revision: ab971c29a56a4c24359b499d05c30c8c9fc4dea3

URL: 
https://github.com/llvm/llvm-project/commit/ab971c29a56a4c24359b499d05c30c8c9fc4dea3
DIFF: 
https://github.com/llvm/llvm-project/commit/ab971c29a56a4c24359b499d05c30c8c9fc4dea3.diff

LOG: [flang][driver] Add options for -fdefault* and -flarge-sizes

Add support for the following Fortran dialect options:
  - -default*
  - -flarge-sizes

It also adds two test cases:
  # For checking whether `flang-new` is passing options correctly to `flang-new 
-fc1`.
  # For checking if `fdefault-` arguments are processed properly.

Also moves the Dialect related option parsing to a dedicated function
and adds a member `defaultKinds()` to `CompilerInvocation`

Depends on: D96032

Differential Revision: https://reviews.llvm.org/D96344

Added: 
flang/test/Flang-Driver/fdefault.f90
flang/test/Flang-Driver/flarge_sizes.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/CompilerInvocation.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Flang-Driver/driver-help-hidden.f90
flang/test/Flang-Driver/driver-help.f90
flang/test/Flang-Driver/frontend-forwarding.f90
flang/unittests/Frontend/CMakeLists.txt

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2f57895d4c23..583d08151e1a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4238,9 +4238,6 @@ defm check_array_temporaries : 
BooleanFFlag<"check-array-temporaries">, Group, Group;
 defm d_lines_as_code : BooleanFFlag<"d-lines-as-code">, Group;
 defm d_lines_as_comments : BooleanFFlag<"d-lines-as-comments">, 
Group;
-defm default_double_8 : BooleanFFlag<"default-double-8">, 
Group;
-defm default_integer_8 : BooleanFFlag<"default-integer-8">, 
Group;
-defm default_real_8 : BooleanFFlag<"default-real-8">, Group;
 defm dollar_ok : BooleanFFlag<"dollar-ok">, Group;
 defm dump_fortran_optimized : BooleanFFlag<"dump-fortran-optimized">, 
Group;
 defm dump_fortran_original : BooleanFFlag<"dump-fortran-original">, 
Group;
@@ -4307,6 +4304,14 @@ file}]>;
 def ffixed_line_length_VALUE : Joined<["-"], "ffixed-line-length-">, 
Group, Alias;
 def fopenacc : Flag<["-"], "fopenacc">, Group,
   HelpText<"Enable OpenACC">;
+def fdefault_double_8 : Flag<["-"],"fdefault-double-8">, Group,
+  HelpText<"Set the default double precision kind to an 8 byte wide type">;
+def fdefault_integer_8 : Flag<["-"],"fdefault-integer-8">, Group,
+  HelpText<"Set the default integer kind to an 8 byte wide type">;
+def fdefault_real_8 : Flag<["-"],"fdefault-real-8">, Group,
+  HelpText<"Set the default real kind to an 8 byte wide type">;
+def flarge_sizes : Flag<["-"],"flarge-sizes">, Group,
+  HelpText<"Use INTEGER(KIND=8) for the result type in size-related 
intrinsics">;
 def fbackslash : Flag<["-"], "fbackslash">, Group,
   HelpText<"Specify that backslash in string introduces an escape character">,
   DocBrief<[{Change the interpretation of backslashes in string literals from

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index b79b94a11956..1a812589d473 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -21,16 +21,18 @@ using namespace llvm::opt;
 
 void Flang::AddFortranDialectOptions(const ArgList &Args,
  ArgStringList &CmdArgs) const {
-  Args.AddAllArgs(CmdArgs,
-  {options::OPT_ffixed_form, options::OPT_ffree_form,
-   options::OPT_ffixed_line_length_EQ, options::OPT_fopenmp,
-   options::OPT_fopenacc, options::OPT_finput_charset_EQ,
-   options::OPT_fimplicit_none, options::OPT_fno_implicit_none,
-   options::OPT_fbackslash, options::OPT_fno_backslash,
-   options::OPT_flogical_abbreviations,
-   options::OPT_fno_logical_abbreviations,
-   options::OPT_fxor_operator, options::OPT_fno_xor_operator,
-   options::OPT_falternative_parameter_statement});
+  Args.AddAllArgs(
+  CmdArgs, {options::OPT_ffixed_form, options::OPT_ffree_form,
+options::OPT_ffixed_line_length_EQ, options::OPT_fopenmp,
+options::OPT_fopenacc, options::OPT_finput_charset_EQ,
+options::OPT_fimplicit_none, options::OPT_fno_implicit_none,
+options::OPT_fbackslash, options::OPT_fno_backslash,
+options::OPT_flogical_abbreviations,
+options::OPT_fno_logical_abbreviations,
+options::OPT_fxor_operator, options::OPT_fno_xor_operator,
+options::OPT_falternative_parameter_statement,
+options::OPT_fdefault_real_

[clang] 523d7bc - [flang][driver] Add `-fdebug-dump-parsing-log`

2021-03-10 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-03-10T12:09:16Z
New Revision: 523d7bc6f427f9ae32e54dbf1764826cfb269d21

URL: 
https://github.com/llvm/llvm-project/commit/523d7bc6f427f9ae32e54dbf1764826cfb269d21
DIFF: 
https://github.com/llvm/llvm-project/commit/523d7bc6f427f9ae32e54dbf1764826cfb269d21.diff

LOG: [flang][driver] Add `-fdebug-dump-parsing-log`

This patch adds `-fdebug-dump-parsing-log` in the new driver. This option is
semantically identical to `-fdebug-instrumented-parse` in `f18` (the
former is added as an alias in `f18`).

As dumping the parsing log makes only sense for instrumented parses, we
set Fortran::parser::Options::instrumentedParse to `True` when
`-fdebug-dump-parsing-log` is used. This is consistent with `f18`.

To facilitate tweaking the configuration of the frontend based on the
action being requested, `setUpFrontendBasedOnAction` is introduced in
CompilerInvocation.cpp.

Differential Revision: https://reviews.llvm.org/D97457

Added: 
flang/test/Driver/debug-parsing-log.f90

Modified: 
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/Driver/driver-help.f90
flang/tools/f18/f18.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 8e71aff2e96d..376a3baf0a4b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4361,6 +4361,8 @@ def fdebug_dump_parse_tree : Flag<["-"], 
"fdebug-dump-parse-tree">, Group;
 def fdebug_dump_provenance : Flag<["-"], "fdebug-dump-provenance">, 
Group,
   HelpText<"Dump provenance">;
+def fdebug_dump_parsing_log : Flag<["-"], "fdebug-dump-parsing-log">, 
Group,
+  HelpText<"Run instrumented parse and dump the parsing log">;
 def fdebug_measure_parse_tree : Flag<["-"], "fdebug-measure-parse-tree">, 
Group,
   HelpText<"Measure the parse tree">;
 def fdebug_pre_fir_tree : Flag<["-"], "fdebug-pre-fir-tree">, 
Group,

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index f6dfdd2dc09b..35d1e6f29b0f 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -54,6 +54,10 @@ class DebugDumpProvenanceAction : public PrescanAction {
   void ExecuteAction() override;
 };
 
+class DebugDumpParsingLogAction : public PrescanAction {
+  void ExecuteAction() override;
+};
+
 class DebugMeasureParseTreeAction : public PrescanAction {
   void ExecuteAction() override;
 };

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index 98a717dfa6ec..48182f488466 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -50,6 +50,9 @@ enum ActionKind {
   /// Dump provenance
   DebugDumpProvenance,
 
+  /// Parse then output the parsing log
+  DebugDumpParsingLog,
+
   /// Parse then output the number of objects in the parse tree and the overall
   /// size
   DebugMeasureParseTree,
@@ -172,6 +175,9 @@ class FrontendOptions {
   /// 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 inputs_;
 

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 0dc7e7c3d395..17649700e0d2 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -85,6 +85,15 @@ bool 
Fortran::frontend::ParseDiagnosticArgs(clang::DiagnosticOptions &opts,
   return true;
 }
 
+// Tweak the frontend configuration based on the frontend action
+static void setUpFrontendBasedOnAction(FrontendOptions &opts) {
+  assert(opts.programAction_ != Fortran::frontend::InvalidAction &&
+  "Fortran frontend action not set!");
+
+  if (opts.programAction_ == DebugDumpParsingLog)
+opts.instrumentedParse_ = true;
+}
+
 static InputKind ParseFrontendArgs(FrontendOptions &opts,
 llvm::opt::ArgList &args, clang::DiagnosticsEngine &diags) {
 
@@ -125,6 +134,9 @@ static InputKind ParseFrontendArgs(FrontendOptions &opts,
 case clang::driver::options::OPT_fdebug_dump_provenance:
   opts.programAction_ = DebugDumpProvenance;
   break;
+case clang::driver::options::OPT_fdebug_dump_parsing_log:
+  opts.programAction_ = DebugDumpParsingLog;
+  break;
 case clang::driver::options::OPT_fdebug_measure_parse_tree:
   opts.programAction_ = DebugMeasureParseTree;
   break;
@@ -264,6 +276,9 @@ static InputKind ParseFrontendArgs(FrontendOptions &opts,
   << arg->getAsStrin

[clang] 174e954 - [flang][nfc] Rename `AddOtherOptions` as `ForwardOptions`

2022-10-14 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-10-14T16:20:04Z
New Revision: 174e954e370e4f2ae82fea3f959e843bc05e3046

URL: 
https://github.com/llvm/llvm-project/commit/174e954e370e4f2ae82fea3f959e843bc05e3046
DIFF: 
https://github.com/llvm/llvm-project/commit/174e954e370e4f2ae82fea3f959e843bc05e3046.diff

LOG: [flang][nfc] Rename `AddOtherOptions` as `ForwardOptions`

The updated name better reflects what this hook is intended for.

Reviewed By: tarunprabhu

Differential Revision: https://reviews.llvm.org/D130078

Added: 


Modified: 
clang/lib/Driver/ToolChains/Flang.cpp
clang/lib/Driver/ToolChains/Flang.h

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index d7ac459db5f5..964f0e261704 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -27,7 +27,7 @@ static void addDashXForInput(const ArgList &Args, const 
InputInfo &Input,
   CmdArgs.push_back(types::getTypeName(Input.getType()));
 }
 
-void Flang::AddFortranDialectOptions(const ArgList &Args,
+void Flang::addFortranDialectOptions(const ArgList &Args,
  ArgStringList &CmdArgs) const {
   Args.AddAllArgs(
   CmdArgs, {options::OPT_ffixed_form, options::OPT_ffree_form,
@@ -44,14 +44,14 @@ void Flang::AddFortranDialectOptions(const ArgList &Args,
 options::OPT_fno_automatic});
 }
 
-void Flang::AddPreprocessingOptions(const ArgList &Args,
+void Flang::addPreprocessingOptions(const ArgList &Args,
 ArgStringList &CmdArgs) const {
   Args.AddAllArgs(CmdArgs,
   {options::OPT_P, options::OPT_D, options::OPT_U,
options::OPT_I, options::OPT_cpp, options::OPT_nocpp});
 }
 
-void Flang::AddOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const 
{
+void Flang::forwardOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
   Args.AddAllArgs(CmdArgs,
   {options::OPT_module_dir, options::OPT_fdebug_module_writer,
options::OPT_fintrinsic_modules_path, options::OPT_pedantic,
@@ -127,9 +127,9 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // Add preprocessing options like -I, -D, etc. if we are using the
   // preprocessor (i.e. skip when dealing with e.g. binary files).
   if (types::getPreprocessedType(InputType) != types::TY_INVALID)
-AddPreprocessingOptions(Args, CmdArgs);
+addPreprocessingOptions(Args, CmdArgs);
 
-  AddFortranDialectOptions(Args, CmdArgs);
+  addFortranDialectOptions(Args, CmdArgs);
 
   // Color diagnostics are parsed by the driver directly from argv and later
   // re-parsed to construct this job; claim any possible color diagnostic here
@@ -142,8 +142,8 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // -fPIC and related options.
   AddPicOptions(Args, CmdArgs);
 
-  // Add other compile options
-  AddOtherOptions(Args, CmdArgs);
+  // Handle options which are simply forwarded to -fc1.
+  forwardOptions(Args, CmdArgs);
 
   // Forward -Xflang arguments to -fc1
   Args.AddAllArgValues(CmdArgs, options::OPT_Xflang);

diff  --git a/clang/lib/Driver/ToolChains/Flang.h 
b/clang/lib/Driver/ToolChains/Flang.h
index c5ac147da768..4d8e2e8ee5aa 100644
--- a/clang/lib/Driver/ToolChains/Flang.h
+++ b/clang/lib/Driver/ToolChains/Flang.h
@@ -29,7 +29,7 @@ class LLVM_LIBRARY_VISIBILITY Flang : public Tool {
   ///
   /// \param [in] Args The list of input driver arguments
   /// \param [out] CmdArgs The list of output command arguments
-  void AddFortranDialectOptions(const llvm::opt::ArgList &Args,
+  void addFortranDialectOptions(const llvm::opt::ArgList &Args,
 llvm::opt::ArgStringList &CmdArgs) const;
 
   /// Extract preprocessing options from the driver arguments and add them to
@@ -37,7 +37,7 @@ class LLVM_LIBRARY_VISIBILITY Flang : public Tool {
   ///
   /// \param [in] Args The list of input driver arguments
   /// \param [out] CmdArgs The list of output command arguments
-  void AddPreprocessingOptions(const llvm::opt::ArgList &Args,
+  void addPreprocessingOptions(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const;
 
   /// Extract PIC options from the driver arguments and add them to
@@ -48,13 +48,12 @@ class LLVM_LIBRARY_VISIBILITY Flang : public Tool {
   void AddPicOptions(const llvm::opt::ArgList &Args,
  llvm::opt::ArgStringList &CmdArgs) const;
 
-  /// Extract other compilation options from the driver arguments and add them
-  /// to the command arguments.
+  /// This method will effectively copy options from \a Args into \a CmdArgs.
   ///
   /// \param [in] Args The list of input driver arguments
   /// \param [out] CmdArgs The list of output command arguments
-  void AddOtherOptions(const llvm::opt::ArgList &Args,
- 

[clang] 3e782ba - [flang][driver] Fix support for `-x`

2022-06-10 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-06-10T10:36:25Z
New Revision: 3e782ba21be4b88c761d3b0854df130d7ca08a56

URL: 
https://github.com/llvm/llvm-project/commit/3e782ba21be4b88c761d3b0854df130d7ca08a56
DIFF: 
https://github.com/llvm/llvm-project/commit/3e782ba21be4b88c761d3b0854df130d7ca08a56.diff

LOG: [flang][driver] Fix support for `-x`

Until now, `-x` wasn't really taken into account in Flang's compiler and
frontend drivers. `flang-new` and `flang-new -fc1` only recently gained
powers to consume inputs other than Fortran files and that's probably
why this hasn't been noticed yet.

This patch makes sure that `-x` is supported correctly and consistently
with Clang. To this end, verification is added when reading LLVM IR
files (i.e. IR modules are verified with `llvm::verifyModule`). This
way, LLVM IR parsing errors are correctly reported to Flang users. This
also aids testing.

With the new functionality, we can verify that `-x ir` breaks
compilation for e.g. Fortran files and vice-versa. Tests are updated
accordingly.

Differential Revision: https://reviews.llvm.org/D127207

Added: 
flang/test/Driver/input-from-stdin-llvm.ll
flang/test/Driver/parse-error.ll
flang/test/Driver/parse-ir-error.f95

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/test/Driver/input-from-stdin.f90
flang/test/Driver/linker-flags.f90

Removed: 
flang/test/Driver/parse-error.f95



diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6707714f170b3..95840760f7746 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4166,7 +4166,8 @@ def why_load : Flag<["-"], "why_load">;
 def whyload : Flag<["-"], "whyload">, Alias;
 def w : Flag<["-"], "w">, HelpText<"Suppress all warnings">, 
Flags<[CC1Option]>,
   MarshallingInfoFlag>;
-def x : JoinedOrSeparate<["-"], "x">, Flags<[NoXarchOption,CC1Option]>,
+def x : JoinedOrSeparate<["-"], "x">,
+Flags<[NoXarchOption,CC1Option,FlangOption,FC1Option]>,
   HelpText<"Treat subsequent input files as having type ">,
   MetaVarName<"">;
 def y : Joined<["-"], "y">;

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 63e3c080a7e7f..ab9287d880a95 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -19,6 +19,14 @@ using namespace clang::driver::tools;
 using namespace clang;
 using namespace llvm::opt;
 
+/// Add -x lang to \p CmdArgs for \p Input.
+static void addDashXForInput(const ArgList &Args, const InputInfo &Input,
+ ArgStringList &CmdArgs) {
+  CmdArgs.push_back("-x");
+  // Map the driver type to the frontend type.
+  CmdArgs.push_back(types::getTypeName(Input.getType()));
+}
+
 void Flang::AddFortranDialectOptions(const ArgList &Args,
  ArgStringList &CmdArgs) const {
   Args.AddAllArgs(
@@ -126,6 +134,9 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
   }
 
   assert(Input.isFilename() && "Invalid input.");
+
+  addDashXForInput(Args, Input, CmdArgs);
+
   CmdArgs.push_back(Input.getFilename());
 
   const auto& D = C.getDriver();

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 9ea4810d64950..cc376f3b7d851 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -263,7 +263,10 @@ static bool parseFrontendArgs(FrontendOptions &opts, 
llvm::opt::ArgList &args,
 llvm::StringRef xValue = a->getValue();
 // Principal languages.
 dashX = llvm::StringSwitch(xValue)
-.Case("f90", Language::Fortran)
+// Flang does not 
diff erentiate between pre-processed and not
+// pre-processed inputs.
+.Case("f95", Language::Fortran)
+.Case("f95-cpp-input", Language::Fortran)
 .Default(Language::Unknown);
 
 // Some special cases cannot be combined with suffixes.

diff  --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index 334849ceeb54c..57b6203f94b2e 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -41,6 +41,7 @@
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Bitcode/BitcodeWriterPass.h"
 #include "llvm/IR/LegacyPassManager.h"
+#include "llvm/IR/Verifier.h"
 #include "llvm/IRReader/IRReader.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Passes/PassBuilder.h"
@@ -78,25 +79,36 @@ bool PrescanAndSemaDebugAction::beginSourceFileAction() {
 
 bool CodeGenAction::beginSourceFileAction() {
   llvmCtx = std::make_unique();
+  CompilerInstance &ci = this->getInstance();
 
   // If the

[clang] 83a0699 - [flang][driver] Update the visibility of Clang options in Flang

2023-08-17 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2023-08-17T19:12:12Z
New Revision: 83a06997c69a17def2f58fd556c094b8f1060b89

URL: 
https://github.com/llvm/llvm-project/commit/83a06997c69a17def2f58fd556c094b8f1060b89
DIFF: 
https://github.com/llvm/llvm-project/commit/83a06997c69a17def2f58fd556c094b8f1060b89.diff

LOG: [flang][driver] Update the visibility of Clang options in Flang

Prior to D157151, there was no mechanism to "disable" unsupported Clang
options in Flang. While the "help" text (`flang-new -help`) was indeed
configured not to display such options, the Flang compiler driver would
happily consume such options and only issue a warning when there was no
logic to parse it:
```
flang-new -fno-experimental-relative-c++-abi-vtables file.f90
flang-new: warning: argument unused during compilation: 
'-fno-experimental-relative-c++-abi-vtables'
```

D157151 introduces visibility flags. In particular, all Clang options
gain a visibility flag (`ClangOption`) that can be excluded when in
Flang driver mode. This way the above invocation will lead to:

```
flang-new: error: unknown argument 
'-fno-experimental-relative-c++-abi-vtables'; did you mean '-Xclang 
-fno-experimental-relative-c++-abi-vtables'?
```

This won't work unless all options/flags supported by Flang have their
visibility flags updated accordingly, hence the changes in Options.td.
Moving forward, this change will allow Flang better control over the
supported options.

Depends on D157151

Differential Revision: https://reviews.llvm.org/D157837

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/test/Driver/flang/flang.f90
clang/test/Driver/flang/flang_ucase.F90
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
flang/test/Driver/fast_math.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 85ce340255d99a..0ef80dafd0586b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -615,8 +615,8 @@ class InternalDriverOpt : Group,
   Flags<[NoXarchOption, HelpHidden]>;
 def driver_mode : Joined<["--"], "driver-mode=">, Group,
   Flags<[NoXarchOption, HelpHidden]>,
-  Visibility<[ClangOption, CLOption, DXCOption]>,
-  HelpText<"Set the driver mode to either 'gcc', 'g++', 'cpp', or 'cl'">;
+  Visibility<[ClangOption, FlangOption, CLOption, DXCOption]>,
+  HelpText<"Set the driver mode to either 'gcc', 'g++', 'cpp', 'cl' or 
'flang'">;
 def rsp_quoting : Joined<["--"], "rsp-quoting=">, Group,
   Flags<[NoXarchOption, HelpHidden]>,
   Visibility<[ClangOption, CLOption, DXCOption]>,
@@ -630,7 +630,9 @@ class InternalDebugOpt : Group,
   Visibility<[ClangOption, CLOption, DXCOption]>;
 def ccc_install_dir : Separate<["-"], "ccc-install-dir">, InternalDebugOpt,
   HelpText<"Simulate installation in the given directory">;
-def ccc_print_phases : Flag<["-"], "ccc-print-phases">, InternalDebugOpt,
+def ccc_print_phases : Flag<["-"], "ccc-print-phases">,
+  Flags<[NoXarchOption, HelpHidden]>, Visibility<[ClangOption, CLOption, 
DXCOption,
+  FlangOption]>,
   HelpText<"Dump list of actions to perform">;
 def ccc_print_bindings : Flag<["-"], "ccc-print-bindings">, InternalDebugOpt,
   HelpText<"Show bindings of tools to actions">;
@@ -849,15 +851,15 @@ def MV : Flag<["-"], "MV">, Group, 
Visibility<[ClangOption, CC1Option]>
 Normalizer<"makeFlagToValueNormalizer(DependencyOutputFormat::NMake)">;
 def Mach : Flag<["-"], "Mach">, Group;
 def O0 : Flag<["-"], "O0">, Group, Flags<[HelpHidden]>,
-  Visibility<[ClangOption, CC1Option, FC1Option]>;
+  Visibility<[ClangOption, CC1Option, FC1Option, FlangOption]>;
 def O4 : Flag<["-"], "O4">, Group, Flags<[HelpHidden]>,
-  Visibility<[ClangOption, CC1Option, FC1Option]>;
+  Visibility<[ClangOption, CC1Option, FC1Option, FlangOption]>;
 def ObjCXX : Flag<["-"], "ObjC++">, Flags<[NoXarchOption]>,
   HelpText<"Treat source input files as Objective-C++ inputs">;
 def ObjC : Flag<["-"], "ObjC">, Flags<[NoXarchOption]>,
   HelpText<"Treat source input files as Objective-C inputs">;
 def O : Joined<["-"], "O">, Group,
-  Visibility<[ClangOption, CC1Option, FC1Option]>;
+  Visibility<[ClangOption, CC1Option, FC1Option, FlangOption]>;
 def O_flag : Flag<["-"], "O">, Visibility<[ClangOption, CC1Option, FC1Option]>,
   Alias, AliasArgs<["1"]>;
 def Ofast : Joined<["-"], "Ofast">, Group,
@@ -893,7 +895,7 @@ def Wa_COMMA : CommaJoined<["-"], "Wa,">,
   HelpText<"Pass the comma separated arguments in  to the assembler">,
   MetaVarName<"">;
 def Wall : Flag<["-"], "Wall">, Group, Flags<[HelpHidden]>,
-  Visibility<[ClangOption, CC1Option]>;
+  Visibility<[ClangOption, CC1Option, FlangOption]>;
 def WCL4 : Flag<["-"], "WCL4">, Group, Flags<[HelpHidden]>,
   Visibility<[ClangOption, CC1Option]>;
 def Wsystem_headers : Flag<["-"], "Wsystem-headers">, Group,
@@ -109

[clang] 3b28dce - [flang][driver] Mark the remaining Flang options as FlangOption

2023-08-18 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2023-08-18T10:48:55Z
New Revision: 3b28dce6daa4e70694cfe9df4526c9e6ee40b87e

URL: 
https://github.com/llvm/llvm-project/commit/3b28dce6daa4e70694cfe9df4526c9e6ee40b87e
DIFF: 
https://github.com/llvm/llvm-project/commit/3b28dce6daa4e70694cfe9df4526c9e6ee40b87e.diff

LOG: [flang][driver] Mark the remaining Flang options as FlangOption

This is a follow-up of https://reviews.llvm.org/D157837 in which I
missed a few Flang options in Options.td. This patch simply updates the
remaining options that are already supported by Flang with the relevant
visibility flag:

Fixes:
  * https://lab.llvm.org/buildbot/#/builders/191/builds/22241

Added: 


Modified: 
clang/include/clang/Driver/Options.td
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index df2e2adef17dde..acdb206c18d128 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1395,10 +1395,6 @@ def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, 
Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">,
   MarshallingInfoInt>;
-def fPIC : Flag<["-"], "fPIC">, Group;
-def fno_PIC : Flag<["-"], "fno-PIC">, Group;
-def fPIE : Flag<["-"], "fPIE">, Group;
-def fno_PIE : Flag<["-"], "fno-PIE">, Group;
 defm access_control : BoolFOption<"access-control",
   LangOpts<"AccessControl">, DefaultTrue,
   NegFlag, Group,
   Visibility<[ClangOption, CC1Option]>,
   HelpText<"Override the default ABI to return all structs on the stack">;
 def fpch_preprocess : Flag<["-"], "fpch-preprocess">, Group;
-def fpic : Flag<["-"], "fpic">, Group;
-def fno_pic : Flag<["-"], "fno-pic">, Group;
-def fpie : Flag<["-"], "fpie">, Visibility<[ClangOption, FlangOption]>, 
Group;
-def fno_pie : Flag<["-"], "fno-pie">, Visibility<[ClangOption, FlangOption]>, 
Group;
 defm pic_data_is_text_relative : SimpleMFlag<"pic-data-is-text-relative",
  "Assume", "Don't assume", " data segments are relative to text segment">;
 def fdirect_access_external_data : Flag<["-"], 
"fdirect-access-external-data">, Group,
@@ -3386,12 +3378,12 @@ defm plt : BoolFOption<"plt",
   PosFlag>;
 defm ropi : BoolFOption<"ropi",
   LangOpts<"ROPI">, DefaultFalse,
-  PosFlag,
   NegFlag>;
 defm rwpi : BoolFOption<"rwpi",
   LangOpts<"RWPI">, DefaultFalse,
-  PosFlag,
   NegFlag>;
 def fplugin_EQ : Joined<["-"], "fplugin=">, Group,
@@ -4254,7 +4246,6 @@ def mguard_EQ : Joined<["-"], "mguard=">, Group,
   Values<"none,cf,cf-nochecks">;
 def mmcu_EQ : Joined<["-"], "mmcu=">, Group;
 def msim : Flag<["-"], "msim">, Group;
-def mdynamic_no_pic : Joined<["-"], "mdynamic-no-pic">, Group;
 def mfix_and_continue : Flag<["-"], "mfix-and-continue">, 
Group;
 def mieee_fp : Flag<["-"], "mieee-fp">, Group;
 def minline_all_stringops : Flag<["-"], "minline-all-stringops">, 
Group;
@@ -5277,7 +5268,7 @@ def undef : Flag<["-"], "undef">, Group,
 def unexported__symbols__list : Separate<["-"], "unexported_symbols_list">;
 def u : JoinedOrSeparate<["-"], "u">, Group;
 def v : Flag<["-"], "v">,
-  Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
+  Visibility<[ClangOption, CC1Option, CLOption, DXCOption, FlangOption]>,
   HelpText<"Show commands to run and use verbose output">,
   MarshallingInfoFlag>;
 def altivec_src_compat : Joined<["-"], "faltivec-src-compat=">,
@@ -5469,6 +5460,22 @@ def _help_hidden : Flag<["--"], "help-hidden">,
 def _sysroot_EQ : Joined<["--"], "sysroot=">, Visibility<[ClangOption, 
FlangOption]>;
 def _sysroot : Separate<["--"], "sysroot">, Alias<_sysroot_EQ>;
 
+//===--===//
+// pie/pic options (clang + flang-new)
+//===--===//
+let Visibility = [ClangOption, FlangOption] in {
+
+def fPIC : Flag<["-"], "fPIC">, Group;
+def fno_PIC : Flag<["-"], "fno-PIC">, Group;
+def fPIE : Flag<["-"], "fPIE">, Group;
+def fno_PIE : Flag<["-"], "fno-PIE">, Group;
+def fpic : Flag<["-"], "fpic">, Group;
+def fno_pic : Flag<["-"], "fno-pic">, Group;
+def fpie : Flag<["-"], "fpie">, Group;
+def fno_pie : Flag<["-"], "fno-pie">, Group;
+
+} // let Vis = [Default, FlangOption]
+
 
//===--===//
 // Target Options (clang + flang-new)
 
//===--===//
@@ -5477,6 +5484,7 @@ let Visibility = [ClangOption, FlangOption] in {
 
 def mcpu_EQ : Joined<["-"], "mcpu=">, Group,
   HelpText<"For a list of available CPUs for the target use '-mcpu=help'">;
+def mdynamic_no_pic : Joined<["-"], "mdynamic-no-pic">, Group;
 
 } // let Vis = [Default, FlangOption]
 } // let Flags = [TargetSpecific]

diff  --gi

[clang] 6cfbfb4 - [flang][driver] Add `-l` to the list of "visble" flags

2023-08-18 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2023-08-18T13:48:23Z
New Revision: 6cfbfb44cb8c140b1b74a3288ed32808bbc066d3

URL: 
https://github.com/llvm/llvm-project/commit/6cfbfb44cb8c140b1b74a3288ed32808bbc066d3
DIFF: 
https://github.com/llvm/llvm-project/commit/6cfbfb44cb8c140b1b74a3288ed32808bbc066d3.diff

LOG: [flang][driver] Add `-l` to the list of "visble" flags

Missed in https://reviews.llvm.org/D157837.

Fixes:
  * https://lab.llvm.org/buildbot/#/builders/197/builds/8996/steps/13/logs/stdio

Added: 
flang/test/Driver/misc-flags.f90

Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index acdb206c18d128..f7c9bb854eb740 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4132,7 +4132,7 @@ def imultilib : Separate<["-"], "imultilib">, 
Group;
 def K : Flag<["-"], "K">, Flags<[LinkerInput]>;
 def keep__private__externs : Flag<["-"], "keep_private_externs">;
 def l : JoinedOrSeparate<["-"], "l">, Flags<[LinkerInput, RenderJoined]>,
-Group;
+Visibility<[ClangOption, FlangOption]>, Group;
 def lazy__framework : Separate<["-"], "lazy_framework">, Flags<[LinkerInput]>;
 def lazy__library : Separate<["-"], "lazy_library">, Flags<[LinkerInput]>;
 def mlittle_endian : Flag<["-"], "mlittle-endian">, Group,

diff  --git a/flang/test/Driver/misc-flags.f90 
b/flang/test/Driver/misc-flags.f90
new file mode 100644
index 00..74df9f7785ba17
--- /dev/null
+++ b/flang/test/Driver/misc-flags.f90
@@ -0,0 +1,6 @@
+! Make sure that `-l` is "visible" to Flang's driver
+! RUN: %flang -lpgmath -### %s
+
+program hello
+  write(*,*), "Hello world!"
+end program hello



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 89053e4 - [flang][driver] Partial revert of D157837

2023-08-18 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2023-08-18T15:51:18Z
New Revision: 89053e49590302c0a704d1af46ee263a5c882df6

URL: 
https://github.com/llvm/llvm-project/commit/89053e49590302c0a704d1af46ee263a5c882df6
DIFF: 
https://github.com/llvm/llvm-project/commit/89053e49590302c0a704d1af46ee263a5c882df6.diff

LOG: [flang][driver] Partial revert of D157837

This is a partial revert of https://reviews.llvm.org/D157837 - it turns
out that the LLVM test suite needs to be updated first not to use any of
the unsupported Flang options:
  * https://github.com/llvm/llvm-test-suite
Sample errors:
```
flang-new: error: unknown argument: '-fbounds-check'
flang-new: error: unknown argument: '-fcheck=all'
flang-new: error: unknown argument: '-fcheck-array-temporaries'
```

Once the test suite is updated, we can restore the reverted setting.

Broken bot:
  * https://lab.llvm.org/buildbot/#/builders/197/builds/9001

Differential Revision: https://reviews.llvm.org/D158289

Added: 


Modified: 
clang/lib/Driver/Driver.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index adaad6760534e3..a3c21545c3a824 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6494,8 +6494,8 @@ Driver::getOptionVisibilityMask(bool UseDriverMode) const 
{
 return llvm::opt::Visibility(options::CLOption);
   if (IsDXCMode())
 return llvm::opt::Visibility(options::DXCOption);
-  if (IsFlangMode()) {
-return llvm::opt::Visibility(options::FlangOption);
+  if (IsFlangMode())  {
+return llvm::opt::Visibility(options::ClangOption | options::FlangOption);
   }
   return llvm::opt::Visibility(options::ClangOption);
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3758aed - [flang][driver] Mark -Wl as visible in Flang

2023-08-21 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2023-08-21T07:06:11Z
New Revision: 3758aed31a512d9219bd31174a300c34d1af9fda

URL: 
https://github.com/llvm/llvm-project/commit/3758aed31a512d9219bd31174a300c34d1af9fda
DIFF: 
https://github.com/llvm/llvm-project/commit/3758aed31a512d9219bd31174a300c34d1af9fda.diff

LOG: [flang][driver] Mark -Wl as visible in Flang

Differential Revision: https://reviews.llvm.org/D158309

Added: 


Modified: 
clang/include/clang/Driver/Options.td
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
flang/test/Driver/misc-flags.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 19a2abf494363c..d668faf650a721 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -912,7 +912,8 @@ def Wdeprecated : Flag<["-"], "Wdeprecated">, 
Group,
   HelpText<"Enable warnings for deprecated constructs and define 
__DEPRECATED">;
 def Wno_deprecated : Flag<["-"], "Wno-deprecated">, Group,
   Visibility<[ClangOption, CC1Option]>;
-def Wl_COMMA : CommaJoined<["-"], "Wl,">, Flags<[LinkerInput, RenderAsInput]>,
+def Wl_COMMA : CommaJoined<["-"], "Wl,">, Visibility<[ClangOption, 
FlangOption]>,
+  Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass the comma separated arguments in  to the linker">,
   MetaVarName<"">, Group;
 // FIXME: This is broken; these should not be Joined arguments.

diff  --git a/flang/test/Driver/driver-help-hidden.f90 
b/flang/test/Driver/driver-help-hidden.f90
index 1842fc7b03c103..80708a7cfafe4b 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -132,6 +132,7 @@
 ! CHECK-NEXT: -U   Undefine macro 
 ! CHECK-NEXT: --version   Print version information
 ! CHECK-NEXT: -v  Show commands to run and use verbose 
output
+! CHECK-NEXT: -Wl,   Pass the comma separated arguments in 
 to the linker
 ! CHECK-NEXT: -W Enable the specified warning
 ! CHECK-NEXT: -XflangPass  to the flang compiler
 ! CHECK-NEXT: -xTreat subsequent input files as having 
type 

diff  --git a/flang/test/Driver/driver-help.f90 
b/flang/test/Driver/driver-help.f90
index 85d707e35f1f58..7e7d127188093f 100644
--- a/flang/test/Driver/driver-help.f90
+++ b/flang/test/Driver/driver-help.f90
@@ -120,6 +120,7 @@
 ! HELP-NEXT: -U   Undefine macro 
 ! HELP-NEXT: --version   Print version information
 ! HELP-NEXT: -v  Show commands to run and use verbose 
output
+! HELP-NEXT: -Wl,   Pass the comma separated arguments in 
 to the linker
 ! HELP-NEXT: -W Enable the specified warning
 ! HELP-NEXT: -XflangPass  to the flang compiler
 ! HELP-NEXT: -xTreat subsequent input files as having 
type 

diff  --git a/flang/test/Driver/misc-flags.f90 
b/flang/test/Driver/misc-flags.f90
index 74df9f7785ba17..0c367b90b0b6c7 100644
--- a/flang/test/Driver/misc-flags.f90
+++ b/flang/test/Driver/misc-flags.f90
@@ -1,6 +1,9 @@
 ! Make sure that `-l` is "visible" to Flang's driver
 ! RUN: %flang -lpgmath -### %s
 
+! Make sure that `-Wl` is "visible" to Flang's driver
+! RUN: %flang -Wl,abs -### %s
+
 program hello
   write(*,*), "Hello world!"
 end program hello



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b16a758 - [flang][driver] Disable Clang options in Flang

2023-08-21 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2023-08-21T09:27:07Z
New Revision: b16a7581ff8bcb2d24aace1239af4440f47ccb5f

URL: 
https://github.com/llvm/llvm-project/commit/b16a7581ff8bcb2d24aace1239af4440f47ccb5f
DIFF: 
https://github.com/llvm/llvm-project/commit/b16a7581ff8bcb2d24aace1239af4440f47ccb5f.diff

LOG: [flang][driver] Disable Clang options in Flang

Restore the desired setting that was reverted in

  https://reviews.llvm.org/D158289.

This is to be merged once Fortran tests in llvm-test-suite are updated
accordingly:

  https://reviews.llvm.org/D158308.

Differential Revision: https://reviews.llvm.org/D158307

Added: 


Modified: 
clang/lib/Driver/Driver.cpp

Removed: 




diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index afbecb126f8f58..1cdd7ec42d8cc8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6495,7 +6495,7 @@ Driver::getOptionVisibilityMask(bool UseDriverMode) const 
{
   if (IsDXCMode())
 return llvm::opt::Visibility(options::DXCOption);
   if (IsFlangMode())  {
-return llvm::opt::Visibility(options::ClangOption | options::FlangOption);
+return llvm::opt::Visibility(options::FlangOption);
   }
   return llvm::opt::Visibility(options::ClangOption);
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e88ff8a - [flang][nfc] Simplify option forwarding

2023-07-28 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2023-07-28T14:23:58Z
New Revision: e88ff8a79b8bee3cfb654d8fc716677669ce8e0d

URL: 
https://github.com/llvm/llvm-project/commit/e88ff8a79b8bee3cfb654d8fc716677669ce8e0d
DIFF: 
https://github.com/llvm/llvm-project/commit/e88ff8a79b8bee3cfb654d8fc716677669ce8e0d.diff

LOG: [flang][nfc] Simplify option forwarding

Use `AddAllArgs` to keep the implementation succinct. Also adds missing
'-flang-experimental-hlfir` in "frontend-forwarding.f90"

Differential Revision: https://reviews.llvm.org/D156524

Added: 


Modified: 
clang/lib/Driver/ToolChains/Flang.cpp
flang/test/Driver/frontend-forwarding.f90

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index a842bc25f29de1..0c86f5269cddd7 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -140,12 +140,11 @@ void Flang::addCodegenOptions(const ArgList &Args,
   !stackArrays->getOption().matches(options::OPT_fno_stack_arrays))
 CmdArgs.push_back("-fstack-arrays");
 
-  if (Args.hasArg(options::OPT_flang_experimental_hlfir))
-CmdArgs.push_back("-flang-experimental-hlfir");
-  if (Args.hasArg(options::OPT_flang_experimental_polymorphism))
-CmdArgs.push_back("-flang-experimental-polymorphism");
   if (shouldLoopVersion(Args))
 CmdArgs.push_back("-fversion-loops-for-stride");
+
+  Args.AddAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
+options::OPT_flang_experimental_polymorphism});
 }
 
 void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {

diff  --git a/flang/test/Driver/frontend-forwarding.f90 
b/flang/test/Driver/frontend-forwarding.f90
index e953c957d2d00d..1395c7a8cbb7bd 100644
--- a/flang/test/Driver/frontend-forwarding.f90
+++ b/flang/test/Driver/frontend-forwarding.f90
@@ -17,6 +17,7 @@
 ! RUN: -fpass-plugin=Bye%pluginext \
 ! RUN: -fversion-loops-for-stride \
 ! RUN: -flang-experimental-polymorphism \
+! RUN: -flang-experimental-hlfir \
 ! RUN: -mllvm -print-before-all \
 ! RUN: -save-temps=obj \
 ! RUN: -P \
@@ -36,7 +37,8 @@
 ! CHECK: "-freciprocal-math"
 ! CHECK: "-fconvert=little-endian"
 ! CHECK: "-fpass-plugin=Bye
-! CHECK: "-flang-experimental-polymorphism"
 ! CHECK: "-fversion-loops-for-stride"
+! CHECK: "-flang-experimental-polymorphism"
+! CHECK: "-flang-experimental-hlfir"
 ! CHECK: "-mllvm" "-print-before-all"
 ! CHECK: "-save-temps=obj"



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e5d98c1 - Revert "[flang][driver] Allow main program to be in an archive"

2023-04-28 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2023-04-28T09:39:27+01:00
New Revision: e5d98c15cb7ba467c5f93b5ef08ac9b18d390133

URL: 
https://github.com/llvm/llvm-project/commit/e5d98c15cb7ba467c5f93b5ef08ac9b18d390133
DIFF: 
https://github.com/llvm/llvm-project/commit/e5d98c15cb7ba467c5f93b5ef08ac9b18d390133.diff

LOG: Revert "[flang][driver] Allow main program to be in an archive"

This reverts commit 876df74dd47196a9ca3b4fff21ffb5441491a0a0.

My understanding (based on https://reviews.llvm.org/D149429) is that
this patch has caused all of Flang's buildbots to fail. I'm not really
able to verify 100% as the buildbot UI is incredibly slow ATM. I am
reverting either way so that we can discuss the right solution offline.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
flang/docs/FlangDriver.md
flang/test/CMakeLists.txt
flang/test/Driver/linker-flags.f90

Removed: 
flang/test/Driver/link-c-main.c
flang/test/Driver/link-f90-main.f90



diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index c4a276126b653..b0716322bc141 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -598,14 +598,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   // these dependencies need to be listed before the C runtime below (i.e.
   // AddRuntTimeLibs).
   if (D.IsFlangMode()) {
-// A Fortran main program will be lowered to a function named _QQmain. Make
-// _QQmain an undefined symbol, so that it's correctly resolved even when
-// creating executable from archives. This is a workaround for how and 
where
-// Flang's `main` is defined. For more context, see:
-//   *  https://github.com/llvm/llvm-project/issues/54787
-if (!Args.hasArg(options::OPT_shared))
-  CmdArgs.push_back("--undefined=_QQmain");
-
 addFortranRuntimeLibraryPath(ToolChain, Args, CmdArgs);
 addFortranRuntimeLibs(ToolChain, CmdArgs);
 CmdArgs.push_back("-lm");

diff  --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md
index 9522e223b17b5..6c2a473820634 100644
--- a/flang/docs/FlangDriver.md
+++ b/flang/docs/FlangDriver.md
@@ -149,6 +149,13 @@ flang-new -ccc-print-phases -c file.f
 +- 3: backend, {2}, assembler
 4: assembler, {3}, object
 ```
+Note that currently Flang does not support code-generation and `flang-new` will
+fail during the second step above with the following error:
+```bash
+error: code-generation is not available yet
+```
+The other phases are printed nonetheless when using `-ccc-print-phases`, as
+that reflects what `clangDriver`, the library, will try to create and run.
 
 For actions specific to the frontend (e.g. preprocessing or code generation), a
 command to call the frontend driver is generated (more specifically, an
@@ -198,41 +205,6 @@ is `ParseSyntaxOnlyAction`, which corresponds to 
`-fsyntax-only`. In other
 words, `flang-new -fc1 ` is equivalent to `flang-new -fc1 
-fsyntax-only
 `.
 
-## Linker invocation
-> **_NOTE:_**  Linker invocation through the `flang-new` driver is so far
-> experimental. This section describes the currently intended design, and not
-> necessarily what is implemented.
-
-Calling
-```bash
-flang-new -flang-experimental-exec prog.f90
-```
-will, on a high level, do two things:
-* call the frontend driver, `flang-new -fc1`, to build the object file `prog.o`
-* call the system linker to build the executable `a.out`.
-
-In both invocations, `flang-new` will add default options to the frontend 
driver
-and the linker invocations. To see the exact invocations on your system, you 
can
-call
-```bash
-flang-new -### prog.f90
-```
-The link line will contain a fair number of options, which will depend on your
-system. Compared to when linking a C program with `clang`, the main additions
-are (on GNU/linux),
-* `--undefined=_QQmain`: A Fortran main program will appear in the 
corresponding
-  object file as a function called `_QQmain`. This flag makes sure that an
-  object file containing a Fortran main program (i.e., a symbol `_QQmain`) be
-  included in the linking also when it is bundled in an archive.
-* `-lFortran_main`: The Fortran_main archive is part of Flang's runtime. It
-  exports the symbol `main`, i.e., a c main function, which will make some
-  initial configuration before calling `_QQmain`, and clean up before 
returning.
-* `-lFortranRuntime`: Flang's Fortran runtime, containing, for example,
-  implementations of intrinsic functions.
-* `-lFortranDecimal`: Part of Flang's runtime, containing routines for parsing
-  and formatting decimal numbers.
-* `-lm`: Link with the math library, on which Flang's runtime depends.
-
 ## The `flang-to-external-fc` script
 The `flang-to-external-fc` wrapper script for `flang-new` was introduced as a
 development tool and to facilitate testing. The `flang-to-external-fc` wrapper

diff  --git a/flang/test

[clang] 2e9439e - [flang][driver] Add support for `--target`/`--triple`

2022-02-25 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-02-25T09:38:10Z
New Revision: 2e9439e4891c3d427c0fed477b54f3da2ff8ec28

URL: 
https://github.com/llvm/llvm-project/commit/2e9439e4891c3d427c0fed477b54f3da2ff8ec28
DIFF: 
https://github.com/llvm/llvm-project/commit/2e9439e4891c3d427c0fed477b54f3da2ff8ec28.diff

LOG: [flang][driver] Add support for `--target`/`--triple`

This patch adds support for:
  * `--target` in the compiler driver (`flang-new`)
  * `--triple` in the frontend driver (`flang-new -fc1`)
The semantics of these flags are inherited from `clangDriver`, i.e.
consistent with `clang --target` and `clang -cc1 --triple`,
respectively.

A new structure is defined, `TargetOptions`, that will hold various
Frontend options related to the target. Currently, this is mostly a
placeholder that contains the target triple. In the future, it will be
used for storing e.g. the CPU to tune for or the target features to
enable.

Additionally, the following target/triple related options are enabled
[*]: `-print-effective-triple`, `-print-target-triple`. Definitions in
Options.td are updated accordingly and, to facilated testing,
`-emit-llvm` is added to the list of options available in `flang-new`
(previously it was only enabled in `flang-new -fc1`).

[*] These options were actually available before (like all other options
defined in `clangDriver`), but not included in `flang-new --help`.
Before this change, `flang-new` would just use `native` for defining the
target, so these options were of little value.

Differential Revision: https://reviews.llvm.org/D120246

Added: 
flang/include/flang/Frontend/TargetOptions.h
flang/test/Driver/print-effective-triple.f90
flang/test/Driver/print-target-triple.f90
flang/test/Driver/target.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/CompilerInvocation.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 8dd16ca990a14..60e90f3f2237a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1078,7 +1078,7 @@ def d_Flag : Flag<["-"], "d">, Group;
 def d_Joined : Joined<["-"], "d">, Group;
 def emit_ast : Flag<["-"], "emit-ast">,
   HelpText<"Emit Clang AST files for source inputs">;
-def emit_llvm : Flag<["-"], "emit-llvm">, Flags<[CC1Option, FC1Option]>, 
Group,
+def emit_llvm : Flag<["-"], "emit-llvm">, Flags<[CC1Option, FC1Option, 
FlangOption]>, Group,
   HelpText<"Use the LLVM representation for assembler and object files">;
 def emit_interface_stubs : Flag<["-"], "emit-interface-stubs">, 
Flags<[CC1Option]>, Group,
   HelpText<"Generate Interface Stub Files.">;
@@ -3894,9 +3894,9 @@ def print_multi_lib : Flag<["-", "--"], 
"print-multi-lib">;
 def print_multi_os_directory : Flag<["-", "--"], "print-multi-os-directory">,
   Flags<[Unsupported]>;
 def print_target_triple : Flag<["-", "--"], "print-target-triple">,
-  HelpText<"Print the normalized target triple">;
+  HelpText<"Print the normalized target triple">, Flags<[FlangOption]>;
 def print_effective_triple : Flag<["-", "--"], "print-effective-triple">,
-  HelpText<"Print the effective target triple">;
+  HelpText<"Print the effective target triple">, Flags<[FlangOption]>;
 def print_multiarch : Flag<["-", "--"], "print-multiarch">,
   HelpText<"Print the multiarch target triple">;
 def print_prog_name_EQ : Joined<["-", "--"], "print-prog-name=">,
@@ -4014,7 +4014,7 @@ def no_system_header_prefix : Joined<["--"], 
"no-system-header-prefix=">,
"system header.">;
 def : Separate<["--"], "no-system-header-prefix">, 
Alias;
 def s : Flag<["-"], "s">, Group;
-def target : Joined<["--"], "target=">, Flags<[NoXarchOption, CoreOption]>,
+def target : Joined<["--"], "target=">, Flags<[NoXarchOption, CoreOption, 
FlangOption]>,
   HelpText<"Generate code for the given target">;
 def darwin_target_variant : Separate<["-"], "darwin-target-variant">,
   Flags<[NoXarchOption, CoreOption]>,
@@ -4803,7 +4803,7 @@ def emit_fir : Flag<["-"], "emit-fir">, Alias;
 let Flags = [CC1Option, NoDriverOption] in {
 
 
//===--===//
-// Target Options
+// Target Options (cc1 + cc1as)
 
//===--===//
 
 let Flags = [CC1Option, CC1AsOption, NoDriverOption] in {
@@ -4817,10 +4817,6 @@ def tune_cpu : Separate<["-"], "tune-cpu">,
 def target_feature : Separate<["-"], "target-feature">,
   HelpText<"Target specific attributes">,
   MarshallingInfoStringVector>;
-def triple : Separate<["-"], "triple">,
-  HelpText<"Specify target triple (e.g. i686-apple-darwin9)">,
- 

[clang] 8321579 - [flang][driver] Add support for `-debug-dump-pft`

2022-03-08 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-03-08T19:21:58Z
New Revision: 8321579b2830d1475a69306a02b61789f8ca3cf7

URL: 
https://github.com/llvm/llvm-project/commit/8321579b2830d1475a69306a02b61789f8ca3cf7
DIFF: 
https://github.com/llvm/llvm-project/commit/8321579b2830d1475a69306a02b61789f8ca3cf7.diff

LOG: [flang][driver] Add support for `-debug-dump-pft`

This patch adds support for dumping the pre-FIR tree in `flang-new
-fc1`, i.e. Flang's frontend driver. This flag is functionally identical
to `-pft-test` in `bbc` and semantically similar to
`-fdebug-dump-parse-tree` from `flang-new -fc1`.

Differential Revision: https://reviews.llvm.org/D121198

Added: 
flang/test/Driver/dump-pft.f90

Modified: 
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/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3b7011760a5b5..3d49e6b165b38 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4773,6 +4773,8 @@ def fdebug_dump_parse_tree : Flag<["-"], 
"fdebug-dump-parse-tree">, Group,
   DocBrief<[{Run the Parser and the semantic checks, and then output the
 parse tree.}]>;
+def fdebug_dump_pft : Flag<["-"], "fdebug-dump-pft">, Group,
+  HelpText<"Dump the pre-fir parse tree">;
 def fdebug_dump_parse_tree_no_sema : Flag<["-"], 
"fdebug-dump-parse-tree-no-sema">, Group,
   HelpText<"Dump the parse tree (skips the semantic checks)">,
   DocBrief<[{Run the Parser and then output the parse tree. Semantic

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index 3ccd39fdd8606..0cb6d6301c066 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -109,6 +109,10 @@ class DebugDumpParseTreeAction : public 
PrescanAndSemaAction {
   void ExecuteAction() override;
 };
 
+class DebugDumpPFTAction : public PrescanAndSemaAction {
+  void ExecuteAction() override;
+};
+
 class DebugPreFIRTreeAction : public PrescanAndSemaAction {
   void ExecuteAction() override;
 };

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index 060910e3d67cd..c396822819ac6 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -57,6 +57,9 @@ enum ActionKind {
   /// Parse, run semantics and then output the parse tree
   DebugDumpParseTree,
 
+  /// Parse, run semantics and then output the pre-fir parse tree
+  DebugDumpPFT,
+
   /// Parse, run semantics and then output the parse tree and symbols
   DebugDumpAll,
 

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 32888bde3ab39..a1d730959f5fc 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -168,6 +168,9 @@ static bool ParseFrontendArgs(FrontendOptions &opts, 
llvm::opt::ArgList &args,
 case clang::driver::options::OPT_fdebug_dump_parse_tree:
   opts.programAction = DebugDumpParseTree;
   break;
+case clang::driver::options::OPT_fdebug_dump_pft:
+  opts.programAction = DebugDumpPFT;
+  break;
 case clang::driver::options::OPT_fdebug_dump_all:
   opts.programAction = DebugDumpAll;
   break;

diff  --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index 68ac24653d993..c72460f159e12 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -506,3 +506,17 @@ void InitOnlyAction::ExecuteAction() {
 }
 
 void PluginParseTreeAction::ExecuteAction() {}
+
+void DebugDumpPFTAction::ExecuteAction() {
+  CompilerInstance &ci = this->instance();
+
+  if (auto ast = Fortran::lower::createPFT(
+  *ci.parsing().parseTree(), ci.semantics().context())) {
+Fortran::lower::dumpPFT(llvm::outs(), *ast);
+return;
+  }
+
+  unsigned DiagID = ci.diagnostics().getCustomDiagID(
+  clang::DiagnosticsEngine::Error, "Pre FIR Tree is NULL.");
+  ci.diagnostics().Report(DiagID);
+}

diff  --git a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp 
b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index d5c15b1c7b567..d97833b376980 100644
--- a/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -49,6 +49,8 @@ static std::unique_ptr 
CreateFrontendBaseAction(
 return std::make_unique();
   case DebugDumpParseTree:
 return std::make_unique();
+  case DebugDumpPFT:
+return std::make_unique();
   case DebugDumpPars

[clang] dfd9879 - [Clang] Make Clang copy its CMake modules into the build dir

2022-01-12 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-01-12T09:51:14Z
New Revision: dfd9879d6f43949443ba3c58cf3969ed582d7466

URL: 
https://github.com/llvm/llvm-project/commit/dfd9879d6f43949443ba3c58cf3969ed582d7466
DIFF: 
https://github.com/llvm/llvm-project/commit/dfd9879d6f43949443ba3c58cf3969ed582d7466.diff

LOG: [Clang] Make Clang copy its CMake modules into the build dir

LLVM has a documented mechanism for passing configuration information to
an out of tree project using CMake. See
https://llvm.org/docs/CMake.html#embedding-llvm-in-your-project.
Similar logic applies to "standalone" builds of other sub-projects
within LLVM that depend on each other. For example, a standalone build
of Flang will use this mechanism to acquire Clang's configuration.

Currently, the relevant CMake modules for Clang will only be copied into
the installation directory. This means that in order to configure a
standalone build of Flang, one has to first build and then install
Clang. This is not required for LLVM nor for MLIR - other sub-projects
that Flang depends on (i.e. the CMake modules for LLVM and MLIR are
available in the build dir, so installation is not needed).

This change removes the need for installing Clang in order to access its
configuration. It makes sure that the required CMake modules are copied
into the build directory. This will make Clang behave consistently with
LLVM and MLIR in this respect. It will also simplify building Flang as
standalone sub-project.

Differential Revision: https://reviews.llvm.org/D116731

Added: 


Modified: 
clang/cmake/modules/CMakeLists.txt

Removed: 




diff  --git a/clang/cmake/modules/CMakeLists.txt 
b/clang/cmake/modules/CMakeLists.txt
index 3890ea14d06c6..e9cc1240dafb7 100644
--- a/clang/cmake/modules/CMakeLists.txt
+++ b/clang/cmake/modules/CMakeLists.txt
@@ -29,6 +29,14 @@ configure_file(
 set(CLANG_CONFIG_CMAKE_DIR)
 set(CLANG_CONFIG_LLVM_CMAKE_DIR)
 
+# For compatibility with projects that include(ClangConfig)
+# via CMAKE_MODULE_PATH, place API modules next to it.
+file(COPY .
+  DESTINATION ${clang_cmake_builddir}
+  FILES_MATCHING PATTERN *.cmake
+  PATTERN CMakeFiles EXCLUDE
+  )
+
 # Generate ClangConfig.cmake for the install tree.
 find_prefix_from_config(CLANG_CONFIG_CODE CLANG_INSTALL_PREFIX 
"${CLANG_INSTALL_PACKAGE_DIR}")
 set(CLANG_CONFIG_CMAKE_DIR 
"\${CLANG_INSTALL_PREFIX}/${CLANG_INSTALL_PACKAGE_DIR}")



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] eefda60 - [flang][driver] Add support for `-fget-symbols-sources`

2021-03-18 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-03-18T14:13:24Z
New Revision: eefda605fe1701937a8fe5379357e0990ad2fb4e

URL: 
https://github.com/llvm/llvm-project/commit/eefda605fe1701937a8fe5379357e0990ad2fb4e
DIFF: 
https://github.com/llvm/llvm-project/commit/eefda605fe1701937a8fe5379357e0990ad2fb4e.diff

LOG: [flang][driver] Add support for `-fget-symbols-sources`

Adds support for `-fget-symbols-sources` in the new Flang driver. All
relevant tests are updated to use the new driver when
`FLANG_BUILD_NEW_DRIVER` is set.

`RUN` lines in tests are updated so `-fsyntax-only`
comes before `-fget-symbols-sources`. That's because:
  * both `-fsyntax-only` and `-fget-symbols-sources` are
action flags, and
  * the new driver, flang-new, will only consider the right-most
action flag.
In other words, this change is needed so that the tests work with both
`f18` (requires both flags) and `flang-new` (only considers the last
action flag).

Differential Revision: https://reviews.llvm.org/D98191

Added: 


Modified: 
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/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

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a3a0d86c054a..55dddab6160c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4364,6 +4364,8 @@ def fdebug_pre_fir_tree : Flag<["-"], 
"fdebug-pre-fir-tree">, Group;
 def fdebug_module_writer : Flag<["-"],"fdebug-module-writer">, 
   HelpText<"Enable debug messages while writing module files">;
+def fget_symbols_sources : Flag<["-"], "fget-symbols-sources">, 
Group,
+  HelpText<"Dump symbols and their source code locations">;
 
 }
 

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index 35d1e6f29b0f..f49f9f4714b5 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -100,6 +100,10 @@ class DebugPreFIRTreeAction : public PrescanAndSemaAction {
   void ExecuteAction() override;
 };
 
+class GetSymbolsSourcesAction : public PrescanAndSemaAction {
+  void ExecuteAction() override;
+};
+
 class ParseSyntaxOnlyAction : public PrescanAndSemaAction {
   void ExecuteAction() override;
 };

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index 48182f488466..1d9002335c3c 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -58,7 +58,10 @@ enum ActionKind {
   DebugMeasureParseTree,
 
   /// Parse, run semantics and then output the pre-FIR tree
-  DebugPreFIRTree
+  DebugPreFIRTree,
+
+  /// Parse, run semantics and then dump symbol sources map
+  GetSymbolsSources
 
   /// TODO: RunPreprocessor, EmitLLVM, EmitLLVMOnly,
   /// EmitCodeGenOnly, EmitAssembly, (...)

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 1271cd314831..d2318d3d683d 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -143,6 +143,9 @@ static InputKind ParseFrontendArgs(FrontendOptions &opts,
 case clang::driver::options::OPT_fdebug_pre_fir_tree:
   opts.programAction_ = DebugPreFIRTree;
   break;
+case clang::driver::options::OPT_fget_symbols_sources:
+  opts.programAction_ = GetSymbolsSources;
+  break;
 
   // TODO:
   // case calng::driver::options::OPT_emit_llvm:

diff  --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index ea283fe7a0c9..1871a35444db 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/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"
@@ -314,6 +315,15 @@ void DebugDumpParsingLogAction::ExecuteAction() {
   ci.parsing().DumpParsingLog(llvm::outs());
 }
 
+void GetSymbolsSourcesAction::ExecuteAction() {
+  // Report and exit if fatal semantic errors are present
+  if (reportFatalSemanticErrors(semantics(), this->instance().diagnostics(),
+  GetCurrentFileOrBufferName()))
+return;
+
+  semantics().DumpSymbolsSources(llvm::outs());

[clang] b3b002b - [clang][flang] Moke the definition of `-module-dir` restricted to Flang

2021-03-22 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-03-22T11:06:50Z
New Revision: b3b002b12f2d6ebdb80b678dec0d14786cbef15a

URL: 
https://github.com/llvm/llvm-project/commit/b3b002b12f2d6ebdb80b678dec0d14786cbef15a
DIFF: 
https://github.com/llvm/llvm-project/commit/b3b002b12f2d6ebdb80b678dec0d14786cbef15a.diff

LOG: [clang][flang] Moke the definition of `-module-dir` restricted to Flang

`-module-dir` is a Flang specific option and should not be visible in
Clang. This patch adds `FlangOnlyOption` flag to its definition. This
way Clang will know that it should reject it and skip it when generating
output for `clang -help`.

The definition of `-module-dir` is moved next to other Flang options.
As `-J` is an alias for `-module-dir`, it has to be moved as well (the
alias cannot be defined before the original option). As `gfortran` mode
is effectively no longer supported (*), `-J` is claimed as Flang only
option.

This is a follow-up of a post-commit review for
https://reviews.llvm.org/D95448.

* https://reviews.llvm.org/rG6a75496836ea14bcfd2f4b59d35a1cad4ac58cee

Differential Revision: https://reviews.llvm.org/D99018

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6e22bd01bea3..2e9d0f53f9a3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -986,11 +986,6 @@ def dependency_dot : Separate<["-"], "dependency-dot">, 
Flags<[CC1Option]>,
 def module_dependency_dir : Separate<["-"], "module-dependency-dir">,
   Flags<[CC1Option]>, HelpText<"Directory to dump module dependencies to">,
   MarshallingInfoString>;
-def module_dir : Separate<["-"], "module-dir">, 
Flags<[FlangOption,FC1Option]>, MetaVarName<"">,
-  HelpText<"Put MODULE files in ">,
-  DocBrief<[{This option specifies where to put .mod files for compiled 
modules.
-It is also added to the list of directories to be searched by an USE statement.
-The default is the current directory.}]>;
 def dsym_dir : JoinedOrSeparate<["-"], "dsym-dir">,
   Flags<[NoXarchOption, RenderAsInput]>,
   HelpText<"Directory to output dSYM's (if any) to">, MetaVarName<"">;
@@ -4220,7 +4215,6 @@ defm devirtualize_speculatively : 
BooleanFFlag<"devirtualize-speculatively">,
 
 // Generic gfortran options.
 def A_DASH : Joined<["-"], "A-">, Group;
-def J : JoinedOrSeparate<["-"], "J">, 
Flags<[RenderJoined,FlangOption,FC1Option]>, Group, 
Alias;
 def cpp : Flag<["-"], "cpp">, Group;
 def nocpp : Flag<["-"], "nocpp">, Group;
 def static_libgfortran : Flag<["-"], "static-libgfortran">, 
Group;
@@ -4303,6 +4297,12 @@ def Xflang : Separate<["-"], "Xflang">,
 
//===--===//
 let Flags = [FC1Option, FlangOption, FlangOnlyOption] in {
 
+def module_dir : Separate<["-"], "module-dir">, MetaVarName<"">,
+  HelpText<"Put MODULE files in ">,
+  DocBrief<[{This option specifies where to put .mod files for compiled 
modules.
+It is also added to the list of directories to be searched by an USE statement.
+The default is the current directory.}]>;
+
 def ffixed_form : Flag<["-"], "ffixed-form">, Group,
   HelpText<"Process source files in fixed form">;
 def ffree_form : Flag<["-"], "ffree-form">, Group,
@@ -4340,6 +4340,11 @@ def falternative_parameter_statement : Flag<["-"], 
"falternative-parameter-state
   HelpText<"Enable the old style PARAMETER statement">;
 }
 
+def J : JoinedOrSeparate<["-"], "J">,
+  Flags<[RenderJoined, FlangOption, FC1Option, FlangOnlyOption]>,
+  Group,
+  Alias;
+
 
//===--===//
 // FC1 Options
 
//===--===//



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b83a445 - [flang][driver] Add support for `-cpp/-nocpp`

2021-04-07 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-04-07T13:01:52Z
New Revision: b83a4450c216879d76d78c21a2a0b864fdc2eb3d

URL: 
https://github.com/llvm/llvm-project/commit/b83a4450c216879d76d78c21a2a0b864fdc2eb3d
DIFF: 
https://github.com/llvm/llvm-project/commit/b83a4450c216879d76d78c21a2a0b864fdc2eb3d.diff

LOG: [flang][driver] Add support for `-cpp/-nocpp`

This patch adds support for the `-cpp` and `-nocpp` flags. The
implemented semantics match f18 (i.e. the "throwaway" driver), but are
different to gfortran. In Flang the preprocessor is always run. Instead,
`-cpp/-nocpp` are used to control whether predefined and command-line
preprocessor macro definitions are enabled or not. In practice this is
sufficient to model gfortran`s `-cpp/-nocpp`.

In the absence of `-cpp/-nocpp`, the driver will use the extension of
the input file to decide whether to include the standard macro
predefinitions. gfortran's documentation [1] was used to decide which
file extension to use for this.

The logic mentioned above was added in FrontendAction::BeginSourceFile.
That's relatively late in the driver set-up, but this roughly where the
name of the input file becomes available. The logic for deciding between
fixed and free form works in a similar way and was also moved to
FrontendAction::BeginSourceFile for consistency (and to reduce
code-duplication).

The `-cpp/-nocpp` flags are respected also when the input is read from
stdin. This is different to:
   * gfortran (behaves as if `-cpp` was used)
   * f18 (behaves as if `-nocpp` was used)

Starting with this patch, file extensions are significant and some test
files had to be renamed to reflect that. Where possible, preprocessor
tests were updated so that they can be shared between `f18` and
`flang-new`. This was implemented on top of adding new test for
`-cpp/-nocpp`.

[1] https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D99292

Added: 
flang/test/Driver/cpp-nocpp-command-line-macro.f90
flang/test/Driver/cpp-nocpp-predefined-macro.F90
flang/test/Driver/macro-def-undef.F90
flang/test/Driver/macro-multiline.F90
flang/test/Driver/predefined-macros-compiler-version.F90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/CompilerInvocation.h
flang/include/flang/Frontend/FrontendOptions.h
flang/include/flang/Frontend/PreprocessorOptions.h
flang/lib/Frontend/CompilerInstance.cpp
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendAction.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/Frontend/FrontendOptions.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
flang/test/Driver/input-from-stdin.f90

Removed: 
flang/test/Driver/macro-def-undef.f90
flang/test/Driver/macro-multiline.f90
flang/test/Driver/predefined-macros-compiler-version.f90



diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1a71d68ec4e2..240656a6e519 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4235,8 +4235,6 @@ defm devirtualize_speculatively : 
BooleanFFlag<"devirtualize-speculatively">,
 
 // Generic gfortran options.
 def A_DASH : Joined<["-"], "A-">, Group;
-def cpp : Flag<["-"], "cpp">, Group;
-def nocpp : Flag<["-"], "nocpp">, Group;
 def static_libgfortran : Flag<["-"], "static-libgfortran">, 
Group;
 
 // "f" options with values for gfortran.
@@ -4316,6 +4314,10 @@ def Xflang : Separate<["-"], "Xflang">,
 
//===--===//
 let Flags = [FC1Option, FlangOption, FlangOnlyOption] in {
 
+def cpp : Flag<["-"], "cpp">, Group,
+  HelpText<"Enable predefined and command line preprocessor macros">;
+def nocpp : Flag<["-"], "nocpp">, Group,
+  HelpText<"Disable predefined and command line preprocessor macros">;
 def module_dir : Separate<["-"], "module-dir">, MetaVarName<"">,
   HelpText<"Put MODULE files in ">,
   DocBrief<[{This option specifies where to put .mod files for compiled 
modules.

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 73dbeacf2563..1bfad6115d51 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -37,7 +37,8 @@ void Flang::AddFortranDialectOptions(const ArgList &Args,
 
 void Flang::AddPreprocessingOptions(const ArgList &Args,
 ArgStringList &CmdArgs) const {
-  Args.AddAllArgs(CmdArgs, {options::OPT_D, options::OPT_U, options::OPT_I});
+  Args.AddAllArgs(CmdArgs, {options::OPT_D, options::OPT_U, options::OPT_I,
+options::OPT_cpp, options::OPT_nocpp});
 }
 
 void Flang::AddOtherOptions(const ArgList &Args, ArgStringList 

[clang] e81b340 - [flang][driver] Add debug options not requiring semantic checks

2021-04-08 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-04-08T09:44:19Z
New Revision: e81b3401177a67481605447ea5250d8345cb4341

URL: 
https://github.com/llvm/llvm-project/commit/e81b3401177a67481605447ea5250d8345cb4341
DIFF: 
https://github.com/llvm/llvm-project/commit/e81b3401177a67481605447ea5250d8345cb4341.diff

LOG: [flang][driver] Add debug options not requiring semantic checks

This patch adds two debugging options in the new Flang driver
(flang-new):
  *fdebug-unparse-no-sema
  *fdebug-dump-parse-tree-no-sema
Each of these options combines two options from the "throwaway" driver
(left: f18, right: flang-new):
  * `-fdebug-uparse -fdebug-no-semantics` --> `-fdebug-unparse-no-sema`
  * `-fdebug-dump-parse-tree -fdebug-no-semantics` -->
`-fdebug-dump-parse-tree-no-sema`

There are no plans to implement `-fdebug-no-semantics` in the new
driver.  Such option would be too powerful. Also, it would only make
sense when combined with specific frontend actions (`-fdebug-unparse`
and `-fdebug-dump-parse-tree`). Instead, this patch adds 2 specialised
options listed above. Each of these is implemented through a dedicated
FrontendAction (also added).

The new frontend actions are implemented in terms of a new abstract base
action: `PrescanAndSemaAction`. This new base class was required so that
we can have finer control over what steps within the frontend are
executed:
  * `PrescanAction`: run the _prescanner_
  * `PrescanAndSemaAction`: run the _prescanner_ and the _parser_ (new
 in this patch)
  * `PrescanAndSemaAction`: run the _prescanner_, _parser_ and run the
_semantic checks_

This patch introduces `PrescanAndParseAction::BeginSourceFileAction`.
Apart from the semantic checks removed at the end, it is similar to
`PrescanAndSemaAction::BeginSourceFileAction`.

Differential Revision: https://reviews.llvm.org/D99645

Added: 
flang/test/Driver/dump-parse-tree-no-sema.f90

Modified: 
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/Driver/driver-help.f90
flang/test/Parser/omp-allocate-unparse.f90
flang/test/Parser/omp-atomic-unparse.f90
flang/tools/f18/f18.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 240656a6e519d..24bb3b8c34c7b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4377,14 +4377,26 @@ let Flags = [FC1Option, FlangOnlyOption] in {
 
 def test_io : Flag<["-"], "test-io">, Group,
   HelpText<"Run the InputOuputTest action. Use for development and testing 
only.">;
+def fdebug_unparse_no_sema : Flag<["-"], "fdebug-unparse-no-sema">, 
Group,
+  HelpText<"Unparse and stop (skips the semantic checks)">,
+  DocBrief<[{Only run the parser, then unparse the parse-tree and output the
+generated Fortran source file. Semantic checks are disabled.}]>;
 def fdebug_unparse : Flag<["-"], "fdebug-unparse">, Group,
-  HelpText<"Unparse and stop.">;
+  HelpText<"Unparse and stop.">,
+  DocBrief<[{Run the parser and the semantic checks. Then unparse the
+parse-tree and output the generated Fortran source file.}]>;
 def fdebug_unparse_with_symbols : Flag<["-"], "fdebug-unparse-with-symbols">, 
Group,
   HelpText<"Unparse and stop.">;
 def fdebug_dump_symbols : Flag<["-"], "fdebug-dump-symbols">, 
Group,
   HelpText<"Dump symbols after the semantic analysis">;
 def fdebug_dump_parse_tree : Flag<["-"], "fdebug-dump-parse-tree">, 
Group,
-  HelpText<"Dump the parse tree">;
+  HelpText<"Dump the parse tree">,
+  DocBrief<[{Run the Parser and the semantic checks, and then output the
+parse tree.}]>;
+def fdebug_dump_parse_tree_no_sema : Flag<["-"], 
"fdebug-dump-parse-tree-no-sema">, Group,
+  HelpText<"Dump the parse tree (skips the semantic checks)">,
+  DocBrief<[{Run the Parser and then output the parse tree. Semantic
+checks are disabled.}]>;
 def fdebug_dump_provenance : Flag<["-"], "fdebug-dump-provenance">, 
Group,
   HelpText<"Dump provenance">;
 def fdebug_dump_parsing_log : Flag<["-"], "fdebug-dump-parsing-log">, 
Group,

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index f49f9f4714b53..83e9652153ae3 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -62,6 +62,22 @@ class DebugMeasureParseTreeAction : public PrescanAction {
   void ExecuteAction() override;
 };
 
+//===--===//
+// PrescanAndParse Actions
+//===--===//
+class PrescanAndParseAction : public FrontendAction {
+  void ExecuteAc

[clang] dc256a4 - [flang][driver] Add support for `-fget-definition`

2021-04-21 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-04-21T09:31:36Z
New Revision: dc256a443a456a8e0e4d72736fee1c9442bcf4bd

URL: 
https://github.com/llvm/llvm-project/commit/dc256a443a456a8e0e4d72736fee1c9442bcf4bd
DIFF: 
https://github.com/llvm/llvm-project/commit/dc256a443a456a8e0e4d72736fee1c9442bcf4bd.diff

LOG: [flang][driver] Add support for `-fget-definition`

This patch adds `-fget-definition` to `flang-new`. The semantics of this
option are identical in both drivers. The error message in the
"throwaway" driver is updated so that it matches the one from
`flang-new` (which is auto-generated and cannot be changed easily).

Tests are updated accordingly. A dedicated test for error handling was
added: get-definition.f90 (for the sake of simplicity,
getdefinition01.f90 no longer tests for errors).

The `ParseFrontendArgs` function is updated so that it can return
errors. This change is required in order to report invalid values
following `-fget-definition`.

The actual implementation of `GetDefinitionAction::ExecuteAction()` was
extracted from f18.cpp (i.e. the bit that deals with
`-fget-definition`).

Depends on: https://reviews.llvm.org/D100556

Differential Revision: https://reviews.llvm.org/D100558

Added: 
flang/test/Driver/get-definition.f90

Modified: 
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/Driver/driver-help.f90
flang/test/Semantics/getdefinition01.f90
flang/test/Semantics/getdefinition02.f
flang/test/Semantics/getdefinition03-a.f90
flang/test/Semantics/getdefinition04.f90
flang/test/Semantics/getdefinition05.f90
flang/tools/f18/f18.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f93b8a2496e07..648cfb0522e14 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4381,6 +4381,9 @@ def J : JoinedOrSeparate<["-"], "J">,
 
//===--===//
 let Flags = [FC1Option, FlangOnlyOption] in {
 
+def fget_definition : MultiArg<["-"], "fget-definition", 3>,
+  HelpText<"Get the symbol definition from   
">,
+  Group;
 def test_io : Flag<["-"], "test-io">, Group,
   HelpText<"Run the InputOuputTest action. Use for development and testing 
only.">;
 def fdebug_unparse_no_sema : Flag<["-"], "fdebug-unparse-no-sema">, 
Group,

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index 83e9652153ae3..619e83ad88c77 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -116,6 +116,10 @@ class DebugPreFIRTreeAction : public PrescanAndSemaAction {
   void ExecuteAction() override;
 };
 
+class GetDefinitionAction : public PrescanAndSemaAction {
+  void ExecuteAction() override;
+};
+
 class GetSymbolsSourcesAction : public PrescanAndSemaAction {
   void ExecuteAction() override;
 };

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index 24fbdd3aff2a9..e18fd961a55b0 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -67,6 +67,9 @@ enum ActionKind {
   /// Parse, run semantics and then output the pre-FIR tree
   DebugPreFIRTree,
 
+  /// `-fget-definition`
+  GetDefinition,
+
   /// Parse, run semantics and then dump symbol sources map
   GetSymbolsSources
 
@@ -206,6 +209,14 @@ class FrontendOptions {
   /// compilation.
   unsigned needProvenanceRangeToCharBlockMappings_ : 1;
 
+  /// Input values from `-fget-definition`
+  struct GetDefinitionVals {
+unsigned line;
+unsigned startColumn;
+unsigned endColumn;
+  };
+  GetDefinitionVals getDefVals_;
+
   /// The input files and their types.
   std::vector inputs_;
 

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index a8879294eebf7..c79c2f2a0d939 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -95,12 +95,14 @@ static void setUpFrontendBasedOnAction(FrontendOptions 
&opts) {
   if (opts.programAction_ == DebugDumpParsingLog)
 opts.instrumentedParse_ = true;
 
-  if (opts.programAction_ == DebugDumpProvenance)
+  if (opts.programAction_ == DebugDumpProvenance ||
+  opts.programAction_ == Fortran::frontend::GetDefinition)
 opts.needProvenanceRangeToCharBlockMappings_ = true;
 }
 
-static void ParseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
+static bool ParseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
 clang::DiagnosticsEn

[clang] 7809fa2 - [flang][driver] Add support for `-D`, `-U`

2021-01-06 Thread Andrzej Warzynski via cfe-commits

Author: Faris Rehman
Date: 2021-01-06T16:17:13Z
New Revision: 7809fa2040fd40b4a4b56696c7fbcd0f0fa9

URL: 
https://github.com/llvm/llvm-project/commit/7809fa2040fd40b4a4b56696c7fbcd0f0fa9
DIFF: 
https://github.com/llvm/llvm-project/commit/7809fa2040fd40b4a4b56696c7fbcd0f0fa9.diff

LOG: [flang][driver] Add support for `-D`, `-U`

Add support for options -D and -U in the new Flang driver.

Summary of changes:
  - Create PreprocessorOptions, to be used by the driver then translated
into Fortran::parser::Options
  - Create CompilerInvocation::setFortranOpts to pass preprocessor
options into the parser options
  - Add a dedicated method, Flang::AddPreprocessingOptions, to extract
preprocessing options from the driver arguments into the preprocessor
command arguments

Macros specified like -DName will default to definition 1.

When defining macros, the new driver will drop anything after an
end-of-line character. This is consistent with gfortran and clang, but
different to what currently f18 does. However, flang (which is a bash
wrapper for f18), also drops everything after an end-of-line character.
So gfortran-like behaviour felt like the natural choice. Test is added
to demonstrate this behaviour.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D93401

Added: 
flang/include/flang/Frontend/PreprocessorOptions.h
flang/test/Flang-Driver/macro_def_undef.f90
flang/test/Flang-Driver/macro_multiline.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
clang/lib/Driver/ToolChains/Flang.h
flang/include/flang/Frontend/CompilerInstance.h
flang/include/flang/Frontend/CompilerInvocation.h
flang/lib/Frontend/CompilerInstance.cpp
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Flang-Driver/driver-help-hidden.f90
flang/test/Flang-Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3c2a9f307c65..428c14a7d9bb 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -631,7 +631,7 @@ def C : Flag<["-"], "C">, Flags<[CC1Option]>, 
Group,
 HelpText<"Include comments in preprocessed output">,
 MarshallingInfoFlag<"PreprocessorOutputOpts.ShowComments">;
 def D : JoinedOrSeparate<["-"], "D">, Group,
-Flags<[CC1Option]>, MetaVarName<"=">,
+Flags<[CC1Option, FlangOption, FC1Option]>, MetaVarName<"=">,
 HelpText<"Define  to  (or 1 if  omitted)">;
 def E : Flag<["-"], "E">, Flags<[NoXarchOption,CC1Option, FlangOption, 
FC1Option]>, Group,
 HelpText<"Only run the preprocessor">;
@@ -730,7 +730,7 @@ def Ttext : JoinedOrSeparate<["-"], "Ttext">, 
Group,
 def T : JoinedOrSeparate<["-"], "T">, Group,
   MetaVarName<"

[clang] e5cdb6c - [flang][driver] Add support for `-c` and `-emit-obj`

2021-01-07 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-01-07T10:52:38Z
New Revision: e5cdb6c56edf656d03f57c5c285cfa8c6b7b6f57

URL: 
https://github.com/llvm/llvm-project/commit/e5cdb6c56edf656d03f57c5c285cfa8c6b7b6f57
DIFF: 
https://github.com/llvm/llvm-project/commit/e5cdb6c56edf656d03f57c5c285cfa8c6b7b6f57.diff

LOG: [flang][driver] Add support for `-c` and `-emit-obj`

This patch adds a frontend action for emitting object files. While Flang
does not support code-generation, this action remains a placeholder.
This patch simply provides glue-code to connect the compiler driver
with the appropriate frontend action.

The new action is triggered with the `-c` compiler driver flag, i.e.
`flang-new -c`. This is then translated to `flang-new -fc1 -emit-obj`,
so `-emit-obj` has to be marked as supported as well.

As code-generation is not available yet, `flang-new -c` results in a
driver error:
```
error: code-generation is not available yet
```
Hopefully this will help communicating the level of available
functionality within Flang.

The definition of `emit-obj` is updated so that it can be shared between
Clang and Flang. As the original definition was enclosed within a
Clang-specific TableGen `let` statement, it is extracted into a new `let`
statement. That felt like the cleanest option.

I also commented out `-triple` in Flang::ConstructJob and updated some
comments there. This is similar to https://reviews.llvm.org/D93027. I
wanted to make sure that it's clear that we can't support `-triple`
until we have code-generation. However, once code-generation is
available we _will need_ `-triple`.

As this patch adds `-emit-obj`, the emit-obj.f90 becomes irrelevant and
is deleted. Instead, phases.f90 is added to demonstrate that users can
control compilation phases (indeed, `-c` is a phase control flag).

Reviewed By: SouraVX, clementval

Differential Revision: https://reviews.llvm.org/D93301

Added: 
flang/test/Flang-Driver/code-gen.f90
flang/test/Flang-Driver/phases.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
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-hidden.f90
flang/test/Flang-Driver/driver-help.f90

Removed: 
flang/test/Flang-Driver/emit-obj.f90



diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6b5ae35ad7e0..ffa7fbd84df9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -857,7 +857,7 @@ def current__version : JoinedOrSeparate<["-"], 
"current_version">;
 def cxx_isystem : JoinedOrSeparate<["-"], "cxx-isystem">, Group,
   HelpText<"Add directory to the C++ SYSTEM include search path">, 
Flags<[CC1Option]>,
   MetaVarName<"">;
-def c : Flag<["-"], "c">, Flags<[NoXarchOption]>, Group,
+def c : Flag<["-"], "c">, Flags<[NoXarchOption, FlangOption]>, 
Group,
   HelpText<"Only run preprocess, compile, and assemble steps">;
 def fconvergent_functions : Flag<["-"], "fconvergent-functions">, 
Group, Flags<[CC1Option]>,
   HelpText<"Assume functions may be convergent">;
@@ -4854,8 +4854,6 @@ def emit_llvm_only : Flag<["-"], "emit-llvm-only">,
   HelpText<"Build ASTs and convert to LLVM, discarding output">;
 def emit_codegen_only : Flag<["-"], "emit-codegen-only">,
   HelpText<"Generate machine code, but discard output">;
-def emit_obj : Flag<["-"], "emit-obj">,
-  HelpText<"Emit native object files">;
 def rewrite_test : Flag<["-"], "rewrite-test">,
   HelpText<"Rewriter playground">;
 def rewrite_macros : Flag<["-"], "rewrite-macros">,
@@ -5229,6 +5227,18 @@ def fsycl_is_device : Flag<["-"], "fsycl-is-device">,
 
 } // let Flags = [CC1Option, NoDriverOption]
 
+//===--===//
+// Frontend Options - cc1 + fc1
+//===--===//
+let Flags = [CC1Option, FC1Option, NoDriverOption] in {
+let Group = Action_Group in {
+
+def emit_obj : Flag<["-"], "emit-obj">,
+  HelpText<"Emit native object files">;
+
+} // let Group = Action_Group
+} // let Flags = [CC1Option, FC1Option, NoDriverOption]
+
 
//===--===//
 // cc1as-only Options
 
//===--===//

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 69f0841bb0c5..bf300d737991 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -28,17 +28,22 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
  const InputInfo &Output, co

[clang] cbea673 - [clang][driver] Restore the original help text for `-I`

2021-01-13 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-01-13T09:19:50Z
New Revision: cbea6737d5130724c7c8cf8ee4ccf1c3dd099450

URL: 
https://github.com/llvm/llvm-project/commit/cbea6737d5130724c7c8cf8ee4ccf1c3dd099450
DIFF: 
https://github.com/llvm/llvm-project/commit/cbea6737d5130724c7c8cf8ee4ccf1c3dd099450.diff

LOG: [clang][driver] Restore the original help text for `-I`

The help text for `-I` was recently expanded in [1]. The expanded
version focuses on explaining the semantics of `-I` in Clang. We are now
in the process of adding support for `-I` in Flang and this new
description is incompatible with the semantics of `-I` in Flang. This
was brought up in this review:
  * https://reviews.llvm.org/D93453

This patch reverts the original change in Options.td. This way the help
text for `-I` remains generic enough so that it applies to both Clang
and Flang.

The expanded description of `-I` from [1] is moved to the
`DocBrief` field for `-I`. This field is prioritised over the help text
when generating ClangCommandLineReference.rst, so the user facing
documentation for Clang retains the expanded description:
  * https://clang.llvm.org/docs/ClangCommandLineReference.html
`DocBrief` fields are currently not used in Flang.

As requested in the reviews, the help text and the expanded description
are slightly refined.

[1] Commit: 8dd4e3ceb804a58bcf25e6856fc6fde5e1995a66

Differential Revision: https://reviews.llvm.org/D94169

Added: 


Modified: 
clang/docs/ClangCommandLineReference.rst
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/docs/ClangCommandLineReference.rst 
b/clang/docs/ClangCommandLineReference.rst
index ac97f6fed935..d8ad75ce 100644
--- a/clang/docs/ClangCommandLineReference.rst
+++ b/clang/docs/ClangCommandLineReference.rst
@@ -1016,7 +1016,12 @@ Flags controlling how ``#include``\s are resolved to 
files.
 
 .. option:: -I, --include-directory , --include-directory=
 
-Add directory to include search path. If there are multiple -I options, these 
directories are searched in the order they are given before the standard system 
directories are searched. If the same directory is in the SYSTEM include search 
paths, for example if also specified with -isystem, the -I option will be 
ignored
+Add directory to include search path. For C++ input, if
+there are multiple -I options, these directories are searched
+in the order they are given before the standard system directories
+are searched. If the same directory is in the SYSTEM include search
+paths, for example if also specified with -isystem, the -I option
+will be ignored
 
 .. option:: -I-, --include-barrier
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b441c1b4c169..acc3db40bdc7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -651,12 +651,13 @@ def I_ : Flag<["-"], "I-">, Group,
  "remove current directory from include path">;
 def I : JoinedOrSeparate<["-"], "I">, Group,
 Flags<[CC1Option,CC1AsOption]>, MetaVarName<"">,
-HelpText<"Add directory to include search path. If there are multiple -I "
- "options, these directories are searched in the order they are "
- "given before the standard system directories are searched. "
- "If the same directory is in the SYSTEM include search paths, for 
"
- "example if also specified with -isystem, the -I option will be "
- "ignored">;
+HelpText<"Add directory to the end of the list of include search paths">,
+DocBrief<[{Add directory to include search path. For C++ inputs, if
+there are multiple -I options, these directories are searched
+in the order they are given before the standard system directories
+are searched. If the same directory is in the SYSTEM include search
+paths, for example if also specified with -isystem, the -I option
+will be ignored}]>;
 def L : JoinedOrSeparate<["-"], "L">, Flags<[RenderJoined]>, Group,
 MetaVarName<"">, HelpText<"Add directory to library search path">;
 def MD : Flag<["-"], "MD">, Group,



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 87dfd5e - [flang][driver] Add support for `-I` in the new driver

2021-01-19 Thread Andrzej Warzynski via cfe-commits

Author: Faris Rehman
Date: 2021-01-19T11:20:56Z
New Revision: 87dfd5e012e147f4bfa3a9a4564e9cbc167278ff

URL: 
https://github.com/llvm/llvm-project/commit/87dfd5e012e147f4bfa3a9a4564e9cbc167278ff
DIFF: 
https://github.com/llvm/llvm-project/commit/87dfd5e012e147f4bfa3a9a4564e9cbc167278ff.diff

LOG: [flang][driver] Add support for `-I` in the new driver

Add support for option -I in the new Flang driver. This will allow for
included headers and module files in other directories, as the default
search path is currently the working folder. The behaviour of this is
consistent with the current f18 driver, where the current folder (i.e.
".") has the highest priority followed by the order of '-I's taking
priority from first to last.

Summary of changes:
- Add SearchDirectoriesFromDashI to PreprocessorOptions, to be forwarded
  into the parser's searchDirectories
- Add header files and non-functional module files to be used in
  regression tests. The module files are just text files and are used to
  demonstrated that paths specified with `-I` are taken into account when
  searching for .mod files.

Differential Revision: https://reviews.llvm.org/D93453

Added: 
flang/test/Flang-Driver/Inputs/basic-header-one.h
flang/test/Flang-Driver/Inputs/basic-header-two.h
flang/test/Flang-Driver/Inputs/basictestmoduleone.mod
flang/test/Flang-Driver/Inputs/header-dir/basic-header-one.h
flang/test/Flang-Driver/Inputs/header-dir/basic-header-two.h
flang/test/Flang-Driver/Inputs/module-dir/basictestmoduletwo.mod
flang/test/Flang-Driver/include-header.f90
flang/test/Flang-Driver/include-module.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/PreprocessorOptions.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/test/Flang-Driver/driver-help-hidden.f90
flang/test/Flang-Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e50c313450a9..8150b24e337b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -678,7 +678,7 @@ def I_ : Flag<["-"], "I-">, Group,
 HelpText<"Restrict all prior -I flags to double-quoted inclusion and "
  "remove current directory from include path">;
 def I : JoinedOrSeparate<["-"], "I">, Group,
-Flags<[CC1Option,CC1AsOption]>, MetaVarName<"">,
+Flags<[CC1Option,CC1AsOption,FlangOption,FC1Option]>, MetaVarName<"">,
 HelpText<"Add directory to the end of the list of include search paths">,
 DocBrief<[{Add directory to include search path. For C++ inputs, if
 there are multiple -I options, these directories are searched

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index bf300d737991..669d911de18a 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -21,7 +21,7 @@ using namespace llvm::opt;
 
 void Flang::AddPreprocessingOptions(const ArgList &Args,
 ArgStringList &CmdArgs) const {
-  Args.AddAllArgs(CmdArgs, {options::OPT_D, options::OPT_U});
+  Args.AddAllArgs(CmdArgs, {options::OPT_D, options::OPT_U, options::OPT_I});
 }
 
 void Flang::ConstructJob(Compilation &C, const JobAction &JA,

diff  --git a/flang/include/flang/Frontend/PreprocessorOptions.h 
b/flang/include/flang/Frontend/PreprocessorOptions.h
index d182969eb78b..39ea4d3d3c6c 100644
--- a/flang/include/flang/Frontend/PreprocessorOptions.h
+++ b/flang/include/flang/Frontend/PreprocessorOptions.h
@@ -24,6 +24,11 @@ namespace Fortran::frontend {
 class PreprocessorOptions {
 public:
   std::vector> macros;
+  // Search directories specified by the user with -I
+  // TODO: When adding support for more options related to search paths,
+  // consider collecting them in a separate aggregate. For now we keep it here
+  // as there is no point creating a class for just one field.
+  std::vector searchDirectoriesFromDashI;
 
 public:
   PreprocessorOptions() {}

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 57f097f189f9..aeb4ac3e274a 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -176,6 +176,10 @@ static void parsePreprocessorArgs(
   opts.addMacroUndef(currentArg->getValue());
 }
   }
+
+  // Add the ordered list of -I's.
+  for (const auto *currentArg : args.filtered(clang::driver::options::OPT_I))
+opts.searchDirectoriesFromDashI.emplace_back(currentArg->getValue());
 }
 
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation &res,
@@ -261,4 +265,9 @@ void CompilerInvocation::setFortranOpts() {
   const auto &preprocessorOptions = preprocessorOpts();
 
   collectMacroDefinitions(preprocessorOptions, fortranOptions);
+
+  fortranOptions