This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Reject TREE_ADDRESSABLE types in inline asm which doesn't allow mem (PR inline-asm/32109)


Hi!

Objects with ctors or dtors can only be passed to inline asm as inputs
as memory.

Ok for 4.1/4.2/4.3?

2007-06-19  Jakub Jelinek  <jakub@redhat.com>

	PR inline-asm/32109
	* gimplify.c (gimplify_asm_expr): Issue error if type is addressable
	and !allows_mem.

	* g++.dg/ext/asm10.C: New test.

--- gcc/gimplify.c.jj	2007-06-19 17:14:58.000000000 +0200
+++ gcc/gimplify.c	2007-06-19 16:42:40.000000000 +0200
@@ -4122,6 +4122,19 @@ gimplify_asm_expr (tree *expr_p, tree *p
       parse_input_constraint (&constraint, 0, 0, noutputs, 0,
 			      oconstraints, &allows_mem, &allows_reg);
 
+      /* If we can't make copies, we can only accept memory.  */
+      if (TREE_ADDRESSABLE (TREE_TYPE (TREE_VALUE (link))))
+	{
+	  if (allows_mem)
+	    allows_reg = 0;
+	  else
+	    {
+	      error ("impossible constraint in %<asm%>");
+	      error ("non-memory input %d must stay in memory", i);
+	      return GS_ERROR;
+	    }
+	}
+
       /* If the operand is a memory input, it should be an lvalue.  */
       if (!allows_reg && allows_mem)
 	{
--- gcc/testsuite/g++.dg/ext/asm10.C.jj	2007-06-19 17:22:15.000000000 +0200
+++ gcc/testsuite/g++.dg/ext/asm10.C	2007-06-19 17:23:11.000000000 +0200
@@ -0,0 +1,14 @@
+// PR inline-asm/32109
+// { dg-do compile }
+// { dg-options "-O2" }
+
+struct A { int i[3]; ~A (); };
+struct A a;
+struct B { struct A c; int i; B (); } b;
+
+B::B ()
+{
+  __asm ("" : : "r" (a));	// { dg-error "impossible constraint|non-memory input" }
+  __asm ("" : : "r" (b.c));	// { dg-error "impossible constraint|non-memory input" }
+  __asm ("" : : "r" (c));	// { dg-error "impossible constraint|non-memory input" }
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]