annotate clang/test/Sema/address_space_print_macro.c @ 169:1f21f60db75c

Added tag llvm10 for changeset 980e56f2e095
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 09:26:57 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 %s -fsyntax-only -verify
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 #define AS1 __attribute__((address_space(1)))
anatofuz
parents:
diff changeset
4 #define AS2 __attribute__((address_space(2), annotate("foo")))
anatofuz
parents:
diff changeset
5 #define AS_ND __attribute__((address_space(2), noderef))
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7 #define AS(i) address_space(i)
anatofuz
parents:
diff changeset
8 #define AS3 __attribute__((AS(3)))
anatofuz
parents:
diff changeset
9 #define AS5 __attribute__((address_space(5))) char
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 void normal_case() {
anatofuz
parents:
diff changeset
12 int *p = 0;
anatofuz
parents:
diff changeset
13 __attribute__((address_space(1))) int *q = p; // expected-error{{initializing '__attribute__((address_space(1))) int *' with an expression of type 'int *' changes address space of pointer}}
anatofuz
parents:
diff changeset
14 }
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 char *cmp(AS1 char *x, AS2 char *y) {
anatofuz
parents:
diff changeset
17 return x < y ? x : y; // expected-error{{conditional operator with the second and third operands of type ('AS1 char *' and 'AS2 char *') which are pointers to non-overlapping address spaces}}
anatofuz
parents:
diff changeset
18 }
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 __attribute__((address_space(1))) char test_array[10];
anatofuz
parents:
diff changeset
21 void test3(void) {
anatofuz
parents:
diff changeset
22 extern void test3_helper(char *p); // expected-note{{passing argument to parameter 'p' here}}
anatofuz
parents:
diff changeset
23 test3_helper(test_array); // expected-error{{passing '__attribute__((address_space(1))) char *' to parameter of type 'char *' changes address space of pointer}}
anatofuz
parents:
diff changeset
24 }
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 char AS2 *test4_array;
anatofuz
parents:
diff changeset
27 void test4(void) {
anatofuz
parents:
diff changeset
28 extern void test3_helper(char *p); // expected-note{{passing argument to parameter 'p' here}}
anatofuz
parents:
diff changeset
29 test3_helper(test4_array); // expected-error{{passing 'AS2 char *' to parameter of type 'char *' changes address space of pointer}}
anatofuz
parents:
diff changeset
30 }
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 void func() {
anatofuz
parents:
diff changeset
33 char AS1 *x;
anatofuz
parents:
diff changeset
34 char AS3 *x2;
anatofuz
parents:
diff changeset
35 AS5 *x3;
anatofuz
parents:
diff changeset
36 char *y;
anatofuz
parents:
diff changeset
37 y = x; // expected-error{{assigning 'AS1 char *' to 'char *' changes address space of pointer}}
anatofuz
parents:
diff changeset
38 y = x2; // expected-error{{assigning 'AS3 char *' to 'char *' changes address space of pointer}}
anatofuz
parents:
diff changeset
39 y = x3; // expected-error{{assigning '__attribute__((address_space(5))) char *' to 'char *' changes address space of pointer}}
anatofuz
parents:
diff changeset
40 }
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 void multiple_attrs(AS_ND int *x) {
anatofuz
parents:
diff changeset
43 __attribute__((address_space(2))) int *y = x; // expected-warning{{casting to dereferenceable pointer removes 'noderef' attribute}}
anatofuz
parents:
diff changeset
44 }
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 void override_macro_name() {
anatofuz
parents:
diff changeset
47 #define ATTRS __attribute__((noderef)) // expected-note{{previous definition is here}}
anatofuz
parents:
diff changeset
48 ATTRS
anatofuz
parents:
diff changeset
49 #define ATTRS __attribute__((address_space(1))) // expected-warning{{'ATTRS' macro redefined}}
anatofuz
parents:
diff changeset
50 ATTRS
anatofuz
parents:
diff changeset
51 int *x;
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 int AS_ND *y = x; // expected-error{{initializing 'AS_ND int *' with an expression of type 'ATTRS int *' changes address space of pointer}}
anatofuz
parents:
diff changeset
54 }
anatofuz
parents:
diff changeset
55
anatofuz
parents:
diff changeset
56 void partial_macro_declaration() {
anatofuz
parents:
diff changeset
57 #define ATTRS2 __attribute__((noderef))
anatofuz
parents:
diff changeset
58 ATTRS2 __attribute__((address_space(1))) int *x;
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 int AS_ND *y = x; // expected-error{{initializing 'AS_ND int *' with an expression of type 'ATTRS2 int __attribute__((address_space(1))) *' changes address space of pointer}}
anatofuz
parents:
diff changeset
61
anatofuz
parents:
diff changeset
62 // The attribute not wrapped with a macro should be printed regularly.
anatofuz
parents:
diff changeset
63 #define ATTRS3 __attribute__((address_space(1)))
anatofuz
parents:
diff changeset
64 ATTRS3 __attribute__((noderef)) int *x2;
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 int AS_ND *y2 = x2; // expected-error{{initializing 'AS_ND int *' with an expression of type 'ATTRS3 int * __attribute__((noderef))' changes address space of pointer}}
anatofuz
parents:
diff changeset
67 }