Debian Codegraph @

gcc/testsuite/g++.dg/warn/Wstringop-overflow-5.C

raw
1 /* PR middle-end/93437 - bogus -Warray-bounds on protobuf generated code
2 { dg-do compile }
3 { dg-options "-O3 -Wall" } */
4
5 typedef __SIZE_TYPE__ size_t;
6 typedef __UINT32_TYPE__ uint32_t;
7
8 inline void* operator new (size_t, void* p)
9 {
10 return p;
11 }
12
13 extern "C" void* memset(void*, int, size_t);
14
15 struct Bucket {
16 Bucket ();
17 uint32_t _has_bits_;
18 uint32_t cumulative_count_;
19 uint32_t upper_bound_;
20 };
21
22 extern Bucket _Bucket_default_instance_;
23
24 Bucket::Bucket ()
25 {
26 memset (&_has_bits_, 0, sizeof _has_bits_);
27 memset (&cumulative_count_, 0, // { dg-bogus "\\\[-Warray-bounds|-Wstringop-overflow" }
28 static_cast<size_t>(reinterpret_cast<char*>(&upper_bound_)
29 - reinterpret_cast<char*>(&cumulative_count_))
30 + sizeof upper_bound_);
31 }
32
33 void* InitDefaultsBucket ()
34 {
35 void* ptr = &::_Bucket_default_instance_;
36 return new (ptr)::Bucket();
37 }