[llvm-branch-commits] [clang] 81aaf55 - [Driver] Fix use of classic Flang as preprocessor
Bryan Chan via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jun 24 08:41:05 PDT 2020
Author: Bryan Chan
Date: 2020-06-24T10:23:23-04:00
New Revision: 81aaf55790cfee9af273fcb820403eaa224ebe7f
URL: https://github.com/llvm/llvm-project/commit/81aaf55790cfee9af273fcb820403eaa224ebe7f
DIFF: https://github.com/llvm/llvm-project/commit/81aaf55790cfee9af273fcb820403eaa224ebe7f.diff
LOG: [Driver] Fix use of classic Flang as preprocessor
Added:
Modified:
clang/include/clang/Driver/Types.def
clang/lib/Driver/Driver.cpp
clang/lib/Driver/Types.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Types.def b/clang/include/clang/Driver/Types.def
index 382175dabcce..ec4d2983fca4 100644
--- a/clang/include/clang/Driver/Types.def
+++ b/clang/include/clang/Driver/Types.def
@@ -72,10 +72,10 @@ TYPE("ada", Ada, INVALID, nullptr, phases
TYPE("assembler", PP_Asm, INVALID, "s", phases::Assemble, phases::Link)
TYPE("assembler-with-cpp", Asm, PP_Asm, "S", phases::Preprocess, phases::Assemble, phases::Link)
#ifdef USE_CLASSIC_FLANG
-TYPE("f77", PP_F_FixedForm, INVALID, "f", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("f77-cpp-input", F_FixedForm, PP_F_FixedForm, "F", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("f95", PP_F_FreeForm, INVALID, "f95", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("f95-cpp-input", F_FreeForm, PP_F_FreeForm, "F95", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("f77", PP_F_FixedForm, INVALID, "f", phases::FortranFrontend, phases::Backend, phases::Assemble, phases::Link)
+TYPE("f77-cpp-input", F_FixedForm, PP_F_FixedForm, "F", phases::FortranFrontend, phases::Backend, phases::Assemble, phases::Link)
+TYPE("f95", PP_F_FreeForm, INVALID, "f95", phases::FortranFrontend, phases::Backend, phases::Assemble, phases::Link)
+TYPE("f95-cpp-input", F_FreeForm, PP_F_FreeForm, "F95", phases::FortranFrontend, phases::Backend, phases::Assemble, phases::Link)
#else
TYPE("f95", PP_Fortran, INVALID, nullptr, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("f95-cpp-input", Fortran, PP_Fortran, nullptr, phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 5b5053f3bb73..41ff7f50af43 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3306,6 +3306,11 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
if (InputArg->isClaimed())
continue;
+ // Fortran input is preprocessed using the frontend.
+ if (InitialPhase == phases::FortranFrontend &&
+ FinalPhase == phases::Preprocess)
+ continue;
+
// Claim here to avoid the more general unused warning.
InputArg->claim();
diff --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp
index 2f2d46cfde66..fb136a7f625e 100755
--- a/clang/lib/Driver/Types.cpp
+++ b/clang/lib/Driver/Types.cpp
@@ -46,9 +46,11 @@ const char *types::getTypeName(ID Id) {
types::ID types::getPreprocessedType(ID Id) {
ID PPT = getInfo(Id).PreprocessedType;
+#ifndef USE_CLASSIC_FLANG
assert((llvm::is_contained(getInfo(Id).Phases, phases::Preprocess) !=
(PPT == TY_INVALID)) &&
"Unexpected Preprocess Type.");
+#endif
return PPT;
}
@@ -354,14 +356,24 @@ void types::getCompilationPhases(const clang::driver::Driver &Driver,
types::getCompilationPhases(Id, PhaseList);
// Filter to compiler mode. When the compiler is run as a preprocessor then
- // compilation is not an option.
+ // compilation is not an option, except when the input is Fortran, for which
+ // preprocessing may be delegated to the classic Flang frontend.
// -S runs the compiler in Assembly listing mode.
if (Driver.CCCIsCPP() || DAL.getLastArg(options::OPT_E) ||
DAL.getLastArg(options::OPT__SLASH_EP) ||
DAL.getLastArg(options::OPT_M, options::OPT_MM) ||
DAL.getLastArg(options::OPT__SLASH_P))
+#ifdef USE_CLASSIC_FLANG
+ llvm::copy_if(PhaseList, std::back_inserter(P),
+ [&](phases::ID Phase) {
+ return (Phase <= phases::Preprocess ||
+ (Phase == phases::FortranFrontend &&
+ Driver.IsFlangMode()));
+ });
+#else
llvm::copy_if(PhaseList, std::back_inserter(P),
[](phases::ID Phase) { return Phase <= phases::Preprocess; });
+#endif
// --precompile only runs up to precompilation.
// This is a clang extension and is not compatible with GCC.
More information about the llvm-branch-commits
mailing list