diff options
author | Paul Osmialowski <pawel.osmialowski@arm.com> | 2024-09-27 16:01:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-27 16:01:25 +0100 |
commit | 84a0a3d3b30360b3cf1db3f1c27ff3175bf0aaf2 (patch) | |
tree | b548fb3fbacd7b8ea38f8d3532242558f3902e2c /flang/lib/Frontend/CompilerInvocation.cpp | |
parent | f1c2331a646d28d5f528309b47cde9c13bc20542 (diff) | |
download | llvm-84a0a3d3b30360b3cf1db3f1c27ff3175bf0aaf2.zip llvm-84a0a3d3b30360b3cf1db3f1c27ff3175bf0aaf2.tar.gz llvm-84a0a3d3b30360b3cf1db3f1c27ff3175bf0aaf2.tar.bz2 |
[flang][driver] Make the -J option less restrictive so we would not have to struggle with autoconf (#110010)
There are autoconf-configured projects for which the generated Makefile
is invoking flang with more than one -J option, each one specifying the
same directory. Although only one module directory should be specified
(by either -J or -module-dir), it should not really matter how many
times this same directory has been specified.
Apparently, other compilers understand it that way, hence autoconf's
configure script may generate a Makefile with the repetitive -J's.
For example, when trying to build the ABINIT [1] project (which can be
configured by either CMake or the configure script) when configured by
autoconf, it fails to build as such:
```
make[3]: Entering directory 'src/98_main'
mpifort -DHAVE_CONFIG_H -I. -I../../../src/98_main -I../.. -I../../src/incs -I../../../src/incs -Ifallbacks/exports/include -Jbuild/mods -Jbuild/mods -c -o abinit-abinit.o `test -f 'abinit.F90' || echo '../../../src/98_main/'`abinit.F90
error: Only one '-module-dir/-J' option allowed
make[3]: *** [Makefile:3961: abinit-abinit.o] Error 1
```
This patch solves the problem.
[1] https://github.com/abinit/abinit.git
Diffstat (limited to 'flang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | flang/lib/Frontend/CompilerInvocation.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 05b03ba..d68534d 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -40,6 +40,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/TargetParser/Host.h" #include "llvm/TargetParser/Triple.h" +#include <algorithm> #include <cstdlib> #include <memory> #include <optional> @@ -830,14 +831,20 @@ static bool parseSemaArgs(CompilerInvocation &res, llvm::opt::ArgList &args, unsigned numErrorsBefore = diags.getNumErrors(); // -J/module-dir option - auto moduleDirList = + std::vector<std::string> moduleDirList = args.getAllArgValues(clang::driver::options::OPT_module_dir); - // User can only specify -J/-module-dir once + // User can only specify one -J/-module-dir directory, but may repeat + // -J/-module-dir as long as the directory is the same each time. // https://gcc.gnu.org/onlinedocs/gfortran/Directory-Options.html + std::sort(moduleDirList.begin(), moduleDirList.end()); + moduleDirList.erase(std::unique(moduleDirList.begin(), moduleDirList.end()), + moduleDirList.end()); if (moduleDirList.size() > 1) { const unsigned diagID = diags.getCustomDiagID(clang::DiagnosticsEngine::Error, - "Only one '-module-dir/-J' option allowed"); + "Only one '-module-dir/-J' directory allowed. " + "'-module-dir/-J' may be given multiple times " + "but the directory must be the same each time."); diags.Report(diagID); } if (moduleDirList.size() == 1) |