1 /* PR middle-end/10138 - warn for uninitialized arrays passed as const*
3 Verify that passing pointers to uninitialized objects to arguments
4 to functions declared with attribute access is diagnosed where expected.
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)
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)
40 void nowarn_array_init_fpcri (void)
46 void nowarn_array_compound_fpri (void)
51 void nowarn_array_compound_fpcri (void)
53 fpcri ((int[3]){ 1 });
56 void warn_scalar_fpcri (void)
59 fpcri (&i
); // { dg-warning "\\\[-Wuninitialized" }
62 void warn_array_fpcri (void)
65 fpcri (a
); // { dg-warning "\\\[-Wuninitialized" }
68 void warn_array_plus_cst_fpcri (void)
71 fpcri (a
+ 1); // { dg-warning "\\\[-Wuninitialized" }
74 void warn_array_plus_var_fpcri (int i
)
77 fpcri (a
+ i
); // { dg-warning "\\\[-Wuninitialized" }
80 void nowarn_struct_assign_fpcri (void)
82 struct { int a
, b
; } s
;
87 void warn_struct_assign_fpcri (void)
89 struct { int a
, b
; } s
;
91 fpcri (&s
.b
); // { dg-warning "\\\[-Wuninitialized" }
94 void nowarn_struct_init_fpcri (void)
96 struct { int a
, b
; } s
= { 0 };
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)
115 void nowarn_array_assign_fpcri1_2 (void)
122 void nowarn_array_assign_fpcri1_2_plus_cst (void)
129 void nowarn_array_init_fpcri1_2 (void)
135 void warn_array_fpcri1_2_rd1 (void)
138 fpcri1_2 (a
, 1); // { dg-warning "\\\[-Wuninitialized" }
141 void warn_array_fpcri1_2_rd2 (void)
144 fpcri1_2 (a
, 2); // { dg-warning "\\\[-Wuninitialized" }