Require target lra in gcc.dg/pr108095.c
[official-gcc.git] / gcc / testsuite / gcc.dg / uninit-33.c
blob732d33e006ddf42eb1b186d18a98856b9bee4492
1 /* PR middle-end/10138 - warn for uninitialized arrays passed as const*
2 arguments
3 Verify that passing pointers to uninitialized objects to arguments
4 to functions declared with attribute access is diagnosed where expected.
5 { dg-do compile }
6 { dg-options "-O -Wall" } */
8 #define RO(...) __attribute__ ((access (read_only, __VA_ARGS__)))
9 #define RW(...) __attribute__ ((access (read_write, __VA_ARGS__)))
10 #define WO(...) __attribute__ ((access (write_only, __VA_ARGS__)))
12 RO (1) void fpri (int*); // { dg-message "in a call to 'fpri' declared with attribute 'access \\\(read_only, 1\\\)' here" }
14 RO (1) void fpcri (const int*);
16 RO (1, 2) void fpcri1_2 (const int*, int);
19 void warn_scalar_fpri (void)
21 int i; // { dg-message "declared here" }
22 fpri (&i); // { dg-warning "'i' is used uninitialized" }
25 void nowarn_scalar_plus_fpri (void)
27 int i;
28 /* This gets a -Wstringop-overflow for reading past the end but not
29 -Wuninitialized because there's nothing to initialize there. */
30 fpri (&i + 1); // { dg-warning "\\\[-Wstringop-overread" }
33 void nowarn_array_assign_fpcri (void)
35 int a[2];
36 a[0] = 0;
37 fpcri (a);
40 void nowarn_array_init_fpcri (void)
42 int a[4] = { 0 };
43 fpcri (a);
46 void nowarn_array_compound_fpri (void)
48 fpri ((int[2]){ 0 });
51 void nowarn_array_compound_fpcri (void)
53 fpcri ((int[3]){ 1 });
56 void warn_scalar_fpcri (void)
58 int i;
59 fpcri (&i); // { dg-warning "\\\[-Wuninitialized" }
62 void warn_array_fpcri (void)
64 int a[4];
65 fpcri (a); // { dg-warning "\\\[-Wuninitialized" }
68 void warn_array_plus_cst_fpcri (void)
70 int a[4];
71 fpcri (a + 1); // { dg-warning "\\\[-Wuninitialized" }
74 void warn_array_plus_var_fpcri (int i)
76 int a[4];
77 fpcri (a + i); // { dg-warning "\\\[-Wuninitialized" }
80 void nowarn_struct_assign_fpcri (void)
82 struct { int a, b; } s;
83 s.a = 0;
84 fpcri (&s.a);
87 void warn_struct_assign_fpcri (void)
89 struct { int a, b; } s;
90 s.a = 0;
91 fpcri (&s.b); // { dg-warning "\\\[-Wuninitialized" }
94 void nowarn_struct_init_fpcri (void)
96 struct { int a, b; } s = { 0 };
97 fpcri (&s.a);
98 fpcri (&s.b);
101 void nowarn_struct_compound_fpcri (void)
103 struct S { int a, b; };
104 fpcri (&(struct S){ }.a);
105 fpcri (&(struct S){ }.b);
109 void nowarn_scalar_fpcri1_2 (void)
111 int i;
112 fpcri1_2 (&i, 0);
115 void nowarn_array_assign_fpcri1_2 (void)
117 int a[2];
118 a[0] = 0;
119 fpcri1_2 (a, 1);
122 void nowarn_array_assign_fpcri1_2_plus_cst (void)
124 int a[3];
125 a[1] = 0;
126 fpcri1_2 (a + 1, 1);
129 void nowarn_array_init_fpcri1_2 (void)
131 int a[4] = { 0 };
132 fpcri1_2 (a, 2);
135 void warn_array_fpcri1_2_rd1 (void)
137 int a[4];
138 fpcri1_2 (a, 1); // { dg-warning "\\\[-Wuninitialized" }
141 void warn_array_fpcri1_2_rd2 (void)
143 int a[4];
144 fpcri1_2 (a, 2); // { dg-warning "\\\[-Wuninitialized" }