]> gcc.gnu.org Git - gcc.git/commitdiff
re PR inline-asm/8832 (traditional "asm volatile" code is illegally optimized)
authorEric Botcazou <ebotcazou@libertysurf.fr>
Thu, 9 Jan 2003 11:13:07 +0000 (12:13 +0100)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Thu, 9 Jan 2003 11:13:07 +0000 (11:13 +0000)
PR inline-asm/8832
* tree.h (expand_asm): New prototype.
* stmt.c (expand_asm): Set the MEM_VOLATILE_P flag if instructed
to do so.
* c-semantics (genrtl_asm_stmt): Pass the RID_VOLATILE qualifier
down to expand_asm.
* c-typeck.c (simple_asm_stmt): Set the RID_VOLATILE qualifier.
* rtlanal.c (volatile_insn_p) [ASM_INPUT]: Test the MEM_VOLATILE_P flag.
(volatile_refs_p) [ASM_INPUT]: Likewise.
(side_effects_p) [ASM_INPUT]: Likewise.

From-SVN: r61099

gcc/ChangeLog
gcc/c-semantics.c
gcc/c-typeck.c
gcc/rtlanal.c
gcc/stmt.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/old-style-asm-1.c [new file with mode: 0644]
gcc/tree.h

index 4055fa12832aa413f1d76d311f3d70cb162c2a76..96ca06396ff3c910ebf4865bb3fca9c1ffc1ba2e 100644 (file)
@@ -1,3 +1,16 @@
+2003-01-09  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+       PR inline-asm/8832
+       * tree.h (expand_asm): New prototype.
+       * stmt.c (expand_asm): Set the MEM_VOLATILE_P flag if instructed
+       to do so.
+       * c-semantics (genrtl_asm_stmt): Pass the RID_VOLATILE qualifier
+       down to expand_asm.
+       * c-typeck.c (simple_asm_stmt): Set the RID_VOLATILE qualifier.
+       * rtlanal.c (volatile_insn_p) [ASM_INPUT]: Test the MEM_VOLATILE_P flag.
+       (volatile_refs_p) [ASM_INPUT]: Likewise.
+       (side_effects_p) [ASM_INPUT]: Likewise.
+
 Thu Jan  9 12:00:36 CET 2003  Jan Hubicka  <jh@suse.cz>
 
        * i386.md (*mul*): FIx constraints; remove confused comment; fix
index 77d7384f9a2ba9c467d3fb21091a1b194d775ede..769c1165d4a35a62498c5f1378cb2e4f63304326 100644 (file)
@@ -749,7 +749,7 @@ genrtl_asm_stmt (cv_qualifier, string, output_operands,
 
   emit_line_note (input_filename, lineno);
   if (asm_input_p)
-    expand_asm (string);
+    expand_asm (string, cv_qualifier != NULL_TREE);
   else
     c_expand_asm_operands (string, output_operands, input_operands, 
                           clobbers, cv_qualifier != NULL_TREE,
index c5b4ecbf9d3e96f837f4cd617510f36647ae4764..87703a730795a0e8b01d389f9838881f4da51de6 100644 (file)
@@ -6853,9 +6853,9 @@ simple_asm_stmt (expr)
     {
       tree stmt;
 
-      stmt = add_stmt (build_stmt (ASM_STMT, NULL_TREE, expr,
-                                  NULL_TREE, NULL_TREE,
-                                  NULL_TREE));
+      /* Simple asm statements are treated as volatile.  */
+      stmt = add_stmt (build_stmt (ASM_STMT, ridpointers[(int) RID_VOLATILE],
+                                  expr, NULL_TREE, NULL_TREE, NULL_TREE));
       ASM_INPUT_P (stmt) = 1;
       return stmt;
     }
index 63d7feb60351cb60da46fd0e1c9fe47433a392fc..030682e43f909bbc2a2410473c5a98aeef5a3b6d 100644 (file)
@@ -2237,7 +2237,6 @@ volatile_insn_p (x)
     case REG:
     case SCRATCH:
     case CLOBBER:
-    case ASM_INPUT:
     case ADDR_VEC:
     case ADDR_DIFF_VEC:
     case CALL:
@@ -2248,6 +2247,7 @@ volatile_insn_p (x)
  /* case TRAP_IF: This isn't clear yet.  */
       return 1;
 
+    case ASM_INPUT:
     case ASM_OPERANDS:
       if (MEM_VOLATILE_P (x))
        return 1;
@@ -2304,7 +2304,6 @@ volatile_refs_p (x)
     case REG:
     case SCRATCH:
     case CLOBBER:
-    case ASM_INPUT:
     case ADDR_VEC:
     case ADDR_DIFF_VEC:
       return 0;
@@ -2313,6 +2312,7 @@ volatile_refs_p (x)
       return 1;
 
     case MEM:
+    case ASM_INPUT:
     case ASM_OPERANDS:
       if (MEM_VOLATILE_P (x))
        return 1;
@@ -2368,7 +2368,6 @@ side_effects_p (x)
     case PC:
     case REG:
     case SCRATCH:
-    case ASM_INPUT:
     case ADDR_VEC:
     case ADDR_DIFF_VEC:
       return 0;
@@ -2391,6 +2390,7 @@ side_effects_p (x)
       return 1;
 
     case MEM:
+    case ASM_INPUT:
     case ASM_OPERANDS:
       if (MEM_VOLATILE_P (x))
        return 1;
index fbdf463ee5715391a93ee0b9f3be130b9682b0a9..ac0aa15bef2952a267a2a77649008abac207ee72 100644 (file)
@@ -1098,18 +1098,26 @@ n_occurrences (c, s)
 }
 \f
 /* Generate RTL for an asm statement (explicit assembler code).
-   BODY is a STRING_CST node containing the assembler code text,
-   or an ADDR_EXPR containing a STRING_CST.  */
+   STRING is a STRING_CST node containing the assembler code text,
+   or an ADDR_EXPR containing a STRING_CST.  VOL nonzero means the
+   insn is volatile; don't optimize it.  */
 
 void
-expand_asm (body)
-     tree body;
+expand_asm (string, vol)
+     tree string;
+     int vol;
 {
-  if (TREE_CODE (body) == ADDR_EXPR)
-    body = TREE_OPERAND (body, 0);
+  rtx body;
+
+  if (TREE_CODE (string) == ADDR_EXPR)
+    string = TREE_OPERAND (string, 0);
+
+  body = gen_rtx_ASM_INPUT (VOIDmode, TREE_STRING_POINTER (string));
+
+  MEM_VOLATILE_P (body) = vol;
 
-  emit_insn (gen_rtx_ASM_INPUT (VOIDmode,
-                               TREE_STRING_POINTER (body)));
+  emit_insn (body);
+  
   clear_last_expr ();
 }
 
index f5d0134f2a1f1ff02f156351838cccc940a3c7e3..8063cf3a40db5fe8ce06a36125c315931b031b91 100644 (file)
@@ -1,3 +1,7 @@
+2003-01-09  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+       gcc.dg/old-style-asm-1.c: New test.
+
 2003-01-09  Richard Sandiford  <rsandifo@redhat.com>
 
        * gcc.c-torture/compile/20030109-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/old-style-asm-1.c b/gcc/testsuite/gcc.dg/old-style-asm-1.c
new file mode 100644 (file)
index 0000000..006cf09
--- /dev/null
@@ -0,0 +1,19 @@
+/* PR inline-asm/8832 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+/* Verify that GCC doesn't optimize
+   old style asm instructions.  */
+
+void foo(int v)
+{
+  if (v)
+    asm ("dummy1");
+
+  asm ("dummy2");
+
+  if (v)
+    asm ("dummy3");
+}
+
+/* { dg-final { scan-assembler "L2" } } */
index 93a237f73f2d1df5e0967749efd624c25ec238ef..6075d83b87f041de63e4e9117c4c9ff829077c66 100644 (file)
@@ -2835,7 +2835,7 @@ extern void expand_decl_init                      PARAMS ((tree));
 extern void clear_last_expr                    PARAMS ((void));
 extern void expand_label                       PARAMS ((tree));
 extern void expand_goto                                PARAMS ((tree));
-extern void expand_asm                         PARAMS ((tree));
+extern void expand_asm                         PARAMS ((tree, int));
 extern void expand_start_cond                  PARAMS ((tree, int));
 extern void expand_end_cond                    PARAMS ((void));
 extern void expand_start_else                  PARAMS ((void));
This page took 0.096559 seconds and 5 git commands to generate.