diff mbox series

IRA: Make sure array is big enough

Message ID 20221025100103.1736564-1-torbjorn.svensson@foss.st.com
State New
Headers show
Series IRA: Make sure array is big enough | expand

Commit Message

Torbjorn SVENSSON Oct. 25, 2022, 10:01 a.m. UTC
In commit 081c96621da, the call to resize_reg_info() was moved before
the call to remove_scratches() and the latter one can increase the
number of regs and that would cause an out of bounds usage on the
reg_renumber global array.

Without this patch, the following testcase randomly fails with:
during RTL pass: ira
In file included from /src/gcc/testsuite/gcc.dg/compat//struct-by-value-5b_y.c:13:
/src/gcc/testsuite/gcc.dg/compat//struct-by-value-5b_y.c: In function 'checkgSf13':
/src/gcc/testsuite/gcc.dg/compat//fp-struct-test-by-value-y.h:28:1: internal compiler error: Segmentation fault
/src/gcc/testsuite/gcc.dg/compat//struct-by-value-5b_y.c:22:1: note: in expansion of macro 'TEST'

gcc/ChangeLog:

	* ira.c: Resize array after reg number increased.

Co-Authored-By: Yvan ROUX <yvan.roux@foss.st.com>
Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
---
 gcc/ira.cc | 1 +
 1 file changed, 1 insertion(+)

Comments

Vladimir Makarov Oct. 26, 2022, 8:26 p.m. UTC | #1
On 2022-10-25 06:01, Torbjörn SVENSSON wrote:
> In commit 081c96621da, the call to resize_reg_info() was moved before
> the call to remove_scratches() and the latter one can increase the
> number of regs and that would cause an out of bounds usage on the
> reg_renumber global array.
>
> Without this patch, the following testcase randomly fails with:
> during RTL pass: ira
> In file included from /src/gcc/testsuite/gcc.dg/compat//struct-by-value-5b_y.c:13:
> /src/gcc/testsuite/gcc.dg/compat//struct-by-value-5b_y.c: In function 'checkgSf13':
> /src/gcc/testsuite/gcc.dg/compat//fp-struct-test-by-value-y.h:28:1: internal compiler error: Segmentation fault
> /src/gcc/testsuite/gcc.dg/compat//struct-by-value-5b_y.c:22:1: note: in expansion of macro 'TEST'
>
> gcc/ChangeLog:
>
> 	* ira.c: Resize array after reg number increased.

The patch is ok to commit it into gcc-11,12 branches and master.

Thank you for fixing this.

> Co-Authored-By: Yvan ROUX <yvan.roux@foss.st.com>
> Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
> ---
>   gcc/ira.cc | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/gcc/ira.cc b/gcc/ira.cc
> index 42c9cead9f8..d28a67b2546 100644
> --- a/gcc/ira.cc
> +++ b/gcc/ira.cc
> @@ -5718,6 +5718,7 @@ ira (FILE *f)
>       regstat_free_ri ();
>       regstat_init_n_sets_and_refs ();
>       regstat_compute_ri ();
> +    resize_reg_info ();
>     };
>   
>     int max_regno_before_rm = max_reg_num ();
Torbjorn SVENSSON Oct. 27, 2022, 7:42 a.m. UTC | #2
On 2022-10-26 22:26, Vladimir Makarov wrote:
> 
> On 2022-10-25 06:01, Torbjörn SVENSSON wrote:
>> In commit 081c96621da, the call to resize_reg_info() was moved before
>> the call to remove_scratches() and the latter one can increase the
>> number of regs and that would cause an out of bounds usage on the
>> reg_renumber global array.
>>
>> Without this patch, the following testcase randomly fails with:
>> during RTL pass: ira
>> In file included from 
>> /src/gcc/testsuite/gcc.dg/compat//struct-by-value-5b_y.c:13:
>> /src/gcc/testsuite/gcc.dg/compat//struct-by-value-5b_y.c: In function 
>> 'checkgSf13':
>> /src/gcc/testsuite/gcc.dg/compat//fp-struct-test-by-value-y.h:28:1: 
>> internal compiler error: Segmentation fault
>> /src/gcc/testsuite/gcc.dg/compat//struct-by-value-5b_y.c:22:1: note: 
>> in expansion of macro 'TEST'
>>
>> gcc/ChangeLog:
>>
>>     * ira.c: Resize array after reg number increased.
> 
> The patch is ok to commit it into gcc-11,12 branches and master.

Thank you for the review!
Pushed to gcc-11, gcc-12 and master.

> 
> Thank you for fixing this.
> 
>> Co-Authored-By: Yvan ROUX <yvan.roux@foss.st.com>
>> Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
>> ---
>>   gcc/ira.cc | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/gcc/ira.cc b/gcc/ira.cc
>> index 42c9cead9f8..d28a67b2546 100644
>> --- a/gcc/ira.cc
>> +++ b/gcc/ira.cc
>> @@ -5718,6 +5718,7 @@ ira (FILE *f)
>>       regstat_free_ri ();
>>       regstat_init_n_sets_and_refs ();
>>       regstat_compute_ri ();
>> +    resize_reg_info ();
>>     };
>>     int max_regno_before_rm = max_reg_num ();
>
diff mbox series

Patch

diff --git a/gcc/ira.cc b/gcc/ira.cc
index 42c9cead9f8..d28a67b2546 100644
--- a/gcc/ira.cc
+++ b/gcc/ira.cc
@@ -5718,6 +5718,7 @@  ira (FILE *f)
     regstat_free_ri ();
     regstat_init_n_sets_and_refs ();
     regstat_compute_ri ();
+    resize_reg_info ();
   };
 
   int max_regno_before_rm = max_reg_num ();