[cfe-dev] Clang incorrectly optimizing out for conditional in Linux kernel

Jonathan Roelofs via cfe-dev cfe-dev at lists.llvm.org
Mon Apr 3 09:32:34 PDT 2017



On 4/3/17 9:33 AM, Derrick McKee via cfe-dev wrote:
> Hi,
>
> I am trying to get the Linux kernel to compile and boot using clang.
> The code compiles fine, but the kernel does not boot.  It looks like the
> following macro in mm/vmalloc.c (line 650) is optimizing out the exit
> condition on the for loop:
>
> #define llist_for_each_entry(pos, node, member)             \
>     for ((pos) = llist_entry((node), typeof(*(pos)), member);   \
>          &(pos)->member != NULL;

This comparison is tautologically true because it'd be UB to construct 
the address if pos were null, and true otherwise.


Jon

         \
>          (pos) = llist_entry((pos)->member.next, typeof(*(pos)), member))
>

snip

> --
> Derrick McKee
> Ph.D. Student at Purdue University
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>

-- 
Jon Roelofs
jonathan at codesourcery.com
CodeSourcery / Mentor Embedded



More information about the cfe-dev mailing list