Skip to content

Commit bfa1e02

Browse files
committed
Move the included vector into HeaderFileInfoTrait::data_type and add a test case.
1 parent 9cc149d commit bfa1e02

File tree

2 files changed

+76
-9
lines changed

2 files changed

+76
-9
lines changed

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,11 +2095,11 @@ namespace {
20952095

20962096
struct data_type {
20972097
data_type(const HeaderFileInfo &HFI,
2098-
const std::vector<const Module *> &Includers,
2098+
std::vector<const Module *> &&Includers,
20992099
ArrayRef<ModuleMap::KnownHeader> KnownHeaders,
21002100
UnresolvedModule Unresolved)
2101-
: HFI(HFI), Includers(Includers), KnownHeaders(KnownHeaders),
2102-
Unresolved(Unresolved) {}
2101+
: HFI(HFI), Includers(std::move(Includers)),
2102+
KnownHeaders(KnownHeaders), Unresolved(Unresolved) {}
21032103

21042104
HeaderFileInfo HFI;
21052105
std::vector<const Module *> Includers;
@@ -2157,10 +2157,11 @@ namespace {
21572157
endian::Writer LE(Out, llvm::endianness::little);
21582158
uint64_t Start = Out.tell(); (void)Start;
21592159

2160-
unsigned char Flags = (Data.HFI.isImport << 5)
2161-
| (Writer.isWritingStdCXXNamedModules() ? 0 :
2162-
Data.HFI.isPragmaOnce << 4)
2163-
| (Data.HFI.DirInfo << 1);
2160+
unsigned char Flags =
2161+
(Data.HFI.isImport << 5) |
2162+
(Writer.isWritingStdCXXNamedModules() ? 0
2163+
: Data.HFI.isPragmaOnce << 4) |
2164+
(Data.HFI.DirInfo << 1);
21642165
LE.write<uint8_t>(Flags);
21652166

21662167
if (Data.HFI.LazyControllingMacro.isID())
@@ -2308,8 +2309,10 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) {
23082309
Filename, File->getSize(), getTimestampForOutput(*File)
23092310
};
23102311
HeaderFileInfoTrait::data_type Data = {
2311-
*HFI, Includers, HS.getModuleMap().findResolvedModulesForHeader(*File), {}
2312-
};
2312+
*HFI,
2313+
std::move(Includers),
2314+
HS.getModuleMap().findResolvedModulesForHeader(*File),
2315+
{}};
23132316
Generator.insert(Key, Data, GeneratorTrait);
23142317
++NumHeaderSearchEntries;
23152318
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// This test checks that imports of headers that appeared in a different submodule than
2+
// what is imported by the current TU don't affect the compilation.
3+
4+
// RUN: rm -rf %t
5+
// RUN: split-file %s %t
6+
7+
//--- C/C.h
8+
#include "Textual.h"
9+
//--- C/module.modulemap
10+
module C { header "C.h" }
11+
12+
//--- D/D1.h
13+
#include "Textual.h"
14+
//--- D/D2.h
15+
//--- D/module.modulemap
16+
module D {
17+
module D1 { header "D1.h" }
18+
module D2 { header "D2.h" }
19+
}
20+
21+
//--- E/E1.h
22+
#include "E2.h"
23+
//--- E/E2.h
24+
#include "Textual.h"
25+
//--- E/module.modulemap
26+
module E {
27+
module E1 { header "E1.h" }
28+
module E2 { header "E2.h" }
29+
}
30+
31+
//--- Textual.h
32+
#define MACRO_TEXTUAL 1
33+
34+
//--- test_top.c
35+
#import "Textual.h"
36+
static int x = MACRO_TEXTUAL;
37+
38+
//--- test_sub.c
39+
#import "D/D2.h"
40+
#import "Textual.h"
41+
static int x = MACRO_TEXTUAL;
42+
43+
//--- test_transitive.c
44+
#import "E/E1.h"
45+
#import "Textual.h"
46+
static int x = MACRO_TEXTUAL;
47+
48+
// Simply loading a PCM file containing top-level module including a header does
49+
// not prevent inclusion of that header in the TU.
50+
//
51+
// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/C/module.modulemap -fmodule-name=C -o %t/C.pcm
52+
// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test_top.c -fmodule-file=%t/C.pcm
53+
54+
// Loading a PCM file and importing its empty submodule does not prevent
55+
// inclusion of headers included by invisible sibling submodules.
56+
//
57+
// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/D/module.modulemap -fmodule-name=D -o %t/D.pcm
58+
// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test_sub.c -fmodule-file=%t/D.pcm
59+
60+
// Loading a PCM file and importing a submodule does not prevent inclusion of
61+
// headers included by some of its transitive un-exported dependencies.
62+
//
63+
// RUN: %clang_cc1 -fmodules -I %t -emit-module %t/E/module.modulemap -fmodule-name=E -o %t/E.pcm
64+
// RUN: %clang_cc1 -fmodules -I %t -fsyntax-only %t/test_transitive.c -fmodule-file=%t/E.pcm

0 commit comments

Comments
 (0)