arnamoy10 updated this revision to Diff 326234.
arnamoy10 edited the summary of this revision.
arnamoy10 added a comment.

Addressing comments, by separating the search directories from 
`fintrinsic-modules-path` in a separate variables.  Also added dummy modules 
for the test case, as using `%llvmshlibdir` did not work out.

Also, not sure what to set as the default directory, as gfortran uses a 
specific installation location.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97080/new/

https://reviews.llvm.org/D97080

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/ieee_arithmetic.mod
  flang/test/Flang-Driver/Inputs/iso_fortran_env.mod
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/intrinsic_module_path.f90

Index: flang/test/Flang-Driver/intrinsic_module_path.f90
===================================================================
--- /dev/null
+++ flang/test/Flang-Driver/intrinsic_module_path.f90
@@ -0,0 +1,32 @@
+! Ensure argument -fintrinsic-modules-path works as expected.
+
+
+!--------------------------
+! FLANG DRIVER (flang-new)
+!--------------------------
+! RUN: not %flang-new -fsyntax-only %s  2>&1 | FileCheck %s --check-prefix=WITHOUT
+! RUN: not %flang-new -fsyntax-only -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-----------------------------------------
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-----------------------------------------
+! RUN: not %flang-new -fc1 %s  2>&1 | FileCheck %s --check-prefix=WITHOUT
+! RUN: not %flang-new -fc1 -fintrinsic-modules-path %S/Inputs/ %s  2>&1 | FileCheck %s --check-prefix=GIVEN
+
+!-----------------------------------------
+! EXPECTED OUTPUT WITHOUT
+!-----------------------------------------
+! WITHOUT: 'ieee_arithmetic.mod' was not found
+! WITHOUT: 'iso_fortran_env.mod' was not found
+
+!-----------------------------------------
+! EXPECTED OUTPUT WITH
+!-----------------------------------------
+! GIVEN-NOT: 'ieee_arithmetic.mod' was not found
+! GIVEN-NOT: 'iso_fortran_env.mod' was not found
+
+
+program test_intrinsic_module_path
+   use ieee_arithmetic, only: ieee_round_type
+   use iso_fortran_env, only: team_type, event_type, lock_type
+end program
Index: flang/test/Flang-Driver/driver-help.f90
===================================================================
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -32,6 +32,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=<value> Specify the default character set for source files
+! HELP-NEXT: -fintrinsic-modules-path <dir>
+! HELP-NEXT:                        Specify where to find the compiled intrinsic modules.
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -fopenacc              Enable OpenACC
@@ -72,6 +74,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=<value> Specify the default character set for source files
+! HELP-FC1-NEXT: -fintrinsic-modules-path <dir>
+! HELP-FC1-NEXT:                        Specify where to find the compiled intrinsic modules.
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-FC1-NEXT: -fopenacc              Enable OpenACC
 ! HELP-FC1-NEXT: -fopenmp               Parse OpenMP pragmas and generate parallel code.
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
@@ -32,6 +32,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=<value> Specify the default character set for source files
+! CHECK-NEXT: -fintrinsic-modules-path <dir>
+! CHECK-NEXT:                        Specify where to find the compiled intrinsic modules.
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! CHECK-NEXT: -fopenacc              Enable OpenACC
Index: flang/test/Flang-Driver/Inputs/iso_fortran_env.mod
===================================================================
--- /dev/null
+++ flang/test/Flang-Driver/Inputs/iso_fortran_env.mod
@@ -0,0 +1,6 @@
+! DUMMY module
+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/Flang-Driver/Inputs/ieee_arithmetic.mod
===================================================================
--- /dev/null
+++ flang/test/Flang-Driver/Inputs/ieee_arithmetic.mod
@@ -0,0 +1,6 @@
+! DUMMY module
+module ieee_arithmetic
+type::ieee_round_type
+integer(1),private::mode=0_1
+end type
+end
Index: flang/lib/Frontend/CompilerInvocation.cpp
===================================================================
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -294,6 +294,11 @@
   // Add the ordered list of -I's.
   for (const auto *currentArg : args.filtered(clang::driver::options::OPT_I))
     opts.searchDirectoriesFromDashI.emplace_back(currentArg->getValue());
+
+  // Add the ordered list of -intrinsic-modules-path
+  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
@@ -438,10 +443,17 @@
 
   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 directory supplied through -J/-module-dir to the list of search
   // directories
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<std::string> searchDirectoriesFromDashI;
+  // Search directories specified by the user with -fintrinsic-modules-path
+  std::vector<std::string> 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: clang/lib/Driver/ToolChains/Flang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -39,7 +39,8 @@
 }
 
 void Flang::AddOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
-  Args.AddAllArgs(CmdArgs, options::OPT_module_dir);
+  Args.AddAllArgs(
+      CmdArgs, {options::OPT_module_dir, options::OPT_fintrinsic_modules_path});
 }
 
 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
@@ -4205,7 +4205,6 @@
 defm frontend_optimize : BooleanFFlag<"frontend-optimize">, Group<gfortran_Group>;
 defm init_local_zero : BooleanFFlag<"init-local-zero">, Group<gfortran_Group>;
 defm integer_4_integer_8 : BooleanFFlag<"integer-4-integer-8">, Group<gfortran_Group>;
-defm intrinsic_modules_path : BooleanFFlag<"intrinsic-modules-path">, Group<gfortran_Group>;
 defm max_identifier_length : BooleanFFlag<"max-identifier-length">, Group<gfortran_Group>;
 defm module_private : BooleanFFlag<"module-private">, Group<gfortran_Group>;
 defm pack_derived : BooleanFFlag<"pack-derived">, Group<gfortran_Group>;
@@ -4278,6 +4277,10 @@
 def fno_implicit_none : Flag<["-"], "fno-implicit-none">, Group<f_Group>;
 def falternative_parameter_statement : Flag<["-"], "falternative-parameter-statement">, Group<f_Group>,
   HelpText<"Enable the old style PARAMETER statement">;
+def fintrinsic_modules_path : Separate<["-"], "fintrinsic-modules-path">,  Group<f_Group>, MetaVarName<"<dir>">,
+  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.}]>;
 }
 
 //===----------------------------------------------------------------------===//
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to