From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C7E863858405; Mon, 3 Jan 2022 09:54:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7E863858405 From: "rguenther at suse dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/95663] static_cast checks for null even when the pointer is dereferenced Date: Mon, 03 Jan 2022 09:54:13 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 10.1.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenther at suse dot de X-Bugzilla-Status: NEW 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Jan 2022 09:54:13 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95663 --- Comment #22 from rguenther at suse dot de --- On Mon, 13 Dec 2021, hubicka at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95663 >=20 > --- Comment #20 from Jan Hubicka --- > I really think with -fdelete-null-pointer-checks we should optimize away = the > pointer adjustment relying on the fact that program will segfault. >=20 > I was wondering, -fdelete-null-pointer-checks currently requires pointer = to be > precisely 0. We are already iffy here since the access is at non-0 offse= t, but > since infer_nonnull_range_by_dereference uses check_loadstore: >=20 > static bool > check_loadstore (gimple *, tree op, tree, void *data) > { > if (TREE_CODE (op) =3D=3D MEM_REF || TREE_CODE (op) =3D=3D TARGET_MEM_R= EF) > { > /* Some address spaces may legitimately dereference zero. */ > addr_space_t as =3D TYPE_ADDR_SPACE (TREE_TYPE (op)); > if (targetm.addr_space.zero_address_valid (as)) > return false; >=20 > return operand_equal_p (TREE_OPERAND (op, 0), (tree)data, 0); > } > return false; > } >=20 > which completely ignores MEM_REF_OFFSET we actually turn into trap access= es > that are arbitrarily far from NULL. We also ignore handled components so= we I think MEM_REF[(void *)0 + 4] is non-canonical (IIRC we "simplify" that=20 to MEM_REF[(void *)4])=