diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2018-11-05 12:46:02 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2018-11-05 12:46:02 +0000 |
commit | 5904c41ed26dd1031acb0dbc991c3fd272ceb21f (patch) | |
tree | f4b460339416b1717630eda20bc8e71b8a1a8c6f | |
parent | 5f60861be706191866341c52b6ce5bbcb1c024ed (diff) | |
download | llvm-5904c41ed26dd1031acb0dbc991c3fd272ceb21f.zip llvm-5904c41ed26dd1031acb0dbc991c3fd272ceb21f.tar.gz llvm-5904c41ed26dd1031acb0dbc991c3fd272ceb21f.tar.bz2 |
Reapply "Fix regression in behavior of clang -x c++-header -fmodule-name=XXX"
This reverts commit r345963. We have a path forward now.
Original commit message:
The driver accidentally stopped passing the input filenames on to -cc1
in this mode due to confusion over what action was being requested.
This change also fixes a couple of crashes I encountered when passing
multiple files to such a -cc1 invocation.
llvm-svn: 346130
-rw-r--r-- | clang/lib/Driver/ToolChains/Clang.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Lex/ModuleMap.cpp | 2 | ||||
-rw-r--r-- | clang/test/Driver/header-module.cpp | 13 | ||||
-rw-r--r-- | clang/test/Modules/strict-decluse-headers.cpp | 17 |
5 files changed, 36 insertions, 9 deletions
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 83830b5..c35f7a9 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3250,18 +3250,15 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, bool IsCuda = JA.isOffloading(Action::OFK_Cuda); bool IsHIP = JA.isOffloading(Action::OFK_HIP); bool IsOpenMPDevice = JA.isDeviceOffloading(Action::OFK_OpenMP); - bool IsModulePrecompile = - isa<PrecompileJobAction>(JA) && JA.getType() == types::TY_ModuleFile; bool IsHeaderModulePrecompile = isa<HeaderModulePrecompileJobAction>(JA); // A header module compilation doesn't have a main input file, so invent a // fake one as a placeholder. - // FIXME: Pick the language based on the header file language. const char *ModuleName = [&]{ auto *ModuleNameArg = Args.getLastArg(options::OPT_fmodule_name_EQ); return ModuleNameArg ? ModuleNameArg->getValue() : ""; }(); - InputInfo HeaderModuleInput(types::TY_CXXModule, ModuleName, ModuleName); + InputInfo HeaderModuleInput(Inputs[0].getType(), ModuleName, ModuleName); const InputInfo &Input = IsHeaderModulePrecompile ? HeaderModuleInput : Inputs[0]; @@ -3272,10 +3269,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, for (const InputInfo &I : Inputs) { if (&I == &Input) { // This is the primary input. - } else if (IsModulePrecompile && + } else if (IsHeaderModulePrecompile && types::getPrecompiledType(I.getType()) == types::TY_PCH) { - types::ID Expected = - types::lookupHeaderTypeForSourceType(Inputs[0].getType()); + types::ID Expected = HeaderModuleInput.getType(); if (I.getType() != Expected) { D.Diag(diag::err_drv_module_header_wrong_kind) << I.getFilename() << types::getTypeName(I.getType()) diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index a9c51d4..719474d 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -372,6 +372,9 @@ static void InitializeFileRemapping(DiagnosticsEngine &Diags, void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { const PreprocessorOptions &PPOpts = getPreprocessorOpts(); + // The module manager holds a reference to the old preprocessor (if any). + ModuleManager.reset(); + // Create a PTH manager if we are using some form of a token cache. PTHManager *PTHMgr = nullptr; if (!PPOpts.TokenCache.empty()) diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index d44bf12..13d2b72 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -523,7 +523,7 @@ void ModuleMap::diagnoseHeaderInclusion(Module *RequestingModule, // At this point, only non-modular includes remain. - if (LangOpts.ModulesStrictDeclUse) { + if (RequestingModule && LangOpts.ModulesStrictDeclUse) { Diags.Report(FilenameLoc, diag::err_undeclared_use_of_module) << RequestingModule->getTopLevelModule()->Name << Filename; } else if (RequestingModule && RequestingModuleIsModuleInterface && diff --git a/clang/test/Driver/header-module.cpp b/clang/test/Driver/header-module.cpp index 2302c49..9a6ba5b 100644 --- a/clang/test/Driver/header-module.cpp +++ b/clang/test/Driver/header-module.cpp @@ -7,7 +7,18 @@ // CHECK-PRECOMPILE-SAME: -fno-implicit-modules // CHECK-PRECOMPILE-SAME: -fmodule-name=foobar // CHECK-PRECOMPILE-SAME: -o {{.*}}.pcm -// CHECK-PRECOMPILE-SAME: -x c++ +// CHECK-PRECOMPILE-SAME: -x c++-header // CHECK-PRECOMPILE-SAME: header1.h // CHECK-PRECOMPILE-SAME: header2.h // CHECK-PRECOMPILE-SAME: header3.h +// +// RUN: %clang -fmodules-ts -fmodule-name=foobar -x c++-header -fsyntax-only %S/Inputs/header1.h %S/Inputs/header2.h %S/Inputs/header3.h -v 2>&1 | FileCheck %s --check-prefix=CHECK-SYNTAX-ONLY +// CHECK-SYNTAX-ONLY: -cc1 {{.*}} -fsyntax-only +// CHECK-SYNTAX-ONLY-SAME: -fmodules-ts +// CHECK-SYNTAX-ONLY-SAME: -fno-implicit-modules +// CHECK-SYNTAX-ONLY-SAME: -fmodule-name=foobar +// CHECK-SYNTAX-ONLY-NOT: -o{{ }} +// CHECK-SYNTAX-ONLY-SAME: -x c++-header +// CHECK-SYNTAX-ONLY-SAME: header1.h +// CHECK-SYNTAX-ONLY-SAME: header2.h +// CHECK-SYNTAX-ONLY-SAME: header3.h diff --git a/clang/test/Modules/strict-decluse-headers.cpp b/clang/test/Modules/strict-decluse-headers.cpp new file mode 100644 index 0000000..deeda2f --- /dev/null +++ b/clang/test/Modules/strict-decluse-headers.cpp @@ -0,0 +1,17 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: touch %t/foo.h +// RUN: echo '#include "foo.h"' > %t/bar.h +// RUN: touch %t/baz.h +// RUN: echo 'module X { header "bar.h" header "baz.h" }' > %t/map +// +// RUN: not %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%t/map -I%t -fmodules-strict-decluse -fmodule-name=X -x c++ %t/bar.h %t/baz.h 2>&1 | FileCheck %s +// RUN: not %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%t/map -I%t -fmodules-strict-decluse -fmodule-name=X -x c++ %t/baz.h %t/bar.h 2>&1 | FileCheck %s +// +// Don't crash on this: (FIXME: we should produce an error that the specified module name is not known) +// RUN: %clang_cc1 -fsyntax-only -fmodules -I%t -fmodules-strict-decluse -fmodule-name=X -x c++ %t/baz.h %t/bar.h +// +// Don't crash on this: (FIXME: we should produce an error that the specified file is not part of the specified module) +// RUN: %clang_cc1 -fsyntax-only -fmodules -fmodule-map-file=%t/map -I%t -fmodules-strict-decluse -fmodule-name=X -x c++ %t/foo.h +// +// CHECK: module X does not depend on a module exporting 'foo.h' |