diff mbox

Fix warn_for_memset ICE (PR c/70852)

Message ID 20160429120136.GA5348@redhat.com
State New
Headers show

Commit Message

Marek Polacek April 29, 2016, 12:01 p.m. UTC
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  <polacek@redhat.com>

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

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


	Marek

Comments

Bernd Schmidt April 29, 2016, 12:08 p.m. UTC | #1
On 04/29/2016 02:01 PM, Marek Polacek wrote:
> 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  <polacek@redhat.com>
>
> 	PR c/70852
> 	* c-common.c (warn_for_memset): Check domain before accessing it.
>
> 	* gcc.dg/pr70852.c: New test.

Ok, thanks.


Bernd
diff mbox

Patch

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);
+}