From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A465D385842E; Tue, 21 Mar 2023 10:07:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A465D385842E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679393235; bh=qs/DGX7mfuCM2bgjIP9DR+MuVzHrHWz2r2HmNrma6SU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=x8zp91j2HQyBRYkeVN5F4SuJpZ0e1kQd6DH6oqDsfZXUQkj8tgiqDDkQfsFCReUuG DxPUQDwpkHhjEGDEyG5DXqCNBESuKzC3uETSBVDBMGHFJ1xZDIqjujdNLDwY5Rz64e U0m9Y/c0M3Wj/onmIGsIuGQWCbpYMnCbzRoD0K/A= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: =?UTF-8?B?W0J1ZyB0cmVlLW9wdGltaXphdGlvbi8xMDkyMTVdIFsxMyBSZWdy?= =?UTF-8?B?ZXNzaW9uXSB3cm9uZyB3YXJuaW5nOiBhcnJheSBzdWJzY3JpcHQgMCBpcyBv?= =?UTF-8?B?dXRzaWRlIHRoZSBib3VuZHMgb2YgYW4gaW50ZXJpb3IgemVyby1sZW5ndGgg?= =?UTF-8?B?YXJyYXkg4oCYc3RydWN0IGxvY2tfY2xhc3Nfa2V5WzNd4oCZ?= Date: Tue, 21 Mar 2023 10:07:14 +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: 13.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.0 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=3D109215 --- Comment #7 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:03041e0361cbdd7f541f2f39060759aad866ed58 commit r13-6782-g03041e0361cbdd7f541f2f39060759aad866ed58 Author: Jakub Jelinek Date: Tue Mar 21 11:06:20 2023 +0100 tree: Fix up component_ref_sam_type handling of arrays of 0 sized eleme= nts [PR109215] Our documentation sadly talks about elt_type arr[0]; as zero-length arr= ays, not arrays with zero elements. Unfortunately, those aren't the only ar= rays which can have zero size, the same size can be also result of zero-leng= th element, like in GNU C struct whatever {} or in GNU C/C++ if the element type is [0] array or combination thereof (dunno if Ada doesn't allow something similar too). One can't do much with them, taking address of their elements, (no-op) copying of the elements in and out. But they behave differently from arr[0] arrays e.g. in that using non-zero index= es in them (as long as they are within bounds as for normal arrays) is val= id. I think this naming inaccuracy resulted in Martin designing special_array_member in an inconsistent way, mixing size zero array mem= bers with array members of one or two or more elements and then using the size zero interchangeably with zero elements. The following patch changes that (but doesn't do any documentation/diagnostics renaming, as this is really a corner case), such that int_0/trail_0 for consistency is just about [0] arrays plus [] for the latter, not one or more zero sized elements case. The testcase has one xfailed case for where perhaps in later GCC versio= ns we could add extra code to handle it, for some reason we don't diagnose out of bounds accesses for the zero sized elements cases. It will be harder because e.g. FRE will canonicalize &var.fld[0] and &var.fld[10] to just one of them because they are provably the same address. But the important thing is to fix this regression (where we warn on completely valid code in the Linux kernel). Anyway, for further work on this we don't really need any extra help from special_array_member, all code can just check integer_zerop (TYPE_SIZE_UNIT (TREE_TYPE (type)= )), it doesn't depend on the position of the members etc. 2023-03-21 Jakub Jelinek PR tree-optimization/109215 * tree.h (enum special_array_member): Adjust comments for int_0 and trail_0. * tree.cc (component_ref_sam_type): Clear zero_elts if memtype has zero sized element type and the array has variable number of elements or constant one or more elements. (component_ref_size): Adjust comments, formatting fix. * gcc.dg/Wzero-length-array-bounds-3.c: New test.=