From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 307543858C3A; Thu, 2 Feb 2023 21:00:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 307543858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675371655; bh=r836XrF7E9xZ+K4hJOen7ljI8FhrplRsSpoNGPNM9UU=; h=From:To:Subject:Date:From; b=TUoeG0sDfiFRK5SwTosF6z7jWmkOv0pDOreCMEc91jnoNJQzjnOyY0LfEKpXt5Ovg ZhPaGsaCXvV55pjtIiJrKDLC9D7sHvE65AeexKCYBxLRxGMXQFkb1dJMirY7g9oIKv G0csK0YSxLaZz8CbwHOz6/ucQAizgQJDi7yP92jM= From: "jg at jguk dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108646] New: nonnull attribute does not detect variables that are NULL being passed Date: Thu, 02 Feb 2023 21:00:54 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jg at jguk dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108646 Bug ID: 108646 Summary: nonnull attribute does not detect variables that are NULL being passed Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jg at jguk dot org Target Milestone: --- If we pass NULL directly, there is a good warning (pasted below from today = on Godblot.org latest gcc trunk) However, there is no error if passing a variable set to NULL. Could gcc detect this situation? #include void * mem2(void *dest) __attribute__((nonnull)); void test(void) { char *dest =3D NULL; mem2(dest);=20 } This is the warning when NULL is passed directly: : In function 'void test()': :6:6: warning: argument 1 null where non-null expected [-Wnonnull] 6 | mem2(NULL); | ~~~~^~~~~~ :2:8: note: in a call to function 'void* mem2(void*)' declared 'nonnull' 2 | void * mem2(void *dest) __attribute__((nonnull)); | ^~~~ Compiler returned: 0=