| Joel E. Denny | c2575a3 | 2018-04-24 14:50:23 +0000 | [diff] [blame] | 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@* {{'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 Lattner | e5a91b4 | 2007-12-03 21:43:25 +0000 | [diff] [blame] | 10 | |
| 11 | typedef void func_typedef(); |
| 12 | func_typedef xxx; |
| 13 | |
| Chris Lattner | b36a98e | 2007-12-06 17:20:20 +0000 | [diff] [blame] | 14 | typedef void func_t(int x); |
| 15 | func_t a; |
| Chris Lattner | e5a91b4 | 2007-12-03 21:43:25 +0000 | [diff] [blame] | 16 | |
| David Blaikie | 8fab8e5 | 2012-11-12 19:12:12 +0000 | [diff] [blame] | 17 | struct blah { |
| 18 | struct { |
| 19 | struct { |
| 20 | int b; |
| 21 | }; |
| 22 | }; |
| 23 | }; |
| 24 | |
| Artem Belevich | 224879e | 2018-01-17 19:29:39 +0000 | [diff] [blame] | 25 | // This used to crash clang. |
| 26 | struct { |
| 27 | }(s1); |
| 28 | |
| David Blaikie | 8fab8e5 | 2012-11-12 19:12:12 +0000 | [diff] [blame] | 29 | int foo(const struct blah *b) { |
| 30 | // CHECK: return b->b; |
| 31 | return b->b; |
| 32 | } |
| Hal Finkel | f3e0265 | 2014-07-18 23:19:20 +0000 | [diff] [blame] | 33 | |
| 34 | int arr(int a[static 3]) { |
| 35 | // CHECK: int a[static 3] |
| 36 | return a[2]; |
| 37 | } |
| 38 | |
| Hal Finkel | bfe2d3c | 2014-07-19 02:01:03 +0000 | [diff] [blame] | 39 | int rarr(int a[restrict static 3]) { |
| 40 | // CHECK: int a[restrict static 3] |
| 41 | return a[2]; |
| 42 | } |
| 43 | |
| Hal Finkel | f3e0265 | 2014-07-18 23:19:20 +0000 | [diff] [blame] | 44 | int varr(int n, int a[static n]) { |
| 45 | // CHECK: int a[static n] |
| 46 | return a[2]; |
| 47 | } |
| 48 | |
| Hal Finkel | bfe2d3c | 2014-07-19 02:01:03 +0000 | [diff] [blame] | 49 | int rvarr(int n, int a[restrict static n]) { |
| 50 | // CHECK: int a[restrict static n] |
| 51 | return a[2]; |
| 52 | } |
| 53 | |
| Steven Watanabe | 9359b8f | 2016-03-18 21:35:59 +0000 | [diff] [blame] | 54 | // CHECK: typedef struct { |
| Aaron Ballman | c960f56 | 2014-08-01 13:49:00 +0000 | [diff] [blame] | 55 | typedef struct { |
| 56 | int f; |
| 57 | } T __attribute__ ((__aligned__)); |
| Aaron Ballman | 5388538 | 2014-09-15 16:45:30 +0000 | [diff] [blame] | 58 | |
| 59 | // CHECK: struct __attribute__((visibility("default"))) S; |
| 60 | struct __attribute__((visibility("default"))) S; |
| Justin Bogner | cb33703 | 2015-05-28 22:19:36 +0000 | [diff] [blame] | 61 | |
| 62 | struct pair_t { |
| 63 | int a; |
| 64 | int b; |
| 65 | }; |
| 66 | |
| 67 | // CHECK: struct pair_t p = {a: 3, .b = 4}; |
| Joel E. Denny | c2575a3 | 2018-04-24 14:50:23 +0000 | [diff] [blame] | 68 | struct pair_t p = {a: 3, .b = 4}; // expected-warning {{use of GNU old-style field designator extension}} |
| Benjamin Kramer | 54f81ed | 2016-01-25 10:34:06 +0000 | [diff] [blame] | 69 | |
| 70 | void 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 Rose | ccca669 | 2017-01-20 03:33:42 +0000 | [diff] [blame] | 79 | |
| Joel E. Denny | c2575a3 | 2018-04-24 14:50:23 +0000 | [diff] [blame] | 80 | // CHECK-LABEL: enum __attribute__((deprecated(""))) EnumWithAttributes { |
| 81 | enum EnumWithAttributes { // expected-warning {{'EnumWithAttributes' is deprecated}} |
| Jordan Rose | ccca669 | 2017-01-20 03:33:42 +0000 | [diff] [blame] | 82 | // CHECK-NEXT: EnumWithAttributesFoo __attribute__((deprecated(""))), |
| 83 | EnumWithAttributesFoo __attribute__((deprecated)), |
| 84 | // CHECK-NEXT: EnumWithAttributesBar __attribute__((unavailable(""))) = 50 |
| 85 | EnumWithAttributesBar __attribute__((unavailable)) = 50 |
| Joel E. Denny | ae7c944 | 2018-05-15 00:44:14 +0000 | [diff] [blame^] | 86 | // CHECK-NEXT: } *EnumWithAttributesPtr; |
| Joel E. Denny | c2575a3 | 2018-04-24 14:50:23 +0000 | [diff] [blame] | 87 | } __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}} |
| 93 | enum __attribute__((deprecated)) EnumWithAttributes2 *EnumWithAttributes2Ptr; |
| 94 | |
| 95 | // CHECK-LABEL: EnumWithAttributes3Fn |
| 96 | void 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 | } |