Skip to content

IRGen: Only emit PragmaCommentDecls if building for Windows, or LTO is enabled #35747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions lib/IRGen/GenClangDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include "IRGenModule.h"
#include "swift/AST/IRGenOptions.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclGroup.h"
Expand Down Expand Up @@ -145,14 +146,20 @@ IRGenModule::getAddrOfClangGlobalDecl(clang::GlobalDecl global,
}

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

Expand Down