PR middle-end/93437 - bogus -Warray-bounds on protobuf generated code
authorMartin Sebor <msebor@redhat.com>
Tue, 28 Jan 2020 21:48:52 +0000 (14:48 -0700)
committerMartin Sebor <msebor@redhat.com>
Tue, 28 Jan 2020 21:48:52 +0000 (14:48 -0700)
gcc/testsuite/ChangeLog:

PR middle-end/93437
* g++.dg/warn/Wstringop-overflow-5.C: New test.

gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wstringop-overflow-5.C [new file with mode: 0644]

index 8610164c77b7109064a21858e2bd5ae2e00f46af..279ab644f6e117a5af8c3da4990e82c9ad857264 100644 (file)
@@ -1,3 +1,8 @@
+2020-01-28  Martin Sebor  <msebor@redhat.com>
+
+       PR middle-end/93437
+       * g++.dg/warn/Wstringop-overflow-5.C: New test.a
+
 2020-01-28  Jan Hubicka  <hubicka@ucw.cz>
 
        * 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 (file)
index 0000000..3e905fc
--- /dev/null
@@ -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<size_t>(reinterpret_cast<char*>(&upper_bound_)
+                            - reinterpret_cast<char*>(&cumulative_count_))
+        + sizeof upper_bound_);
+}
+
+void* InitDefaultsBucket ()
+{
+  void* ptr = &::_Bucket_default_instance_;
+  return new (ptr)::Bucket();
+}