public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 5/8] Simplify binop_promote
Date: Fri,  3 Mar 2023 14:12:04 -0700	[thread overview]
Message-ID: <20230303211207.1053037-6-tromey@adacore.com> (raw)
In-Reply-To: <20230303211207.1053037-1-tromey@adacore.com>

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;
 	}
-- 
2.39.1


  parent reply	other threads:[~2023-03-03 21:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-03 21:11 [PATCH 0/8] Arithmetic for 128-bit types Tom Tromey
2023-03-03 21:12 ` [PATCH 1/8] Add many operators to gdb_mpz Tom Tromey
2023-03-07 13:38   ` Alexandra Petlanova Hajkova
2023-03-03 21:12 ` [PATCH 2/8] Avoid a copy in gdb_mpz::safe_export Tom Tromey
2023-03-03 21:12 ` [PATCH 3/8] Add truncation mode to gdb_mpz Tom Tromey
2023-03-03 21:12 ` [PATCH 4/8] Add value_as_mpz and value_from_mpz Tom Tromey
2023-03-08 10:47   ` Lancelot SIX
2023-03-08 15:48     ` Tom Tromey
2023-03-03 21:12 ` Tom Tromey [this message]
2023-03-03 21:12 ` [PATCH 6/8] Use value_true in value_equal and value_less Tom Tromey
2023-03-03 21:12 ` [PATCH 7/8] Use gdb_gmp for scalar arithmetic Tom Tromey
2023-03-03 21:12 ` [PATCH 8/8] Fix 128-bit integer bug in Ada Tom Tromey
2023-03-04  7:04 ` [PATCH 0/8] Arithmetic for 128-bit types Eli Zaretskii
2023-03-08 16:17   ` Tom Tromey
2023-03-27 14:20 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230303211207.1053037-6-tromey@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).