Skip to content

Commit 563ea45

Browse files
arnamoy10banach-space
authored andcommitted
[flang][driver] Fix -fdefault* family bug
This patch provides a fix for the `fdefault-*` family in f18 (Please consult `D96344` for details) Differential Revision: https://reviews.llvm.org/D97724
1 parent 9a2e2de commit 563ea45

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

flang/tools/f18/f18.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ struct DriverOptions {
102102
bool dumpSymbols{false};
103103
bool debugNoSemantics{false};
104104
bool debugModuleWriter{false};
105+
bool defaultReal8{false};
105106
bool measureTree{false};
106107
bool unparseTypedExprsToF18_FC{false};
107108
std::vector<std::string> F18_FCArgs;
@@ -563,10 +564,20 @@ int main(int argc, char *const argv[]) {
563564
}
564565
} else if (arg.substr(0, 2) == "-U") {
565566
predefinitions.emplace_back(arg.substr(2), std::optional<std::string>{});
566-
} else if (arg == "-fdefault-double-8") {
567-
defaultKinds.set_defaultRealKind(4);
568567
} else if (arg == "-r8" || arg == "-fdefault-real-8") {
568+
driver.defaultReal8 = true;
569569
defaultKinds.set_defaultRealKind(8);
570+
defaultKinds.set_doublePrecisionKind(16);
571+
} else if (arg == "-fdefault-double-8") {
572+
if (!driver.defaultReal8) {
573+
// -fdefault-double-8 has to be used with -fdefault-real-8
574+
// to be compatible with gfortran. See:
575+
// https://gcc.gnu.org/onlinedocs/gfortran/Fortran-Dialect-Options.html
576+
llvm::errs()
577+
<< "Use of `-fdefault-double-8` requires `-fdefault-real-8`\n";
578+
return EXIT_FAILURE;
579+
}
580+
defaultKinds.set_doublePrecisionKind(8);
570581
} else if (arg == "-i8" || arg == "-fdefault-integer-8") {
571582
defaultKinds.set_defaultIntegerKind(8);
572583
defaultKinds.set_subscriptIntegerKind(8);

0 commit comments

Comments
 (0)