[PATCH] Fix -Wshadow=local warnings in rtl.h

Bernd Edlinger bernd.edlinger@hotmail.de
Fri Oct 4 18:11:00 GMT 2019


On 10/4/19 7:09 PM, Richard Sandiford wrote:
> Bernd Edlinger <bernd.edlinger@hotmail.de> writes:
>>
>> Actually I wanted to do it with a template, and invoke it using __typeof(RTX).
>>
>> BUT with that I ran into a lmitation of the template vs. block statements
>> See PR#91803:  We cannot instantiate a template on the
>> type of a statement expression, only when the expression is completely
>> written down without statement expressions.
>>
>> So even if we remove that limitation, it will be impossible to use
>> templates dependent on __typeof(statement-expressions) as we need
>> to bootstrap from rather old gcc versions.
>>
>> However if we are able to replace all statement-expressions in
>> rtl.h then it will probably be possible to use a template here,
>> without that type cast.
>>
>> I still need a const and a non-const version of that function because
>> otherwise the -Werror=cast-qual warning will kill me.
>>
>>
>>> #define GET_CODE(RTX) ((rtx_code) static_cast<const_rtx> (RTX)->code)
>>>
>>> (Wonder how much code that will break :-))
>>>
>>> And if we do use templates instead of const_rtx/rtx variants,
>>> it might be simpler to keep the checking and assert together:
>>>
>>> #define RTL_FLAG_CHECK(NAME, RTX, ...) 				\
>>>   (rtl_flag_check<__VA_ARGS__> (NAME, RTX, __FILE__, __LINE__,	\
>>> 				__FUNCTION__))
>>>
>>> template<rtx_code C1, typename T>
>>> inline T
>>> rtl_flag_check (const char *name, T rtl, const char *file, int line,
>>> 		const char *func)
>>> { 
>>>   if (GET_CODE (rtl) != C1)
>>>     rtl_check_failed_flag (name, rtl, file, line, func);
>>>   return rtl;
>>> }
>>>
>>> ...etc...
>>>
>>
>> I somehow expected the typename T need to be given int the template arguments
>> like rtl_flag_check<__typeof(RTX), __VA_ARGS__> (NAME, RTX,
>>
>> Could be that there is way to make that work without __typeof ?
> 
> Yeah, the typename will be deduced automatically in the example above.
> I don't think we need __typeof here.
> 

Yes, indeed it works.

The updated patch uses only one template function for rtl_flag_check.

It also fixes the --enable-checking=rtl issue.  I wonder if that can
also be simplified into one template, unlike the rtl_flag_check the
result is either a const or a non-const object but not the same
type as the rtvec probably you'll have
immediately an idea here?


Thanks
Bernd.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch-wshadow-rtl.diff
Type: text/x-patch
Size: 11858 bytes
Desc: patch-wshadow-rtl.diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20191004/59b9ff9a/attachment.bin>


More information about the Gcc-patches mailing list