From 4a3751ff246394755e113f162435829b7d67d6ed Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 8 May 2017 20:30:47 +0000 Subject: [PATCH] If we are building a module, and we read a second description of the same module from a different module map, ignore it. This happens during builds of preprocessed modules (where it is harmless). llvm-svn: 302463 --- clang/lib/Lex/ModuleMap.cpp | 14 +++++++++++++- clang/test/Modules/preprocess-module.cpp | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index 70d37d3d7082..568894c32b9d 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -1485,7 +1485,19 @@ void ModuleMapParser::parseModuleDecl() { // Determine whether this (sub)module has already been defined. if (Module *Existing = Map.lookupModuleQualified(ModuleName, ActiveModule)) { - if (Existing->DefinitionLoc.isInvalid() && !ActiveModule) { + // We might see a (re)definition of a module that we already have a + // definition for in two cases: + // - If we loaded one definition from an AST file and we've just found a + // corresponding definition in a module map file, or + bool LoadedFromASTFile = Existing->DefinitionLoc.isInvalid(); + // - If we're building a (preprocessed) module and we've just loaded the + // module map file from which it was created. + bool ParsedAsMainInput = + Map.LangOpts.getCompilingModule() == LangOptions::CMK_ModuleMap && + Map.LangOpts.CurrentModule == ModuleName && + SourceMgr.getDecomposedLoc(ModuleNameLoc).first != + SourceMgr.getDecomposedLoc(Existing->DefinitionLoc).first; + if (!ActiveModule && (LoadedFromASTFile || ParsedAsMainInput)) { // Skip the module definition. skipUntil(MMToken::RBrace); if (Tok.is(MMToken::RBrace)) diff --git a/clang/test/Modules/preprocess-module.cpp b/clang/test/Modules/preprocess-module.cpp index a3b789238388..64af00c471df 100644 --- a/clang/test/Modules/preprocess-module.cpp +++ b/clang/test/Modules/preprocess-module.cpp @@ -19,6 +19,11 @@ // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/no-rewrite.ii -emit-module -o %t/no-rewrite.pcm // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/rewrite.ii -emit-module -o %t/rewrite.pcm +// Check that we can load the original module map in the same compilation (this +// could happen if we had a redundant -fmodule-map-file= in the original +// build). +// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -fmodule-map-file=%S/Inputs/preprocess/module.modulemap -x c++-module-map-cpp-output %t/rewrite.ii -emit-module -o /dev/null + // Check the module we built works. // RUN: %clang_cc1 -fmodules -fmodule-file=%t/no-rewrite.pcm %s -verify // RUN: %clang_cc1 -fmodules -fmodule-file=%t/rewrite.pcm %s -verify