annotate clang/test/Frontend/noderef.cpp @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900 (2020-02-13)
parents
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fblocks -verify %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 /**
anatofuz
parents:
diff changeset
4 * Test 'noderef' attribute with c++ constructs.
anatofuz
parents:
diff changeset
5 */
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7 #define NODEREF __attribute__((noderef))
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 void Normal() {
anatofuz
parents:
diff changeset
10 int NODEREF i; // expected-warning{{'noderef' can only be used on an array or pointer type}}
anatofuz
parents:
diff changeset
11 int NODEREF *i_ptr; // expected-note 2 {{i_ptr declared here}}
anatofuz
parents:
diff changeset
12 int NODEREF **i_ptr2; // ok
anatofuz
parents:
diff changeset
13 int *NODEREF i_ptr3; // expected-warning{{'noderef' can only be used on an array or pointer type}}
anatofuz
parents:
diff changeset
14 int *NODEREF *i_ptr4; // ok
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 auto NODEREF *auto_i_ptr = i_ptr;
anatofuz
parents:
diff changeset
17 auto NODEREF auto_i = i; // expected-warning{{'noderef' can only be used on an array or pointer type}}
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 struct {
anatofuz
parents:
diff changeset
20 int x;
anatofuz
parents:
diff changeset
21 int y;
anatofuz
parents:
diff changeset
22 } NODEREF *s;
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 int __attribute__((noderef(10))) * no_args; // expected-error{{'noderef' attribute takes no arguments}}
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 int i2 = *i_ptr; // expected-warning{{dereferencing i_ptr; was declared with a 'noderef' type}}
anatofuz
parents:
diff changeset
27 int &i3 = *i_ptr; // expected-warning{{dereferencing i_ptr; was declared with a 'noderef' type}}
anatofuz
parents:
diff changeset
28 int *i_ptr5 = i_ptr; // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}}
anatofuz
parents:
diff changeset
29 int *i_ptr6(i_ptr); // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}}
anatofuz
parents:
diff changeset
30 }
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 const int NODEREF *const_i_ptr;
anatofuz
parents:
diff changeset
33 static int NODEREF *static_i_ptr;
anatofuz
parents:
diff changeset
34
anatofuz
parents:
diff changeset
35 void ParenTypes() {
anatofuz
parents:
diff changeset
36 int NODEREF(*i_ptr); // ok (same as `int NODEREF *`)
anatofuz
parents:
diff changeset
37 int NODEREF *(*i_ptr2); // ok (same as `int NODEREF **`)
anatofuz
parents:
diff changeset
38 }
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 // Function declarations
anatofuz
parents:
diff changeset
41 int NODEREF func(); // expected-warning{{'noderef' can only be used on an array or pointer type}}
anatofuz
parents:
diff changeset
42 int NODEREF *func2(); // ok (returning pointer)
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 typedef int NODEREF (*func3)(int); // expected-warning{{'noderef' can only be used on an array or pointer type}}
anatofuz
parents:
diff changeset
45 typedef int NODEREF *(*func4)(int);
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 void Arrays() {
anatofuz
parents:
diff changeset
48 int NODEREF i_arr[10]; // ok
anatofuz
parents:
diff changeset
49 int NODEREF i_arr2[10][10]; // ok
anatofuz
parents:
diff changeset
50 int NODEREF *i_arr3[10]; // ok
anatofuz
parents:
diff changeset
51 int NODEREF i_arr4[] = {1, 2};
anatofuz
parents:
diff changeset
52 }
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54 void ParenArrays() {
anatofuz
parents:
diff changeset
55 int NODEREF(i_ptr[10]);
anatofuz
parents:
diff changeset
56 int NODEREF(i_ptr2[10])[10];
anatofuz
parents:
diff changeset
57 }
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59 typedef int NODEREF *(*func5[10])(int);
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61 // Arguments
anatofuz
parents:
diff changeset
62 void func6(int NODEREF x); // expected-warning{{'noderef' can only be used on an array or pointer type}}
anatofuz
parents:
diff changeset
63 void func7(int NODEREF *x);
anatofuz
parents:
diff changeset
64 void func8() NODEREF;
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 void References() {
anatofuz
parents:
diff changeset
67 int x = 2;
anatofuz
parents:
diff changeset
68 int NODEREF &y = x; // expected-warning{{'noderef' can only be used on an array or pointer type}}
anatofuz
parents:
diff changeset
69 int *xp = &x;
anatofuz
parents:
diff changeset
70 int NODEREF *&a = xp; // ok (reference to a NODEREF *)
anatofuz
parents:
diff changeset
71 int *NODEREF &b = xp; // expected-warning{{'noderef' can only be used on an array or pointer type}}
anatofuz
parents:
diff changeset
72 }
anatofuz
parents:
diff changeset
73
anatofuz
parents:
diff changeset
74 void BlockPointers() {
anatofuz
parents:
diff changeset
75 typedef int NODEREF (^IntBlock)(); // expected-warning{{'noderef' can only be used on an array or pointer type}}
anatofuz
parents:
diff changeset
76 }
anatofuz
parents:
diff changeset
77
anatofuz
parents:
diff changeset
78 class A {
anatofuz
parents:
diff changeset
79 public:
anatofuz
parents:
diff changeset
80 int member;
anatofuz
parents:
diff changeset
81 int NODEREF *member2;
anatofuz
parents:
diff changeset
82 int NODEREF member3; // expected-warning{{'noderef' can only be used on an array or pointer type}}
anatofuz
parents:
diff changeset
83 };
anatofuz
parents:
diff changeset
84
anatofuz
parents:
diff changeset
85 void MemberPointer() {
anatofuz
parents:
diff changeset
86 int NODEREF A::*var = &A::member; // expected-warning{{'noderef' can only be used on an array or pointer type}}
anatofuz
parents:
diff changeset
87 }
anatofuz
parents:
diff changeset
88
anatofuz
parents:
diff changeset
89 template <class Ty>
anatofuz
parents:
diff changeset
90 class B {
anatofuz
parents:
diff changeset
91 Ty NODEREF *member;
anatofuz
parents:
diff changeset
92 Ty NODEREF member2; // expected-warning{{'noderef' can only be used on an array or pointer type}}
anatofuz
parents:
diff changeset
93 };
anatofuz
parents:
diff changeset
94
anatofuz
parents:
diff changeset
95 void test_lambdas() {
anatofuz
parents:
diff changeset
96 auto l = [](int NODEREF *x){ // expected-note{{x declared here}}
anatofuz
parents:
diff changeset
97 return *x; // expected-warning{{dereferencing x; was declared with a 'noderef' type}}
anatofuz
parents:
diff changeset
98 };
anatofuz
parents:
diff changeset
99 }
anatofuz
parents:
diff changeset
100
anatofuz
parents:
diff changeset
101 int NODEREF *glob_ptr; // expected-note{{glob_ptr declared here}}
anatofuz
parents:
diff changeset
102 int glob_int = *glob_ptr; // expected-warning{{dereferencing glob_ptr; was declared with a 'noderef' type}}