[PATCH] D97724: [flang][driver] Add -module-dir alias to f18, also fix -fdefault* family bug

Arnamoy B via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 1 13:22:48 PST 2021


arnamoy10 created this revision.
arnamoy10 added reviewers: awarzynski, tskeith, SouraVX, AMDChirag, clementval.
arnamoy10 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch introduces a `-module-dir ` alias to f18 to make it comparable with the flang driver option.

It also provides a fix for the `fdefault-*` family in f18.

(Please consult `D96344` for details)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97724

Files:
  flang/tools/f18/f18.cpp


Index: flang/tools/f18/f18.cpp
===================================================================
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -85,7 +85,7 @@
   bool compileOnly{false}; // -c
   std::string outputPath; // -o path
   std::vector<std::string> searchDirectories; // -I dir
-  std::string moduleDirectory{"."s}; // -module dir
+  std::string moduleDirectory{"."s}; // -module/-module-dir dir
   std::string moduleFileSuffix{".mod"}; // -moduleSuffix suff
   bool forcedForm{false}; // -Mfixed or -Mfree appeared
   bool warnOnNonstandardUsage{false}; // -Mstandard
@@ -102,6 +102,7 @@
   bool dumpSymbols{false};
   bool debugNoSemantics{false};
   bool debugModuleWriter{false};
+  bool defaultReal8{false};
   bool measureTree{false};
   bool unparseTypedExprsToF18_FC{false};
   std::vector<std::string> F18_FCArgs;
@@ -563,10 +564,22 @@
       }
     } else if (arg.substr(0, 2) == "-U") {
       predefinitions.emplace_back(arg.substr(2), std::optional<std::string>{});
-    } else if (arg == "-fdefault-double-8") {
-      defaultKinds.set_defaultRealKind(4);
     } else if (arg == "-r8" || arg == "-fdefault-real-8") {
+      driver.defaultReal8 = true;
       defaultKinds.set_defaultRealKind(8);
+      defaultKinds.set_doublePrecisionKind(16);
+    } else if (arg == "-fdefault-double-8") {
+      if (!driver.defaultReal8) {
+        // -fdefault-double-8 has to be used with -fdefault-real-8
+        // to be compatible with gfortran
+        llvm::errs() << "Use of `-fdefault-double-8` requires `-fdefault-real-8`\n";
+        return EXIT_FAILURE;
+      }
+      // For -fdefault-double-8 + -fdefault-real-8, only the size of
+      // DOUBLE PRECISION type changes, the size of default real type stays
+      // the same
+      // https://gcc.gnu.org/onlinedocs/gfortran/Fortran-Dialect-Options.html
+      defaultKinds.set_doublePrecisionKind(8);
     } else if (arg == "-i8" || arg == "-fdefault-integer-8") {
       defaultKinds.set_defaultIntegerKind(8);
       defaultKinds.set_subscriptIntegerKind(8);
@@ -582,6 +595,7 @@
       defaultKinds.set_sizeIntegerKind(4);
     } else if (arg == "-module") {
       driver.moduleDirectory = args.front();
+      driver.searchDirectories.push_back(driver.moduleDirectory);
       args.pop_front();
     } else if (arg == "-module-dir") {
       driver.moduleDirectory = args.front();
@@ -655,7 +669,7 @@
           << "  -Werror              treat warnings as errors\n"
           << "  -ed                  enable fixed form D lines\n"
           << "  -E                   prescan & preprocess only\n"
-          << "  -module dir          module output directory (default .)\n"
+          << "  -module/-module-dir <dir> module output directory (default .)\n"
           << "  -flatin              interpret source as Latin-1 (ISO 8859-1) "
              "rather than UTF-8\n"
           << "  -fsyntax-only        parsing and semantics only, no output "


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97724.327259.patch
Type: text/x-patch
Size: 2952 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210301/7a2bf3de/attachment.bin>


More information about the llvm-commits mailing list