diff mbox series

[committed] add test for PR 50476

Message ID 8bd23f97-092f-3b4e-7ec7-c8fc677572d1@gmail.com
State New
Headers show
Series [committed] add test for PR 50476 | expand

Commit Message

Martin Sebor Aug. 6, 2019, 12:34 a.m. UTC
The expected warning is now issued so I resolved the bug and
committed the test below in r274135.

As an aside, the warning points to the pointer dereference
but mentions the name of the local variable to which it points.
Since the local variable is defined in a different function
whose name isn't printed the warning is liable to be hard to
deal with in non-trivial code.  I think it needs to print
the inlining stack to be more user-friendly.

Martin

+}
diff mbox series

Patch

Index: gcc/testsuite/gcc.dg/uninit-pr50476.c
===================================================================
--- gcc/testsuite/gcc.dg/uninit-pr50476.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/uninit-pr50476.c	(working copy)
@@ -0,0 +1,18 @@ 
+/* PR middle-end/50476 - Warn of pointer set to object whose lifetime 
is limited
+   { dg-do compile }
+   { dg-options "-O1 -Wall" } */
+
+int *x = 0;
+
+void f (void)
+{
+  int y = 1;
+  x = &y;
+}
+
+int g (void)
+{
+  f ();
+
+  return *x;    // { dg-warning "\\\[-Wuninitialized" }