FarisRehman updated this revision to Diff 315090. FarisRehman added a comment.
Rename test files Rename test files to use dashes instead of underscores, as other test files do. 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/basic-test-header.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,39 @@ +! 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 INCLUDED FILE +!-------------------------------------------- +! 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 <basic-test-header.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 ! 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 ! 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 ! 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/basic-test-header.h =================================================================== --- /dev/null +++ flang/test/Flang-Driver/Inputs/basic-test-header.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 + + fortranOptions.searchDirectories.insert( + fortranOptions.searchDirectories.end(), + preprocessorOptions.searchDirectoriesFromDashI.begin(), + preprocessorOptions.searchDirectoriesFromDashI.end()); +} Index: flang/include/flang/Frontend/PreprocessorOptions.h =================================================================== --- flang/include/flang/Frontend/PreprocessorOptions.h +++ flang/include/flang/Frontend/PreprocessorOptions.h @@ -24,6 +24,11 @@ class PreprocessorOptions { public: std::vector<std::pair<std::string, /*isUndef*/ bool>> 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<std::string> searchDirectoriesFromDashI; public: PreprocessorOptions() {} Index: clang/lib/Driver/ToolChains/Flang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Flang.cpp +++ clang/lib/Driver/ToolChains/Flang.cpp @@ -21,7 +21,7 @@ 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, 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