public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tilegx: Fix infinite loop in gen-mul-tables generator
@ 2022-06-22 17:30 Iain Buclaw
  2022-06-22 18:16 ` Jeff Law
  0 siblings, 1 reply; 4+ messages in thread
From: Iain Buclaw @ 2022-06-22 17:30 UTC (permalink / raw)
  To: gcc-patches

Hi,

Since around GCC 10, the condition `j < (INTMAX_MAX / 10)' will get
optimized into `j != 922337203685477580', which will result in an
infinite loop for certain inputs of `j'.

This patch just copies the condition already used by the -DTILEPRO
generator code, which doesn't fall into the same trap.

OK for mainline?  OK for backporting to all open release branches?

Regards,
Iain.

---
gcc/ChangeLog:

	* config/tilepro/gen-mul-tables.cc (tilegx_emit): Adjust loop
	condition to avoid overflow.
---
 gcc/config/tilepro/gen-mul-tables.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/config/tilepro/gen-mul-tables.cc b/gcc/config/tilepro/gen-mul-tables.cc
index 52183982f65..c125748a328 100644
--- a/gcc/config/tilepro/gen-mul-tables.cc
+++ b/gcc/config/tilepro/gen-mul-tables.cc
@@ -1192,11 +1192,11 @@ tilegx_emit (long long multiplier, int num_ops)
     long long next_pow10;
 
     while (((j * 10) < abs_multiplier)
-	   && (j < (INTMAX_MAX / 10)))
+	   && (j < (j * 10)))
       j = j * 10;
 
     prev_pow10 = j;
-    next_pow10 = (j > (INTMAX_MAX / 10)) ? 0 : j * 10;
+    next_pow10 = j * 10;
 
     if ((abs_multiplier - prev_pow10 <= 100)
 	|| (next_pow10
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tilegx: Fix infinite loop in gen-mul-tables generator
  2022-06-22 17:30 [PATCH] tilegx: Fix infinite loop in gen-mul-tables generator Iain Buclaw
@ 2022-06-22 18:16 ` Jeff Law
  2022-06-24 18:19   ` Iain Buclaw
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff Law @ 2022-06-22 18:16 UTC (permalink / raw)
  To: gcc-patches



On 6/22/2022 11:30 AM, Iain Buclaw via Gcc-patches wrote:
> Hi,
>
> Since around GCC 10, the condition `j < (INTMAX_MAX / 10)' will get
> optimized into `j != 922337203685477580', which will result in an
> infinite loop for certain inputs of `j'.
>
> This patch just copies the condition already used by the -DTILEPRO
> generator code, which doesn't fall into the same trap.
>
> OK for mainline?  OK for backporting to all open release branches?
Sure, but note the tile ports have been deprecated for a long time and 
I've got a TODO to finally remove them.

jeff


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tilegx: Fix infinite loop in gen-mul-tables generator
  2022-06-22 18:16 ` Jeff Law
@ 2022-06-24 18:19   ` Iain Buclaw
  2022-06-24 23:43     ` Jeff Law
  0 siblings, 1 reply; 4+ messages in thread
From: Iain Buclaw @ 2022-06-24 18:19 UTC (permalink / raw)
  To: gcc-patches, Jeff Law

Excerpts from Jeff Law via Gcc-patches's message of Juni 22, 2022 8:16 pm:
> 
> 
> On 6/22/2022 11:30 AM, Iain Buclaw via Gcc-patches wrote:
>> Hi,
>>
>> Since around GCC 10, the condition `j < (INTMAX_MAX / 10)' will get
>> optimized into `j != 922337203685477580', which will result in an
>> infinite loop for certain inputs of `j'.
>>
>> This patch just copies the condition already used by the -DTILEPRO
>> generator code, which doesn't fall into the same trap.
>>
>> OK for mainline?  OK for backporting to all open release branches?
> Sure, but note the tile ports have been deprecated for a long time and 
> I've got a TODO to finally remove them.
> 

Noted, and I wouldn't mind seeing the back of this port either.

I encountered this as I occasionally I run a modified version of
config-list.mk to test the D front-end.  As the target isn't gone yet,
best to ensure it can still build, even when it is assumed broken.

Iain.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tilegx: Fix infinite loop in gen-mul-tables generator
  2022-06-24 18:19   ` Iain Buclaw
@ 2022-06-24 23:43     ` Jeff Law
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff Law @ 2022-06-24 23:43 UTC (permalink / raw)
  To: Iain Buclaw, gcc-patches



On 6/24/2022 12:19 PM, Iain Buclaw wrote:
> Excerpts from Jeff Law via Gcc-patches's message of Juni 22, 2022 8:16 pm:
>>
>> On 6/22/2022 11:30 AM, Iain Buclaw via Gcc-patches wrote:
>>> Hi,
>>>
>>> Since around GCC 10, the condition `j < (INTMAX_MAX / 10)' will get
>>> optimized into `j != 922337203685477580', which will result in an
>>> infinite loop for certain inputs of `j'.
>>>
>>> This patch just copies the condition already used by the -DTILEPRO
>>> generator code, which doesn't fall into the same trap.
>>>
>>> OK for mainline?  OK for backporting to all open release branches?
>> Sure, but note the tile ports have been deprecated for a long time and
>> I've got a TODO to finally remove them.
>>
> Noted, and I wouldn't mind seeing the back of this port either.
>
> I encountered this as I occasionally I run a modified version of
> config-list.mk to test the D front-end.  As the target isn't gone yet,
> best to ensure it can still build, even when it is assumed broken.
Understood.  I've got no objection to you going ahead and installing the 
patch if it makes your life easier...  Just wanted to make you aware if 
you were looking to do something more with that port.

jeff

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-06-24 23:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-22 17:30 [PATCH] tilegx: Fix infinite loop in gen-mul-tables generator Iain Buclaw
2022-06-22 18:16 ` Jeff Law
2022-06-24 18:19   ` Iain Buclaw
2022-06-24 23:43     ` Jeff Law

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).