On 10/16/19 9:11 AM, Richard Sandiford wrote:
Sorry for the slow reply.

Bernd Edlinger <bernd.edlin...@hotmail.de> writes:
Hi,

this is probably on the border to obvious.

The REGEXP_xxx macros in genautomata are invoked
recursively, and the local values are all named _regexp
and shadow each other.


Fixed by using different names _regexp1..6 for each
macro.

Sorry to repeat the complaint about numerical suffixes, but I think
we'd need better names.  E.g. _regexp_unit or _re_unit for REGEXP_UNIT
and similarly for the other macros.  But a similar fix to rtl.h might
be better.

Should the warning trigger when the shadowing name results from
macro expansion?  The author of a macro can't (in general) know
what context it's going to be used, and when different macros
come from two different third party headers, it would seem
pointless to force their users to jump through hoops just to
avoid the innocuous shadowing.  Such as in this example:

#define Abs(x) \
  __extension__ (({ __typeof__ (x) _x = x; _x < 0 ? -_x : _x; }))

#define Min(x, y) \
__extension__ (({ __typeof__ (x) _x = x; __typeof__ (y) _y = y; _x < _y ? _x : _y; }))

int f (int x, int y)
{
  return Abs (Min (x, y));   // -Wshadow for _x?
}

Martin

Thanks,
Richard

Bootstrapped and reg-tested on x86_64-pc-linux-gnu.
Is it OK for trunk?


Thanks
Bernd.

2019-10-04  Bernd Edlinger  <bernd.edlin...@hotmail.de>

        * genautomata.c (REGEXP_UNIT, REGEXP_RESERV, REGEXP_SEQUENCE,
        REGEXP_REPEAT, REGEXP_ALLOF, REGEXP_ONEOF): Rename local vars.

Index: gcc/genautomata.c
===================================================================
--- gcc/genautomata.c   (revision 276484)
+++ gcc/genautomata.c   (working copy)
@@ -984,46 +984,46 @@ decl_mode_check_failed (enum decl_mode mode, const
#define REGEXP_UNIT(r) __extension__ \
-(({ struct regexp *const _regexp = (r);                                        
\
-     if (_regexp->mode != rm_unit)                                  \
-       regexp_mode_check_failed (_regexp->mode, "rm_unit",                \
+(({ struct regexp *const _regex1 = (r);                                        
\
+     if (_regex1->mode != rm_unit)                                  \
+       regexp_mode_check_failed (_regex1->mode, "rm_unit",                \
                               __FILE__, __LINE__, __FUNCTION__);       \
-     &(_regexp)->regexp.unit; }))
+     &(_regex1)->regexp.unit; }))
#define REGEXP_RESERV(r) __extension__ \
-(({ struct regexp *const _regexp = (r);                                        
\
-     if (_regexp->mode != rm_reserv)                                        \
-       regexp_mode_check_failed (_regexp->mode, "rm_reserv",              \
+(({ struct regexp *const _regex2 = (r);                                        
\
+     if (_regex2->mode != rm_reserv)                                        \
+       regexp_mode_check_failed (_regex2->mode, "rm_reserv",              \
                               __FILE__, __LINE__, __FUNCTION__);       \
-     &(_regexp)->regexp.reserv; }))
+     &(_regex2)->regexp.reserv; }))
#define REGEXP_SEQUENCE(r) __extension__ \
-(({ struct regexp *const _regexp = (r);                                        
\
-     if (_regexp->mode != rm_sequence)                                      \
-       regexp_mode_check_failed (_regexp->mode, "rm_sequence",            \
+(({ struct regexp *const _regex3 = (r);                                        
\
+     if (_regex3->mode != rm_sequence)                                      \
+       regexp_mode_check_failed (_regex3->mode, "rm_sequence",            \
                               __FILE__, __LINE__, __FUNCTION__);       \
-     &(_regexp)->regexp.sequence; }))
+     &(_regex3)->regexp.sequence; }))
#define REGEXP_REPEAT(r) __extension__ \
-(({ struct regexp *const _regexp = (r);                                        
\
-     if (_regexp->mode != rm_repeat)                                        \
-       regexp_mode_check_failed (_regexp->mode, "rm_repeat",              \
+(({ struct regexp *const _regex4 = (r);                                        
\
+     if (_regex4->mode != rm_repeat)                                        \
+       regexp_mode_check_failed (_regex4->mode, "rm_repeat",              \
                               __FILE__, __LINE__, __FUNCTION__);       \
-     &(_regexp)->regexp.repeat; }))
+     &(_regex4)->regexp.repeat; }))
#define REGEXP_ALLOF(r) __extension__ \
-(({ struct regexp *const _regexp = (r);                                        
\
-     if (_regexp->mode != rm_allof)                                 \
-       regexp_mode_check_failed (_regexp->mode, "rm_allof",               \
+(({ struct regexp *const _regex5 = (r);                                        
\
+     if (_regex5->mode != rm_allof)                                 \
+       regexp_mode_check_failed (_regex5->mode, "rm_allof",               \
                               __FILE__, __LINE__, __FUNCTION__);       \
-     &(_regexp)->regexp.allof; }))
+     &(_regex5)->regexp.allof; }))
#define REGEXP_ONEOF(r) __extension__ \
-(({ struct regexp *const _regexp = (r);                                        
\
-     if (_regexp->mode != rm_oneof)                                 \
-       regexp_mode_check_failed (_regexp->mode, "rm_oneof",               \
+(({ struct regexp *const _regex6 = (r);                                        
\
+     if (_regex6->mode != rm_oneof)                                 \
+       regexp_mode_check_failed (_regex6->mode, "rm_oneof",               \
                               __FILE__, __LINE__, __FUNCTION__);       \
-     &(_regexp)->regexp.oneof; }))
+     &(_regex6)->regexp.oneof; }))
static const char *regexp_name (enum regexp_mode);
  static void regexp_mode_check_failed (enum regexp_mode, const char *,

Reply via email to