diff options
author | Marek Polacek <polacek@redhat.com> | 2016-08-22 21:53:59 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2016-08-22 21:53:59 +0000 |
commit | b00e6e758ab9ba1ccc2b6c32f735013de37092a4 (patch) | |
tree | b58bd9ccb553baa7fdeab15929228481b247c105 | |
parent | bb748b89dfae944fe6e075f1b5d1c3d1501c0948 (diff) | |
download | gcc-b00e6e758ab9ba1ccc2b6c32f735013de37092a4.zip gcc-b00e6e758ab9ba1ccc2b6c32f735013de37092a4.tar.gz gcc-b00e6e758ab9ba1ccc2b6c32f735013de37092a4.tar.bz2 |
re PR c++/77321 (crash in warn_for_memset)
PR c++/77321
* c-common.c (warn_for_memset): Check type for null.
* g++.dg/cpp1y/pr77321.C: New test.
From-SVN: r239676
-rw-r--r-- | gcc/c-family/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1y/pr77321.C | 24 |
4 files changed, 35 insertions, 1 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index c142384..fe98090 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2016-08-22 Marek Polacek <polacek@redhat.com> + + PR c++/77321 + * c-common.c (warn_for_memset): Check type for null. + 2016-08-22 Joseph Myers <joseph@codesourcery.com> * c-family/c-cppbuiltin.c (c_cpp_builtins): Check _FloatN and diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 32468ca..3feb910 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -11991,7 +11991,7 @@ warn_for_memset (location_t loc, tree arg0, tree arg2, if (TREE_CODE (arg0) == ADDR_EXPR) arg0 = TREE_OPERAND (arg0, 0); tree type = TREE_TYPE (arg0); - if (TREE_CODE (type) == ARRAY_TYPE) + if (type != NULL_TREE && TREE_CODE (type) == ARRAY_TYPE) { tree elt_type = TREE_TYPE (type); tree domain = TYPE_DOMAIN (type); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 013cee3..f25acf4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-08-22 Marek Polacek <polacek@redhat.com> + + PR c++/77321 + * g++.dg/cpp1y/pr77321.C: New test. + 2016-08-22 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/60774 diff --git a/gcc/testsuite/g++.dg/cpp1y/pr77321.C b/gcc/testsuite/g++.dg/cpp1y/pr77321.C new file mode 100644 index 0000000..b25f492 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/pr77321.C @@ -0,0 +1,24 @@ +// PR c++/77321 +// { dg-do compile { target c++14 } } +// { dg-options "-Wall" } + +extern "C" void *memset (void *, int, __SIZE_TYPE__); +extern "C" void *malloc(__SIZE_TYPE__); + +struct S { + char *a; +}; + +template <typename T> +void Test(T & Obj) { + auto && a(Obj.a); + a = (char*)::malloc(1024 * 1024); + ::memset(a + 28, 'X', 6); +} + +int main() +{ + S d; + Test(d); + return 0; +} |