This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[committed] add test for PR 50476


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

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" }
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]