-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang][CodeGen] Emit annotations for function declarations. (#66716)
Previously, annotations were only emitted for function definitions. With this change annotations are also emitted for declarations. Also, emitting function annotations is now deferred until the end so that the most up to date declaration is used which will have any inherited annotations.
- Loading branch information
1 parent
efc60dc
commit c6d7072
Showing
9 changed files
with
101 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s | ||
|
||
// Test annotation attributes are still emitted when the function is used before | ||
// it is defined with annotations. | ||
|
||
void foo(void); | ||
void *xxx = (void*)foo; | ||
void __attribute__((annotate("bar"))) foo(); | ||
|
||
// CHECK: target triple | ||
// CHECK-DAG: private unnamed_addr constant [4 x i8] c"bar\00", section "llvm.metadata" | ||
|
||
// CHECK: @llvm.global.annotations = appending global [1 x { ptr, ptr, ptr, i32, ptr }] [{ | ||
// CHECK-SAME: { ptr @foo, | ||
// CHECK-SAME: }], section "llvm.metadata" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s | ||
|
||
// Test annotation attributes are still emitted when the function is used before | ||
// it is defined with annotations. | ||
|
||
void foo(void); | ||
void *xxx = (void*)foo; | ||
void __attribute__((annotate("bar"))) foo() {} | ||
|
||
// CHECK: target triple | ||
// CHECK-DAG: private unnamed_addr constant [4 x i8] c"bar\00", section "llvm.metadata" | ||
|
||
// CHECK: @llvm.global.annotations = appending global [1 x { ptr, ptr, ptr, i32, ptr }] [{ | ||
// CHECK-SAME: { ptr @foo, | ||
// CHECK-SAME: }], section "llvm.metadata" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s | ||
|
||
// Test annotation attributes are emitted for declarations. | ||
|
||
__attribute__((annotate("bar"))) int foo(); | ||
|
||
int main() { | ||
return foo(); | ||
} | ||
|
||
// CHECK: target triple | ||
// CHECK-DAG: private unnamed_addr constant [4 x i8] c"bar\00", section "llvm.metadata" | ||
|
||
// CHECK: @llvm.global.annotations = appending global [1 x { ptr, ptr, ptr, i32, ptr }] [{ | ||
// CHECK-SAME: { ptr @foo, | ||
// CHECK-SAME: }], section "llvm.metadata" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// RUN: %clang %s -S -emit-llvm -target x86_64-unknown-linux -o - | ||
|
||
// Test annotation attributes on constructors do not crash. | ||
|
||
class Foo { | ||
public: | ||
[[clang::annotate("test")]] Foo() {} | ||
}; | ||
|
||
Foo foo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// RUN: %clang_cc1 %s -S -emit-llvm -triple x86_64-unknown-linux-gnu -o - | FileCheck %s | ||
|
||
// Test annotation attributes on destructors do not crash. | ||
|
||
struct k { | ||
~k() __attribute__((annotate(""))) {} | ||
}; | ||
void m() { k(); } | ||
|
||
// CHECK: @llvm.global.annotations = appending global [2 x { ptr, ptr, ptr, i32, ptr }] [{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters