I filed an issue with the Kernel (here 195235 – llist.h llist_for_each_entry/llist_for_each_entry_safe have undefined behavior) 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.
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.
(pos) = llist_entry((pos)->member.next, typeof(*(pos)), member))