r345803 - Fix regression in behavior of clang -x c++-header -fmodule-name=XXX

Shoaib Meenai via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 31 18:04:53 PDT 2018


Comment inline (Outlook handles quoting terribly, so I'm not sure how much it'll end up standing out, but I believe you typo'd "preprocessor" as " prepreocssor").

From: cfe-commits <cfe-commits-bounces at lists.llvm.org> on behalf of Richard Smith via cfe-commits <cfe-commits at lists.llvm.org>
Reply-To: Richard Smith <richard-llvm at metafoo.co.uk>
Date: Wednesday, October 31, 2018 at 5:49 PM
To: "cfe-commits at lists.llvm.org" <cfe-commits at lists.llvm.org>
Subject: r345803 - Fix regression in behavior of clang -x c++-header -fmodule-name=XXX

Author: rsmith
Date: Wed Oct 31 17:46:54 2018
New Revision: 345803

URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D345803-26view-3Drev&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=fuhDqKU4xiQGQizq6Oszj5RJTGnnRK6S35y0Pk_bRcg&s=xpyBxlufGiJ3htehnYAB4PVF1WQvpPF9AR-tGM8UMfQ&e=
Log:
Fix regression in behavior of clang -x c++-header -fmodule-name=XXX
-fsyntax-only.

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.

Added:
    cfe/trunk/test/Modules/strict-decluse-headers.cpp
Modified:
    cfe/trunk/lib/Driver/ToolChains/Clang.cpp
    cfe/trunk/lib/Frontend/CompilerInstance.cpp
    cfe/trunk/lib/Lex/ModuleMap.cpp
    cfe/trunk/test/Driver/header-module.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_lib_Driver_ToolChains_Clang.cpp-3Frev-3D345803-26r1-3D345802-26r2-3D345803-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=fuhDqKU4xiQGQizq6Oszj5RJTGnnRK6S35y0Pk_bRcg&s=ffTui8JxCdjW5IP4JDgCIPKtFCLV4p96l0j4dM3OM4o&e=
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed Oct 31 17:46:54 2018
@@ -3250,8 +3250,6 @@ void Clang::ConstructJob(Compilation &C,
   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
@@ -3272,7 +3270,7 @@ void Clang::ConstructJob(Compilation &C,
   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());

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_lib_Frontend_CompilerInstance.cpp-3Frev-3D345803-26r1-3D345802-26r2-3D345803-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=fuhDqKU4xiQGQizq6Oszj5RJTGnnRK6S35y0Pk_bRcg&s=KzBhYXfmPHLMrIoUboynLdE1ADPHU0qpcmI6eN5hG9w&e=
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Wed Oct 31 17:46:54 2018
@@ -372,6 +372,9 @@ static void InitializeFileRemapping(Diag
void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
   const PreprocessorOptions &PPOpts = getPreprocessorOpts();
+  // The module manager holds a reference to the old prepreocssor (if any).

I'm guessing this was meant to be "preprocessor"?

+  ModuleManager.reset();
+
   // Create a PTH manager if we are using some form of a token cache.
   PTHManager *PTHMgr = nullptr;
   if (!PPOpts.TokenCache.empty())

Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_lib_Lex_ModuleMap.cpp-3Frev-3D345803-26r1-3D345802-26r2-3D345803-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=fuhDqKU4xiQGQizq6Oszj5RJTGnnRK6S35y0Pk_bRcg&s=nNcoGXKyPGb6zXQpXy0g-2NVm65eDiskYntWuXgkrmQ&e=
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Wed Oct 31 17:46:54 2018
@@ -523,7 +523,7 @@ void ModuleMap::diagnoseHeaderInclusion(
   // 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 &&

Modified: cfe/trunk/test/Driver/header-module.cpp
URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_test_Driver_header-2Dmodule.cpp-3Frev-3D345803-26r1-3D345802-26r2-3D345803-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=fuhDqKU4xiQGQizq6Oszj5RJTGnnRK6S35y0Pk_bRcg&s=NZLaogjPrzbf0BsFHDpWA5l8cTRJDs11eDYky1EWLkg&e=
==============================================================================
--- cfe/trunk/test/Driver/header-module.cpp (original)
+++ cfe/trunk/test/Driver/header-module.cpp Wed Oct 31 17:46:54 2018
@@ -11,3 +11,14 @@
// 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++
+// CHECK-SYNTAX-ONLY-SAME: header1.h
+// CHECK-SYNTAX-ONLY-SAME: header2.h
+// CHECK-SYNTAX-ONLY-SAME: header3.h

Added: cfe/trunk/test/Modules/strict-decluse-headers.cpp
URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_test_Modules_strict-2Ddecluse-2Dheaders.cpp-3Frev-3D345803-26view-3Dauto&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=fuhDqKU4xiQGQizq6Oszj5RJTGnnRK6S35y0Pk_bRcg&s=J0oYrXB66AueyeEEv8WPnwoGPl1lemvbwRTcoLhC5wA&e=
==============================================================================
--- cfe/trunk/test/Modules/strict-decluse-headers.cpp (added)
+++ cfe/trunk/test/Modules/strict-decluse-headers.cpp Wed Oct 31 17:46:54 2018
@@ -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'


_______________________________________________
cfe-commits mailing list
cfe-commits at lists.llvm.org<mailto:cfe-commits at lists.llvm.org>
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_cfe-2Dcommits&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=fuhDqKU4xiQGQizq6Oszj5RJTGnnRK6S35y0Pk_bRcg&s=9N-FCRVsXGX1zREUCH5S_6grC4c09So-ZYXshtWepWI&e=

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181101/ee315829/attachment-0001.html>


More information about the cfe-commits mailing list