Thread (84 messages) 84 messages, 6 authors, 2023-01-11

Re: [PATCH v2 02/24] netmem: Add utility functions

From: Matthew Wilcox <willy@infradead.org>
Date: 2023-01-06 20:35:20
Also in: linux-mm, llvm, oe-kbuild-all

On Fri, Jan 06, 2023 at 10:24:30AM +0800, kernel test robot wrote:
quoted
quoted
include/net/page_pool.h:111:21: warning: due to lvalue conversion of the controlling expression, association of type 'const struct netmem' will never be selected because it is qualified [-Wunreachable-code-generic-assoc]
           return page_to_pfn(netmem_page(nmem));
                              ^
   include/net/page_pool.h:100:8: note: expanded from macro 'netmem_page'
           const struct netmem:    (const struct page *)nmem,              \
                 ^
OK, figured out what this error means.

#define netmem_page(nmem) (_Generic((*nmem),                            \
        const struct netmem:    (const struct page *)nmem,              \
        struct netmem:          (struct page *)nmem))

Because I defined this with _Generic((*nmem),...) instead of
_Generic((nmem),...) (like page_folio() is defined), clang always
selects the second case and not the const case.  Apparently lvalue
coversions remove the const (backed up by
https://en.cppreference.com/w/c/language/conversion) but I had no idea
that _Generic applied lvalue conversion to the controlling-expression
(it does!  https://en.cppreference.com/w/c/language/generic)

So, yay for clang's extra warning.  I'll fix this up (as below) and send
a v3 next week including the various R-b that I've received.

-#define netmem_page(nmem) (_Generic((*nmem),                           \
-       const struct netmem:    (const struct page *)nmem,              \
-       struct netmem:          (struct page *)nmem))
+#define netmem_page(nmem) (_Generic((nmem),                            \
+       const struct netmem *:  (const struct page *)nmem,              \
+       struct netmem *:        (struct page *)nmem))

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help