From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4469 invoked by alias); 13 Mar 2009 02:21:49 -0000 Received: (qmail 4460 invoked by uid 22791); 13 Mar 2009 02:21:47 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 13 Mar 2009 02:21:40 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 24DE42C686F for ; Thu, 12 Mar 2009 22:21:39 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id MQte725UKc7T for ; Thu, 12 Mar 2009 22:21:39 -0400 (EDT) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id D6F1D2C686D for ; Thu, 12 Mar 2009 22:21:38 -0400 (EDT) Received: by joel.gnat.com (Postfix, from userid 1000) id A8ED7F5C8D; Thu, 12 Mar 2009 19:21:35 -0700 (PDT) Date: Fri, 13 Mar 2009 02:25:00 -0000 From: Joel Brobecker To: gdb-patches@sourceware.org Subject: [commit/Ada] Print the correct type for float division/multiplication Message-ID: <20090313022135.GF11284@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="vA66WO2vHvL/CRSR" Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-03/txt/msg00191.txt.bz2 --vA66WO2vHvL/CRSR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1258 This is a bug that we (actually Pierre Muller) found by code inspection. We don't need to debug any program in order to reproduce the problem: (gdb) set lang ada (gdb) ptype 3 / 2.0 type = <4-byte integer> The debugger was using the type of the left hand operand in order to determine the type of the result. Although the expression is strictly illegal in Ada, we try to be accepting in what the user can enter, and we already do handle the case where the user prints the actual result instead of querying the result type: (gdb) print 3 / 2.0 $1 = 1.5 (gdb) ptype $ type = <12-byte float> So it seems reasonable and even expected that the ptype above should return: (gdb) ptype 3 / 2.0 type = <12-byte float> Especially since this was very easy to do. 2009-03-12 Joel Brobecker * ada-lang.c (ada_evaluate_subexp) : make sure to promote the operands when noside is EVAL_AVOID_SIDE_EFFECTS. 2009-03-12 Joel Brobecker * gdb.ada/ptype_arith_binop.exp: New testcase. Tested on amd64-linux. Checked in. (I do realize now that I forgot to remove some commented out code in the .exp file, so I'll fix that next. Sorry!) -- Joel --vA66WO2vHvL/CRSR Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="11-div.diff" Content-length: 663 diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index aa5dece..f1a4268 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -8458,7 +8458,10 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp, goto nosideret; else if (noside == EVAL_AVOID_SIDE_EFFECTS && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD)) - return value_zero (value_type (arg1), not_lval); + { + binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2); + return value_zero (value_type (arg1), not_lval); + } else { type = builtin_type (exp->gdbarch)->builtin_double; --vA66WO2vHvL/CRSR Content-Type: text/plain; charset=us-ascii Content-Description: ptype_arith_binop.exp Content-Disposition: attachment; filename="ptype_arith_binop.exp" Content-length: 1547 # Copyright 2009 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . if $tracelevel then { strace $tracelevel } load_lib "ada.exp" # set testdir "array_bounds" # set testfile "${testdir}/bar" # set srcfile ${srcdir}/${subdir}/${testfile}.adb # set binfile ${objdir}/${subdir}/${testfile} # # file mkdir ${objdir}/${subdir}/${testdir} # if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } { # return -1 # } gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir # gdb_load ${binfile} #set bp_location [gdb_get_line_number "STOP" ${testdir}/bar.adb] #if ![runto "bar.adb:$bp_location" ] then { # perror "Couldn't run ${testfile}" # return #} gdb_test "set lang ada" \ "" \ "set lang ada" gdb_test "ptype 3 * 2.0" \ "= <\[0-9\]+-byte float>" \ "ptype 3 * 2.0" gdb_test "ptype 3 / 2.0" \ "= <\[0-9\]+-byte float>" \ "ptype 3 / 2.0" --vA66WO2vHvL/CRSR--