Here, we segv because we're checking TYPE_MAXVAL of domain that is actually
null for "extern int a[];".  The fix is trivial.

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

2016-04-29  Marek Polacek  <pola...@redhat.com>

        PR c/70852
        * c-common.c (warn_for_memset): Check domain before accessing it.

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

diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index c086dee..88507a2 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -11796,6 +11796,7 @@ warn_for_memset (location_t loc, tree arg0, tree arg2,
          tree elt_type = TREE_TYPE (type);
          tree domain = TYPE_DOMAIN (type);
          if (!integer_onep (TYPE_SIZE_UNIT (elt_type))
+             && domain != NULL_TREE
              && TYPE_MAXVAL (domain)
              && TYPE_MINVAL (domain)
              && integer_zerop (TYPE_MINVAL (domain))
diff --git gcc/testsuite/gcc.dg/pr70852.c gcc/testsuite/gcc.dg/pr70852.c
index e69de29..2dec082 100644
--- gcc/testsuite/gcc.dg/pr70852.c
+++ gcc/testsuite/gcc.dg/pr70852.c
@@ -0,0 +1,11 @@
+/* PR c/70852 */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+extern void *memset (void *, int, __SIZE_TYPE__);
+extern int A[];
+void
+fn1 (void)
+{
+  memset (A, 0, 1);
+}

        Marek

Reply via email to