PR c/43395
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 1 May 2014 07:29:38 +0000 (07:29 +0000)
committermpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 1 May 2014 07:29:38 +0000 (07:29 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@209973 138bc75d-0d04-0410-961f-82ee72b054a4

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 e04a38d..f0630e2 100644 (file)
@@ -1,5 +1,11 @@
 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
        * c-decl.c (declspecs_add_type): Pedwarn if boolean types are used
        in C89 mode.
index e25a25c..2a40c70 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 c078e06..4d16855 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 729e22e..8b7cb8d 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 05e9240..61a48f3 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 } */
+}