PR middle-end/65182 - -Wuninitialized fails when pointer to variable later passed...
authorMartin Sebor <msebor@redhat.com>
Wed, 31 Mar 2021 16:39:24 +0000 (10:39 -0600)
committerMartin Sebor <msebor@redhat.com>
Wed, 31 Mar 2021 16:39:24 +0000 (10:39 -0600)
gcc/testsuite:
PR middle-end/65182
* gcc.dg/uninit-pr65182.c: New test.

gcc/testsuite/gcc.dg/uninit-pr65182.c [new file with mode: 0644]

diff --git a/gcc/testsuite/gcc.dg/uninit-pr65182.c b/gcc/testsuite/gcc.dg/uninit-pr65182.c
new file mode 100644 (file)
index 0000000..45b538d
--- /dev/null
@@ -0,0 +1,44 @@
+/* PR middle-end/65182 - -Wuninitialized fails when pointer to variable
+   later passed to function
+   { dg-do compile }
+   { dg-options "-O0 -Wall" } */
+
+void bar (int *a);
+
+int baz (void);
+
+__attribute__ ((noipa)) void foo_O0 (int *b)
+{
+  int a;
+
+  if (a)            // { dg-warning "\\\[-Wuninitialized" }
+    {
+      *b = 0;
+      return;
+    }
+
+  bar (&a);
+
+  a = baz ();
+
+  *b = a + 2;
+}
+
+#pragma GCC optimize ("2")
+
+__attribute__ ((noipa)) void foo_O2 (int *b)
+{
+  int a;
+
+  if (a)            // { dg-warning "\\\[-Wuninitialized" }
+    {
+      *b = 0;
+      return;
+    }
+
+  bar (&a);
+
+  a = baz ();
+
+  *b = a + 3;
+}