]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/43395 (Gcc warns label as local variable)
authorMarek Polacek <polacek@redhat.com>
Thu, 1 May 2014 07:29:38 +0000 (07:29 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 1 May 2014 07:29:38 +0000 (07:29 +0000)
PR c/43395
c/
* c-typeck.c (c_finish_return): Distinguish between label and variable
when warning about returning local address.
cp/
* typeck.c (maybe_warn_about_returning_address_of_local): Distinguish
between label and variable when warning about returning local address.
testsuite/
* c-c++-common/pr43395.c: New test.

From-SVN: r209973

gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr43395.c [new file with mode: 0644]

index e04a38d93618822263f5b71ae39b050475f5194e..f0630e2bed0c9d46f871bd2f7abcd4f0fd6abc2c 100644 (file)
@@ -1,3 +1,9 @@
+2014-05-01  Marek Polacek  <polacek@redhat.com>
+
+       PR c/43395
+       * c-typeck.c (c_finish_return): Distinguish between label and variable
+       when warning about returning local address.
+
 2014-05-01  Marek Polacek  <polacek@redhat.com>
 
        PR c/29467
index e25a25ca48e823a952cfbbf67c07b48083d75d87..2a40c701ebc1a43efc8979715ef06ac08312d971 100644 (file)
@@ -9265,7 +9265,8 @@ c_finish_return (location_t loc, tree retval, tree origtype)
                  && DECL_CONTEXT (inner) == current_function_decl)
                warning_at (loc,
                            OPT_Wreturn_local_addr, "function returns address "
-                           "of local variable");
+                           "of %s", TREE_CODE (inner) == LABEL_DECL
+                                    ? "label" : "local variable");
              break;
 
            default:
index c078e0685cc29bf57a7b839e84cdb96a67b6e524..4d16855390e5ff765ba62ba350df591c9b3df524 100644 (file)
@@ -1,3 +1,9 @@
+2014-05-01  Marek Polacek  <polacek@redhat.com>
+
+       PR c/43395
+       * typeck.c (maybe_warn_about_returning_address_of_local): Distinguish
+       between label and variable when warning about returning local address.
+
 2014-04-30  Jason Merrill  <jason@redhat.com>
 
        PR c++/60980
index 729e22eadc57dc262759fbcd9880df4424acc008..8b7cb8df17a2c2ffb49ef36b480055766c0082f2 100644 (file)
@@ -8310,8 +8310,9 @@ maybe_warn_about_returning_address_of_local (tree retval)
        warning (OPT_Wreturn_local_addr, "reference to local variable %q+D returned",
                 whats_returned);
       else
-       warning (OPT_Wreturn_local_addr, "address of local variable %q+D returned",
-                whats_returned);
+       warning (OPT_Wreturn_local_addr, "address of %s %q+D returned",
+                TREE_CODE (whats_returned) == LABEL_DECL
+                ? "label" : "local variable", whats_returned);
       return;
     }
 }
index 05e92409df1dc94b65d5fbc1078cf3ea9f7bdd10..61a48f33c3ce3a3bffe1c12ab07669e41d2b7574 100644 (file)
@@ -1,3 +1,8 @@
+2014-05-01  Marek Polacek  <polacek@redhat.com>
+
+       PR c/43395
+       * c-c++-common/pr43395.c: New test.
+
 2014-05-01  Yuri Rumyantsev  <ysrumyan@gmail.com>
 
        * gcc.dg/cond-reduc-1.c: New test.
diff --git a/gcc/testsuite/c-c++-common/pr43395.c b/gcc/testsuite/c-c++-common/pr43395.c
new file mode 100644 (file)
index 0000000..92f048d
--- /dev/null
@@ -0,0 +1,30 @@
+/* PR c/43395 */
+/* { dg-do compile } */
+
+void *
+foo (void)
+{
+lab:
+  return &&lab;
+/* { dg-warning "function returns address of label" "" { target c } 8 } */
+/* { dg-warning "address of label" "" { target c++ } 7 } */
+}
+
+void *
+bar (void)
+{
+  __label__ lab;
+lab:
+  return &&lab;
+/* { dg-warning "function returns address of label" "" { target c } 18 } */
+/* { dg-warning "address of label" "" { target c++ } 17 } */
+}
+
+void *
+baz (void)
+{
+  int i;
+  return &i;
+/* { dg-warning "function returns address of local variable" "" { target c } 27 } */
+/* { dg-warning "address of local variable" "" { target c++ } 26 } */
+}