From patchwork Fri Mar 3 21:12:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 65992 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 D1FFE3850873 for ; Fri, 3 Mar 2023 21:13:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D1FFE3850873 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677878000; bh=hdPdKIKHtW/e1I4kOgHdw3MhhJlkJd6t3vKTze3TPZY=; 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=tvdwOw4C6hE/1si4KddspU1sSxI04OSYjFNDsyQG8g3qFbuIm7RzSQMcKQmXCXDQN PyM8Z101Vo3sT1tL63ead3HBQhirckMW5l5CzDnlQmbpmiVjRAILY6jfgQo9NwaV19 7MeiFSu3cw6TTOYCtSkQAJOzMoA7LeeI2V675Lik= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 933713858C33 for ; Fri, 3 Mar 2023 21:12:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 933713858C33 Received: by mail-il1-x12a.google.com with SMTP id i4so2594320ils.1 for ; Fri, 03 Mar 2023 13:12:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677877942; 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=hdPdKIKHtW/e1I4kOgHdw3MhhJlkJd6t3vKTze3TPZY=; b=3lwaeth0RSLDS7+UfBZ0JX31/z9rg2ITieg4EUARl+HRkyi2ICxM8W3QrHUqMonuY0 Pqq07a8KUeoP55C9M41e4Z9ylniQMNymONRex8ecwYHbVibWlJOHuwrUNIugZxEogmA6 Qt/bWTPLN/CIwqQGUiHZLUW7XIw8qVjj6Etv9+g2OckdEeGUC1mKJHVLjPwOcXaFFPAW RPcZyyy1+BvhrgDOGX27qoyKi0T+CMRtwk7GOy87GymLdMAc8b9qn4B9a+VSgRDtQNqh mP3CiaRy4WRKtYS10NEBYBK0yC+7ijk7yrcHIsld4x9iOhYY4ExQAAPCRzh4pr6LhYQz /t7Q== X-Gm-Message-State: AO0yUKWE5tNbVBk1uUrXRxsVyqS+lnBRQ5+rHGNpexSM/exAH1kQw6Rs QfuUIMC5QzVmBfPNUB0W/HNiLdjm+h66DH8MtJI= X-Google-Smtp-Source: AK7set84bMIzwmK9ZDNtxHohZ4vRWvUJxT8kbQECn5YSDNRlWb2eEFwaL7iCCg0NpmTqxQEB5r+2pw== X-Received: by 2002:a05:6e02:1b09:b0:315:34b8:4c6d with SMTP id i9-20020a056e021b0900b0031534b84c6dmr2684327ilv.17.1677877941852; Fri, 03 Mar 2023 13:12:21 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Mar 2023 13:12:21 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 5/8] Simplify binop_promote Date: Fri, 3 Mar 2023 14:12:04 -0700 Message-Id: <20230303211207.1053037-6-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, 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" binop_promote currently only handles integer sizes up to builtin_long_long. However, this may not handle 128-bit types. Simplify this code, unify the C and non-C (but not OpenCL, as I don't know how to test this) cases, and handle 128-bit integers as well. This still doesn't exactly follow C or C++ rules. This could be implemented, but if so, I think it makes more sense as a C-specific expression node. --- gdb/eval.c | 55 +++++++++++++++++++----------------------------------- 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/gdb/eval.c b/gdb/eval.c index f8bbb9ef766..6b362f46424 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -371,29 +371,6 @@ binop_promote (const struct language_defn *language, struct gdbarch *gdbarch, switch (language->la_language) { - case language_c: - case language_cplus: - case language_asm: - case language_objc: - if (result_len <= builtin->builtin_int->length ()) - { - promoted_type = (unsigned_operation - ? builtin->builtin_unsigned_int - : builtin->builtin_int); - } - else if (result_len <= builtin->builtin_long->length ()) - { - promoted_type = (unsigned_operation - ? builtin->builtin_unsigned_long - : builtin->builtin_long); - } - else - { - promoted_type = (unsigned_operation - ? builtin->builtin_unsigned_long_long - : builtin->builtin_long_long); - } - break; case language_opencl: if (result_len <= lookup_signed_typename (language, "int")->length()) @@ -413,23 +390,29 @@ binop_promote (const struct language_defn *language, struct gdbarch *gdbarch, } break; default: - /* For other languages the result type is unchanged from gdb - version 6.7 for backward compatibility. - If either arg was long long, make sure that value is also long - long. Otherwise use long. */ - if (unsigned_operation) + if (result_len <= builtin->builtin_int->length ()) { - if (result_len > gdbarch_long_bit (gdbarch) / HOST_CHAR_BIT) - promoted_type = builtin->builtin_unsigned_long_long; - else - promoted_type = builtin->builtin_unsigned_long; + promoted_type = (unsigned_operation + ? builtin->builtin_unsigned_int + : builtin->builtin_int); + } + else if (result_len <= builtin->builtin_long->length ()) + { + promoted_type = (unsigned_operation + ? builtin->builtin_unsigned_long + : builtin->builtin_long); + } + else if (result_len <= builtin->builtin_long_long->length ()) + { + promoted_type = (unsigned_operation + ? builtin->builtin_unsigned_long_long + : builtin->builtin_long_long); } else { - if (result_len > gdbarch_long_bit (gdbarch) / HOST_CHAR_BIT) - promoted_type = builtin->builtin_long_long; - else - promoted_type = builtin->builtin_long; + promoted_type = (unsigned_operation + ? builtin->builtin_uint128 + : builtin->builtin_int128); } break; }