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]

[PATCH] Fix C++/14329, badly formatted warnings for SRA replacements used uninitialized


Hi,
  RTH's C++ patch in
http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01988.html was almost
correct.  There were two problems with it.  First the use of the
variable name "t" was causing regressions as the variable shadowing
another variable named "t" which was used to set the locus later on.
Second, we needed to change the order of DECL_DEBUG_EXPR and
DECL_DEBUG_EXPR_IS_FROM and then add a check for DECL_P.  With those
minor changes, we get the correct result and no regressions.

OK? Bootstrapped and tested on i686-linux-gnu with no regressions.
Should this apply to the 4.2 branch also, it is not a regression but
getting a correct formatted warning in 4.2 would nice and it is one of
the most reported bugs lately.

Thanks,
Andrew Pinski

ChangeLog:

200x-mm-dd  Richard Henderson  <rth@redhat.com>
            Andrew Pinski  <pinskia@gmail.com>

	* error.c (cp_printer) <'D'>: Handle DECL_DEBUG_EXPR.

	* g++.dg/warn/unit-1.C: New test.
Index: testsuite/g++.dg/warn/unit-1.C
===================================================================
--- testsuite/g++.dg/warn/unit-1.C	(revision 0)
+++ testsuite/g++.dg/warn/unit-1.C	(revision 0)
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wuninitialized" } */
+
+struct a { int mode; };
+int sys_msgctl (void)
+{
+  struct a setbuf;  /* { dg-warning "'setbuf\.a::mode' is used" } */
+  return setbuf.mode;
+}
+
Index: cp/error.c
===================================================================
--- cp/error.c	(revision 119245)
+++ cp/error.c	(working copy)
@@ -2337,7 +2337,22 @@ cp_printer (pretty_printer *pp, text_inf
     {
     case 'A': result = args_to_string (next_tree, verbose);	break;
     case 'C': result = code_to_string (next_tcode);		break;
-    case 'D': result = decl_to_string (next_tree, verbose);	break;
+    case 'D':
+      {
+	tree temp = next_tree;
+	if (DECL_P (temp)
+	    && DECL_DEBUG_EXPR_IS_FROM (temp) && DECL_DEBUG_EXPR (temp))
+	  {
+	    temp = DECL_DEBUG_EXPR (temp);
+	    if (!DECL_P (temp))
+	      {
+		result = expr_to_string (temp);
+		break;
+	      }
+	  }
+	result = decl_to_string (temp, verbose);
+      }
+      break;
     case 'E': result = expr_to_string (next_tree);		break;
     case 'F': result = fndecl_to_string (next_tree, verbose);	break;
     case 'L': result = language_to_string (next_lang);		break;

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