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

Keane, Erich via cfe-dev cfe-dev at lists.llvm.org
Mon Apr 3 12:24:41 PDT 2017


I filed an issue with the Kernel (here https://bugzilla.kernel.org/show_bug.cgi?id=195235) to capture this issue.  Hopefully this is something that they will fix!  I'll note that my suggested answer assumes they want the behavior to remain the same, though I'm not sure that is what they MEANT.

-Erich

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


------------------------------

Subject: Digest Footer

_______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


------------------------------

End of cfe-dev Digest, Vol 118, Issue 8
***************************************


More information about the cfe-dev mailing list