[LTP] [PATCH v1] syscalls/signal06: add volatile to loop variable
Edward Liaw
edliaw@google.com
Wed Jul 27 23:37:26 CEST 2022
Hey Cyril, sorry for the late reply, I was on vacation.
On Tue, Jul 19, 2022 at 3:19 AM Cyril Hrubis <chrubis@suse.cz> wrote:
>
> Hi!
> > On Android compiled with clang, the loop variable will be optimized out
> > unless it is tagged with volatile.
>
> Looking at the code it looks strange that it's optimized out since we
> use the value for the loop as:
>
> loop = 0;
>
> D = VALUE;
> while (D == VALUE && loop < LOOPS) {
> asm(...);
> loop++;
> }
>
> And the D variable is properly marked as volatile so it's not like the
> loop can be expected to iterate preciselly LOOPS iterations.
>
> It looks to me like the compiler actually forgets about the volatility
> of D for some reason and then assumes that the loop does LOOPS
> iterations.
I'm not totally sure how the compiler is working in this case.
What I saw with Android is that it fails with:
signal06 0 TINFO : loop = 2076174312
signal06 1 TFAIL :
external/ltp/testcases/kernel/syscalls/signal/signal06.c:87: Bug
Reproduced!
It makes one iteration, then loop is set to a random large int and the
loop terminates. Printing the value of loop inside the for loop
actually caused it to iterate 30000 times and succeed.
Compared to a successful run, which looks like:
signal06 0 TINFO : loop = 30000
signal06 1 TPASS : signal06 call succeeded
Thanks,
Edward
More information about the ltp
mailing list