On Montag, 8. März 2021 15:30:23 CET Philippe Mathieu-Daudé wrote: > On 3/8/21 3:17 PM, Akihiko Odaki wrote: > > 2021年3月8日(月) 23:03 Christian Schoenebeck <qemu_...@crudebyte.com>: > >> BTW, there is __nonnull supported by clang, e.g.: > >> > >> static void foo(void *__nonnull p) { > >> > >> ... > >> > >> } > >> > >> Maybe as an optionally defined macro (if supported by compiler) this > >> could be a useful tool for such intended nonnull designs, as it > >> immediately emits compiler errors. > >> > >> Best regards, > >> Christian Schoenebeck > > > > GCC has nonnull attribute and clang accepts it too. However, it > > specifies argument indices, which is harder to understand and to > > maintain. > > __attribute__((nonnull(2))) > > void f(void *k, void *l); > > Richard once suggested to add QEMU_NONNULL(), I have been using > it on a series trying to enforce non-null uses of QOM > 'struct Object *owner' but it didn't work out because migrations > of MemoryRegion, some have NULL owner in MachineState. > > I also discarded it because Daniel said it could have side-effects > https://www.mail-archive.com/qemu-devel@nongnu.org/msg720739.html
Yes, but the optimizer part could be disabled with -fno-delete-null-pointer-checks which would render it a pure diagnostic feature: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-nonnull-function-attribute Is there an example where the compiler failed to detect a NULL user case? Best regards, Christian Schoenebeck