From patchwork Fri Mar 3 21:12:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 65995 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 579FE3850209 for ; Fri, 3 Mar 2023 21:13:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 579FE3850209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677878031; bh=vL+T5FWqkcH25sIygTO+71lGG6uEEhxg7B5ls2Dbu/c=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=TQMc43nY3TqDNqYUbG9nXvbxRKrymm95gl+MfAXYY4SZQgZiIMNtcbcl9wkQOyjaM jsBgynPElv/IFmzNTAox4sFmb6YLpUM1OWzARYy+ZAc7+8j5Gqxtg7gDQ0MuQSlb06 o5pVI7rs9DNjIo09Bm8JZ/NMjhHbWE8Ujs0lM3ls= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id 95DD938582A1 for ; Fri, 3 Mar 2023 21:12:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 95DD938582A1 Received: by mail-il1-x12f.google.com with SMTP id z5so2622926ilq.0 for ; Fri, 03 Mar 2023 13:12:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677877944; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vL+T5FWqkcH25sIygTO+71lGG6uEEhxg7B5ls2Dbu/c=; b=Slb8Nih4Q7AKOBA5z/NtZpf+3o+f1QF7T60bm/82pP+wxOv+J1mCw2oOjGorpK503V BxdAr2FdFQJIF/2cWOuDH05wdQIsmaoN0gT1BwUxHrMmrGDNmjn8ps0IFqfybr3KHgRf 0f3poHinYNHIw6IO5wIUaXDCFcXvOVkeo2kYd63vJw/aBNpmEHNeSn6eY8AKzWM+IXtN o//sWBcLXMaM8jBXWUjHZQxneq0XIRZUfvcQqasfj/hTTAdJndRe8pKoqAyoqgY5LHBe UEBhO1Mx2XVqyaqoQofCwnRz/JdK4J9P5MIWc2Ew1Ic5BWiV2vTjl8eOgQzXAFW15Gnz jV9Q== X-Gm-Message-State: AO0yUKV5XN9YzH6S9UEVCgHozq5XLf+K9knvsIeUJC3DfMDiSPrMFfdY Q+xzXgmSwhK/vs6Z/KFxPvmjV4lwq2kxlzbwuhU= X-Google-Smtp-Source: AK7set8oWBuzHtjE/mVN68Ib9SI4RFWd6Q/Fi9a+IP1YvBU5Q0RrvVhx8JZgUogITODimUs433+P/g== X-Received: by 2002:a05:6e02:12cf:b0:317:c80f:b405 with SMTP id i15-20020a056e0212cf00b00317c80fb405mr2758272ilm.15.1677877943742; Fri, 03 Mar 2023 13:12:23 -0800 (PST) Received: from localhost.localdomain (75-166-130-93.hlrn.qwest.net. [75.166.130.93]) by smtp.gmail.com with ESMTPSA id g8-20020a925208000000b00313b281ecd2sm867988ilb.70.2023.03.03.13.12.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Mar 2023 13:12:23 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 8/8] Fix 128-bit integer bug in Ada Date: Fri, 3 Mar 2023 14:12:07 -0700 Message-Id: <20230303211207.1053037-9-tromey@adacore.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230303211207.1053037-1-tromey@adacore.com> References: <20230303211207.1053037-1-tromey@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" While working on 128-bit integer support, I found one spot in Ada that needed a fix as well. --- gdb/ada-lang.c | 27 ++++-------------- gdb/testsuite/gdb.ada/verylong.exp | 37 +++++++++++++++++++++++++ gdb/testsuite/gdb.ada/verylong/prog.adb | 20 +++++++++++++ 3 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 gdb/testsuite/gdb.ada/verylong.exp create mode 100644 gdb/testsuite/gdb.ada/verylong/prog.adb diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 7b07c4f9473..d1afb1a27b1 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -62,14 +62,6 @@ #include "charset.h" #include "ax-gdb.h" -/* Define whether or not the C operator '/' truncates towards zero for - differently signed operands (truncation direction is undefined in C). - Copied from valarith.c. */ - -#ifndef TRUNCATION_TOWARDS_ZERO -#define TRUNCATION_TOWARDS_ZERO ((-5 / 2) == -2) -#endif - static struct type *desc_base_type (struct type *); static struct type *desc_bounds_type (struct type *); @@ -9351,9 +9343,7 @@ coerce_for_assign (struct type *type, struct value *val) static struct value * ada_value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) { - struct value *val; struct type *type1, *type2; - LONGEST v, v1, v2; arg1 = coerce_ref (arg1); arg2 = coerce_ref (arg2); @@ -9374,8 +9364,8 @@ ada_value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) return value_binop (arg1, arg2, op); } - v2 = value_as_long (arg2); - if (v2 == 0) + gdb_mpz v2 = value_as_mpz (arg2); + if (v2.sgn () == 0) { const char *name; if (op == BINOP_MOD) @@ -9394,13 +9384,12 @@ ada_value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) if (type1->is_unsigned () || op == BINOP_MOD) return value_binop (arg1, arg2, op); - v1 = value_as_long (arg1); + gdb_mpz v1 = value_as_mpz (arg1); + gdb_mpz v; switch (op) { case BINOP_DIV: v = v1 / v2; - if (!TRUNCATION_TOWARDS_ZERO && v1 * (v1 % v2) < 0) - v += v > 0 ? -1 : 1; break; case BINOP_REM: v = v1 % v2; @@ -9409,14 +9398,10 @@ ada_value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) break; default: /* Should not reach this point. */ - v = 0; + gdb_assert_not_reached ("invalid operator"); } - val = value::allocate (type1); - store_unsigned_integer (val->contents_raw ().data (), - val->type ()->length (), - type_byte_order (type1), v); - return val; + return value_from_mpz (type1, v); } static int diff --git a/gdb/testsuite/gdb.ada/verylong.exp b/gdb/testsuite/gdb.ada/verylong.exp new file mode 100644 index 00000000000..93df785862b --- /dev/null +++ b/gdb/testsuite/gdb.ada/verylong.exp @@ -0,0 +1,37 @@ +# Copyright 2023 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 . + +load_lib "ada.exp" + +require allow_ada_tests + +standard_ada_testfile prog + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} { + return -1 +} + +clean_restart ${testfile} + +set bp_location [gdb_get_line_number "START" ${testdir}/prog.adb] +runto "prog.adb:$bp_location" + +gdb_test "print x" " = 170141183460469231731687303715884105727" +gdb_test "print x / 2" " = 85070591730234615865843651857942052863" +gdb_test "print (x / 4) * 2" " = 85070591730234615865843651857942052862" +gdb_test "print x - x" " = 0" +gdb_test "print x - 99 + 1" " = 170141183460469231731687303715884105629" +gdb_test "print -x" " = -170141183460469231731687303715884105727" +gdb_test "print +x" " = 170141183460469231731687303715884105727" diff --git a/gdb/testsuite/gdb.ada/verylong/prog.adb b/gdb/testsuite/gdb.ada/verylong/prog.adb new file mode 100644 index 00000000000..766419d0a4f --- /dev/null +++ b/gdb/testsuite/gdb.ada/verylong/prog.adb @@ -0,0 +1,20 @@ +-- Copyright 2023 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 . + +procedure Main is + X : Long_Long_Long_Integer := Long_Long_Long_Integer'Last; +begin + null; -- START +end Main;