From 08c273bb9ca995bc8c8f58a3cbdb2be6a47765bd Mon Sep 17 00:00:00 2001 From: Segher Boessenkool Date: Fri, 23 Jun 2017 19:37:27 +0200 Subject: [PATCH] Fix expand_builtin_atomic_fetch_op for pre-op (PR80902) __atomic_add_fetch adds a value to some memory, and returns the result. If there is no direct support for this, expand_builtin_atomic_fetch_op is asked to implement this as __atomic_fetch_add (which returns the original value of the mem), followed by the addition. Now, the __atomic_add_fetch could have been a tail call, but we shouldn't perform the __atomic_fetch_add as a tail call: following code would not be executed, and in fact thrown away because there is a barrier after tail calls. This fixes it. PR middle-end/80902 * builtins.c (expand_builtin_atomic_fetch_op): If emitting code after a call, force the call to not be a tail call. From-SVN: r249603 --- gcc/ChangeLog | 6 ++++++ gcc/builtins.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 130fa37ad34..ff2c7238ee6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-06-23 Segher Boessenkool + + PR middle-end/80902 + * builtins.c (expand_builtin_atomic_fetch_op): If emitting code after + a call, force the call to not be a tail call. + 2017-06-23 Jeff Law * doc/contrib.texi: Add entry for Steven Pemberton's work on diff --git a/gcc/builtins.c b/gcc/builtins.c index ce657bf9e30..7e829ef1408 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -6079,6 +6079,12 @@ expand_builtin_atomic_fetch_op (machine_mode mode, tree exp, rtx target, gcc_assert (TREE_OPERAND (addr, 0) == fndecl); TREE_OPERAND (addr, 0) = builtin_decl_explicit (ext_call); + /* If we will emit code after the call, the call can not be a tail call. + If it is emitted as a tail call, a barrier is emitted after it, and + then all trailing code is removed. */ + if (!ignore) + CALL_EXPR_TAILCALL (exp) = 0; + /* Expand the call here so we can emit trailing code. */ ret = expand_call (exp, target, ignore); -- 2.30.2