sanitizer/99673 - bad -Wstringop-overread diagnostic with asan

Message ID 20220121125852.7F3FE13AF2@imap2.suse-dmz.suse.de
State Committed
Commit caca8eddd9356777f5fe28454eb083b1779adc26
Headers
Series sanitizer/99673 - bad -Wstringop-overread diagnostic with asan |

Commit Message

Richard Biener Jan. 21, 2022, 12:58 p.m. UTC
  The testcase got fixed by lowering of &MEM[ptr + CST] to ptr + CST.

Pushed.

2022-01-21  Richard Biener  <rguenther@suse.de>

	PR sanitizer/99673
	* gcc.dg/asan/pr99673.c: New testcase.
---
 gcc/testsuite/gcc.dg/asan/pr99673.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/asan/pr99673.c
  

Patch

diff --git a/gcc/testsuite/gcc.dg/asan/pr99673.c b/gcc/testsuite/gcc.dg/asan/pr99673.c
new file mode 100644
index 00000000000..05857fd46c7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/asan/pr99673.c
@@ -0,0 +1,27 @@ 
+/* { dg-do compile } */
+/* { dg-additional-options "-Wstringop-overread" } */
+
+struct B {
+  int i;
+  struct A {
+    short sa[8];
+  } a[2];
+};
+
+struct C {
+  char n, ax[];
+};
+
+struct D { int i, j, k; };
+
+int f (const short[8]);
+
+void g (struct C *pc, struct D *pd, int i)
+{
+  struct B *pb = (void *)pc->ax;
+  pd->i = pb->i;
+
+  const short *psa = pb->a[i].sa;
+  if (f (psa))
+    return;
+}