From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0AC553858409; Wed, 16 Aug 2023 20:12:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0AC553858409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692216738; bh=rx1UxSUAUTIV9wbtpJZs+LoqBiZE6nw39Oow51UNKLo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=E9g0iFb8Lr/to3/cS+L9XqNrT9w2K6yz0hT41/znAM2cEz4aW5eSShTV7uT+qf7Fd cs3r+4AOHlIKwWS91zEsM+u78q7yRV70m/2/FQmMIOqiEpqvW7nwiU357HMzOReoTO i0MxST+0ThX5jS8D6CeZ3CykS3cZdwDHmm8Q5e78= From: "qinzhao at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/111040] __builtin_object_size: inconsistent result for subobject with member arrays. Date: Wed, 16 Aug 2023 20:12:17 +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: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: qinzhao 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: 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=3D111040 --- Comment #1 from qinzhao at gcc dot gnu.org --- an initial study inside gdb shows the following: 1. the guilty pass is "ccp1", when folding the call to __builtin_dynamic_object_size(p->array, 1) 2. In this pass, the IR for p->array is represented as: (stop at routine "addr_object_size")=20 (gdb) call debug_generic_expr(ptr) &MEM [(void *)&q + 9B] (gdb) call debug_generic_expr(pt_var) MEM [(void *)&q + 9B] therefore the following condition at line 585: 585 if (pt_var !=3D TREE_OPERAND (ptr, 0)) 586 { 587 tree var; was not satisfied, the computation for size of the sub-object is not invoke= d at all. as a result, the size for the whole object is used instead. therefore = the wrong result. I suspect that this is a bug in tree-object-size.cc that cannot handle the = IR &MEM [(void *)&q + 9B] correctly. Current algorithm can only han= dle the IR p->array correctly=