Skip to content

Commit 235d684

Browse files
committed
[C++20] [Modules] [Reduced BMI] Don't record declarations in functions
by default For reduced BMI, it is meaningless to record the local declarations in functions if not required explicitly during the process of writing the function bodies. It wastes time for reduced BMI and may be problematic if we want to avoid transiting unnecessary changes.
1 parent 7d3924c commit 235d684

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3195,6 +3195,10 @@ uint64_t ASTWriter::WriteDeclContextLexicalBlock(ASTContext &Context,
31953195
if (DC->decls_empty())
31963196
return 0;
31973197

3198+
// In reduced BMI, we don't care the declarations in functions.
3199+
if (GeneratingReducedBMI && DC->isFunctionOrMethod())
3200+
return 0;
3201+
31983202
uint64_t Offset = Stream.GetCurrentBitNo();
31993203
SmallVector<uint32_t, 128> KindDeclPairs;
32003204
for (const auto *D : DC->decls()) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Test that we won't record local declarations by default in reduced BMI.
2+
3+
// RUN: rm -rf %t
4+
// RUN: split-file %s %t
5+
// RUN: cd %t
6+
//
7+
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o %t/a.pcm
8+
// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/a.pcm > %t/a.dump
9+
// RUN: cat %t/a.dump | FileCheck %t/a.cppm
10+
//
11+
// RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-reduced-module-interface -o %t/b.pcm
12+
// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/b.pcm > %t/b.dump
13+
// RUN: cat %t/b.dump | FileCheck %t/b.cppm
14+
15+
//--- a.cppm
16+
export module a;
17+
export int func() {
18+
int v = 43;
19+
return 43;
20+
}
21+
22+
// Test that the variable declaration is not recorded completely.
23+
// CHECK-NOT: <DECL_VAR
24+
25+
//--- b.cppm
26+
export module b;
27+
export inline int func() {
28+
int v = 43;
29+
return v;
30+
}
31+
32+
// Check that we still records the declaration from inline functions.
33+
// CHECK: <DECL_VAR

0 commit comments

Comments
 (0)