[llvm-dev] broken C code only when optimized "-O2"
Adrian Moreno via llvm-dev
llvm-dev at lists.llvm.org
Tue Dec 21 10:48:13 PST 2021
On 12/21/21 19:44, James Dutton wrote:
> On Tue, 21 Dec 2021 at 16:30, Adrian Moreno via llvm-dev
> <llvm-dev at lists.llvm.org> wrote:
>>
>> Hello,
>>
>> I need some help understanding what might be wrong with a piece of code from the
>> openvswitch project. By ${subject} I'm not suggesting there's a problem in
>> clang, gcc also shows the same behavior so it's likely our code is broken. I am
>> kindly asking for help to understand/troubleshoot the problem.
>>
>> Summary: It seems that certain interaction between two main openvswitch data
>> structures, when optimized ("-O2 -flto=auto") is broken.
>> The two data structures are:
>>
>> hmap: https://github.com/openvswitch/ovs/blob/master/include/openvswitch/hmap.h
>> list: https://github.com/openvswitch/ovs/blob/master/include/openvswitch/list.h
>>
>> I've reproduced the problem outside of openvswitch daemon using a short C
>> program (attached)
>>
>> Code snippet:
>>
> ...
>
> It is quite obvious that the code is wrong.
> Can't you spot the problem with this?:
> member1 = malloc(sizeof *member1);
> member2 = malloc(sizeof *member2);
> memset(member1, 0, sizeof (struct member));
> memset(member2, 0, sizeof (struct member));
>
Sorry, I pasted that code snippet from a semi-uncooked version. Removing the
pointer dereference in the sizeof (as in the attached version) has no effect on
the problem.
--
Adrián Moreno
More information about the llvm-dev
mailing list