[llvm-dev] broken C code only when optimized "-O2"

via llvm-dev llvm-dev at lists.llvm.org
Tue Dec 21 13:03:01 PST 2021


> It is quite obvious that the code is wrong.
> Can't you spot the problem with this?:

Please keep your comments positive and helpful, in accordance with
the standards of the LLVM community.

>      member1 = malloc(sizeof *member1);
>      member2 = malloc(sizeof *member2);
>      memset(member1, 0, sizeof (struct member));
>      memset(member2, 0, sizeof (struct member));

If you're referring to the dereference in (sizeof *member1), 
the operand of sizeof is unevaluated, which AFAICT means it
won't trigger undefined behavior for being a null dereference.
--paulr



More information about the llvm-dev mailing list