]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Improve -Wuninitialized note location.
authorMartin Sebor <msebor@redhat.com>
Thu, 2 Sep 2021 15:20:09 +0000 (09:20 -0600)
committerMartin Sebor <msebor@redhat.com>
Thu, 2 Sep 2021 15:20:09 +0000 (09:20 -0600)
Related:
PR tree-optimization/17506 - warning about uninitialized variable points to wrong location
PR testsuite/37182 - Revision 139286 caused gcc.dg/pr17506.c and gcc.dg/uninit-15.c

gcc/ChangeLog:

PR tree-optimization/17506
PR testsuite/37182
* tree-ssa-uninit.c (warn_uninit): Remove conditional guarding note.

gcc/testsuite/ChangeLog:

PR tree-optimization/17506
PR testsuite/37182
* gcc.dg/diagnostic-tree-expr-ranges-2.c: Add expected output.
* gcc.dg/uninit-15-O0.c: Remove xfail.
* gcc.dg/uninit-15.c: Same.

gcc/testsuite/gcc.dg/diagnostic-tree-expr-ranges-2.c
gcc/testsuite/gcc.dg/uninit-15-O0.c
gcc/testsuite/gcc.dg/uninit-15.c
gcc/tree-ssa-uninit.c

index 302e233a04acccf20dd25ffd92f0345614e81716..1cbcad5ac7dde3f9ef9fb7e8317343f31dfc9129 100644 (file)
@@ -3,21 +3,25 @@
 
 int test_uninit_1 (void)
 {
-  int result;
-  return result;  /* { dg-warning "uninitialized" } */
-/* { dg-begin-multiline-output "" }
-   return result;
-          ^~~~~~
+  int result_1;     /* { dg-message "declared here" } */
+  return result_1;  /* { dg-warning "uninitialized" } */
+  /* { dg-begin-multiline-output "" }
+   return result_1;
+          ^~~~~~~~
+   int result_1;
+       ^~~~~~~~
    { dg-end-multiline-output "" } */
 }
 
 int test_uninit_2 (void)
 {
-  int result;
-  result += 3; /* { dg-warning "uninitialized" } */
-/* { dg-begin-multiline-output "" }
-   result += 3;
-   ~~~~~~~^~~~
+  int result_2;     /* { dg-message "declared here" } */
+  result_2 += 3;    /* { dg-warning "uninitialized" } */
+  /* { dg-begin-multiline-output "" }
+   result_2 += 3;
+   ~~~~~~~~~^~~~
+   int result_2;
+       ^~~~~~~~
    { dg-end-multiline-output "" } */
-  return result;
+  return result_2;
 }
index 36d963486175ba7353e7f9bb85cea6ccf9bdb935..1ddddee1388b61148cd1f609a63c9a9f2e0b727a 100644 (file)
@@ -14,7 +14,7 @@ void baz();
 
 void bar()
 {
-    int j;           /* { dg-message "was declared here" {} { xfail *-*-* } } */
+    int j;              /* { dg-message "declared here" } */
     for (; foo(j); ++j) /* { dg-warning "is used uninitialized" } */
         baz();
 }
index 85cb116f349458466d8a09f3565f95f01cf13a3e..7352662f62769ac91bd65ce71c9c0c403a98f916 100644 (file)
@@ -20,7 +20,7 @@ void baz (void);
 void
 bar (void)
 {
-  int j; /* { dg-message "note: 'j' was declared here" "" { xfail *-*-* } } */
+  int j;                /* { dg-message "note: 'j' was declared here" } */
   for (; foo (j); ++j)  /* { dg-warning "'j' is used uninitialized" } */
     baz ();
 }
index 394dbf40c9ca78322a78c073f770c5d0c8c3e183..cb6d11452026bd38d70616e57bbce05fb03c6a23 100644 (file)
@@ -206,14 +206,7 @@ warn_uninit (opt_code opt, tree t, tree var, const char *gmsgid,
   if (location == var_loc)
     return;
 
-  location_t cfun_loc = DECL_SOURCE_LOCATION (cfun->decl);
-  expanded_location xloc = expand_location (location);
-  expanded_location floc = expand_location (cfun_loc);
-  if (xloc.file != floc.file
-      || linemap_location_before_p (line_table, location, cfun_loc)
-      || linemap_location_before_p (line_table, cfun->function_end_locus,
-                                       location))
-    inform (var_loc, "%qD was declared here", var);
+  inform (var_loc, "%qD was declared here", var);
 }
 
 struct check_defs_data