This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH 0/7] Fix invalid left shift of negative value.
- From: Andreas Schwab <schwab at linux-m68k dot org>
- To: DJ Delorie <dj at redhat dot com>
- Cc: vogt at linux dot vnet dot ibm dot com, binutils at sourceware dot org
- Date: Fri, 30 Oct 2015 18:26:28 +0100
- Subject: Re: [PATCH 0/7] Fix invalid left shift of negative value.
- Authentication-results: sourceware.org; auth=none
- References: <20151030143814 dot GA18070 at linux dot vnet dot ibm dot com> <20151030144201 dot GC18875 at linux dot vnet dot ibm dot com> <201510301714 dot t9UHEVS7016878 at greed dot delorie dot com>
DJ Delorie <dj@redhat.com> writes:
> - return ((size + (1 << align) - 1) & (-1 << align));
> + return ((size + (1 << align) - 1) & -(1 << align));
>
> This is an annoying new rule to remember. Would this be a valid substitution?
>
> return ((size + (1 << align) - 1) & (~0 << align));
>
> In cases where we're forming bitmasks, a mathematical negation doesn't
> "fit" as well as logical operations.
~0 is still a negative number.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."