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 <trie...@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. 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); + } } } }