This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PR/24146, asms with no outputs are not treated as volatile
- From: Paolo Bonzini <paolo dot bonzini at lu dot unisi dot ch>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 30 Sep 2005 16:41:33 +0200
- Subject: 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.
This patch passes the new testcase and is undergoing
bootstrap/regtesting. Ok if it passes?
Paolo
2005-09-30 Paolo Bonzini <bonzini@gnu.org>
PR tree-optimization/24146
* stmt.c (expand_asm_operands): Do not special case a
zero-output ASM to be volatile.
* c-typeck.c (build_asm_expr): Do it here.
2005-09-30 Paolo Bonzini <bonzini@gnu.org>
* gcc.dg/pr24146.c: New testcase.
Index: stmt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stmt.c,v
retrieving revision 1.426
diff -p -u -u -r1.426 stmt.c
--- stmt.c 6 Aug 2005 11:31:42 -0000 1.426
+++ stmt.c 30 Sep 2005 14:36:16 -0000
@@ -649,10 +649,6 @@ expand_asm_operands (tree string, tree o
= alloca ((noutputs + ninputs) * sizeof (const char *));
int old_generating_concat_p = generating_concat_p;
- /* An ASM with no outputs needs to be treated as volatile, for now. */
- if (noutputs == 0)
- vol = 1;
-
if (! check_operand_nalternatives (outputs, inputs))
return;
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.479
diff -p -u -u -r1.479 c-typeck.c
--- c-typeck.c 6 Sep 2005 20:06:52 -0000 1.479
+++ c-typeck.c 30 Sep 2005 14:36:17 -0000
@@ -6627,12 +6627,15 @@ build_asm_expr (tree string, tree output
args = build_stmt (ASM_EXPR, string, outputs, inputs, clobbers);
- /* Simple asm statements are treated as volatile. */
+ /* Simple asm statements, and asm statements without outputs, are treated
+ as volatile. */
if (simple)
{
ASM_VOLATILE_P (args) = 1;
ASM_INPUT_P (args) = 1;
}
+ else
+ ASM_VOLATILE_P (args) = (noutputs == 0);
return args;
}
/* { 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" } } */