[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Sema / ast-print.c
blob2ba5ca34b5134746085e9d055960c41474486b1c
1 // RUN: %clang_cc1 %s -ast-print -verify > %t.c
2 // RUN: FileCheck %s --input-file %t.c
3 //
4 // RUN: echo >> %t.c "// expected""-warning@* {{use of GNU old-style field designator extension}}"
5 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes' is deprecated}}"
6 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes' has been explicitly marked deprecated here}}"
7 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes2' is deprecated}}"
8 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes2' has been explicitly marked deprecated here}}"
9 // RUN: echo >> %t.c "// expected""-warning@* {{'EnumWithAttributes3' is deprecated}}"
10 // RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes3' has been explicitly marked deprecated here}}"
11 // RUN: %clang_cc1 -fsyntax-only %t.c -verify
13 typedef void func_typedef(void);
14 func_typedef xxx;
16 typedef void func_t(int x);
17 func_t a;
19 struct blah {
20 struct {
21 struct {
22 int b;
27 // This used to crash clang.
28 struct {
29 }(s1);
31 int foo(const struct blah *b) {
32 // CHECK: return b->b;
33 return b->b;
36 int arr(int a[static 3]) {
37 // CHECK: int a[static 3]
38 return a[2];
41 int rarr(int a[restrict static 3]) {
42 // CHECK: int a[restrict static 3]
43 return a[2];
46 int varr(int n, int a[static n]) {
47 // CHECK: int a[static n]
48 return a[2];
51 int rvarr(int n, int a[restrict static n]) {
52 // CHECK: int a[restrict static n]
53 return a[2];
56 // CHECK: typedef struct {
57 typedef struct {
58 int f;
59 } T __attribute__ ((__aligned__));
61 // CHECK: struct __attribute__((visibility("default"))) S;
62 struct __attribute__((visibility("default"))) S;
64 struct pair_t {
65 int a;
66 int b;
69 // CHECK: struct pair_t p = {a: 3, .b = 4};
70 struct pair_t p = {a: 3, .b = 4}; // expected-warning {{use of GNU old-style field designator extension}}
72 void initializers(void) {
73 // CHECK: int *x = ((void *)0), *y = ((void *)0);
74 int *x = ((void *)0), *y = ((void *)0);
75 struct Z{};
76 struct {
77 struct Z z;
78 // CHECK: } z = {(struct Z){}};
79 } z = {(struct Z){}};
82 // CHECK-LABEL: enum __attribute__((deprecated(""))) EnumWithAttributes {
83 enum EnumWithAttributes { // expected-warning {{'EnumWithAttributes' is deprecated}}
84 // CHECK-NEXT: EnumWithAttributesFoo __attribute__((deprecated(""))),
85 EnumWithAttributesFoo __attribute__((deprecated)),
86 // CHECK-NEXT: EnumWithAttributesBar __attribute__((unavailable(""))) = 50
87 EnumWithAttributesBar __attribute__((unavailable)) = 50
88 // CHECK-NEXT: } *EnumWithAttributesPtr;
89 } __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note {{'EnumWithAttributes' has been explicitly marked deprecated here}}
91 // CHECK-LABEL: enum __attribute__((deprecated(""))) EnumWithAttributes2 *EnumWithAttributes2Ptr;
92 // expected-warning@+2 {{'EnumWithAttributes2' is deprecated}}
93 // expected-note@+1 {{'EnumWithAttributes2' has been explicitly marked deprecated here}}
94 enum __attribute__((deprecated)) EnumWithAttributes2 *EnumWithAttributes2Ptr;
96 // CHECK-LABEL: EnumWithAttributes3Fn
97 void EnumWithAttributes3Fn(void) {
98 // CHECK-NEXT: enum __attribute__((deprecated(""))) EnumWithAttributes3 *EnumWithAttributes3Ptr;
99 // expected-warning@+2 {{'EnumWithAttributes3' is deprecated}}
100 // expected-note@+1 {{'EnumWithAttributes3' has been explicitly marked deprecated here}}
101 enum __attribute__((deprecated)) EnumWithAttributes3 *EnumWithAttributes3Ptr;
102 // Printing must not put the attribute after the tag where it would apply to
103 // the variable instead of the type, and then our deprecation warning would
104 // move to this use of the variable.
105 void *p = EnumWithAttributes3Ptr;