From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1C1223857408; Mon, 9 Aug 2021 17:01:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C1223857408 From: "kees at outflux dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/101832] New: __builtin_object_size(P->M, 1) where M ends with a flex-array behaves like sizeof() Date: Mon, 09 Aug 2021 17:01:33 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: kees at outflux dot net 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 attachments.created 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 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, 09 Aug 2021 17:01:34 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101832 Bug ID: 101832 Summary: __builtin_object_size(P->M, 1) where M ends with a flex-array behaves like sizeof() Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: kees at outflux dot net Target Milestone: --- Created attachment 51279 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D51279&action=3Dedit bos1 fails to recognize flex array under specific conditions It is unclear to me if this is a duplicate of bug 64715. bos1 in at least one situation fails to notice when a member contains a flex-array, and returns sizeof() instead of -1. For example: struct nlmsg { __u32 nlmsg_len; __u16 nlmsg_type; __u16 nlmsg_flags; __u32 nlmsg_seq; __u32 nlmsg_pid; __u8 nlmsg_content[]; }; struct wrapper { __u8 a; __u8 b; struct nlmsg msg; }; ok: sizeof(wrap->msg) =3D=3D 16 ok: __builtin_object_size(wrap->msg.nlmsg_content, 1) =3D=3D -1 ok: __builtin_object_size(&wrap->msg, 0) =3D=3D -1 WAT: __builtin_object_size(&wrap->msg, 1) =3D=3D 16 (expected -1) https://godbolt.org/z/95n4ofT53=