1 /* PR c++/97201 - ICE in -Warray-bounds writing to result of operator new(0)
2 Verify that out-of-bounds accesses to memory returned by nothrow operator
5 { dg-options "-O2 -Wall -Warray-bounds -ftrack-macro-expansion=0" } */
8 // Avoid including <new> to make cross-compiler testing easy.
13 typedef __SIZE_TYPE__ size_t;
15 extern const nothrow_t nothrow;
19 void* operator new (std::size_t, const std::nothrow_t &) throw ()
20 __attribute__ ((__alloc_size__ (1), __malloc__));
21 void* operator new[] (std::size_t, const std::nothrow_t &) throw ()
22 __attribute__ ((__alloc_size__ (1), __malloc__));
26 typedef __INT32_TYPE__ int32_t;
30 #define OP_NEW(n) operator new (n, std::nothrow)
31 #define T(T, n, i) do { \
32 T *p = (T*) OP_NEW (n); \
39 T (int32_t, 0, 0); // { dg-warning "array subscript 0 is outside array bounds of 'int32_t \\\[0]'" }
40 // { dg-message "object of size \\d allocated by '\[^\n\r]*operator new\[^\n\r]*'" "note" { target *-*-* } .-1 }
41 T (int32_t, 1, 0); // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[0]' is partly outside array bounds of 'unsigned char \\\[1]'" }
42 T (int32_t, 2, 0); // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[0]' is partly outside array bounds of 'unsigned char \\\[2]'" }
43 T (int32_t, 3, 0); // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[0]' is partly outside array bounds of 'unsigned char \\\[3]'" }
47 T (int32_t, 0, 1); // { dg-warning "array subscript 1 is outside array bounds of 'int32_t \\\[0]'" }
48 T (int32_t, 1, 1); // { dg-warning "array subscript 1 is outside array bounds " }
49 T (int32_t, 2, 1); // { dg-warning "array subscript 1 is outside array bounds " }
50 T (int32_t, 3, 1); // { dg-warning "array subscript 1 is outside array bounds " }
51 T (int32_t, 4, 1); // { dg-warning "array subscript 1 is outside array bounds " }
52 T (int32_t, 5, 1); // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[1]' is partly outside array bounds of 'unsigned char \\\[5]" }
53 T (int32_t, 6, 1); // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[1]' is partly outside array bounds of 'unsigned char \\\[6]" }
54 T (int32_t, 7, 1); // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[1]' is partly outside array bounds of 'unsigned char \\\[7]" }
60 void warn_op_array_new ()
63 #define OP_NEW(n) operator new[] (n, std::nothrow)
65 T (int32_t, 0, 0); // { dg-warning "array subscript 0 is outside array bounds of 'int32_t \\\[0]'" }
66 // { dg-message "object of size \\d allocated by '\[^\n\r]*operator new\[^\n\r]*'" "note" { target *-*-* } .-1 }
67 T (int32_t, 1, 0); // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[0]' is partly outside array bounds of 'unsigned char \\\[1]'" }
68 T (int32_t, 2, 0); // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[0]' is partly outside array bounds of 'unsigned char \\\[2]'" }
69 T (int32_t, 3, 0); // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[0]' is partly outside array bounds of 'unsigned char \\\[3]'" }
73 T (int32_t, 0, 1); // { dg-warning "array subscript 1 is outside array bounds of 'int32_t \\\[0]'" }
74 T (int32_t, 1, 1); // { dg-warning "array subscript 1 is outside array bounds " }
75 T (int32_t, 2, 1); // { dg-warning "array subscript 1 is outside array bounds " }
76 T (int32_t, 3, 1); // { dg-warning "array subscript 1 is outside array bounds " }
77 T (int32_t, 4, 1); // { dg-warning "array subscript 1 is outside array bounds " }
78 T (int32_t, 5, 1); // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[1]' is partly outside array bounds of 'unsigned char \\\[5]" }
79 T (int32_t, 6, 1); // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[1]' is partly outside array bounds of 'unsigned char \\\[6]" }
80 T (int32_t, 7, 1); // { dg-warning "array subscript 'int32_t {aka (long )?int}\\\[1]' is partly outside array bounds of 'unsigned char \\\[7]" }