From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4E1353858D35; Tue, 25 Apr 2023 16:45:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E1353858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682441121; bh=ETR2ZgYiQYFFeUCmSHgD/7vVIJ9eXotHayykKF9CYfc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=EgDuwZu8+XcFLRQRxO1/7vExazlptx/3EEuW0vbb8CqKMmhqh3Wsj5q9N4e934tiW 9mtt7tMxWGDehRGQhVsAHYEuIvr3CFEWyUkfxsuCl6LzJJNKbd5i7VBoWcktsxc7sg gHSp0YFm6LQb9bOopQQgfBf8Qkfb+a2mnnVzjaBY= From: "david at westcontrol dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/105523] Wrong warning array subscript [0] is outside array bounds Date: Tue, 25 Apr 2023 16:45:20 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: david at westcontrol dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: saaadhu 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=3D105523 --- Comment #25 from David Brown --- (In reply to Andrew Pinski from comment #24) > (In reply to LIU Hao from comment #22) > > Yes, GCC should be told to shut up about dereferencing artificial addre= ss > > values. >=20 > NO. > Take: > ``` > static inline int f(int *a) > { > return a[10]; > } >=20 > int g() > { > return f(0); > } > ``` > The warning is there for the above case really (and similar ones with str= uct > offsets). Where you originally have a null pointer and have an offset from > there; by the time the warning happens, the IR does not know if it was > originally from an offset of a null pointer or if the value was written i= n. > The paramater is there to "tune" the heurstic to figure out if it is null > pointer deference or if it is some real (HW) address. Maybe > -fno-delete-null-pointer-checks should imply --param=3Dmin-pagesize=3D0, = though > some folks want the warning indepdent of trying to delete null pointer > checks. It is worth noting, I think, that although on a target like the AVR (and mo= st embedded systems without an MMU) the address 0 is a real part of memory, and can really be read and/or written, any code that tries to dereference a 0 pointer is almost always wrong. I don't want gcc to consider 0 as an acceptable address on these targets - I want it to warn me if it sees a null pointer dereference. If I really want to target address 0, as I might occasionally do, I'll use a pointer to volatile - /then/ I'd like gcc to believe me without question. I don't know if every embedded developer feels the same way. (Georg-Johann could chime in with his opinion.)=