blob: 92b317e00b090cc9e1b78a2427858751f0371dbb [file] [log] [blame]
Joel E. Dennyc2575a32018-04-24 14:50:23 +00001// 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@* {{'EnumWithAttributes3' is deprecated}}"
8// RUN: echo >> %t.c "// expected""-note@* {{'EnumWithAttributes3' has been explicitly marked deprecated here}}"
9// RUN: %clang_cc1 -fsyntax-only %t.c -verify
Chris Lattnere5a91b42007-12-03 21:43:25 +000010
11typedef void func_typedef();
12func_typedef xxx;
13
Chris Lattnerb36a98e2007-12-06 17:20:20 +000014typedef void func_t(int x);
15func_t a;
Chris Lattnere5a91b42007-12-03 21:43:25 +000016
David Blaikie8fab8e52012-11-12 19:12:12 +000017struct blah {
18 struct {
19 struct {
20 int b;
21 };
22 };
23};
24
Artem Belevich224879e2018-01-17 19:29:39 +000025// This used to crash clang.
26struct {
27}(s1);
28
David Blaikie8fab8e52012-11-12 19:12:12 +000029int foo(const struct blah *b) {
30 // CHECK: return b->b;
31 return b->b;
32}
Hal Finkelf3e02652014-07-18 23:19:20 +000033
34int arr(int a[static 3]) {
35 // CHECK: int a[static 3]
36 return a[2];
37}
38
Hal Finkelbfe2d3c2014-07-19 02:01:03 +000039int rarr(int a[restrict static 3]) {
40 // CHECK: int a[restrict static 3]
41 return a[2];
42}
43
Hal Finkelf3e02652014-07-18 23:19:20 +000044int varr(int n, int a[static n]) {
45 // CHECK: int a[static n]
46 return a[2];
47}
48
Hal Finkelbfe2d3c2014-07-19 02:01:03 +000049int rvarr(int n, int a[restrict static n]) {
50 // CHECK: int a[restrict static n]
51 return a[2];
52}
53
Steven Watanabe9359b8f2016-03-18 21:35:59 +000054// CHECK: typedef struct {
Aaron Ballmanc960f562014-08-01 13:49:00 +000055typedef struct {
56 int f;
57} T __attribute__ ((__aligned__));
Aaron Ballman53885382014-09-15 16:45:30 +000058
59// CHECK: struct __attribute__((visibility("default"))) S;
60struct __attribute__((visibility("default"))) S;
Justin Bognercb337032015-05-28 22:19:36 +000061
62struct pair_t {
63 int a;
64 int b;
65};
66
67// CHECK: struct pair_t p = {a: 3, .b = 4};
Joel E. Dennyc2575a32018-04-24 14:50:23 +000068struct pair_t p = {a: 3, .b = 4}; // expected-warning {{use of GNU old-style field designator extension}}
Benjamin Kramer54f81ed2016-01-25 10:34:06 +000069
70void initializers() {
71 // CHECK: int *x = ((void *)0), *y = ((void *)0);
72 int *x = ((void *)0), *y = ((void *)0);
73 struct Z{};
74 struct {
75 struct Z z;
76 // CHECK: } z = {(struct Z){}};
77 } z = {(struct Z){}};
78}
Jordan Roseccca6692017-01-20 03:33:42 +000079
Joel E. Dennyc2575a32018-04-24 14:50:23 +000080// CHECK-LABEL: enum __attribute__((deprecated(""))) EnumWithAttributes {
81enum EnumWithAttributes { // expected-warning {{'EnumWithAttributes' is deprecated}}
Jordan Roseccca6692017-01-20 03:33:42 +000082 // CHECK-NEXT: EnumWithAttributesFoo __attribute__((deprecated(""))),
83 EnumWithAttributesFoo __attribute__((deprecated)),
84 // CHECK-NEXT: EnumWithAttributesBar __attribute__((unavailable(""))) = 50
85 EnumWithAttributesBar __attribute__((unavailable)) = 50
Joel E. Dennyae7c9442018-05-15 00:44:14 +000086 // CHECK-NEXT: } *EnumWithAttributesPtr;
Joel E. Dennyc2575a32018-04-24 14:50:23 +000087} __attribute__((deprecated)) *EnumWithAttributesPtr; // expected-note {{'EnumWithAttributes' has been explicitly marked deprecated here}}
88
89// FIXME: If enum is forward-declared at file scope, attributes are lost.
90// CHECK-LABEL: enum EnumWithAttributes2 *EnumWithAttributes2Ptr;
91// expected-warning@+2 {{'EnumWithAttributes2' is deprecated}}
92// expected-note@+1 {{'EnumWithAttributes2' has been explicitly marked deprecated here}}
93enum __attribute__((deprecated)) EnumWithAttributes2 *EnumWithAttributes2Ptr;
94
95// CHECK-LABEL: EnumWithAttributes3Fn
96void EnumWithAttributes3Fn() {
97 // CHECK-NEXT: enum __attribute__((deprecated(""))) EnumWithAttributes3 *EnumWithAttributes3Ptr;
98 // expected-warning@+2 {{'EnumWithAttributes3' is deprecated}}
99 // expected-note@+1 {{'EnumWithAttributes3' has been explicitly marked deprecated here}}
100 enum __attribute__((deprecated)) EnumWithAttributes3 *EnumWithAttributes3Ptr;
101 // Printing must not put the attribute after the tag where it would apply to
102 // the variable instead of the type, and then our deprecation warning would
103 // move to this use of the variable.
104 void *p = EnumWithAttributes3Ptr;
105}