From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 103FA386103A; Sat, 14 Nov 2020 11:45:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 103FA386103A From: "vries at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug exp/26875] Incorrect value printed for address of first element of zero-length array Date: Sat, 14 Nov 2020 11:45:43 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: exp X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vries at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot 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://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gdb-prs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-prs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Nov 2020 11:45:44 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D26875 --- Comment #5 from Tom de Vries --- (In reply to Tom de Vries from comment #4) > This passed with gdb 9. >=20 > The first bad commit is either: > - commit 7c6f271296319576fa00587928e5ff52ced9c1bb (could not build) > gdb: make get_discrete_bounds check for non-constant range bounds, or > - commit 8c2e4e0689ea244d0ed979171a3d09c9176b8175 > gdb: add accessors to struct dynamic_prop Hmm, before these commits, we handle this type in get_discrete_bounds: ... (gdb) p recursive_dump_type (type, 0) type node 0x2283020 name '' (0x0) code 0xc (TYPE_CODE_RANGE) length 8 objfile 0x1fced60 target_type 0x223c440 type node 0x223c440 name 'long unsigned int' (0x225be83) code 0x8 (TYPE_CODE_INT) length 8 objfile 0x1fced60 target_type 0x0 pointer_type 0x0 reference_type 0x0 type_chain 0x223c440 instance_flags 0x0 flags TYPE_UNSIGNED nfields 0 0x0 pointer_type 0x0 reference_type 0x0 type_chain 0x2283020 instance_flags 0x0 flags TYPE_UNSIGNED nfields 0 0x22830a0 low 0 high 0 (undefined) $12 =3D void ... and ignored the TYPE_HIGH_BOUND_UNDEFINED, and just return 1, with lowerbou= nd =3D=3D 0 and upperbound =3D=3D 0. The setting of lowerbound =3D=3D 0 had t= he effect that we printed the right value. After the commits, get_discrete_bounds returns -1, and we have both lowerbo= und and upperbound uninitialized. We don't check the return status though in value_subscript, and proceed with the uninitialized values: ... (gdb) p lowerbound $2 =3D 36429408 (gdb) p upperbound $3 =3D 11281392 ... And after this: ... (gdb)=20 171 index -=3D lowerbound; ... we have: ... (gdb) p index $4 =3D -36429408 ... So we end up here: ... return value_ind (value_ptradd (array, index)); ... constructing a value "*(array + -36429408)", and we end up printing=20 &ubound.a[-36429408]. This is an ad-hoc patch that sets lowerbound, even if upperbound is undefin= ed: ... diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 686edafcf64..dfc3de870c1 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -1049,11 +1049,16 @@ get_discrete_bounds (struct type *type, LONGEST *lo= wp, LONGEST *highp) case TYPE_CODE_RANGE: /* This function currently only works for ranges with two defined, constant bounds. */ - if (type->bounds ()->low.kind () !=3D PROP_CONST - || type->bounds ()->high.kind () !=3D PROP_CONST) + if (type->bounds ()->low.kind () !=3D PROP_CONST) return -1; - *lowp =3D type->bounds ()->low.const_val (); + + if (type->bounds ()->high.kind () !=3D PROP_CONST) + { + *highp =3D *lowp - 1; + return 1; + } + *highp =3D type->bounds ()->high.const_val (); if (TYPE_TARGET_TYPE (type)->code () =3D=3D TYPE_CODE_ENUM) ... and handles the undefined upper bound by returning an empty range. --=20 You are receiving this mail because: You are on the CC list for the bug.=