broken code only when optimized "-O2"

David Brown david.brown@hesbynett.no
Tue Dec 21 17:05:39 GMT 2021


On 21/12/2021 17:05, Stefan Ring via Gcc-help wrote:
> On Tue, Dec 21, 2021 at 4:40 PM Adrian Moreno via Gcc-help
> <gcc-help@gcc.gnu.org> wrote:
>>
>> I'd really appreciate any hint or idea to try to understand this problem.
> 
> I guess the compiler doesn't like the dereferencing of uninitialized
> pointers (in the sizeof expressions). I am not 100% sure that this
> counts as dereferencing, but I would assume so. Because of this the
> compiler will be free to behave however it likes to.
> 

The operand of a sizeof expression is not evaluated (unless it is a
VLA).  So there is no problem with the "member1 = malloc(sizeof
*member1);" lines.  (Which is fortunate, because it is a very common idiom!)

I think the next step would be to start pulling in some of the
definitions for the various macros here, and then trying to reduce the
code further to get a smaller test case.


More information about the Gcc-help mailing list