public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Pedro Alves <pedro@palves.net>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v2 1/2] gdb: Avoid undefined shifts
Date: Mon, 04 Apr 2022 11:21:20 -0600	[thread overview]
Message-ID: <87k0c4ix2n.fsf@tromey.com> (raw)
In-Reply-To: <20220404125141.663987-2-pedro@palves.net> (Pedro Alves's message of "Mon, 4 Apr 2022 13:51:40 +0100")

>>>>> "Pedro" == Pedro Alves <pedro@palves.net> writes:

Pedro> Compilers don't error out on such shifts, at best they warn, so I
Pedro> think GDB should just continue doing the shifts anyhow too.

Pedro> - Adjust scalar_binop to avoid the undefined paths, either by adding
Pedro>   explicit result paths, or by casting the lhs of the left shift to
Pedro>   unsigned, as appropriate.  For the shifts by negative amount or a
Pedro>   too-large amount, I made the result be 0 (and warn).  This is
Pedro>   undefined, so we're free to pick any value, and 0 seems reasonable,
Pedro>   as it's what you'd get if you split a too-large shift by a number of
Pedro>   smaller valid shifts, and if you imagine a shift by a negative value
Pedro>   as a shift by a very-large unsigned value, you get the same too.

Pedro> - Make GDB warn for the cases that are still undefined in C++20.  The
Pedro>   warnings' texts are the same as what GCC prints.

I wonder whether any of the supported languages define shifts differently.
Rust is a bit vague about these cases, but I know Java had different
semantics (but OTOH Java would have had to implement its own expression
node for this anyway).

Anyway what I'm wondering is whether the warnings are always appropriate.

Pedro> +      warning (_("right shift count is negative"));

Pedro>  	    case BINOP_LSH:
Pedro> -	      v = v1 << v2;
Pedro> +	      if (!check_valid_shift_rhs (result_type, v2))

This is a left shift but the warning will mention a right shift.

Tom

  reply	other threads:[~2022-04-04 17:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-04 12:51 [PATCH v2 0/2] Fix a couple undefined behaviors flagged by UBSan Pedro Alves
2022-04-04 12:51 ` [PATCH v2 1/2] gdb: Avoid undefined shifts Pedro Alves
2022-04-04 17:21   ` Tom Tromey [this message]
2022-04-04 17:54     ` Pedro Alves
2022-04-04 17:59       ` Tom Tromey
2022-04-04 12:51 ` [PATCH v2 2/2] Avoid undefined behavior in gdbscm_make_breakpoint Pedro Alves
2022-04-04 17:15   ` Tom Tromey
2022-04-04 19:50     ` Pedro Alves

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=87k0c4ix2n.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    /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).