https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106080

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-10-22
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, this should change the warning to be correct.
```
diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index 59a70530600..2c2572dc402 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -4595,6 +4595,27 @@ pass_waccess::check_dangling_stores (basic_block bb,
       if (!is_auto_decl (rhs_ref.ref))
        continue;

+      if (TREE_CODE (rhs_ref.ref) == LABEL_DECL)
+       {
+         auto_diagnostic_group d;
+         location_t loc = gimple_location (stmt);
+         if (warning_at (loc, OPT_Wdangling_pointer_,
+                         "storing the address of local label %qD in %qE",
+                         rhs_ref.ref, lhs))
+           {
+             suppress_warning (stmt, OPT_Wdangling_pointer_);
+
+             location_t loc = DECL_SOURCE_LOCATION (rhs_ref.ref);
+             inform (loc, "%qD declared here", rhs_ref.ref);
+
+             loc = DECL_SOURCE_LOCATION (lhs_ref.ref);
+
+             if (loc != UNKNOWN_LOCATION)
+             inform (loc, "%qE declared here", lhs_ref.ref);
+           }
+         continue;
+       }
+
       auto_diagnostic_group d;
       location_t loc = gimple_location (stmt);
       if (warning_at (loc, OPT_Wdangling_pointer_,


```
The documentation even warns about the use of labels as addresses too:
https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Labels-as-Values.html#Labels-as-Values
`
You may not use this mechanism to jump to code in a different function. If you
do that, totally unpredictable things happen. The best way to avoid this is to
store the label address only in automatic variables and never pass it as an
argument.
`

Reply via email to