annotate clang/test/Sema/assign.c @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 79ff65ed7e25
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 void *test1(void) { return 0; }
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 void test2 (const struct {int a;} *x) {
anatofuz
parents:
diff changeset
6 // expected-note@-1 {{variable 'x' declared const here}}
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8 x->a = 10;
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
9 // expected-error-re@-1 {{cannot assign to variable 'x' with const-qualified type 'const struct (unnamed struct at {{.*}}assign.c:5:19) *'}}
150
anatofuz
parents:
diff changeset
10 }
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 typedef int arr[10];
anatofuz
parents:
diff changeset
13 void test3() {
anatofuz
parents:
diff changeset
14 const arr b; // expected-note {{variable 'b' declared const here}}
anatofuz
parents:
diff changeset
15 const int b2[10]; // expected-note {{variable 'b2' declared const here}}
anatofuz
parents:
diff changeset
16 b[4] = 1; // expected-error {{cannot assign to variable 'b' with const-qualified type 'const arr' (aka 'int const[10]')}}
anatofuz
parents:
diff changeset
17 b2[4] = 1; // expected-error {{cannot assign to variable 'b2' with const-qualified type 'const int [10]'}}
anatofuz
parents:
diff changeset
18 }
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 typedef struct I {
anatofuz
parents:
diff changeset
21 const int a; // expected-note 4{{nested data member 'a' declared const here}} \
anatofuz
parents:
diff changeset
22 expected-note 6{{data member 'a' declared const here}}
anatofuz
parents:
diff changeset
23 } I;
anatofuz
parents:
diff changeset
24 typedef struct J {
anatofuz
parents:
diff changeset
25 struct I i;
anatofuz
parents:
diff changeset
26 } J;
anatofuz
parents:
diff changeset
27 typedef struct K {
anatofuz
parents:
diff changeset
28 struct J *j;
anatofuz
parents:
diff changeset
29 } K;
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 void testI(struct I i1, struct I i2) {
anatofuz
parents:
diff changeset
32 i1 = i2; // expected-error {{cannot assign to variable 'i1' with const-qualified data member 'a'}}
anatofuz
parents:
diff changeset
33 }
anatofuz
parents:
diff changeset
34 void testJ1(struct J j1, struct J j2) {
anatofuz
parents:
diff changeset
35 j1 = j2; // expected-error {{cannot assign to variable 'j1' with nested const-qualified data member 'a'}}
anatofuz
parents:
diff changeset
36 }
anatofuz
parents:
diff changeset
37 void testJ2(struct J j, struct I i) {
anatofuz
parents:
diff changeset
38 j.i = i; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}}
anatofuz
parents:
diff changeset
39 }
anatofuz
parents:
diff changeset
40 void testK1(struct K k, struct J j) {
anatofuz
parents:
diff changeset
41 *(k.j) = j; // expected-error {{cannot assign to lvalue with nested const-qualified data member 'a'}}
anatofuz
parents:
diff changeset
42 }
anatofuz
parents:
diff changeset
43 void testK2(struct K k, struct I i) {
anatofuz
parents:
diff changeset
44 k.j->i = i; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}}
anatofuz
parents:
diff changeset
45 }
anatofuz
parents:
diff changeset
46
anatofuz
parents:
diff changeset
47 void testI_(I i1, I i2) {
anatofuz
parents:
diff changeset
48 i1 = i2; // expected-error {{cannot assign to variable 'i1' with const-qualified data member 'a'}}
anatofuz
parents:
diff changeset
49 }
anatofuz
parents:
diff changeset
50 void testJ1_(J j1, J j2) {
anatofuz
parents:
diff changeset
51 j1 = j2; // expected-error {{cannot assign to variable 'j1' with nested const-qualified data member 'a'}}
anatofuz
parents:
diff changeset
52 }
anatofuz
parents:
diff changeset
53 void testJ2_(J j, I i) {
anatofuz
parents:
diff changeset
54 j.i = i; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}}
anatofuz
parents:
diff changeset
55 }
anatofuz
parents:
diff changeset
56 void testK1_(K k, J j) {
anatofuz
parents:
diff changeset
57 *(k.j) = j; // expected-error {{cannot assign to lvalue with nested const-qualified data member 'a'}}
anatofuz
parents:
diff changeset
58 }
anatofuz
parents:
diff changeset
59 void testK2_(K k, I i) {
anatofuz
parents:
diff changeset
60 k.j->i = i; // expected-error {{cannot assign to non-static data member 'i' with const-qualified data member 'a'}}
anatofuz
parents:
diff changeset
61 }
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 // PR39946: Recursive checking of hasConstFields caused stack overflow.
anatofuz
parents:
diff changeset
64 struct L { // expected-note {{definition of 'struct L' is not complete until the closing '}'}}
anatofuz
parents:
diff changeset
65 struct L field; // expected-error {{field has incomplete type 'struct L'}}
anatofuz
parents:
diff changeset
66 };
anatofuz
parents:
diff changeset
67 void testL(struct L *l) {
anatofuz
parents:
diff changeset
68 *l = 0; // expected-error {{assigning to 'struct L' from incompatible type 'int'}}
anatofuz
parents:
diff changeset
69 }
anatofuz
parents:
diff changeset
70
anatofuz
parents:
diff changeset
71 // Additionally, this example overflowed the stack when figuring out the field.
anatofuz
parents:
diff changeset
72 struct M1; // expected-note {{forward declaration of 'struct M1'}}
anatofuz
parents:
diff changeset
73 struct M2 {
anatofuz
parents:
diff changeset
74 //expected-note@+1 {{nested data member 'field' declared const here}}
anatofuz
parents:
diff changeset
75 const struct M1 field; // expected-error {{field has incomplete type 'const struct M1'}}
anatofuz
parents:
diff changeset
76 };
anatofuz
parents:
diff changeset
77 struct M1 {
anatofuz
parents:
diff changeset
78 struct M2 field;
anatofuz
parents:
diff changeset
79 };
anatofuz
parents:
diff changeset
80
anatofuz
parents:
diff changeset
81 void testM(struct M1 *l) {
anatofuz
parents:
diff changeset
82 *l = 0; // expected-error {{cannot assign to lvalue with nested const-qualified data member 'field'}}
anatofuz
parents:
diff changeset
83 }
anatofuz
parents:
diff changeset
84
anatofuz
parents:
diff changeset
85 struct N1; // expected-note {{forward declaration of 'struct N1'}}
anatofuz
parents:
diff changeset
86 struct N2 {
anatofuz
parents:
diff changeset
87 struct N1 field; // expected-error {{field has incomplete type 'struct N1'}}
anatofuz
parents:
diff changeset
88 };
anatofuz
parents:
diff changeset
89 struct N1 {
anatofuz
parents:
diff changeset
90 struct N2 field;
anatofuz
parents:
diff changeset
91 };
anatofuz
parents:
diff changeset
92
anatofuz
parents:
diff changeset
93 void testN(struct N1 *l) {
anatofuz
parents:
diff changeset
94 *l = 0; // expected-error {{assigning to 'struct N1' from incompatible type 'int'}}
anatofuz
parents:
diff changeset
95 }