Here we were crashing because the code wasn't prepared for NULL_TREE types.
Thus fixed in a rather obvious way.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2016-08-22  Marek Polacek  <pola...@redhat.com>

        PR c++/77321
        * c-common.c (warn_for_memset): Check type for null.

        * g++.dg/cpp1y/pr77321.C: New test.

diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 32468ca..3feb910 100644
--- gcc/c-family/c-common.c
+++ 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 gcc/testsuite/g++.dg/cpp1y/pr77321.C 
gcc/testsuite/g++.dg/cpp1y/pr77321.C
index e69de29..ff33437 100644
--- gcc/testsuite/g++.dg/cpp1y/pr77321.C
+++ gcc/testsuite/g++.dg/cpp1y/pr77321.C
@@ -0,0 +1,10 @@
+// PR c++/77321
+// { dg-do compile { target c++14 } }
+// { dg-options "-Wall" }
+
+template <typename>
+void foo (void)
+{
+  auto &a();
+  __builtin_memset(a, 'X', 4);
+}

        Marek

Reply via email to