public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Error out on uses of void type expressions in inline asm in C FE (PR c/48552)
@ 2011-04-11 19:49 Jakub Jelinek
  2011-04-11 21:28 ` Joseph S. Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2011-04-11 19:49 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc-patches

Hi!

Several of the functions in the following testcases ICE.  Unlike
C++ FE, C FE doesn't error out on void type derefs right away,
just warns.  But using void type expression for "r" or "=r" doesn't
make sense and was ICEing.  The patch still tollerates it for
constraints that allow only mem, as that case wasn't crashing and
just address of it was presented to the asm.

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

2011-04-11  Jakub Jelinek  <jakub@redhat.com>

	PR c/48552
	* c-typeck.c (build_asm_expr): Error out on attempts to use
	void type outputs or inputs for constraints that allow reg or
	don't allow memory.

	* gcc.dg/pr48552-1.c: New test.
	* gcc.dg/pr48552-2.c: New test.

--- gcc/c-typeck.c.jj	2011-03-31 08:51:03.000000000 +0200
+++ gcc/c-typeck.c	2011-04-11 13:29:17.000000000 +0200
@@ -8502,6 +8502,13 @@ build_asm_expr (location_t loc, tree str
 	     mark it addressable.  */
 	  if (!allows_reg && !c_mark_addressable (output))
 	    output = error_mark_node;
+	  if (!(!allows_reg && allows_mem)
+	      && output != error_mark_node
+	      && VOID_TYPE_P (TREE_TYPE (output)))
+	    {
+	      error_at (loc, "invalid use of void expression");
+	      output = error_mark_node;
+	    }
 	}
       else
 	output = error_mark_node;
@@ -8528,7 +8535,12 @@ build_asm_expr (location_t loc, tree str
 	      STRIP_NOPS (input);
 	      if (!c_mark_addressable (input))
 		input = error_mark_node;
-	  }
+	    }
+	  else if (input != error_mark_node && VOID_TYPE_P (TREE_TYPE (input)))
+	    {
+	      error_at (loc, "invalid use of void expression");
+	      input = error_mark_node;
+	    }
 	}
       else
 	input = error_mark_node;
--- gcc/testsuite/gcc.dg/pr48552-1.c.jj	2011-04-11 14:22:13.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr48552-1.c	2011-04-11 14:24:40.000000000 +0200
@@ -0,0 +1,53 @@
+/* PR c/48552 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct S;
+
+void
+f1 (void *x)
+{
+  __asm volatile ("" : : "r" (*x));	/* { dg-warning "dereferencing" } */
+}					/* { dg-error "invalid use of void expression" "" { target *-*-* } 10 } */
+
+void
+f2 (void *x)
+{
+  __asm volatile ("" : "=r" (*x));	/* { dg-warning "dereferencing" } */
+}					/* { dg-error "invalid use of void expression" "" { target *-*-* } 16 } */
+					/* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 16 } */
+void
+f3 (void *x)
+{
+  __asm volatile ("" : : "m" (*x));	/* { dg-warning "dereferencing" } */
+}
+
+void
+f4 (void *x)
+{
+  __asm volatile ("" : "=m" (*x));	/* { dg-warning "dereferencing" } */
+}
+
+void
+f5 (void *x)
+{
+  __asm volatile ("" : : "g" (*x));	/* { dg-warning "dereferencing" } */
+}					/* { dg-error "invalid use of void expression" "" { target *-*-* } 34 } */
+
+void
+f6 (void *x)
+{
+  __asm volatile ("" : "=g" (*x));	/* { dg-warning "dereferencing" } */
+}					/* { dg-error "invalid use of void expression" "" { target *-*-* } 40 } */
+					/* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 40 } */
+void
+f7 (struct S *x)
+{
+  __asm volatile ("" : : "r" (*x));	/* { dg-error "dereferencing pointer to incomplete type" } */
+}
+
+void
+f8 (struct S *x)
+{
+  __asm volatile ("" : "=r" (*x));	/* { dg-error "dereferencing pointer to incomplete type" } */
+}					/* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 52 } */
--- gcc/testsuite/gcc.dg/pr48552-2.c.jj	2011-04-11 14:22:13.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr48552-2.c	2011-04-11 14:24:59.000000000 +0200
@@ -0,0 +1,53 @@
+/* PR c/48552 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct S;
+
+void
+f1 (void *x)
+{
+  __asm ("" : : "r" (*x));	/* { dg-warning "dereferencing" } */
+}				/* { dg-error "invalid use of void expression" "" { target *-*-* } 10 } */
+
+void
+f2 (void *x)
+{
+  __asm ("" : "=r" (*x));	/* { dg-warning "dereferencing" } */
+}				/* { dg-error "invalid use of void expression" "" { target *-*-* } 16 } */
+				/* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 16 } */
+void
+f3 (void *x)
+{
+  __asm ("" : : "m" (*x));	/* { dg-warning "dereferencing" } */
+}
+
+void
+f4 (void *x)
+{
+  __asm ("" : "=m" (*x));	/* { dg-warning "dereferencing" } */
+}
+
+void
+f5 (void *x)
+{
+  __asm ("" : : "g" (*x));	/* { dg-warning "dereferencing" } */
+}				/* { dg-error "invalid use of void expression" "" { target *-*-* } 34 } */
+
+void
+f6 (void *x)
+{
+  __asm ("" : "=g" (*x));	/* { dg-warning "dereferencing" } */
+}				/* { dg-error "invalid use of void expression" "" { target *-*-* } 40 } */
+				/* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 40 } */
+void
+f7 (struct S *x)
+{
+  __asm ("" : : "r" (*x));	/* { dg-error "dereferencing pointer to incomplete type" } */
+}
+
+void
+f8 (struct S *x)
+{
+  __asm ("" : "=r" (*x));	/* { dg-error "dereferencing pointer to incomplete type" } */
+}				/* { dg-error "invalid lvalue in asm output 0" "" { target *-*-* } 52 } */

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Error out on uses of void type expressions in inline asm in C FE (PR c/48552)
  2011-04-11 19:49 [PATCH] Error out on uses of void type expressions in inline asm in C FE (PR c/48552) Jakub Jelinek
@ 2011-04-11 21:28 ` Joseph S. Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph S. Myers @ 2011-04-11 21:28 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Mon, 11 Apr 2011, Jakub Jelinek wrote:

> 2011-04-11  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c/48552
> 	* c-typeck.c (build_asm_expr): Error out on attempts to use
> 	void type outputs or inputs for constraints that allow reg or
> 	don't allow memory.
> 
> 	* gcc.dg/pr48552-1.c: New test.
> 	* gcc.dg/pr48552-2.c: New test.

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-04-11 21:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-11 19:49 [PATCH] Error out on uses of void type expressions in inline asm in C FE (PR c/48552) Jakub Jelinek
2011-04-11 21:28 ` Joseph S. Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).