]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c/38957 (return of local variable pointer)
authorRichard Guenther <rguenther@suse.de>
Tue, 20 Apr 2010 14:09:52 +0000 (14:09 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 20 Apr 2010 14:09:52 +0000 (14:09 +0000)
2010-04-20  Richard Guenther  <rguenther@suse.de>

Backport from mainline
2009-01-24  Jakub Jelinek  <jakub@redhat.com>

PR c/38957
* c-typeck.c (c_finish_return): Handle POINTER_PLUS_EXPR the same way
as PLUS_EXPR.

* gcc.dg/pr38957.c: New test.

From-SVN: r158559

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr38957.c [new file with mode: 0644]

index d99458a3fc5ae7829fb80cb7662b533babcd8eb4..177aba29feaec2510845bd4a1c367fd45cdba820 100644 (file)
@@ -1,3 +1,12 @@
+2010-04-20  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline
+       2009-01-24  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/38957
+       * c-typeck.c (c_finish_return): Handle POINTER_PLUS_EXPR the same way
+       as PLUS_EXPR.
+
 2010-04-20  Richard Guenther  <rguenther@suse.de>
 
        Backport from mainline
index 5b2b61d3065223341ee925221c18ed649cb6a09f..e00de1fe430a369e18fae9d5ee25e9ef2549dabc 100644 (file)
@@ -7136,6 +7136,7 @@ c_finish_return (tree retval)
            {
            case NOP_EXPR:   case NON_LVALUE_EXPR:  case CONVERT_EXPR:
            case PLUS_EXPR:
+           case POINTER_PLUS_EXPR:
              inner = TREE_OPERAND (inner, 0);
              continue;
 
index c9842fb3aea79996fe5ed5dfde60c3439094de35..8002421e21e8776d19a4cf2436e8d5bc55572283 100644 (file)
@@ -1,3 +1,11 @@
+2010-04-20  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline
+       2009-01-24  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/38957
+       * gcc.dg/pr38957.c: New test.
 2010-04-20  Richard Guenther  <rguenther@suse.de>
 
        Backport from mainline
diff --git a/gcc/testsuite/gcc.dg/pr38957.c b/gcc/testsuite/gcc.dg/pr38957.c
new file mode 100644 (file)
index 0000000..f94cd76
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR c/38957 */
+/* { dg-do compile } */
+
+char *
+foo (void)
+{
+  char a[2];
+  return a+1;  /* { dg-warning "returns address of local variable" } */
+}
+
+char *
+bar (void)
+{
+  char a[2];
+  return a;    /* { dg-warning "returns address of local variable" } */
+}