Patchwork [trans-mem] error on inlined asms

login
register
mail settings
Submitter Aldy Hernandez
Date Jan. 10, 2011, 6:45 p.m.
Message ID <4D2B53C9.5080201@redhat.com>
Download mbox | patch
Permalink /patch/78192/
State New
Headers show

Comments

Aldy Hernandez - Jan. 10, 2011, 6:45 p.m.
In the following test, we correctly error at -O0 because inline_death() 
has an unsafe construct and is being called from an atomic transaction.  
This error is triggered at ipa_tm_diagnose_transaction() because the 
diagnostic machinery (diagnose_tm*) has marked inline_death() as 
possibly entering irrevocable mode.

However, at any optimization level, we don't error because we no longer 
have an irrevocable function call, instead the ASM has been inlined into 
the transaction.  Since the asm complaining code gets run before 
inlining (diagnose_tm*), we don't notice the asm that ends up inside the 
transaction.

        static inline void
        inline_death ()
        {
           __asm__ ("");
        }

        void
        tranfunction ()
        {
           __transaction
           {
             inline_death ();
           }
        }

My fix is to notice ASMs that have been inlined into transactions at IPA 
time, since we're iterating over the transaction code anyhow.

OK for branch?
* trans-mem.c (ipa_tm_diagnose_transaction): Do not allow asms in
	atomic transactions.
Richard Henderson - Jan. 10, 2011, 7:44 p.m.
On 01/10/2011 10:45 AM, Aldy Hernandez wrote:
> 	* trans-mem.c (ipa_tm_diagnose_transaction): Do not allow asms in
> 	atomic transactions.

Ok.


r~

Patch

Index: testsuite/c-c++-common/tm/inline-asm.c
===================================================================
--- testsuite/c-c++-common/tm/inline-asm.c	(revision 0)
+++ testsuite/c-c++-common/tm/inline-asm.c	(revision 0)
@@ -0,0 +1,17 @@ 
+/* { dg-do compile } */
+/* { dg-options "-fgnu-tm -O1" } */
+
+static inline void
+inline_death ()
+{
+  __asm__ ("");			/* { dg-error "asm not allowed" } */
+}
+
+void
+tranfunction ()
+{
+  __transaction
+    {
+      inline_death ();
+    }
+}
Index: trans-mem.c
===================================================================
--- trans-mem.c	(revision 168123)
+++ trans-mem.c	(working copy)
@@ -3929,6 +3929,13 @@  ipa_tm_diagnose_transaction (struct cgra
 	      gimple stmt = gsi_stmt (gsi);
 	      tree fndecl;
 
+	      if (gimple_code (stmt) == GIMPLE_ASM)
+		{
+		  error_at (gimple_location (stmt),
+			    "asm not allowed in atomic transaction");
+		  continue;
+		}
+
 	      if (!is_gimple_call (stmt))
 		continue;
 	      fndecl = gimple_call_fndecl (stmt);