From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 821E1385840F; Thu, 23 Feb 2023 12:28:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 821E1385840F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677155316; bh=ZJf/W9XR9MGXNzUmgWa/RAX1S3/UNGXH1jnLCIdZS1E=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fALkT0XN7IGmbbupsrVT3BzUI/gfQjqreb63v5h0zovhbwEJcSq/Ogmz0yZdiPpkm H9moLgaZDq7vv33T/X02tH8Xc1E65vvCht+w8cmzcbGDjTohNVAjldZ3PTRyA5FNNj XjIFyzuX65nLGxVQ+xC8bePueXXSmxVJQvoRqv/A= From: "jg at jguk dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug ipa/108871] attribute nonnull does not spot nullptr O2 and above when function inlined Date: Thu, 23 Feb 2023 12:28:35 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: ipa X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: missed-optimization 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: Message-ID: In-Reply-To: References: 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=3D108871 --- Comment #4 from Jonny Grant --- (In reply to Andrew Pinski from comment #3) > *** Bug 108893 has been marked as a duplicate of this bug. *** Hello Andrew May I check, I thought attribute access read_only was different from attrib= ute nonnull? https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html "Note that the access attribute merely specifies how an object referenced by the pointer argument can be accessed; it does not imply that an access will happen. Also, the access attribute does not imply the attribute nonnull; it= may be appropriate to add both attributes at the declaration of a function that unconditionally manipulates a buffer via a pointer argument. See the nonnull attribute for more information and caveats." Seems to be stating, nonnull is not the same as access read_only. Or am I missing something? I had understood __attribute__((access(read_only, 1))); would be enough on= a -O3 -Wall build to generate a warning that a nullptr had been passed (even = if it was not actually dereferenced) Here is an example that actually does derefernence, and runtime SEGV, but it the access read_only itself doesn't give any build warning. Just an example, I'm only hoping to get build warnings when optimizer sees that nullptr got through g++ -std=3Dc++23 -O3 -Wall https://godbolt.org/z/KbzcjEjYj void f(const char * const str) __attribute__((access(read_only,1))); void f(const char * const str) { if(*str =3D=3D 'a') { __builtin_puts("a1"); } else { __builtin_puts("a2"); } } int main() { const char * a =3D nullptr; f(a); }=