Skip to contentSkip to conversation

__builtin_types_compatible_p() is too accepting

DISCUSSION Dan Carpenter 1 participant 2 messages Nov 3, 2021 – Nov 8, 2021 Sparse checker

lore
Share & tools
lore
#0 lore raw

The kunmap_atomic() has a BUILD_BUG_ON(__same_type((__addr), struct page *)) which does __builtin_types_compatible_p(typeof(a), typeof(b)).

The problem is that Sparse considers "void *" compatible with "struct page *" so the BUILD_BUG_ON() triggers but GCC says they are not compatible (which is the desired behavior for the kernel).

regards,
dan carpenter

#1 lore raw
Quoted 6 lines · Dan Carpenter

The kunmap_atomic() has a BUILD_BUG_ON(__same_type((__addr), struct page *)) which does __builtin_types_compatible_p(typeof(a), typeof(b)).

The problem is that Sparse considers "void *" compatible with "struct page *" so the BUILD_BUG_ON() triggers but GCC says they are not compatible (which is the desired behavior for the kernel).

Sorry, this was a bug in Smatch, not Sparse.

regards,
dan carpenter