Debian Codegraph @

clang/test/AST/attr-print-emit.cpp

raw
1 // RUN: %clang_cc1 %s -ast-print | FileCheck %s
2 // RUN: %clang_cc1 -emit-pch -o %t.ast %s
3 // RUN: %clang_cc1 %t.ast -ast-print | FileCheck %s
4
5 // CHECK: void *aa() __attribute__((assume_aligned(64)));
6 void *aa() __attribute__((assume_aligned(64)));
7
8 // CHECK: void *aa2() __attribute__((assume_aligned(64, 8)));
9 void *aa2() __attribute__((assume_aligned(64, 8)));
10
11 // CHECK: void xla(int a) __attribute__((xray_log_args(1)));
12 void xla(int a) __attribute__((xray_log_args(1)));
13
14 // CHECK: void *as2(int, int) __attribute__((alloc_size(1, 2)));
15 void *as2(int, int) __attribute__((alloc_size(1, 2)));
16 // CHECK: void *as1(void *, int) __attribute__((alloc_size(2)));
17 void *as1(void *, int) __attribute__((alloc_size(2)));
18
19 // CHECK: void fmt(int, const char *, ...) __attribute__((format(printf, 2, 3)));
20 void fmt(int, const char *, ...) __attribute__((format(printf, 2, 3)));
21
22 // CHECK: char *fmta(int, const char *) __attribute__((format_arg(2)));
23 char *fmta(int, const char *) __attribute__((format_arg(2)));
24
25 // CHECK: void nn(int *, int *) __attribute__((nonnull(1, 2)));
26 void nn(int *, int *) __attribute__((nonnull(1, 2)));
27
28 // CHECK: int *aa(int i) __attribute__((alloc_align(1)));
29 int *aa(int i) __attribute__((alloc_align(1)));
30
31 // CHECK: void ownt(int *, int *) __attribute__((ownership_takes(foo, 1, 2)));
32 void ownt(int *, int *) __attribute__((ownership_takes(foo, 1, 2)));
33 // CHECK: void ownh(int *, int *) __attribute__((ownership_holds(foo, 1, 2)));
34 void ownh(int *, int *) __attribute__((ownership_holds(foo, 1, 2)));
35 // CHECK: void *ownr(int) __attribute__((ownership_returns(foo, 1)));
36 void *ownr(int) __attribute__((ownership_returns(foo, 1)));
37
38 // CHECK: void awtt(int, int, ...) __attribute__((argument_with_type_tag(foo, 3, 2)));
39 void awtt(int, int, ...) __attribute__((argument_with_type_tag(foo, 3, 2)));
40 // CHECK: void pwtt(void *, int) __attribute__((pointer_with_type_tag(foo, 1, 2)));
41 void pwtt(void *, int) __attribute__((pointer_with_type_tag(foo, 1, 2)));
42
43 class C {
44 // CHECK: void xla(int a) __attribute__((xray_log_args(2)));
45 void xla(int a) __attribute__((xray_log_args(2)));
46
47 // CHECK: void *as2(int, int) __attribute__((alloc_size(2, 3)));
48 void *as2(int, int) __attribute__((alloc_size(2, 3)));
49 // CHECK: void *as1(void *, int) __attribute__((alloc_size(3)));
50 void *as1(void *, int) __attribute__((alloc_size(3)));
51
52 // CHECK: void fmt(int, const char *, ...) __attribute__((format(printf, 3, 4)));
53 void fmt(int, const char *, ...) __attribute__((format(printf, 3, 4)));
54
55 // CHECK: char *fmta(int, const char *) __attribute__((format_arg(3)));
56 char *fmta(int, const char *) __attribute__((format_arg(3)));
57
58 // CHECK: void nn(int *, int *) __attribute__((nonnull(2, 3)));
59 void nn(int *, int *) __attribute__((nonnull(2, 3)));
60
61 // CHECK: int *aa(int i) __attribute__((alloc_align(2)));
62 int *aa(int i) __attribute__((alloc_align(2)));
63
64 // CHECK: void ownt(int *, int *) __attribute__((ownership_takes(foo, 2, 3)));
65 void ownt(int *, int *) __attribute__((ownership_takes(foo, 2, 3)));
66 // CHECK: void ownh(int *, int *) __attribute__((ownership_holds(foo, 2, 3)));
67 void ownh(int *, int *) __attribute__((ownership_holds(foo, 2, 3)));
68 // CHECK: void *ownr(int) __attribute__((ownership_returns(foo, 2)));
69 void *ownr(int) __attribute__((ownership_returns(foo, 2)));
70
71 // CHECK: void awtt(int, int, ...) __attribute__((argument_with_type_tag(foo, 4, 3)));
72 void awtt(int, int, ...) __attribute__((argument_with_type_tag(foo, 4, 3)));
73 // CHECK: void pwtt(void *, int) __attribute__((pointer_with_type_tag(foo, 2, 3)));
74 void pwtt(void *, int) __attribute__((pointer_with_type_tag(foo, 2, 3)));
75 };
76
77 #define ANNOTATE_ATTR __attribute__((annotate("Annotated")))
78 ANNOTATE_ATTR int annotated_attr ANNOTATE_ATTR = 0;
79 // CHECK: __attribute__((annotate("Annotated"))) int annotated_attr __attribute__((annotate("Annotated"))) = 0;
80
81 void increment() { [[clang::annotate("Annotated")]] annotated_attr++; }
82 // CHECK: {{\[\[}}clang::annotate("Annotated")]] annotated_attr++;
83
84 // FIXME: We do not print the attribute as written after the type specifier.
85 int ANNOTATE_ATTR annotated_attr_fixme = 0;
86 // CHECK: __attribute__((annotate("Annotated"))) int annotated_attr_fixme = 0;
87
88 #define NONNULL_ATTR __attribute__((nonnull(1)))
89 ANNOTATE_ATTR NONNULL_ATTR void fn_non_null_annotated_attr(int *) __attribute__((annotate("AnnotatedRHS")));
90 // CHECK:__attribute__((annotate("Annotated"))) __attribute__((nonnull(1))) void fn_non_null_annotated_attr(int *) __attribute__((annotate("AnnotatedRHS")));
91
92 [[gnu::nonnull(1)]] [[gnu::always_inline]] void cxx11_attr(int*) ANNOTATE_ATTR;
93 // CHECK: {{\[\[}}gnu::nonnull(1)]] {{\[\[}}gnu::always_inline]] void cxx11_attr(int *) __attribute__((annotate("Annotated")));
94
95 struct Foo;
96
97 // CHECK: void as_member_fn_ptr(int *(Foo::*member)(int) __attribute__((alloc_size(1))));
98 void as_member_fn_ptr(int* (Foo::*member)(int) __attribute__((alloc_size(1))));