On 13/12/2018 07:53, Chris Teague wrote:

> For some
> reason, valgrind produces errors on this code with -O0, but not with any
> other settings (-O1, -O2, -O3, -Os, -Ofast).

It might just be the case that gcc is clever enough to know that the memset
has no visible effect on the program state, since you're just about to free
the memory.  So it simply removes the memset:

    memset(p_stack, 'A', stack_size); <-- redundant
    free(p_stack);

Gcc version 6 acquired a new optimisation, "lifetime dead-store elimination",
which is suspiciously similar to the above scenario.  So it might be that.
But the only way to know for sure is to look at the generated machine code.

(Maybe try with -O -fno-lifetime-dse ?)

J


_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to