Skip to content

Commit 20bd214

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 35ef4c9 commit 20bd214

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
@@ -4522,6 +4522,9 @@ def fdebug_module_writer : Flag<["-"],"fdebug-module-writer">,
45224522
def fget_symbols_sources : Flag<["-"], "fget-symbols-sources">, Group<Action_Group>,
45234523
HelpText<"Dump symbols and their source code locations">;
45244524

4525+
def module_suffix : Separate<["-"], "module-suffix">, Group<f_Group>, MetaVarName<"<suffix>">,
4526+
HelpText<"Use <suffix> as the suffix for module files (the default value is `.mod`)">;
4527+
45254528
}
45264529

45274530
//===----------------------------------------------------------------------===//

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
@@ -392,6 +392,12 @@ static bool parseSemaArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
392392
res.SetDebugModuleDir(true);
393393
}
394394

395+
// -module-suffix
396+
if (const auto *moduleSuffix =
397+
args.getLastArg(clang::driver::options::OPT_module_suffix)) {
398+
res.SetModuleFileSuffix(moduleSuffix->getValue());
399+
}
400+
395401
return diags.getNumErrors() == numErrorsBefore;
396402
}
397403

@@ -639,5 +645,6 @@ void CompilerInvocation::setSemanticsOpts(
639645
semanticsContext_->set_moduleDirectory(moduleDir())
640646
.set_searchDirectories(fortranOptions.searchDirectories)
641647
.set_warnOnNonstandardUsage(enableConformanceChecks())
642-
.set_warningsAreErrors(warnAsErr());
648+
.set_warningsAreErrors(warnAsErr())
649+
.set_moduleFileSuffix(moduleFileSuffix());
643650
}

flang/test/Driver/driver-help.f90

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