From 4dd27b527c503aa50909fe1eb7d308266b1e103a Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Tue, 28 Jan 2020 14:48:52 -0700 Subject: [PATCH] PR middle-end/93437 - bogus -Warray-bounds on protobuf generated code gcc/testsuite/ChangeLog: PR middle-end/93437 * g++.dg/warn/Wstringop-overflow-5.C: New test. --- gcc/testsuite/ChangeLog | 5 +++ .../g++.dg/warn/Wstringop-overflow-5.C | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/Wstringop-overflow-5.C diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8610164c77b..279ab644f6e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-01-28 Martin Sebor + + PR middle-end/93437 + * g++.dg/warn/Wstringop-overflow-5.C: New test.a + 2020-01-28 Jan Hubicka * g++.dg/tree-prof/indir-call-prof.C: Update template. diff --git a/gcc/testsuite/g++.dg/warn/Wstringop-overflow-5.C b/gcc/testsuite/g++.dg/warn/Wstringop-overflow-5.C new file mode 100644 index 00000000000..3e905fc47c5 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstringop-overflow-5.C @@ -0,0 +1,37 @@ +/* PR middle-end/93437 - bogus -Warray-bounds on protobuf generated code + { dg-do compile } + { dg-options "-O3 -Wall" } */ + +typedef __SIZE_TYPE__ size_t; +typedef __UINT32_TYPE__ uint32_t; + +inline void* operator new (size_t, void* p) +{ + return p; +} + +extern "C" void* memset(void*, int, size_t); + +struct Bucket { + Bucket (); + uint32_t _has_bits_; + uint32_t cumulative_count_; + uint32_t upper_bound_; +}; + +extern Bucket _Bucket_default_instance_; + +Bucket::Bucket () +{ + memset (&_has_bits_, 0, sizeof _has_bits_); + memset (&cumulative_count_, 0, // { dg-bogus "\\\[-Warray-bounds|-wstringop-overflow" } + static_cast(reinterpret_cast(&upper_bound_) + - reinterpret_cast(&cumulative_count_)) + + sizeof upper_bound_); +} + +void* InitDefaultsBucket () +{ + void* ptr = &::_Bucket_default_instance_; + return new (ptr)::Bucket(); +} -- 2.30.2