From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 975903A5143B; Fri, 13 Nov 2020 14:47:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 975903A5143B 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: Fri, 13 Nov 2020 14:47:00 +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: Fri, 13 Nov 2020 14:47:00 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D26875 --- Comment #3 from Tom de Vries --- This passes testing: ... diff --git a/gdb/eval.c b/gdb/eval.c index 8d0c5747f39..0e8698bd488 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -2814,6 +2814,39 @@ evaluate_subexp_for_address (struct expression *exp,= int *pos, switch (op) { + case BINOP_SUBSCRIPT: + if (noside !=3D EVAL_SKIP) + { + /* Skip over the base to get the position of the index. */ + int pos_index =3D *pos + 1; + evaluate_subexp (nullptr, exp, &pos_index, EVAL_SKIP); + + /* Check if the index is zero. Do this without evaluating + side effects, such that we can still fall back to default_case= .=20 */ + struct value *index + =3D evaluate_subexp (nullptr, exp, &pos_index, + EVAL_AVOID_SIDE_EFFECTS); + if (value_equal (index, value_zero (value_type (index), not_lval)= )) + { + /* We're handling op here, skip it. */ + (*pos)++; + + /* Evaluate base. */ + struct value *base =3D evaluate_subexp (nullptr, exp, pos, no= side); + + /* Evaluate index, for the side-effect, and to return with pos + past index. */ + evaluate_subexp (nullptr, exp, pos, noside); + + /* Translate &base[0] into (typeof(base[0]) *)base. */ + type *element_type =3D TYPE_TARGET_TYPE (value_type (base)); + type *return_type =3D lookup_pointer_type (element_type); + return value_cast (return_type, base); + } + } + + goto default_case; + case UNOP_IND: (*pos)++; x =3D evaluate_subexp (nullptr, exp, pos, noside); ... --=20 You are receiving this mail because: You are on the CC list for the bug.=