Without this patch it is perfectly fine to assign non-transaction_safe
functions to function pointers marked as transaction_safe. Unpleasantness
happens at run time.
e.g.
__attribute__((transaction_safe)) long (*compare)(int, int);
compare = my_funky_random_function;
gcc/c-typeck.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index fc01a79..69687d6 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -5608,6 +5608,13 @@ convert_for_assignment (location_t location, tree type,
tree rhs,
}
}
+ /* Check for assignment to transaction safe */
+ if (is_tm_safe(type) && !is_tm_safe_or_pure (rhs)) {
+ warning_at (location, 0,
+ "Assigning unsafe function to transaction_safe "
+ "function pointer");
+ }
+
/* Any non-function converts to a [const][volatile] void *
and vice versa; otherwise, targets must be the same.
Meanwhile, the lhs target must have all the qualifiers of the rhs. */
--
1.7.9.5
--
This patch is available for review at http://codereview.appspot.com/6198054