Skip to content

Commit 57d601f

Browse files
authored
Merge pull request #35796 from slavapestov/irgen-clang-deserialization-regression-5.4
IRGen: Only emit PragmaCommentDecls if building for Windows, or LTO is enabled [5.4]
2 parents 85da9b0 + e76c396 commit 57d601f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lib/IRGen/GenClangDecl.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "IRGenModule.h"
14+
#include "swift/AST/IRGenOptions.h"
1415
#include "clang/AST/Decl.h"
1516
#include "clang/AST/DeclGroup.h"
1617
#include "clang/AST/GlobalDecl.h"
@@ -118,14 +119,20 @@ IRGenModule::getAddrOfClangGlobalDecl(clang::GlobalDecl global,
118119
}
119120

120121
void IRGenModule::finalizeClangCodeGen() {
121-
// Ensure that code is emitted for any `PragmaCommentDecl`s. (These are
122-
// always guaranteed to be directly below the TranslationUnitDecl.)
123-
// In Clang, this happens automatically during the Sema phase, but here we
124-
// need to take care of it manually because our Clang CodeGenerator is not
125-
// attached to Clang Sema as an ASTConsumer.
126-
for (const auto *D : ClangASTContext->getTranslationUnitDecl()->decls()) {
127-
if (const auto *PCD = dyn_cast<clang::PragmaCommentDecl>(D)) {
128-
emitClangDecl(PCD);
122+
// FIXME: We try to avoid looking for PragmaCommentDecls unless we need to,
123+
// since clang::DeclContext::decls_begin() can trigger expensive
124+
// de-serialization.
125+
if (Triple.isWindowsMSVCEnvironment() || Triple.isWindowsItaniumEnvironment() ||
126+
IRGen.Opts.LLVMLTOKind != IRGenLLVMLTOKind::None) {
127+
// Ensure that code is emitted for any `PragmaCommentDecl`s. (These are
128+
// always guaranteed to be directly below the TranslationUnitDecl.)
129+
// In Clang, this happens automatically during the Sema phase, but here we
130+
// need to take care of it manually because our Clang CodeGenerator is not
131+
// attached to Clang Sema as an ASTConsumer.
132+
for (const auto *D : ClangASTContext->getTranslationUnitDecl()->decls()) {
133+
if (const auto *PCD = dyn_cast<clang::PragmaCommentDecl>(D)) {
134+
emitClangDecl(PCD);
135+
}
129136
}
130137
}
131138

0 commit comments

Comments
 (0)