[cfe-dev] no warning with returns_nonnull

George Burgess IV via cfe-dev cfe-dev at lists.llvm.org
Mon Dec 7 22:45:27 PST 2015


Patch to fix this is in review at http://reviews.llvm.org/D15324 . It
should be able to catch simple cases like the one you posted.

Thanks for catching this! :)

On Mon, Dec 7, 2015 at 6:47 AM, Xavier Chantry via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> clang 3.6 brought some very useful warnings when a function argument with
> __attribute__((nonnull)) had a NULL check:
> warning: nonnull parameter 'p' will evaluate to 'true' on first encounter
> [-Wpointer-bool-conversion]
>
> With gcc and earlier clang versions, the NULL check was silently optimized
> away.
>
> We just realized that the same problem remains with
> __attribute__((returns_nonnull)): NULL checks are silently optimized away,
> as in the following test case.
>
> int *nul(void) {
>     return NULL;
> }
>
> __attribute__((returns_nonnull)) int *foo(void)
> {
>     return nul();
> }
>
> int main(void)
> {
>     fprintf(stderr, "%p\n", foo());
>     if (foo() == NULL) {
>         fprintf(stderr, "foo is null\n");
>     }
>     return 0;
> }
>
> Is it planned to have a warning in that case ?
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20151207/ed8975cf/attachment.html>


More information about the cfe-dev mailing list