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]

Re: PR/24146, asms with no outputs are not treated as volatile



The problem is that expand_asm_operands does mark the asm as volatile, but only after the tree optimization passes have had many opportunities to optimize it away. It can be fixed in the gimplifier or in the front-end, I chose the latter.

Plus you forgot about the C++ front-end also.

Which is why I'd rather have fixed this in the gimplifier. But since I was at it, I noticed that the C++ front-end was not marking old-style asm statements as volatile, and this patch fixes that too. The C and C++ testcases are identical.


Thanks,

Paolo
2005-09-30  Paolo Bonzini  <bonzini@gnu.org>

	PR tree-optimization/24146

	* semantics.c (finish_asm_stmt): Mark a zero-output ASM as volatile.
	* parser.c (cp_parser_asm_definition): Ditto for old-style ASMs.

2005-09-30  Paolo Bonzini  <bonzini@gnu.org>

	* g++.dg/ext/asm7.C: New testcase.

Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.358
diff -p -u -u -r1.358 parser.c
--- cp/parser.c	13 Sep 2005 02:41:04 -0000	1.358
+++ cp/parser.c	30 Sep 2005 14:55:30 -0000
@@ -10637,6 +10637,7 @@ cp_parser_asm_definition (cp_parser* par
 	    temp = TREE_OPERAND (temp, 0);
 
 	  ASM_INPUT_P (temp) = 1;
+	  ASM_VOLATILE_P (temp) = 1;
 	}
     }
   else
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.490
diff -p -u -u -r1.490 semantics.c
--- cp/semantics.c	12 Sep 2005 19:54:04 -0000	1.490
+++ cp/semantics.c	30 Sep 2005 14:55:30 -0000
@@ -1254,7 +1254,7 @@ finish_asm_stmt (int volatile_p, tree st
   r = build_stmt (ASM_EXPR, string,
 		  output_operands, input_operands,
 		  clobbers);
-  ASM_VOLATILE_P (r) = volatile_p;
+  ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
   r = maybe_cleanup_point_expr_void (r);
   return add_stmt (r);
 }



/* { dg-do compile } */

/* Test that asm with no outputs are treated as volatile.  */

void f(int x)
{
  __asm__ ("not discarded" : : "r" (x));
}

/* { dg-final { scan-assembler "not discarded" } } */


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