Patchwork PR47747: Fix error messages for calls to transaction_unsafe virtual functions.

login
register
mail settings
Submitter Torvald Riegel
Date Nov. 21, 2011, 8:37 p.m.
Message ID <1321907829.12248.150.camel@triegel.csb>
Download mbox | patch
Permalink /patch/126925/
State New
Headers show

Comments

Torvald Riegel - Nov. 21, 2011, 8:37 p.m.
This just tweaks the error message to use an expression (%qE) instead of
a declaration (%qD) when we complain about an indirect call being
unsafe.  The output isn't very pretty, but it does seem to do the job.
Also, if it is a direct call, it should hopefully always be some kind of
expression.  All the other uses of %qD I saw in trans-mem.c seemed to
indeed be for full declarations AFAICT, so I left them as-is.

OK for trunk?
commit c7e5c91a935737a0725607a35b9e6bb9d67be09b
Author: Torvald Riegel <triegel@redhat.com>
Date:   Mon Nov 21 16:43:17 2011 +0100

    PR47747: Fix error messages for calls to unsafe virtual functions.
    
    	gcc/
    	* trans-mem.c (diagnose_tm_1): Print an expression instead of a
    	declaration in error messages for indirect calls.
    
    	testsuite/
    	g++.dg/tm/pr47747.C: New test.
Richard Henderson - Nov. 21, 2011, 9:39 p.m.
On 11/21/2011 12:37 PM, Torvald Riegel wrote:
>     PR47747: Fix error messages for calls to unsafe virtual functions.
>     
>     	gcc/
>     	* trans-mem.c (diagnose_tm_1): Print an expression instead of a
>     	declaration in error messages for indirect calls.
>     
>     	testsuite/
>     	g++.dg/tm/pr47747.C: New test.

Ok.


r~

Patch

diff --git a/gcc/testsuite/g++.dg/tm/pr47747.C b/gcc/testsuite/g++.dg/tm/pr47747.C
new file mode 100644
index 0000000..3b50904
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tm/pr47747.C
@@ -0,0 +1,21 @@ 
+// { dg-do compile }
+// { dg-options "-fgnu-tm -O" }
+
+class InputStream
+{
+        public:
+//        __attribute__((transaction_safe))
+        virtual unsigned int readUint32 () = 0;
+};
+
+class Building
+{
+        public:
+        __attribute__((transaction_safe))
+        Building (InputStream *stream);
+};
+
+Building::Building (InputStream *stream)
+{
+        stream->readUint32 (); /* { dg-error "InputStream::readUint32" } */
+}
diff --git a/gcc/trans-mem.c b/gcc/trans-mem.c
index 3c0bd60..347183b 100644
--- a/gcc/trans-mem.c
+++ b/gcc/trans-mem.c
@@ -659,13 +659,27 @@  diagnose_tm_1 (gimple_stmt_iterator *gsi, bool *handled_ops_p,
 		if (TREE_CODE (fn) == ADDR_EXPR)
 		  fn = TREE_OPERAND (fn, 0);
 		if (d->block_flags & DIAG_TM_SAFE)
-		  error_at (gimple_location (stmt),
-			    "unsafe function call %qD within "
-			    "atomic transaction", fn);
+		  {
+		    if (direct_call_p)
+		      error_at (gimple_location (stmt),
+				"unsafe function call %qD within "
+				"atomic transaction", fn);
+		    else
+		      error_at (gimple_location (stmt),
+				"unsafe function call %qE within "
+				"atomic transaction", fn);
+		  }
 		else
-		  error_at (gimple_location (stmt),
-			    "unsafe function call %qD within "
-			    "%<transaction_safe%> function", fn);
+		  {
+		    if (direct_call_p)
+		      error_at (gimple_location (stmt),
+				"unsafe function call %qD within "
+				"%<transaction_safe%> function", fn);
+		    else
+		      error_at (gimple_location (stmt),
+				"unsafe function call %qE within "
+				"%<transaction_safe%> function", fn);
+		  }
 	      }
 	  }
       }