public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Robustify REAL_MODE_FORMAT
@ 2015-10-29 15:33 Richard Sandiford
  2015-10-29 15:37 ` Bernd Schmidt
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Sandiford @ 2015-10-29 15:33 UTC (permalink / raw)
  To: gcc-patches

Make sure that REAL_MODE_FORMAT aborts if it is passed an invalid mode,
rather than stepping beyond the bounds of an array.  It turned out that
some code was passing non-float modes to the real.h routines.

Tested on x86_64-linux-gnu, arm-linux-gnueabi and aarch64-linux-gnu.
OK to install?

Thanks,
Richard


gcc/
	* real.h (REAL_MODE_FORMAT): Abort if the mode isn't a
	SCALAR_FLOAT_MODE_P.

diff --git a/gcc/real.h b/gcc/real.h
index e65b526..d3b14e5 100644
--- a/gcc/real.h
+++ b/gcc/real.h
@@ -167,7 +167,9 @@ extern const struct real_format *
   (real_format_for_mode[DECIMAL_FLOAT_MODE_P (MODE)			\
 			? (((MODE) - MIN_MODE_DECIMAL_FLOAT)		\
 			   + (MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1))	\
-			: ((MODE) - MIN_MODE_FLOAT)])
+			: GET_MODE_CLASS (MODE) == MODE_FLOAT		\
+			? ((MODE) - MIN_MODE_FLOAT)			\
+			: (gcc_unreachable (), 0)])
 
 #define FLOAT_MODE_FORMAT(MODE) \
   (REAL_MODE_FORMAT (SCALAR_FLOAT_MODE_P (MODE)? (MODE) \

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

* Re: Robustify REAL_MODE_FORMAT
  2015-10-29 15:33 Robustify REAL_MODE_FORMAT Richard Sandiford
@ 2015-10-29 15:37 ` Bernd Schmidt
  2015-10-29 16:29   ` Richard Biener
  0 siblings, 1 reply; 5+ messages in thread
From: Bernd Schmidt @ 2015-10-29 15:37 UTC (permalink / raw)
  To: gcc-patches, richard.sandiford

On 10/29/2015 04:30 PM, Richard Sandiford wrote:
> Make sure that REAL_MODE_FORMAT aborts if it is passed an invalid mode,
> rather than stepping beyond the bounds of an array.  It turned out that
> some code was passing non-float modes to the real.h routines.

> gcc/
> 	* real.h (REAL_MODE_FORMAT): Abort if the mode isn't a
> 	SCALAR_FLOAT_MODE_P.

I'm assuming that the code you mention has already been fixed so that we 
don't trigger the abort. Ok.


Bernd

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

* Re: Robustify REAL_MODE_FORMAT
  2015-10-29 15:37 ` Bernd Schmidt
@ 2015-10-29 16:29   ` Richard Biener
  2015-10-29 16:33     ` Richard Sandiford
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Biener @ 2015-10-29 16:29 UTC (permalink / raw)
  To: Bernd Schmidt, gcc-patches, richard.sandiford

On October 29, 2015 4:33:17 PM GMT+01:00, Bernd Schmidt <bschmidt@redhat.com> wrote:
>On 10/29/2015 04:30 PM, Richard Sandiford wrote:
>> Make sure that REAL_MODE_FORMAT aborts if it is passed an invalid
>mode,
>> rather than stepping beyond the bounds of an array.  It turned out
>that
>> some code was passing non-float modes to the real.h routines.
>
>> gcc/
>> 	* real.h (REAL_MODE_FORMAT): Abort if the mode isn't a
>> 	SCALAR_FLOAT_MODE_P.
>
>I'm assuming that the code you mention has already been fixed so that
>we 
>don't trigger the abort. Ok.

Rather than the weird macro can't we turn real_mode_format to an inline function?

Richard.

>
>Bernd


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

* Re: Robustify REAL_MODE_FORMAT
  2015-10-29 16:29   ` Richard Biener
@ 2015-10-29 16:33     ` Richard Sandiford
  2015-10-30  9:02       ` Richard Biener
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Sandiford @ 2015-10-29 16:33 UTC (permalink / raw)
  To: Richard Biener; +Cc: Bernd Schmidt, gcc-patches

Richard Biener <richard.guenther@gmail.com> writes:
> On October 29, 2015 4:33:17 PM GMT+01:00, Bernd Schmidt
> <bschmidt@redhat.com> wrote:
>>On 10/29/2015 04:30 PM, Richard Sandiford wrote:
>>> Make sure that REAL_MODE_FORMAT aborts if it is passed an invalid
>>mode,
>>> rather than stepping beyond the bounds of an array.  It turned out
>>that
>>> some code was passing non-float modes to the real.h routines.
>>
>>> gcc/
>>> 	* real.h (REAL_MODE_FORMAT): Abort if the mode isn't a
>>> 	SCALAR_FLOAT_MODE_P.
>>
>>I'm assuming that the code you mention has already been fixed so that
>>we 
>>don't trigger the abort. Ok.
>
> Rather than the weird macro can't we turn real_mode_format to an inline
> function?

It needs to be an lvalue for things like:

	REAL_MODE_FORMAT (TFmode) = &ibm_extended_format;

I suppose we could return a non-const reference, but I'd rather stay
clear of returning those :-)

Thanks,
Richard

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

* Re: Robustify REAL_MODE_FORMAT
  2015-10-29 16:33     ` Richard Sandiford
@ 2015-10-30  9:02       ` Richard Biener
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Biener @ 2015-10-30  9:02 UTC (permalink / raw)
  To: Richard Biener, Bernd Schmidt, GCC Patches, richard.sandiford

On Thu, Oct 29, 2015 at 5:32 PM, Richard Sandiford
<richard.sandiford@arm.com> wrote:
> Richard Biener <richard.guenther@gmail.com> writes:
>> On October 29, 2015 4:33:17 PM GMT+01:00, Bernd Schmidt
>> <bschmidt@redhat.com> wrote:
>>>On 10/29/2015 04:30 PM, Richard Sandiford wrote:
>>>> Make sure that REAL_MODE_FORMAT aborts if it is passed an invalid
>>>mode,
>>>> rather than stepping beyond the bounds of an array.  It turned out
>>>that
>>>> some code was passing non-float modes to the real.h routines.
>>>
>>>> gcc/
>>>>     * real.h (REAL_MODE_FORMAT): Abort if the mode isn't a
>>>>     SCALAR_FLOAT_MODE_P.
>>>
>>>I'm assuming that the code you mention has already been fixed so that
>>>we
>>>don't trigger the abort. Ok.
>>
>> Rather than the weird macro can't we turn real_mode_format to an inline
>> function?
>
> It needs to be an lvalue for things like:
>
>         REAL_MODE_FORMAT (TFmode) = &ibm_extended_format;
>
> I suppose we could return a non-const reference, but I'd rather stay
> clear of returning those :-)

Yes please.  But SET_REAL_MODE_FORMAT (TFmode, &ibm_extended_format)
would work as well.

Richard.

> Thanks,
> Richard
>

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

end of thread, other threads:[~2015-10-30  8:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-29 15:33 Robustify REAL_MODE_FORMAT Richard Sandiford
2015-10-29 15:37 ` Bernd Schmidt
2015-10-29 16:29   ` Richard Biener
2015-10-29 16:33     ` Richard Sandiford
2015-10-30  9:02       ` Richard Biener

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