[PATCH] D93453: [flang][driver] Add support for `-I`

Faris via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 17 05:09:44 PST 2020


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

Add support for option -I in the Flang driver.
This will allow for included headers in other directories, as the default search path is currently the working folder.
The behaviour of this is consistent with the current F18 <https://reviews.llvm.org/F18> driver.

Summary of changes:

- Add SearchDirectoriesFromI to PreprocessorOptions, to be forwarded into the parser's searchDirectories


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93453

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp


Index: flang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -165,6 +165,10 @@
       opts.addMacroUndef(A->getValue());
     }
   }
+
+  // Add the ordered list of -I's.
+  for (const auto *A : args.filtered(clang::driver::options::OPT_I))
+    opts.SearchDirectoriesFromI.emplace_back(A->getValue());
 }
 
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation &res,
@@ -237,10 +241,15 @@
   auto &fortranOptions = fortranOpts();
   const auto &preprocessorOptions = preprocessorOpts();
 
-  // These defaults are based on the defaults in f18/f18.cpp.
-  std::vector<std::string> searchDirectories{"."s};
-  fortranOptions.searchDirectories = searchDirectories;
   fortranOptions.isFixedForm = false;
 
   collectMacroDefinitions(fortranOptions, preprocessorOptions);
+
+  // These defaults are based on the defaults in f18/f18.cpp.
+  std::vector<std::string> searchDirectories{"."s};
+  for (const auto &searchDirectoryFromI :
+      preprocessorOptions.SearchDirectoriesFromI) {
+    searchDirectories.emplace_back(searchDirectoryFromI);
+  }
+  fortranOptions.searchDirectories = searchDirectories;
 }
Index: flang/include/flang/Frontend/PreprocessorOptions.h
===================================================================
--- flang/include/flang/Frontend/PreprocessorOptions.h
+++ flang/include/flang/Frontend/PreprocessorOptions.h
@@ -10,6 +10,7 @@
 class PreprocessorOptions {
 public:
   std::vector<std::pair<std::string, bool /*isUndef*/>> Macros;
+  std::vector<std::string> SearchDirectoriesFromI;
 
 public:
   PreprocessorOptions() {}
Index: clang/lib/Driver/ToolChains/Flang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -72,6 +72,8 @@
   }
   Args.ClaimAllArgs(options::OPT_D);
 
+  Args.AddAllArgs(CmdArgs, options::OPT_I);
+
   if (Output.isFilename()) {
     CmdArgs.push_back("-o");
     CmdArgs.push_back(Output.getFilename());
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -661,7 +661,7 @@
     HelpText<"Restrict all prior -I flags to double-quoted inclusion and "
              "remove current directory from include path">;
 def I : JoinedOrSeparate<["-"], "I">, Group<I_Group>,
-    Flags<[CC1Option,CC1AsOption]>, MetaVarName<"<dir>">,
+    Flags<[CC1Option,CC1AsOption,FlangOption,FC1Option]>, MetaVarName<"<dir>">,
     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. "


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93453.312454.patch
Type: text/x-patch
Size: 2909 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201217/e8f75ef3/attachment.bin>


More information about the cfe-commits mailing list