Skip to content

Commit f99072b

Browse files
[Clang][BPF] Add tests for btf_type_tag c2x-style attributes (#133666)
For btf_type_tag implementation, in order to have the same results with clang (__attribute__((btf_type_tag("...")))), gcc intends to use c2x syntax '[[...]]'. Clang also supports similar c2x syntax. Currently, the clang selftest contains the following five tests: ``` attr-btf_type_tag-func.c attr-btf_type_tag-similar-type.c attr-btf_type_tag-var.c attr-btf_type_tag-func-ptr.c attr-btf_type_tag-typedef-field.c ``` Tests attr-btf_type_tag-func.c and attr-btf_type_tag-var.c already have c2x syntax test. Test attr-btf_type_tag-func-ptr.c does not support c2x syntax when '__attribute__((...))' is replaced with with '[[...]]'. This should not be an issue since we do not have use cases for function pointer yet. This patch added '[[...]]' syntax for ``` attr-btf_type_tag-similar-type.c attr-btf_type_tag-typedef-field.c ```
1 parent 48a4b14 commit f99072b

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

clang/test/CodeGen/attr-btf_type_tag-similar-type.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
// RUN: %clang_cc1 -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s
2+
// RUN: %clang_cc1 -triple %itanium_abi_triple -DDOUBLE_BRACKET_ATTRS=1 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s
3+
4+
#if DOUBLE_BRACKET_ATTRS
5+
#define __tag1 [[clang::btf_type_tag("tag1")]]
6+
#define __tag2 [[clang::btf_type_tag("tag2")]]
7+
#define __tag3 [[clang::btf_type_tag("tag3")]]
8+
#define __tag4 [[clang::btf_type_tag("tag4")]]
9+
#else
10+
#define __tag1 __attribute__((btf_type_tag("tag1")))
11+
#define __tag2 __attribute__((btf_type_tag("tag2")))
12+
#define __tag3 __attribute__((btf_type_tag("tag3")))
13+
#define __tag4 __attribute__((btf_type_tag("tag4")))
14+
#endif
215

316
struct map_value {
4-
int __attribute__((btf_type_tag("tag1"))) __attribute__((btf_type_tag("tag3"))) *a;
5-
int __attribute__((btf_type_tag("tag2"))) __attribute__((btf_type_tag("tag4"))) *b;
17+
int __tag1 __tag3 *a;
18+
int __tag2 __tag4 *b;
619
};
720

821
struct map_value *func(void);

clang/test/CodeGen/attr-btf_type_tag-typedef-field.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
// RUN: %clang_cc1 -triple %itanium_abi_triple -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s
2+
// RUN: %clang_cc1 -triple %itanium_abi_triple -DDOUBLE_BRACKET_ATTRS=1 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s
23

4+
#if DOUBLE_BRACKET_ATTRS
5+
#define __tag1 [[clang::btf_type_tag("tag1")]]
6+
#define __tag2 [[clang::btf_type_tag("tag2")]]
7+
#else
38
#define __tag1 __attribute__((btf_type_tag("tag1")))
49
#define __tag2 __attribute__((btf_type_tag("tag2")))
10+
#endif
511

612
typedef void __fn_t(int);
713
typedef __fn_t __tag1 __tag2 *__fn2_t;
@@ -31,5 +37,5 @@ int *foo1(struct t *a1) {
3137
// CHECK: ![[L28]] = !DISubroutineType(types: ![[L29:[0-9]+]])
3238
// CHECK: ![[L29]] = !{null, ![[L4]]}
3339
// CHECK: ![[L30]] = !{![[L21]], ![[L23]]}
34-
// CHECK: ![[L31]] = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: ![[#]], file: ![[#]], line: [[#]]1, baseType: ![[L32:[0-9]+]]
40+
// CHECK: ![[L31]] = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[L32:[0-9]+]]
3541
// CHECK: ![[L32]] = !DIBasicType(name: "long", size: [[#]], encoding: DW_ATE_signed)

0 commit comments

Comments
 (0)