Skip to content

Commit 9eeea3f

Browse files
committed
[clang][modules] Do consider module maps of included textual headers affecting
1 parent 17b1860 commit 9eeea3f

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ GetAffectingModuleMaps(const Preprocessor &PP, Module *RootModule) {
187187
continue;
188188

189189
const HeaderFileInfo *HFI = HS.getExistingLocalFileInfo(*File);
190-
if (!HFI || ((HFI->isModuleHeader || HFI->isTextualModuleHeader) &&
191-
!HFI->isCompilingModuleHeader))
190+
if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader) ||
191+
(HFI->isTextualModuleHeader && !PP.alreadyIncluded(*File)))
192192
continue;
193193

194194
for (const auto &KH : HS.findResolvedModulesForHeader(*File)) {
@@ -2058,12 +2058,14 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) {
20582058

20592059
// Get the file info. Skip emitting this file if we have no information on
20602060
// it as a header file (in which case HFI will be null) or if it hasn't
2061-
// changed since it was loaded. Also skip it if it's for a non-excluded
2062-
// header from a different module; in that case, we rely on the module(s)
2063-
// containing the header to provide this information.
2061+
// changed since it was loaded. Also skip it if it's for a modular header
2062+
// from a different module; in that case, we rely on the module(s)
2063+
// containing the header to provide this information. Also skip it if it's
2064+
// for a textual header from a different module that has not been included;
2065+
// in that case, we don't need the information at all.
20642066
const HeaderFileInfo *HFI = HS.getExistingLocalFileInfo(*File);
2065-
if (!HFI || ((HFI->isModuleHeader || HFI->isTextualModuleHeader) &&
2066-
!HFI->isCompilingModuleHeader))
2067+
if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader) ||
2068+
(HFI->isTextualModuleHeader && !PP->alreadyIncluded(*File)))
20672069
continue;
20682070

20692071
// Massage the file path into an appropriate form.
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
// This test checks that a module map with a textual header can be marked as
2-
// non-affecting.
2+
// non-affecting if its header did not get included.
33

44
// RUN: rm -rf %t && mkdir %t
55
// RUN: split-file %s %t
66

77
//--- A.modulemap
88
module A { textual header "A.h" }
99
//--- B.modulemap
10-
module B { header "B.h" export * }
10+
module B { header "B.h" }
1111
//--- A.h
12-
typedef int A_int;
1312
//--- B.h
14-
#include "A.h"
15-
typedef A_int B_int;
16-
17-
// RUN: %clang_cc1 -fmodules -emit-module %t/A.modulemap -fmodule-name=A -o %t/A.pcm \
18-
// RUN: -fmodule-map-file=%t/A.modulemap -fmodule-map-file=%t/B.modulemap
1913

2014
// RUN: %clang_cc1 -fmodules -emit-module %t/B.modulemap -fmodule-name=B -o %t/B0.pcm \
21-
// RUN: -fmodule-map-file=%t/A.modulemap -fmodule-map-file=%t/B.modulemap -fmodule-file=%t/A.pcm
15+
// RUN: -fmodule-map-file=%t/A.modulemap -fmodule-map-file=%t/B.modulemap
2216

2317
// RUN: %clang_cc1 -fmodules -emit-module %t/B.modulemap -fmodule-name=B -o %t/B1.pcm \
24-
// RUN: -fmodule-map-file=%t/B.modulemap -fmodule-file=%t/A.pcm
18+
// RUN: -fmodule-map-file=%t/B.modulemap
2519

2620
// RUN: diff %t/B0.pcm %t/B1.pcm

0 commit comments

Comments
 (0)