From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 60E7E3858D39; Tue, 11 Jan 2022 12:11:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 60E7E3858D39 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103964] [9/10/11/12 Regression] OVS miscompilation since r0-92313-g5006671f1aaa63cd Date: Tue, 11 Jan 2022 12:11:53 +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: 12.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 9.5 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: Tue, 11 Jan 2022 12:11:53 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103964 --- Comment #6 from Jakub Jelinek --- (In reply to Ilya Maximets from comment #5) > (In reply to Richard Biener from comment #4) > > the IVOPTs reference is likely due to the fact that while IVOPTs uses > > uintptrs to create the base pointer the TARGET_MEM_REF contained arithm= etic > > itself is still considered pointer arithmetic (like also here the embed= ded > > MEM_REF pointer offsetting) and the base "pointer" cannot be a non-poin= ter > > to disable that behavior. >=20 > Does this mean that this is UB and the GCC itself relies on a certain res= ult > of it? If GCC through optimizations introduces UB in a code which wasn't there in = the user's code, then it would be a GCC bug and something the compiler needs to fix. > Maybe there is a way to not treat a &pos->elem as a pointer arithmetic? > Maybe there should be one? I mean, compilers allows users to perform > computations with offsets of structure fields where the base pointer > is NULL, and NULL obviously doesn't point to any valid object. I'm not > sure if it's an UB or not, but constructions like '&((struct s > *)NULL)->field' > are very common. &((struct s *)NULL)->field is not valid in C or C++, but for many years the offsetof macro which is valid in those has been defined like that and vario= us projects occassionally still use the above, so GCC supports those as an extension (poor man's offsetof). See e.g. spots with comments like Cope with user tricks that amount to offsetof. etc. in GCC sources. That doesn't change anything about this case, the poor man's offsetof is folded into a constant very early (well, with variable offsets in array refs in there could also into an expression, but still integral expression, the pointer arithmetics is gone from there). What is the reason why OVS (and kernel) doesn't use 2 variables, one for the iterator that is a pointer to the prev/next structure only and one assigned e.g. in the condition from the iterator that is used only when it isn't the start? At least if targetting C99 and above (or C++) one can declare one of those iterators in the for loop init expression...=