Skip to content

Commit d8baec2

Browse files
committedAug 1, 2018
[Modules] Do not emit relocation error when -fno-validate-pch is set
Summary: Clang emits error when implicit modules was relocated from the first build directory. However this was biting our usecase where we copy the contents of build directory to another directory in order to distribute. Differential Revision: https://reviews.llvm.org/D49852 llvm-svn: 338503
1 parent 8aca1c8 commit d8baec2

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed
 

‎clang/lib/Serialization/ASTReader.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -2632,7 +2632,9 @@ ASTReader::ReadControlBlock(ModuleFile &F,
26322632
if (M && M->Directory) {
26332633
// If we're implicitly loading a module, the base directory can't
26342634
// change between the build and use.
2635-
if (F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) {
2635+
// Don't emit module relocation error if we have -fno-validate-pch
2636+
if (!PP.getPreprocessorOpts().DisablePCHValidation &&
2637+
F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) {
26362638
const DirectoryEntry *BuildDir =
26372639
PP.getFileManager().getDirectory(Blob);
26382640
if (!BuildDir || BuildDir != M->Directory) {
@@ -3602,7 +3604,8 @@ ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
36023604
Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName);
36033605
auto &Map = PP.getHeaderSearchInfo().getModuleMap();
36043606
const FileEntry *ModMap = M ? Map.getModuleMapFileForUniquing(M) : nullptr;
3605-
if (!ModMap) {
3607+
// Don't emit module relocation error if we have -fno-validate-pch
3608+
if (!PP.getPreprocessorOpts().DisablePCHValidation && !ModMap) {
36063609
assert(ImportedBy && "top-level import should be verified");
36073610
if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) {
36083611
if (auto *ASTFE = M ? M->getASTFile() : nullptr) {
@@ -5039,7 +5042,9 @@ ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) {
50395042

50405043
if (!ParentModule) {
50415044
if (const FileEntry *CurFile = CurrentModule->getASTFile()) {
5042-
if (CurFile != F.File) {
5045+
// Don't emit module relocation error if we have -fno-validate-pch
5046+
if (!PP.getPreprocessorOpts().DisablePCHValidation &&
5047+
CurFile != F.File) {
50435048
if (!Diags.isDiagnosticInFlight()) {
50445049
Diag(diag::err_module_file_conflict)
50455050
<< CurrentModule->getTopLevelModuleName()

‎clang/test/Modules/resolution-change.m

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/modules-with-same-name/DependsOnA -I %S/Inputs/modules-with-same-name/path2/A -include-pch %t-A.pch %s -fsyntax-only 2>&1 | FileCheck -check-prefix=CHECK-WRONGA %s
2222
// CHECK-WRONGA: module 'A' was built in directory '{{.*Inputs.modules-with-same-name.path1.A}}' but now resides in directory '{{.*Inputs.modules-with-same-name.path2.A}}'
2323

24+
// RUN: %clang_cc1 -fno-validate-pch -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/modules-with-same-name/DependsOnA -I %S/Inputs/modules-with-same-name/path2/A -include-pch %t-A.pch %s -fsyntax-only
25+
2426
#ifndef HEADER
2527
#define HEADER
2628
@import DependsOnA;

0 commit comments

Comments
 (0)