From: Marek Polacek Date: Mon, 22 Aug 2016 21:53:59 +0000 (+0000) Subject: re PR c++/77321 (crash in warn_for_memset) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b00e6e758ab9ba1ccc2b6c32f735013de37092a4;p=gcc.git 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 --- diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index c1423849b83..fe98090ba02 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2016-08-22 Marek Polacek + + PR c++/77321 + * c-common.c (warn_for_memset): Check type for null. + 2016-08-22 Joseph Myers * 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 32468ca1351..3feb910f09f 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 013cee3798a..f25acf494d6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-08-22 Marek Polacek + + PR c++/77321 + * g++.dg/cpp1y/pr77321.C: New test. + 2016-08-22 Steven G. Kargl 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 00000000000..b25f492dc4f --- /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 +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; +}