diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/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, - Flags<[CC1Option,CC1AsOption]>, MetaVarName<"">, + Flags<[CC1Option,CC1AsOption,FlangOption,FC1Option]>, 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. " diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/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()); diff --git a/flang/include/flang/Frontend/PreprocessorOptions.h b/flang/include/flang/Frontend/PreprocessorOptions.h --- a/flang/include/flang/Frontend/PreprocessorOptions.h +++ b/flang/include/flang/Frontend/PreprocessorOptions.h @@ -10,6 +10,7 @@ class PreprocessorOptions { public: std::vector> Macros; + std::vector SearchDirectoriesFromI; public: PreprocessorOptions() {} diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -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 searchDirectories{"."s}; - fortranOptions.searchDirectories = searchDirectories; fortranOptions.isFixedForm = false; collectMacroDefinitions(fortranOptions, preprocessorOptions); + + // These defaults are based on the defaults in f18/f18.cpp. + std::vector searchDirectories{"."s}; + for (const auto &searchDirectoryFromI : + preprocessorOptions.SearchDirectoriesFromI) { + searchDirectories.emplace_back(searchDirectoryFromI); + } + fortranOptions.searchDirectories = searchDirectories; }