This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[trans-mem] diagnose unsafe function calls better
- From: Aldy Hernandez <aldyh at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org, rth at redhat dot com
- Date: Wed, 21 Apr 2010 06:29:28 -0400
- Subject: [trans-mem] diagnose unsafe function calls better
If you have an unsafe function call in a source line with multiple
function calls, it's impossible to determine which function has the
problem.
Fixed thusly.
OK for branch?
* trans-mem.c (diagnose_tm_1): Include function name when
displaying error.
(ipa_tm_diagnose_tm_safe): Same.
(ipa_tm_diagnose_transaction): Same.
Index: testsuite/gcc.dg/tm/unsafe.c
===================================================================
--- testsuite/gcc.dg/tm/unsafe.c (revision 0)
+++ testsuite/gcc.dg/tm/unsafe.c (revision 0)
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fgnu-tm" } */
+
+__attribute__((transaction_callable))
+static int func ()
+{
+ return 12345;
+}
+
+int main()
+{
+ __transaction { return func(); } /* { dg-error "unsafe function call .func. " } */
+}
Index: trans-mem.c
===================================================================
--- trans-mem.c (revision 158551)
+++ trans-mem.c (working copy)
@@ -568,13 +568,16 @@ diagnose_tm_1 (gimple_stmt_iterator *gsi
if (!is_safe)
{
+ 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 within atomic transaction");
+ "unsafe function call %qE within "
+ "atomic transaction", fn);
else
error_at (gimple_location (stmt),
- "unsafe function call within "
- "%<transaction_safe%> function");
+ "unsafe function call %qE within "
+ "%<transaction_safe%> function", fn);
}
}
}
@@ -3645,7 +3648,8 @@ ipa_tm_diagnose_tm_safe (struct cgraph_n
if (!is_tm_callable (e->callee->decl)
&& e->callee->local.tm_may_enter_irr)
error_at (gimple_location (e->call_stmt),
- "unsafe function call within %<transaction_safe%> function");
+ "unsafe function call %qE within "
+ "%<transaction_safe%> function", e->callee->decl);
}
/* Diagnose call from atomic transactions to unmarked functions
@@ -3704,7 +3708,8 @@ ipa_tm_diagnose_transaction (struct cgra
if (cgraph_local_info (fndecl)->tm_may_enter_irr)
error_at (gimple_location (stmt),
- "unsafe function call within atomic transaction");
+ "unsafe function call %qE within "
+ "atomic transaction", fndecl);
}
VEC_free (basic_block, heap, bbs);