Skip to content

Commit 1ae38f8

Browse files
authored
Merge pull request #35747 from slavapestov/irgen-clang-deserialization-regression
IRGen: Only emit PragmaCommentDecls if building for Windows, or LTO is enabled
2 parents bcd6416 + c0aa202 commit 1ae38f8

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/DeclCXX.h"
1617
#include "clang/AST/DeclGroup.h"
@@ -145,14 +146,20 @@ IRGenModule::getAddrOfClangGlobalDecl(clang::GlobalDecl global,
145146
}
146147

147148
void IRGenModule::finalizeClangCodeGen() {
148-
// Ensure that code is emitted for any `PragmaCommentDecl`s. (These are
149-
// always guaranteed to be directly below the TranslationUnitDecl.)
150-
// In Clang, this happens automatically during the Sema phase, but here we
151-
// need to take care of it manually because our Clang CodeGenerator is not
152-
// attached to Clang Sema as an ASTConsumer.
153-
for (const auto *D : ClangASTContext->getTranslationUnitDecl()->decls()) {
154-
if (const auto *PCD = dyn_cast<clang::PragmaCommentDecl>(D)) {
155-
emitClangDecl(PCD);
149+
// FIXME: We try to avoid looking for PragmaCommentDecls unless we need to,
150+
// since clang::DeclContext::decls_begin() can trigger expensive
151+
// de-serialization.
152+
if (Triple.isWindowsMSVCEnvironment() || Triple.isWindowsItaniumEnvironment() ||
153+
IRGen.Opts.LLVMLTOKind != IRGenLLVMLTOKind::None) {
154+
// Ensure that code is emitted for any `PragmaCommentDecl`s. (These are
155+
// always guaranteed to be directly below the TranslationUnitDecl.)
156+
// In Clang, this happens automatically during the Sema phase, but here we
157+
// need to take care of it manually because our Clang CodeGenerator is not
158+
// attached to Clang Sema as an ASTConsumer.
159+
for (const auto *D : ClangASTContext->getTranslationUnitDecl()->decls()) {
160+
if (const auto *PCD = dyn_cast<clang::PragmaCommentDecl>(D)) {
161+
emitClangDecl(PCD);
162+
}
156163
}
157164
}
158165

0 commit comments

Comments
 (0)