With an uninitialized oldctx, the compiler is free to observe that
the only path that sets up a value in oldctx is through the
"if (global == 2)" arm, in which arm we apparently return 0 without
referencing oldctx again.
Then, after the "if" cascade, the compiler can inline the "check"
function and then observe that the sigset_t "set" variable there
is only used locally, before any apparent uses of oldctx, and as a
result it can decide to use the same stack region for both variables.
Unfortunately this has the effect of clobbering oldctx when we call
sigprocmask, and results in the test failing.
By initializing oldctx at the top, we let the compiler know that it
has a value that has to be preserved down to the part of the code
after the "if" cascade, and it won't try to place another variable
in that same part of the stack.
Seen on tilegx with gcc 4.8 at -O3.
---
2017-01-13 Chris Metcalf <cmetcalf@mellanox.com>
* stdlib/tst-setcontext2.c (do_test): Initialize oldctx.
stdlib/tst-setcontext2.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/stdlib/tst-setcontext2.c b/stdlib/tst-setcontext2.c
index 07fb974..3fccb7e 100644
--- a/stdlib/tst-setcontext2.c
+++ b/stdlib/tst-setcontext2.c
@@ -87,7 +87,7 @@ handler (int __attribute__ ((unused)) signum)
static int
do_test (void)
{
- ucontext_t ctx, oldctx;
+ ucontext_t ctx, oldctx = { 0 };
struct sigaction action;
pid_t pid;