public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Andreas Krebbel <krebbel@linux.ibm.com>
To: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Martin Liska <mliska@suse.cz>, Alan Modra <amodra@gmail.com>,
	binutils@sourceware.org
Subject: Re: [PATCH] IBM zSystems: Fix left-shifting negative PCRel32 values (PR gas/29152)
Date: Mon, 16 May 2022 22:01:04 +0200	[thread overview]
Message-ID: <35e41d0e-5de2-9bf7-bde0-05f21e5bd3a9@linux.ibm.com> (raw)
In-Reply-To: <20220516183523.2466672-1-iii@linux.ibm.com>

On 5/16/22 20:35, Ilya Leoshkevich wrote:
> s390_insert_operand ()'s val, min and max are encoded PCRel32 values
> and need to be left-shifted by 1 before being shown to the user.
> Left-shifting negative values is undefined behavior in C, but the
> current code does not try to prevent it, causing UBSan to complain.
> 
> Fix by casting the values to their unsigned equivalents before
> shifting.
> ---
>  gas/config/tc-s390.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/gas/config/tc-s390.c b/gas/config/tc-s390.c
> index fb452f8a986..04a3c059c91 100644
> --- a/gas/config/tc-s390.c
> +++ b/gas/config/tc-s390.c
> @@ -622,9 +622,9 @@ s390_insert_operand (unsigned char *insn,
>  
>  	  if (operand->flags & S390_OPERAND_PCREL)
>  	    {
> -	      val <<= 1;
> -	      min <<= 1;
> -	      max <<= 1;
> +	      val = (offsetT) ((addressT) val << 1);
> +	      min = (offsetT) ((addressT) min << 1);
> +	      max = (offsetT) ((addressT) max << 1);
>  	    }
>  	  if (file == (char *) NULL)
>  	    as_bad (err, (int64_t) val, (int64_t) min, (int64_t) max);

Committed to master. Thanks!

Andreas

      reply	other threads:[~2022-05-16 20:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-16 18:35 Ilya Leoshkevich
2022-05-16 20:01 ` Andreas Krebbel [this message]

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=35e41d0e-5de2-9bf7-bde0-05f21e5bd3a9@linux.ibm.com \
    --to=krebbel@linux.ibm.com \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=iii@linux.ibm.com \
    --cc=mliska@suse.cz \
    /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).