From 88b7e06dcf9723d0869b0c6bee030b4140e4366d Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 13 Sep 2023 13:22:57 +0200 Subject: Revert "[clang][CodeGen] Emit annotations for function declarations." This reverts commit c6a33ff49dfb3498dae15c718820ea3d9c19f3cb. Makes clang segfault. // clang t.cc class a; class c { public: [[clang::annotate("")]] c(const c *) {} }; class d { d(const c *, a *, a *); c e; }; d::d(const c *f, a *, a *) : e(f) {} --- clang/lib/CodeGen/CodeGenModule.cpp | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 0ee9c4a..8b0c934 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -697,7 +697,6 @@ void CodeGenModule::checkAliases() { void CodeGenModule::clear() { DeferredDeclsToEmit.clear(); EmittedDeferredDecls.clear(); - DeferredAnnotations.clear(); if (OpenMPRuntime) OpenMPRuntime->clear(); } @@ -3094,10 +3093,6 @@ void CodeGenModule::EmitVTablesOpportunistically() { } void CodeGenModule::EmitGlobalAnnotations() { - for (const auto& [MangledName, VD] : DeferredAnnotations) - AddGlobalAnnotations(VD, GetGlobalValue(MangledName)); - DeferredAnnotations.clear(); - if (Annotations.empty()) return; @@ -3602,14 +3597,6 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) { // Ignore declarations, they will be emitted on their first use. if (const auto *FD = dyn_cast(Global)) { - // Update deferred annotations with the latest declaration if the function - // function was already used or defined. - if (FD->hasAttr()) { - StringRef MangledName = getMangledName(GD); - if (GetGlobalValue(MangledName)) - DeferredAnnotations[MangledName] = FD; - } - // Forward declarations are emitted lazily on first use. if (!FD->doesThisDeclarationHaveABody()) { if (!FD->doesDeclarationForceExternallyVisibleDefinition()) @@ -4383,11 +4370,6 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction( llvm::Function::Create(FTy, llvm::Function::ExternalLinkage, Entry ? StringRef() : MangledName, &getModule()); - // Store the declaration associated with this function so it is potentially - // updated by further declarations or definitions and emitted at the end. - if (D && D->hasAttr()) - DeferredAnnotations[MangledName] = cast(D); - // If we already created a function with the same mangled name (but different // type) before, take its name and add it to the list of functions to be // replaced with F at the end of CodeGen. @@ -5682,6 +5664,8 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD, AddGlobalCtor(Fn, CA->getPriority()); if (const DestructorAttr *DA = D->getAttr()) AddGlobalDtor(Fn, DA->getPriority(), true); + if (D->hasAttr()) + AddGlobalAnnotations(D, Fn); if (getLangOpts().OpenMP && D->hasAttr()) getOpenMPRuntime().emitDeclareTargetFunction(D, GV); } -- cgit v1.1