Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -4261,7 +4261,6 @@ defm frontend_optimize : BooleanFFlag<"frontend-optimize">, Group; defm init_local_zero : BooleanFFlag<"init-local-zero">, Group; defm integer_4_integer_8 : BooleanFFlag<"integer-4-integer-8">, Group; -defm intrinsic_modules_path : BooleanFFlag<"intrinsic-modules-path">, Group; defm max_identifier_length : BooleanFFlag<"max-identifier-length">, Group; defm module_private : BooleanFFlag<"module-private">, Group; defm pack_derived : BooleanFFlag<"pack-derived">, Group; @@ -4342,6 +4341,10 @@ 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">; +def fintrinsic_modules_path : Separate<["-"], "fintrinsic-modules-path">, Group, MetaVarName<"">, + HelpText<"Specify where to find the compiled intrinsic modules">, + DocBrief<[{This option specifies the location of pre-compiled intrinsic modules, + if they are not in the default location expected by the compiler.}]>; } //===----------------------------------------------------------------------===// Index: clang/lib/Driver/ToolChains/Flang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Flang.cpp +++ clang/lib/Driver/ToolChains/Flang.cpp @@ -42,7 +42,8 @@ void Flang::AddOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const { Args.AddAllArgs(CmdArgs, - {options::OPT_module_dir, options::OPT_fdebug_module_writer}); + {options::OPT_module_dir, options::OPT_fdebug_module_writer, + options::OPT_fintrinsic_modules_path}); } void Flang::ConstructJob(Compilation &C, const JobAction &JA, Index: flang/include/flang/Frontend/PreprocessorOptions.h =================================================================== --- flang/include/flang/Frontend/PreprocessorOptions.h +++ flang/include/flang/Frontend/PreprocessorOptions.h @@ -29,6 +29,8 @@ // 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; + // Search directories specified by the user with -fintrinsic-modules-path + std::vector searchDirectoriesFromIntrModPath; public: PreprocessorOptions() {} @@ -44,4 +46,4 @@ } // namespace Fortran::frontend -#endif // LLVM_FLANG_PREPROCESSOROPTIONS_H \ No newline at end of file +#endif // LLVM_FLANG_PREPROCESSOROPTIONS_H Index: flang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- flang/lib/Frontend/CompilerInvocation.cpp +++ flang/lib/Frontend/CompilerInvocation.cpp @@ -21,8 +21,11 @@ #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" #include "llvm/Option/OptTable.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/FileUtilities.h" #include "llvm/Support/Process.h" #include "llvm/Support/raw_ostream.h" + #include using namespace Fortran::frontend; @@ -282,6 +285,14 @@ return dashX; } +// Generate the path to look for intrinsic modules +static std::string getIntrinsicDir() { + // TODO: Find a system independent API + std::string driverPath = llvm::sys::fs::getMainExecutable(nullptr, nullptr); + driverPath = driverPath.substr(0, driverPath.size() - 9); + return driverPath.append("/../include/flang/"); +} + /// Parses all preprocessor input arguments and populates the preprocessor /// options accordingly. /// @@ -302,6 +313,12 @@ // Add the ordered list of -I's. for (const auto *currentArg : args.filtered(clang::driver::options::OPT_I)) opts.searchDirectoriesFromDashI.emplace_back(currentArg->getValue()); + + // Prepend the ordered list of -intrinsic-modules-path + // to the default location to search (currently hardcoded). + for (const auto *currentArg : + args.filtered(clang::driver::options::OPT_fintrinsic_modules_path)) + opts.searchDirectoriesFromIntrModPath.emplace_back(currentArg->getValue()); } /// Parses all semantic related arguments and populates the variables @@ -496,11 +513,21 @@ collectMacroDefinitions(preprocessorOptions, fortranOptions); + // Adding search directories specified by -I fortranOptions.searchDirectories.insert( fortranOptions.searchDirectories.end(), preprocessorOptions.searchDirectoriesFromDashI.begin(), preprocessorOptions.searchDirectoriesFromDashI.end()); + // Add the ordered list of -intrinsic-modules-path + fortranOptions.searchDirectories.insert( + fortranOptions.searchDirectories.end(), + preprocessorOptions.searchDirectoriesFromIntrModPath.begin(), + preprocessorOptions.searchDirectoriesFromIntrModPath.end()); + + // Add the default intrinsic module directory at the end + fortranOptions.searchDirectories.emplace_back(getIntrinsicDir()); + // Add the directory supplied through -J/-module-dir to the list of search // directories if (moduleDirJ.compare(".") != 0) Index: flang/test/Driver/Inputs/ieee_arithmetic.mod =================================================================== --- /dev/null +++ flang/test/Driver/Inputs/ieee_arithmetic.mod @@ -0,0 +1,7 @@ +! DUMMY module +! Added for testing purposes. The contents of this file are currently not relevant. +module ieee_arithmetic +type::ieee_round_type +integer(1),private::mode=0_1 +end type +end Index: flang/test/Driver/Inputs/iso_fortran_env.mod =================================================================== --- /dev/null +++ flang/test/Driver/Inputs/iso_fortran_env.mod @@ -0,0 +1,7 @@ +! DUMMY module +! Added for testing purposes. The contents of this file are currently not relevant. +module iso_fortran_env +use __fortran_builtins,only:event_type=>__builtin_event_type +use __fortran_builtins,only:lock_type=>__builtin_lock_type +use __fortran_builtins,only:team_type=>__builtin_team_type +end Index: flang/test/Driver/driver-help-hidden.f90 =================================================================== --- flang/test/Driver/driver-help-hidden.f90 +++ flang/test/Driver/driver-help-hidden.f90 @@ -35,6 +35,8 @@ ! CHECK-NEXT: -ffree-form Process source files in free form ! CHECK-NEXT: -fimplicit-none No implicit typing allowed unless overridden by IMPLICIT statements ! CHECK-NEXT: -finput-charset= Specify the default character set for source files +! CHECK-NEXT: -fintrinsic-modules-path +! CHECK-NEXT: Specify where to find the compiled intrinsic modules ! CHECK-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics Index: flang/test/Driver/driver-help.f90 =================================================================== --- flang/test/Driver/driver-help.f90 +++ flang/test/Driver/driver-help.f90 @@ -35,6 +35,8 @@ ! HELP-NEXT: -ffree-form Process source files in free form ! HELP-NEXT: -fimplicit-none No implicit typing allowed unless overridden by IMPLICIT statements ! HELP-NEXT: -finput-charset= Specify the default character set for source files +! HELP-NEXT: -fintrinsic-modules-path +! HELP-NEXT: Specify where to find the compiled intrinsic modules ! HELP-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics @@ -82,6 +84,8 @@ ! HELP-FC1-NEXT: -ffree-form Process source files in free form ! HELP-FC1-NEXT: -fimplicit-none No implicit typing allowed unless overridden by IMPLICIT statements ! HELP-FC1-NEXT: -finput-charset= Specify the default character set for source files +! HELP-FC1-NEXT: -fintrinsic-modules-path +! HELP-FC1-NEXT: Specify where to find the compiled intrinsic modules ! HELP-FC1-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations ! HELP-FC1-NEXT: -fopenacc Enable OpenACC