Skip to content

Commit 88b7e06

Browse files
committed
Revert "[clang][CodeGen] Emit annotations for function declarations."
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) {}
1 parent 47a9cd0 commit 88b7e06

File tree

8 files changed

+9
-88
lines changed

8 files changed

+9
-88
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,6 @@ void CodeGenModule::checkAliases() {
697697
void CodeGenModule::clear() {
698698
DeferredDeclsToEmit.clear();
699699
EmittedDeferredDecls.clear();
700-
DeferredAnnotations.clear();
701700
if (OpenMPRuntime)
702701
OpenMPRuntime->clear();
703702
}
@@ -3094,10 +3093,6 @@ void CodeGenModule::EmitVTablesOpportunistically() {
30943093
}
30953094

30963095
void CodeGenModule::EmitGlobalAnnotations() {
3097-
for (const auto& [MangledName, VD] : DeferredAnnotations)
3098-
AddGlobalAnnotations(VD, GetGlobalValue(MangledName));
3099-
DeferredAnnotations.clear();
3100-
31013096
if (Annotations.empty())
31023097
return;
31033098

@@ -3602,14 +3597,6 @@ void CodeGenModule::EmitGlobal(GlobalDecl GD) {
36023597

36033598
// Ignore declarations, they will be emitted on their first use.
36043599
if (const auto *FD = dyn_cast<FunctionDecl>(Global)) {
3605-
// Update deferred annotations with the latest declaration if the function
3606-
// function was already used or defined.
3607-
if (FD->hasAttr<AnnotateAttr>()) {
3608-
StringRef MangledName = getMangledName(GD);
3609-
if (GetGlobalValue(MangledName))
3610-
DeferredAnnotations[MangledName] = FD;
3611-
}
3612-
36133600
// Forward declarations are emitted lazily on first use.
36143601
if (!FD->doesThisDeclarationHaveABody()) {
36153602
if (!FD->doesDeclarationForceExternallyVisibleDefinition())
@@ -4383,11 +4370,6 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
43834370
llvm::Function::Create(FTy, llvm::Function::ExternalLinkage,
43844371
Entry ? StringRef() : MangledName, &getModule());
43854372

4386-
// Store the declaration associated with this function so it is potentially
4387-
// updated by further declarations or definitions and emitted at the end.
4388-
if (D && D->hasAttr<AnnotateAttr>())
4389-
DeferredAnnotations[MangledName] = cast<ValueDecl>(D);
4390-
43914373
// If we already created a function with the same mangled name (but different
43924374
// type) before, take its name and add it to the list of functions to be
43934375
// replaced with F at the end of CodeGen.
@@ -5682,6 +5664,8 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD,
56825664
AddGlobalCtor(Fn, CA->getPriority());
56835665
if (const DestructorAttr *DA = D->getAttr<DestructorAttr>())
56845666
AddGlobalDtor(Fn, DA->getPriority(), true);
5667+
if (D->hasAttr<AnnotateAttr>())
5668+
AddGlobalAnnotations(D, Fn);
56855669
if (getLangOpts().OpenMP && D->hasAttr<OMPDeclareTargetDeclAttr>())
56865670
getOpenMPRuntime().emitDeclareTargetFunction(D, GV);
56875671
}

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,6 @@ class CodeGenModule : public CodeGenTypeCache {
431431
/// Global annotations.
432432
std::vector<llvm::Constant*> Annotations;
433433

434-
// Store deferred function annotations so they can be emitted at the end with
435-
// most up to date ValueDecl that will have all the inherited annotations.
436-
llvm::DenseMap<StringRef, const ValueDecl *> DeferredAnnotations;
437-
438434
/// Map used to get unique annotation strings.
439435
llvm::StringMap<llvm::Constant*> AnnotationStrings;
440436

clang/test/CodeGen/annotations-decl-use-decl.c

Lines changed: 0 additions & 16 deletions
This file was deleted.

clang/test/CodeGen/annotations-decl-use-define.c

Lines changed: 0 additions & 16 deletions
This file was deleted.

clang/test/CodeGen/annotations-declaration.c

Lines changed: 0 additions & 17 deletions
This file was deleted.

clang/test/CodeGen/annotations-global.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ __attribute((address_space(1))) __attribute__((annotate("addrspace1_ann"))) char
3333
// CHECK: @llvm.global.annotations = appending global [11 x { ptr, ptr, ptr, i32, ptr }] [{
3434
// CHECK-SAME: { ptr @a.bar,
3535
// CHECK-SAME: { ptr @a.bar,
36+
// CHECK-SAME: { ptr @a,
37+
// CHECK-SAME: { ptr @a,
38+
// CHECK-SAME: { ptr @a,
39+
// CHECK-SAME: { ptr @a,
3640
// CHECK-SAME: { ptr @sfoo,
3741
// CHECK-SAME: { ptr @sfoo,
3842
// CHECK-SAME: { ptr @foo,
3943
// CHECK-SAME: { ptr @foo,
4044
// CHECK-SAME: { ptr addrspacecast (ptr addrspace(1) @addrspace1_var to ptr),
41-
// CHECK-SAME: { ptr @a,
42-
// CHECK-SAME: { ptr @a,
43-
// CHECK-SAME: { ptr @a,
44-
// CHECK-SAME: { ptr @a,
4545
// CHECK-SAME: }], section "llvm.metadata"
4646

4747
// AS1-GLOBALS: target datalayout = "{{.+}}-A5-G1"

clang/test/CodeGenCXX/attr-annotate-destructor.cpp

Lines changed: 0 additions & 10 deletions
This file was deleted.

clang/test/CodeGenCXX/attr-annotate.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
//CHECK: @[[STR1:.*]] = private unnamed_addr constant [{{.*}} x i8] c"{{.*}}attr-annotate.cpp\00", section "llvm.metadata"
44
//CHECK: @[[STR2:.*]] = private unnamed_addr constant [4 x i8] c"abc\00", align 1
55
//CHECK: @[[STR:.*]] = private unnamed_addr constant [5 x i8] c"test\00", section "llvm.metadata"
6-
//CHECK: @[[ARGS:.*]] = private unnamed_addr constant { %struct.Struct } { %struct.Struct { ptr @_ZN1AIjLj9EE2SVE, ptr getelementptr (i8, ptr @_ZN1AIjLj9EE2SVE, i64 4) } }, section "llvm.metadata"
7-
//CHECK: @[[ARGS2:.*]] = private unnamed_addr constant { i32, ptr, i32 } { i32 9, ptr @[[STR2:.*]], i32 8 }, section "llvm.metadata"
8-
//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:.*]] }]
6+
//CHECK: @[[ARGS:.*]] = private unnamed_addr constant { i32, ptr, i32 } { i32 9, ptr @[[STR2:.*]], i32 8 }, section "llvm.metadata"
7+
//CHECK: @[[ARGS2:.*]] = private unnamed_addr constant { %struct.Struct } { %struct.Struct { ptr @_ZN1AIjLj9EE2SVE, ptr getelementptr (i8, ptr @_ZN1AIjLj9EE2SVE, i64 4) } }, section "llvm.metadata"
8+
//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]] }]
99

1010
constexpr const char* str() {
1111
return "abc";

0 commit comments

Comments
 (0)