diff mbox

Don't segv on __atomic_store (PR c/61553)

Message ID 20140623143955.GK14420@redhat.com
State New
Headers show

Commit Message

Marek Polacek June 23, 2014, 2:39 p.m. UTC
We ICEd on the following testcase since the void type has a NULL
TYPE_SIZE_UNIT.  I took Andrew's patch from gcc@ ML and added
a testcase.

Regtested/bootstrapped on x86_64-linux, ok for trunk?

2014-06-23  Marek Polacek  <polacek@redhat.com>
	    Andrew MacLeod  <amacleod@redhat.com>

	PR c/61553
	* c-common.c (get_atomic_generic_size): Don't segfault if the
	type doesn't have a size.

	* c-c++-common/pr61553.c: New test.


	Marek

Comments

Joseph Myers June 23, 2014, 4:53 p.m. UTC | #1
On Mon, 23 Jun 2014, Marek Polacek wrote:

> We ICEd on the following testcase since the void type has a NULL
> TYPE_SIZE_UNIT.  I took Andrew's patch from gcc@ ML and added
> a testcase.
> 
> Regtested/bootstrapped on x86_64-linux, ok for trunk?
> 
> 2014-06-23  Marek Polacek  <polacek@redhat.com>
> 	    Andrew MacLeod  <amacleod@redhat.com>
> 
> 	PR c/61553
> 	* c-common.c (get_atomic_generic_size): Don't segfault if the
> 	type doesn't have a size.
> 
> 	* c-c++-common/pr61553.c: New test.

OK.
diff mbox

Patch

diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 077263e..087f036 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -10471,7 +10471,8 @@  get_atomic_generic_size (location_t loc, tree function,
 		    function);
 	  return 0;
 	}
-      size = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (type)));
+      tree type_size = TYPE_SIZE_UNIT (TREE_TYPE (type));
+      size = type_size ? tree_to_uhwi (type_size) : 0;
       if (size != size_0)
 	{
 	  error_at (loc, "size mismatch in argument %d of %qE", x + 1,
diff --git gcc/testsuite/c-c++-common/pr61553.c gcc/testsuite/c-c++-common/pr61553.c
index e69de29..fa97e94 100644
--- gcc/testsuite/c-c++-common/pr61553.c
+++ gcc/testsuite/c-c++-common/pr61553.c
@@ -0,0 +1,8 @@ 
+/* PR c/61553 */
+/* { dg-do compile } */
+
+void
+foo (char *s)
+{
+  __atomic_store (s, (void *) 0, __ATOMIC_SEQ_CST);
+}