This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [gold commit] PR 19577: Fix build failure in gold due to signed vs. unsigned comparisons
- From: Cary Coutant <ccoutant at gmail dot com>
- To: Andreas Schwab <schwab at linux-m68k dot org>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Sat, 6 Feb 2016 10:29:05 -0800
- Subject: Re: [gold commit] PR 19577: Fix build failure in gold due to signed vs. unsigned comparisons
- Authentication-results: sourceware.org; auth=none
- References: <CAJimCsGtSKEG2vNmtfTsVec=apHDaFYRrFvh7pn7tuzfrW4+cw at mail dot gmail dot com> <871t8p678v dot fsf at linux-m68k dot org> <CAJimCsE9y2hVXWFBrPknKpVSLDv7N0jL7m7XowOEWcnxUdUVQQ at mail dot gmail dot com>
>>> - int32_t max = static_cast<int32_t>((1U << bits) - 1);
>>> + uint32_t max = static_cast<int32_t>((1U << bits) - 1);
>>
>> Shouldn't the cast be changed as well?
>
>>> - int64_t max = static_cast<int64_t>((static_cast<uint64_t>(1) << bits) - 1);
>>> + uint64_t max = static_cast<int64_t>((static_cast<uint64_t>(1) <<
>>> bits) - 1);
>>
>> Here the cast doesn't make sense any more.
>
> Oops, yes. Thanks. (I blame it on Saturday morning.)
Committed the following...
-cary
2016-02-06 Cary Coutant <ccoutant@gmail.com>
gold/
PR gold/19577
* reloc.h (Bits::has_unsigned_overflow32): Fix static_cast.
(Bits::has_unsigned_overflow): Remove unnecessary static_cast.
diff --git a/gold/reloc.h b/gold/reloc.h
index fce7313..9c09c7c 100644
--- a/gold/reloc.h
+++ b/gold/reloc.h
@@ -1015,7 +1015,7 @@ class Bits
gold_assert(bits > 0 && bits <= 32);
if (bits == 32)
return false;
- uint32_t max = static_cast<int32_t>((1U << bits) - 1);
+ uint32_t max = static_cast<uint32_t>((1U << bits) - 1);
return val > max;
}
@@ -1081,7 +1081,7 @@ class Bits
gold_assert(bits > 0 && bits <= 64);
if (bits == 64)
return false;
- uint64_t max = static_cast<int64_t>((static_cast<uint64_t>(1) <<
bits) - 1);
+ uint64_t max = (static_cast<uint64_t>(1) << bits) - 1;
return val > max;
}