Skip to content

Commit cad802f

Browse files
koplasShaderKeeper
and
ShaderKeeper
committed
[PATCH] [clang][modules] Fix serialization and de-serialization of PCH module file refs (#105994)
Co-authored-by: ShaderKeeper <no-reply@shaderkeeper.com>
1 parent 7764847 commit cad802f

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

clang/lib/Serialization/ASTReader.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -9615,7 +9615,7 @@ ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &M, unsigned ID) const {
96159615
// It's a prefix (preamble, PCH, ...). Look it up by index.
96169616
unsigned IndexFromEnd = ID >> 1;
96179617
assert(IndexFromEnd && "got reference to unknown module file");
9618-
return getModuleManager().pch_modules().end()[-IndexFromEnd];
9618+
return getModuleManager().pch_modules().end()[-static_cast<int>(IndexFromEnd)];
96199619
}
96209620
}
96219621

@@ -9633,7 +9633,7 @@ unsigned ASTReader::getModuleFileID(ModuleFile *M) {
96339633
auto PCHModules = getModuleManager().pch_modules();
96349634
auto I = llvm::find(PCHModules, M);
96359635
assert(I != PCHModules.end() && "emitting reference to unknown file");
9636-
return (I - PCHModules.end()) << 1;
9636+
return std::distance(I, PCHModules.end()) << 1;
96379637
}
96389638

96399639
std::optional<ASTSourceDescriptor> ASTReader::getSourceDescriptor(unsigned ID) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Tests mixed usage of precompiled headers and modules.
2+
//
3+
// RUN: rm -rf %t
4+
// RUN: mkdir -p %t
5+
// RUN: split-file %s %t
6+
//
7+
// RUN: %clang_cc1 -std=c++20 -x c++-header -emit-pch %t/a.hpp \
8+
// RUN: -o %t/a.pch
9+
10+
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part1.cppm \
11+
// RUN: -include-pch %t/a.pch -o %t/Part1.pcm
12+
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part2.cppm \
13+
// RUN: -include-pch %t/a.pch -o %t/Part2.pcm
14+
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part3.cppm \
15+
// RUN: -include-pch %t/a.pch -o %t/Part3.pcm
16+
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Part4.cppm \
17+
// RUN: -include-pch %t/a.pch -o %t/Part4.pcm
18+
19+
// RUN: %clang_cc1 -std=c++20 -emit-module-interface -fprebuilt-module-path=%t -fprebuilt-implicit-modules %t/Mod.cppm \
20+
// RUN: -include-pch %t/a.pch -o %t/Mod.pcm
21+
22+
23+
//--- a.hpp
24+
#pragma once
25+
26+
class a {
27+
virtual ~a();
28+
a() {}
29+
};
30+
31+
//--- Part1.cppm
32+
export module mod:part1;
33+
34+
//--- Part2.cppm
35+
export module mod:part2;
36+
37+
//--- Part3.cppm
38+
export module mod:part3;
39+
40+
//--- Part4.cppm
41+
export module mod:part4;
42+
43+
//--- Mod.cppm
44+
export module mod;
45+
export import :part1;
46+
export import :part2;
47+
export import :part3;
48+
export import :part4;
49+

0 commit comments

Comments
 (0)