* [PATCH] Use 1UL constant in order to not overflow (PR c++/89383).
@ 2019-02-18 8:46 Martin Liška
2019-02-18 8:54 ` Jakub Jelinek
0 siblings, 1 reply; 3+ messages in thread
From: Martin Liška @ 2019-02-18 8:46 UTC (permalink / raw)
To: gcc-patches; +Cc: David Malcolm
[-- Attachment #1: Type: text/plain, Size: 430 bytes --]
Hi.
The patch handles an undefined behavior caused by 1U << 32 shift
for an integer type.
Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
Ready to be installed?
Thanks,
Martin
libcpp/ChangeLog:
2019-02-18 Martin Liska <mliska@suse.cz>
PR c++/89383
* line-map.c (linemap_line_start): Use 1UL in order
to not overflow.
---
libcpp/line-map.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[-- Attachment #2: 0001-Use-1UL-constant-in-order-to-not-overflow-PR-c-89383.patch --]
[-- Type: text/x-patch, Size: 664 bytes --]
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index 0e30b4b2b39..284bbd74009 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -745,7 +745,7 @@ linemap_line_start (struct line_maps *set, linenum_type to_line,
|| ( /* We can't reuse the map if the line offset is sufficiently
large to cause overflow when computing location_t values. */
(to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (map))
- >= (1U << (CHAR_BIT * sizeof (linenum_type) - column_bits)))
+ >= (1UL << (CHAR_BIT * sizeof (linenum_type) - column_bits)))
|| range_bits < map->m_range_bits)
map = linemap_check_ordinary
(const_cast <line_map *>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Use 1UL constant in order to not overflow (PR c++/89383).
2019-02-18 8:46 [PATCH] Use 1UL constant in order to not overflow (PR c++/89383) Martin Liška
@ 2019-02-18 8:54 ` Jakub Jelinek
2019-02-18 9:44 ` Martin Liška
0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2019-02-18 8:54 UTC (permalink / raw)
To: Martin Liška; +Cc: gcc-patches, David Malcolm
On Mon, Feb 18, 2019 at 09:46:33AM +0100, Martin Liška wrote:
> Hi.
>
> The patch handles an undefined behavior caused by 1U << 32 shift
> for an integer type.
That will still ICE on 32-bit hosts, won't it?
So, either you need ((uint64_t) 1) << ..., or column_bits && ... >= ...
> 2019-02-18 Martin Liska <mliska@suse.cz>
>
> PR c++/89383
> * line-map.c (linemap_line_start): Use 1UL in order
> to not overflow.
> ---
> libcpp/line-map.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>
> diff --git a/libcpp/line-map.c b/libcpp/line-map.c
> index 0e30b4b2b39..284bbd74009 100644
> --- a/libcpp/line-map.c
> +++ b/libcpp/line-map.c
> @@ -745,7 +745,7 @@ linemap_line_start (struct line_maps *set, linenum_type to_line,
> || ( /* We can't reuse the map if the line offset is sufficiently
> large to cause overflow when computing location_t values. */
> (to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (map))
> - >= (1U << (CHAR_BIT * sizeof (linenum_type) - column_bits)))
> + >= (1UL << (CHAR_BIT * sizeof (linenum_type) - column_bits)))
> || range_bits < map->m_range_bits)
> map = linemap_check_ordinary
> (const_cast <line_map *>
>
Jakub
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Use 1UL constant in order to not overflow (PR c++/89383).
2019-02-18 8:54 ` Jakub Jelinek
@ 2019-02-18 9:44 ` Martin Liška
0 siblings, 0 replies; 3+ messages in thread
From: Martin Liška @ 2019-02-18 9:44 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches, David Malcolm
On 2/18/19 9:54 AM, Jakub Jelinek wrote:
> On Mon, Feb 18, 2019 at 09:46:33AM +0100, Martin Liška wrote:
>> Hi.
>>
>> The patch handles an undefined behavior caused by 1U << 32 shift
>> for an integer type.
>
> That will still ICE on 32-bit hosts, won't it?
> So, either you need ((uint64_t) 1) << ..., or column_bits && ... >= ...
Ah, thanks! I'm going to install the former one.
Martin
>
>> 2019-02-18 Martin Liska <mliska@suse.cz>
>>
>> PR c++/89383
>> * line-map.c (linemap_line_start): Use 1UL in order
>> to not overflow.
>> ---
>> libcpp/line-map.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>>
>
>> diff --git a/libcpp/line-map.c b/libcpp/line-map.c
>> index 0e30b4b2b39..284bbd74009 100644
>> --- a/libcpp/line-map.c
>> +++ b/libcpp/line-map.c
>> @@ -745,7 +745,7 @@ linemap_line_start (struct line_maps *set, linenum_type to_line,
>> || ( /* We can't reuse the map if the line offset is sufficiently
>> large to cause overflow when computing location_t values. */
>> (to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (map))
>> - >= (1U << (CHAR_BIT * sizeof (linenum_type) - column_bits)))
>> + >= (1UL << (CHAR_BIT * sizeof (linenum_type) - column_bits)))
>> || range_bits < map->m_range_bits)
>> map = linemap_check_ordinary
>> (const_cast <line_map *>
>>
>
>
> Jakub
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-02-18 9:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-18 8:46 [PATCH] Use 1UL constant in order to not overflow (PR c++/89383) Martin Liška
2019-02-18 8:54 ` Jakub Jelinek
2019-02-18 9:44 ` Martin Liška
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).