Message ID | 20161209152719.GN2337@redhat.com |
---|---|
State | New |
Headers | show |
On December 9, 2016 4:27:19 PM GMT+01:00, Marek Polacek <polacek@redhat.com> wrote: >The attached test crashed because we wound up with an SSA_NAME of >a reference type in get_range_info which has > > gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name))); > >I think this could be fixed by treating "char &" the same as "char *" >in >check_sizes (the POINTER_TYPE_P macro handles both >pointers/references). > >Bootstrapped/regtested on x86_64-linux, ok for trunk? OK. Richard. >2016-12-09 Marek Polacek <polacek@redhat.com> > > PR middle-end/78750 > * builtins.c (check_sizes): Use POINTER_TYPE_P. > > * g++.dg/torture/pr78750.C: New. > >diff --git gcc/builtins.c gcc/builtins.c >index 20515e7..b056e12 100644 >--- gcc/builtins.c >+++ gcc/builtins.c >@@ -3091,7 +3091,7 @@ check_sizes (int opt, tree exp, tree size, tree >maxlen, tree str, tree objsize) > { > /* STR is normally a pointer to string but as a special case > it can be an integer denoting the length of a string. */ >- if (TREE_CODE (TREE_TYPE (str)) == POINTER_TYPE) >+ if (POINTER_TYPE_P (TREE_TYPE (str))) > { > /* Try to determine the range of lengths the source string > refers to. If it can be determined add one to it for >diff --git gcc/testsuite/g++.dg/torture/pr78750.C >gcc/testsuite/g++.dg/torture/pr78750.C >index e69de29..54232e6 100644 >--- gcc/testsuite/g++.dg/torture/pr78750.C >+++ gcc/testsuite/g++.dg/torture/pr78750.C >@@ -0,0 +1,10 @@ >+// PR middle-end/78750 >+// { dg-do compile } >+ >+extern "C" char *strcpy (char *, const char *); >+ >+void >+fn (char *p, char &as) >+{ >+ strcpy (p, &as); >+} > > Marek
diff --git gcc/builtins.c gcc/builtins.c index 20515e7..b056e12 100644 --- gcc/builtins.c +++ gcc/builtins.c @@ -3091,7 +3091,7 @@ check_sizes (int opt, tree exp, tree size, tree maxlen, tree str, tree objsize) { /* STR is normally a pointer to string but as a special case it can be an integer denoting the length of a string. */ - if (TREE_CODE (TREE_TYPE (str)) == POINTER_TYPE) + if (POINTER_TYPE_P (TREE_TYPE (str))) { /* Try to determine the range of lengths the source string refers to. If it can be determined add one to it for diff --git gcc/testsuite/g++.dg/torture/pr78750.C gcc/testsuite/g++.dg/torture/pr78750.C index e69de29..54232e6 100644 --- gcc/testsuite/g++.dg/torture/pr78750.C +++ gcc/testsuite/g++.dg/torture/pr78750.C @@ -0,0 +1,10 @@ +// PR middle-end/78750 +// { dg-do compile } + +extern "C" char *strcpy (char *, const char *); + +void +fn (char *p, char &as) +{ + strcpy (p, &as); +}