[PATCH] [clang][modules] Fix serialization and de-serialization of PC… · llvm/llvm-project@e740675 (original) (raw)

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -9616,9 +9616,9 @@ ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &M, unsigned ID) const {
9616 9616 return I == GlobalSubmoduleMap.end() ? nullptr : I->second;
9617 9617 } else {
9618 9618 // It's a prefix (preamble, PCH, ...). Look it up by index.
9619 - unsigned IndexFromEnd = ID >> 1;
9619 +int IndexFromEnd = static_cast<int>(ID >> 1);
9620 9620 assert(IndexFromEnd && "got reference to unknown module file");
9621 -return getModuleManager().pch_modules().end()[-IndexFromEnd];
9621 +return getModuleManager().pch_modules().end()[-static_cast<int>(IndexFromEnd)];
9622 9622 }
9623 9623 }
9624 9624
@@ -9636,7 +9636,7 @@ unsigned ASTReader::getModuleFileID(ModuleFile *M) {
9636 9636 auto PCHModules = getModuleManager().pch_modules();
9637 9637 auto I = llvm::find(PCHModules, M);
9638 9638 assert(I != PCHModules.end() && "emitting reference to unknown file");
9639 -return (I - PCHModules.end()) << 1;
9639 +return std::distance(I, PCHModules.end()) << 1;
9640 9640 }
9641 9641
9642 9642 std::optional ASTReader::getSourceDescriptor(unsigned ID) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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 \
20 +// RUN: -fmodule-file=mod:part1=%t/Part1.pcm \
21 +// RUN: -fmodule-file=mod:part2=%t/Part2.pcm \
22 +// RUN: -fmodule-file=mod:part3=%t/Part3.pcm \
23 +// RUN: -fmodule-file=mod:part4=%t/Part4.pcm \
24 +// RUN: %t/Mod.cppm \
25 +// RUN: -include-pch %t/a.pch -o %t/Mod.pcm
26 +
27 +// RUN: %clang_cc1 -std=c++20 -emit-obj \
28 +// RUN: -main-file-name Mod.cppm \
29 +// RUN: -fmodule-file=mod:part1=%t/Part1.pcm \
30 +// RUN: -fmodule-file=mod:part2=%t/Part2.pcm \
31 +// RUN: -fmodule-file=mod:part3=%t/Part3.pcm \
32 +// RUN: -fmodule-file=mod:part4=%t/Part4.pcm \
33 +// RUN: -x pcm %t/Mod.pcm \
34 +// RUN: -include-pch %t/a.pch -o %t/Mod.o
35 +
36 +
37 +//--- a.hpp
38 +#pragma once
39 +
40 +class a {
41 +virtual ~a();
42 +a() {}
43 +};
44 +
45 +//--- Part1.cppm
46 +export module mod:part1;
47 +
48 +//--- Part2.cppm
49 +export module mod:part2;
50 +
51 +//--- Part3.cppm
52 +export module mod:part3;
53 +
54 +//--- Part4.cppm
55 +export module mod:part4;
56 +
57 +//--- Mod.cppm
58 +export module mod;
59 +export import :part1;
60 +export import :part2;
61 +export import :part3;
62 +export import :part4;
63 +