Skip to content

Commit a4f75ec

Browse files
authored
[C++20] [Modules] Don't record implicitly declarations to BMI by default (#93459)
I found we may insert unused implciit declarations like AArch SVE declarations by default on AArch64 due to we will insert that by default. But it should be completely redundant and this patch tries to remove that.
1 parent 8b03786 commit a4f75ec

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5037,6 +5037,14 @@ void ASTWriter::PrepareWritingSpecialDecls(Sema &SemaRef) {
50375037
continue;
50385038
}
50395039

5040+
// If we're writing C++ named modules, don't emit declarations which are
5041+
// not from modules by default. They may be built in declarations (be
5042+
// handled above) or implcit declarations (see the implementation of
5043+
// `Sema::Initialize()` for example).
5044+
if (isWritingStdCXXNamedModules() && !D->getOwningModule() &&
5045+
D->isImplicit())
5046+
continue;
5047+
50405048
GetDeclRef(D);
50415049
}
50425050

@@ -6197,8 +6205,9 @@ bool ASTWriter::wasDeclEmitted(const Decl *D) const {
61976205
return true;
61986206

61996207
bool Emitted = DeclIDs.contains(D);
6200-
assert((Emitted || GeneratingReducedBMI) &&
6201-
"The declaration can only be omitted in reduced BMI.");
6208+
assert((Emitted || (!D->getOwningModule() && isWritingStdCXXNamedModules()) ||
6209+
GeneratingReducedBMI) &&
6210+
"The declaration within modules can only be omitted in reduced BMI.");
62026211
return Emitted;
62036212
}
62046213

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir %t
3+
//
4+
// RUN: %clang_cc1 -std=c++20 %s -emit-module-interface -o %t/a.pcm
5+
// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/a.pcm > %t/a.dump
6+
// RUN: cat %t/a.dump | FileCheck %s
7+
//
8+
// RUN: %clang_cc1 -std=c++20 %s -emit-reduced-module-interface -o %t/a.pcm
9+
// RUN: llvm-bcanalyzer --dump --disable-histogram --show-binary-blobs %t/a.pcm > %t/a.dump
10+
// RUN: cat %t/a.dump | FileCheck %s
11+
12+
export module a;
13+
// Contain something at least to make sure the compiler won't
14+
// optimize this out.
15+
export int a = 43;
16+
17+
// CHECK: <DECLTYPES_BLOCK
18+
// CHECK-NOT: <DECL_TYPEDEF
19+
// CHECK: <DECL_CONTEXT_LEXICAL
20+
// CHECK: <UnknownCode
21+
// CHECK: <TYPE_TYPEDEF
22+
// CHECK: <DECL_VAR
23+
// CHECK: <EXPR_INTEGER_LITERAL
24+
// CHECK: <STMT_STOP
25+
// CHECK: <TYPE_RECORD
26+
// CHECK: </DECLTYPES_BLOCK>

0 commit comments

Comments
 (0)