From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3B1943858CDA; Fri, 2 Dec 2022 14:04:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B1943858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669989891; bh=iiS9FSdWP9p3k2ce+c8X4h5s4v8f9oRoZ0X54F5nXAM=; h=From:To:Subject:Date:From; b=guLZ/qUu6rrQfZNGizJyYHNXtVX8JBjZ5y0GRGCIwRtmref53WpVdaMpZFF0Y5c/+ hyKmRleHcRJyQemfe15kxLVi1yutHyTK73tlQR9R8RVRCskBOkdL7bCH3z4Mkw4KcU k2Hce4F4B733EOPfe3SKABWY5KcQPFWjOvoOQgpY= From: "siddhesh at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107952] New: tree-object-size: inconsistent size for flexible arrays nested in structs Date: Fri, 02 Dec 2022 14:04:50 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: siddhesh at gcc dot gnu.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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D107952 Bug ID: 107952 Summary: tree-object-size: inconsistent size for flexible arrays nested in structs Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: siddhesh at gcc dot gnu.org Target Milestone: --- With -fstrict-flex-arrays, there is a clearer definition of what constitutes flexible array members, controlled by the frontend. tree-object-size howev= er doesn't seem to handle this well enough when the flex array is nested. e.g= .: typedef struct { char pad; char data[8]; } F2; typedef struct { unsigned pad; F2 flex; } S2; #define NULL (void *) 0 __SIZE_TYPE__ nested_flexarray (__SIZE_TYPE__ n) { S2 *p =3D (S2 *) __builtin_malloc (n); return __builtin_dynamic_object_size (p->flex.data, 1); } __SIZE_TYPE__ nested_flexarray2 (S2 *p) { return __builtin_dynamic_object_size (p->flex.data, 1); } The current behaviour is to treat data as a flex array and nested_flexarray returns the size as if it were a flex array. nested_flexarray2 however ret= urns the subscripted size, thinking of it as a fixed array, which should not be = the expected behaviour with -fstrict-flex-arrays=3D0. Instead it should return= -1 for maximum size and perhaps 8 as minimum size. If F2 is changed to: typedef struct { char pad; char data[0]; } F2; the current behaviour ends up returning 0 in both cases, which is incorrect= .=20 Again, it should return the size as if it were a flex array in nested_flexa= rray and -1 for maximum size for nested_flexarray2. I have a patch that does this, but I need to fix up tests that currently ex= pect older behaviour and wanted to get some consensus before I fixed them up.=