Skip to content

Commit b976b4a

Browse files
committed
[flang][driver] Add support for -module-suffix
This option is supported in `f18`, but not yet available in `flang-new`. It is required in order to call `flang-new` from the `flang` bash script. Differential Revision: https://reviews.llvm.org/D103613
1 parent 8167052 commit b976b4a

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4519,6 +4519,9 @@ def fdebug_module_writer : Flag<["-"],"fdebug-module-writer">,
45194519
def fget_symbols_sources : Flag<["-"], "fget-symbols-sources">, Group<Action_Group>,
45204520
HelpText<"Dump symbols and their source code locations">;
45214521

4522+
def module_suffix : Separate<["-"], "module-suffix">, Group<f_Group>, MetaVarName<"<suffix>">,
4523+
HelpText<"Use <suffix> as the suffix for module files (the default value is `.mod`)">;
4524+
45224525
}
45234526

45244527
//===----------------------------------------------------------------------===//

flang/include/flang/Frontend/CompilerInvocation.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class CompilerInvocation : public CompilerInvocationBase {
6969
// of options.
7070
std::string moduleDir_ = ".";
7171

72+
std::string moduleFileSuffix_ = ".mod";
73+
7274
bool debugModuleDir_ = false;
7375

7476
bool warnAsErr_ = false;
@@ -97,6 +99,9 @@ class CompilerInvocation : public CompilerInvocationBase {
9799
std::string &moduleDir() { return moduleDir_; }
98100
const std::string &moduleDir() const { return moduleDir_; }
99101

102+
std::string &moduleFileSuffix() { return moduleFileSuffix_; }
103+
const std::string &moduleFileSuffix() const { return moduleFileSuffix_; }
104+
100105
bool &debugModuleDir() { return debugModuleDir_; }
101106
const bool &debugModuleDir() const { return debugModuleDir_; }
102107

@@ -129,6 +134,10 @@ class CompilerInvocation : public CompilerInvocationBase {
129134
/// Useful setters
130135
void SetModuleDir(std::string &moduleDir) { moduleDir_ = moduleDir; }
131136

137+
void SetModuleFileSuffix(const char *moduleFileSuffix) {
138+
moduleFileSuffix_ = std::string(moduleFileSuffix);
139+
}
140+
132141
void SetDebugModuleDir(bool flag) { debugModuleDir_ = flag; }
133142

134143
void SetWarnAsErr(bool flag) { warnAsErr_ = flag; }

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,12 @@ static bool parseSemaArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
395395
res.SetDebugModuleDir(true);
396396
}
397397

398+
// -module-suffix
399+
if (const auto *moduleSuffix =
400+
args.getLastArg(clang::driver::options::OPT_module_suffix)) {
401+
res.SetModuleFileSuffix(moduleSuffix->getValue());
402+
}
403+
398404
return diags.getNumErrors() == numErrorsBefore;
399405
}
400406

@@ -642,5 +648,6 @@ void CompilerInvocation::setSemanticsOpts(
642648
semanticsContext_->set_moduleDirectory(moduleDir())
643649
.set_searchDirectories(fortranOptions.searchDirectories)
644650
.set_warnOnNonstandardUsage(enableConformanceChecks())
645-
.set_warningsAreErrors(warnAsErr());
651+
.set_warningsAreErrors(warnAsErr())
652+
.set_moduleFileSuffix(moduleFileSuffix());
646653
}

flang/test/Driver/driver-help.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
! HELP-FC1-NEXT: -help Display available options
108108
! HELP-FC1-NEXT: -I <dir> Add directory to the end of the list of include search paths
109109
! HELP-FC1-NEXT: -module-dir <dir> Put MODULE files in <dir>
110+
! HELP-FC1-NEXT: -module-suffix <suffix> Use <suffix> as the suffix for module files (the default value is `.mod`)
110111
! HELP-FC1-NEXT: -nocpp Disable predefined and command line preprocessor macros
111112
! HELP-FC1-NEXT: -o <file> Write output to <file>
112113
! HELP-FC1-NEXT: -pedantic Warn on language extensions

flang/test/Driver/module-suffix.f90

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
! Tests `-module-suffix` frontend option
2+
3+
!--------------------------
4+
! RUN lines
5+
!--------------------------
6+
! RUN: rm -rf %t && mkdir -p %t/dir-flang/
7+
! RUN: cd %t && %flang_fc1 -fsyntax-only -module-suffix .f18.mod -module-dir %t/dir-flang %s
8+
! RUN: ls %t/dir-flang/testmodule.f18.mod && not ls %t/dir-flang/testmodule.mod
9+
10+
!--------------------------
11+
! INPUT
12+
!--------------------------
13+
module testmodule
14+
type::t2
15+
end type
16+
end

0 commit comments

Comments
 (0)