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: DJ Delorie <dj at redhat dot com>
- To: vogt at linux dot vnet dot ibm dot com
- Cc: binutils at sourceware dot org
- Date: Fri, 30 Oct 2015 13:14:31 -0400
- 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>
- 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.