FarisRehman updated this revision to Diff 313319. FarisRehman added a comment.
Address review comments Summary of changes: - Add a regression test for -I - Move claiming of -I option to the dedicated parsing preprocessing options method - Rename SearchDirectoriesFromI to SearchDirectoriesFromDashI - Undo unrelated changes Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D93453/new/ 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 flang/test/Flang-Driver/Inputs/included.h flang/test/Flang-Driver/driver-help-hidden.f90 flang/test/Flang-Driver/driver-help.f90 flang/test/Flang-Driver/include_header.f90
Index: flang/test/Flang-Driver/include_header.f90 =================================================================== --- /dev/null +++ flang/test/Flang-Driver/include_header.f90 @@ -0,0 +1,41 @@ +! Ensure argument -I works as expected. + +! REQUIRES: new-flang-driver + +!-------------------------- +! FLANG DRIVER (flang-new) +!-------------------------- +! RUN: %flang-new -E %s 2>&1 | FileCheck %s --check-prefix=UNINCLUDED +! RUN: %flang-new -E -I %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=INCLUDED +! RUN: %flang-new -E -I %S/InvalidFolder %s 2>&1 | FileCheck %s --check-prefix=UNINCLUDED + +!----------------------------------------- +! FRONTEND FLANG DRIVER (flang-new -fc1) +!----------------------------------------- +! RUN: %flang-new -fc1 -E %s 2>&1 | FileCheck %s --check-prefix=UNINCLUDED +! RUN: %flang-new -fc1 -E -I %S/Inputs %s 2>&1 | FileCheck %s --check-prefix=INCLUDED +! RUN: %flang-new -fc1 -E -I %S/InvalidFolder %s 2>&1 | FileCheck %s --check-prefix=UNINCLUDED + + +!-------------------------------------------- +! EXPECTED OUTPUT FOR MISSING INCLUDE +!-------------------------------------------- +! UNINCLUDED:program b +! UNINCLUDED-NOT:program a +! UNINCLUDED-NEXT:end + +!-------------------------------------------- +! EXPECTED OUTPUT FOR INCLUDE +!-------------------------------------------- +! INCLUDED:program a +! INCLUDED-NOT:program b +! INCLUDED-NEXT:end + +! Include.F: +#include <included.h> +#ifdef X +program A +#else +program B +#endif +end \ No newline at end of file Index: flang/test/Flang-Driver/driver-help.f90 =================================================================== --- flang/test/Flang-Driver/driver-help.f90 +++ flang/test/Flang-Driver/driver-help.f90 @@ -24,6 +24,7 @@ ! HELP-NEXT: -fcolor-diagnostics Enable colors in diagnostics ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics ! HELP-NEXT: -help Display available options +! HELP-NEXT: -I <dir> 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 ! HELP-NEXT: -o <file> Write output to <file> ! HELP-NEXT: -U <macro> Undefine macro <macro> ! HELP-NEXT: --version Print version information @@ -37,6 +38,7 @@ ! HELP-FC1-NEXT: -D <macro>=<value> Define <macro> to <value> (or 1 if <value> omitted) ! HELP-FC1-NEXT: -E Only run the preprocessor ! HELP-FC1-NEXT: -help Display available options +! HELP-FC1-NEXT: -I <dir> 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 ! HELP-FC1-NEXT: -o <file> Write output to <file> ! HELP-FC1-NEXT: -U <macro> Undefine macro <macro> ! HELP-FC1-NEXT: --version Print version information Index: flang/test/Flang-Driver/driver-help-hidden.f90 =================================================================== --- flang/test/Flang-Driver/driver-help-hidden.f90 +++ flang/test/Flang-Driver/driver-help-hidden.f90 @@ -24,6 +24,7 @@ ! CHECK-NEXT: -fcolor-diagnostics Enable colors in diagnostics ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics ! CHECK-NEXT: -help Display available options +! CHECK-NEXT: -I <dir> 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 ! CHECK-NEXT: -o <file> Write output to <file> ! CHECK-NEXT: -test-io Run the InputOuputTest action. Use for development and testing only. ! CHECK-NEXT: -U <macro> Undefine macro <macro> Index: flang/test/Flang-Driver/Inputs/included.h =================================================================== --- /dev/null +++ flang/test/Flang-Driver/Inputs/included.h @@ -0,0 +1 @@ +#define X \ No newline at end of file Index: flang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- flang/lib/Frontend/CompilerInvocation.cpp +++ flang/lib/Frontend/CompilerInvocation.cpp @@ -171,6 +171,10 @@ 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, @@ -256,4 +260,9 @@ const auto &preprocessorOptions = preprocessorOpts(); collectMacroDefinitions(preprocessorOptions, fortranOptions); -} \ No newline at end of file + + for (const auto &searchDirectoryFromI : + preprocessorOptions.SearchDirectoriesFromDashI) { + fortranOptions.searchDirectories.emplace_back(searchDirectoryFromI); + } +} Index: flang/include/flang/Frontend/PreprocessorOptions.h =================================================================== --- flang/include/flang/Frontend/PreprocessorOptions.h +++ flang/include/flang/Frontend/PreprocessorOptions.h @@ -24,6 +24,7 @@ class PreprocessorOptions { public: std::vector<std::pair<std::string, /*isUndef*/ bool>> Macros; + std::vector<std::string> SearchDirectoriesFromDashI; public: PreprocessorOptions() {} Index: clang/lib/Driver/ToolChains/Flang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Flang.cpp +++ clang/lib/Driver/ToolChains/Flang.cpp @@ -22,6 +22,7 @@ void Flang::AddPreprocessingOptions(const ArgList &Args, ArgStringList &CmdArgs) const { Args.AddAllArgs(CmdArgs, {options::OPT_D, options::OPT_U}); + Args.AddAllArgs(CmdArgs, options::OPT_I); } void Flang::ConstructJob(Compilation &C, const JobAction &JA, 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. "
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits