From: Richard Smith Date: Fri, 2 Nov 2018 00:24:40 +0000 (+0000) Subject: When building a header module, treat inputs as headers rather than X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=36e55fc3d8bc29d392902c98b856536fd2232bf4;p=clang When building a header module, treat inputs as headers rather than source files. This suppresses certain warnings (eg, '#include_next in main source file'). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@345915 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index eda8912156..926db3d4f9 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -3254,12 +3254,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &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,8 +3271,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // This is the primary input. } 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/test/Driver/header-module.cpp b/test/Driver/header-module.cpp index 7765840042..9a6ba5b108 100644 --- a/test/Driver/header-module.cpp +++ b/test/Driver/header-module.cpp @@ -7,7 +7,7 @@ // 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 @@ -18,7 +18,7 @@ // 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: -x c++-header // CHECK-SYNTAX-ONLY-SAME: header1.h // CHECK-SYNTAX-ONLY-SAME: header2.h // CHECK-SYNTAX-ONLY-SAME: header3.h