Skip to content

Commit

Permalink
Revert "[clang][CodeGen] Emit annotations for function declarations."
Browse files Browse the repository at this point in the history
This reverts commit c6a33ff. 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) {}
  • Loading branch information
d0k committed Sep 13, 2023
1 parent 47a9cd0 commit 88b7e06
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 88 deletions.
20 changes: 2 additions & 18 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,6 @@ void CodeGenModule::checkAliases() {
void CodeGenModule::clear() {
DeferredDeclsToEmit.clear();
EmittedDeferredDecls.clear();
DeferredAnnotations.clear();
if (OpenMPRuntime)
OpenMPRuntime->clear();
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<FunctionDecl>(Global)) {
// Update deferred annotations with the latest declaration if the function
// function was already used or defined.
if (FD->hasAttr<AnnotateAttr>()) {
StringRef MangledName = getMangledName(GD);
if (GetGlobalValue(MangledName))
DeferredAnnotations[MangledName] = FD;
}

// Forward declarations are emitted lazily on first use.
if (!FD->doesThisDeclarationHaveABody()) {
if (!FD->doesDeclarationForceExternallyVisibleDefinition())
Expand Down Expand Up @@ -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<AnnotateAttr>())
DeferredAnnotations[MangledName] = cast<ValueDecl>(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.
Expand Down Expand Up @@ -5682,6 +5664,8 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD,
AddGlobalCtor(Fn, CA->getPriority());
if (const DestructorAttr *DA = D->getAttr<DestructorAttr>())
AddGlobalDtor(Fn, DA->getPriority(), true);
if (D->hasAttr<AnnotateAttr>())
AddGlobalAnnotations(D, Fn);
if (getLangOpts().OpenMP && D->hasAttr<OMPDeclareTargetDeclAttr>())
getOpenMPRuntime().emitDeclareTargetFunction(D, GV);
}
Expand Down
4 changes: 0 additions & 4 deletions clang/lib/CodeGen/CodeGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,6 @@ class CodeGenModule : public CodeGenTypeCache {
/// Global annotations.
std::vector<llvm::Constant*> Annotations;

// Store deferred function annotations so they can be emitted at the end with
// most up to date ValueDecl that will have all the inherited annotations.
llvm::DenseMap<StringRef, const ValueDecl *> DeferredAnnotations;

/// Map used to get unique annotation strings.
llvm::StringMap<llvm::Constant*> AnnotationStrings;

Expand Down
16 changes: 0 additions & 16 deletions clang/test/CodeGen/annotations-decl-use-decl.c

This file was deleted.

16 changes: 0 additions & 16 deletions clang/test/CodeGen/annotations-decl-use-define.c

This file was deleted.

17 changes: 0 additions & 17 deletions clang/test/CodeGen/annotations-declaration.c

This file was deleted.

8 changes: 4 additions & 4 deletions clang/test/CodeGen/annotations-global.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ __attribute((address_space(1))) __attribute__((annotate("addrspace1_ann"))) char
// CHECK: @llvm.global.annotations = appending global [11 x { ptr, ptr, ptr, i32, ptr }] [{
// CHECK-SAME: { ptr @a.bar,
// CHECK-SAME: { ptr @a.bar,
// CHECK-SAME: { ptr @a,
// CHECK-SAME: { ptr @a,
// CHECK-SAME: { ptr @a,
// CHECK-SAME: { ptr @a,
// CHECK-SAME: { ptr @sfoo,
// CHECK-SAME: { ptr @sfoo,
// CHECK-SAME: { ptr @foo,
// CHECK-SAME: { ptr @foo,
// CHECK-SAME: { ptr addrspacecast (ptr addrspace(1) @addrspace1_var to ptr),
// CHECK-SAME: { ptr @a,
// CHECK-SAME: { ptr @a,
// CHECK-SAME: { ptr @a,
// CHECK-SAME: { ptr @a,
// CHECK-SAME: }], section "llvm.metadata"

// AS1-GLOBALS: target datalayout = "{{.+}}-A5-G1"
Expand Down
10 changes: 0 additions & 10 deletions clang/test/CodeGenCXX/attr-annotate-destructor.cpp

This file was deleted.

6 changes: 3 additions & 3 deletions clang/test/CodeGenCXX/attr-annotate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//CHECK: @[[STR1:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}attr-annotate.cpp\00", section "llvm.metadata"
//CHECK: @[[STR2:.*]] = private unnamed_addr constant [4 x i8] c"abc\00", align 1
//CHECK: @[[STR:.*]] = private unnamed_addr constant [5 x i8] c"test\00", section "llvm.metadata"
//CHECK: @[[ARGS:.*]] = private unnamed_addr constant { %struct.Struct } { %struct.Struct { ptr @_ZN1AIjLj9EE2SVE, ptr getelementptr (i8, ptr @_ZN1AIjLj9EE2SVE, i64 4) } }, section "llvm.metadata"
//CHECK: @[[ARGS2:.*]] = private unnamed_addr constant { i32, ptr, i32 } { i32 9, ptr @[[STR2:.*]], i32 8 }, section "llvm.metadata"
//CHECK: @llvm.global.annotations = appending global [2 x { ptr, ptr, ptr, i32, ptr }] [{ ptr, ptr, ptr, i32, ptr } { ptr @_ZN1AIjLj9EE5test2Ev, ptr @.str.6, ptr @.str.1, i32 24, ptr @[[ARGS]] }, { ptr, ptr, ptr, i32, ptr } { ptr @_ZN1AIjLj9EE4testILi8EEEvv, ptr @[[STR:.*]], ptr @[[STR1:.*]], i32 {{.*}}, ptr @[[ARGS2:.*]] }]
//CHECK: @[[ARGS:.*]] = private unnamed_addr constant { i32, ptr, i32 } { i32 9, ptr @[[STR2:.*]], i32 8 }, section "llvm.metadata"
//CHECK: @[[ARGS2:.*]] = private unnamed_addr constant { %struct.Struct } { %struct.Struct { ptr @_ZN1AIjLj9EE2SVE, ptr getelementptr (i8, ptr @_ZN1AIjLj9EE2SVE, i64 4) } }, section "llvm.metadata"
//CHECK: @llvm.global.annotations = appending global [2 x { ptr, ptr, ptr, i32, ptr }] [{ ptr, ptr, ptr, i32, ptr } { ptr @_ZN1AIjLj9EE4testILi8EEEvv, ptr @[[STR:.*]], ptr @[[STR1:.*]], i32 {{.*}}, ptr @[[ARGS:.*]] }, { ptr, ptr, ptr, i32, ptr } { ptr @_ZN1AIjLj9EE5test2Ev, ptr @.str.6, ptr @.str.1, i32 24, ptr @[[ARGS2]] }]

constexpr const char* str() {
return "abc";
Expand Down

0 comments on commit 88b7e06

Please sign in to comment.