On 10/5/19 9:26 AM, Segher Boessenkool wrote:
> On Fri, Oct 04, 2019 at 02:26:26PM -0600, Jeff Law wrote:
>> Same objections as before.  As long as we're using macros like this,
>> we're going to have increased potential for shadowing problems and
>> macros which touch implementation details that just happen to be
>> available in the context where the macro is used.
>>
>> Convert to real functions.  It avoids the shadowing problem and avoids
>> macros touching/referencing things they shouldn't.  Code in macros may
>> have been reasonable in the 80s/90s, but we should know better by now.
>>
>> I'm not ranting against you Bernd, it's more a rant against the original
>> coding style for GCC.  Your changes just highlight how bad of an idea
>> this kind of macro usage really is.  We should take the opportunity to
>> fix this stuff for real.
> 
> To get 95% of the benefit for only 2% of the pain, you can make an inline
> function where there was a macro before, and define that same macro to
> just call the function.
> 
> Like
> 
> #define DEFAULT_SOME_MACRO(PARMS) { lots of code }
> 
> becomes
> 
> #define DEFAULT_SOME_MACRO(PARMS) default_some_macro(PARMS)
> 
> static inline int
> default_some_macro (int parm, long another)
> {
>   lots of code;
> }
> 
> The point is that all this is completely *local* changes.
> 

Hmm, I tried this but it does not work:


Index: elfos.h
===================================================================
--- elfos.h     (revision 276598)
+++ elfos.h     (working copy)
@@ -309,34 +309,35 @@
 #endif
 
 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL)                      \
-  do                                                                   \
-    {                                                                  \
-      HOST_WIDE_INT size;                                              \
-                                                                       \
-      /* For template static data member instantiations or             \
-        inline fn local statics and their guard variables, use         \
-        gnu_unique_object so that they will be combined even under     \
-        RTLD_LOCAL.  Don't use gnu_unique_object for typeinfo,         \
-        vtables and other read-only artificial decls.  */              \
-      if (USE_GNU_UNIQUE_OBJECT && DECL_ONE_ONLY (DECL)                        
\
-         && (!DECL_ARTIFICIAL (DECL) || !TREE_READONLY (DECL)))        \
-       ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "gnu_unique_object");    \
-      else                                                             \
-       ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object");               \
-                                                                       \
-      size_directive_output = 0;                                       \
-      if (!flag_inhibit_size_directive                                 \
-         && (DECL) && DECL_SIZE (DECL))                                \
-       {                                                               \
-         size_directive_output = 1;                                    \
-         size = tree_to_uhwi (DECL_SIZE_UNIT (DECL));                  \
-         ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, size);                 \
-       }                                                               \
-                                                                       \
-      ASM_OUTPUT_LABEL (FILE, NAME);                                   \
-    }                                                                  \
-  while (0)
+  elfos_asm_declare_object_name (FILE, NAME, DECL)
 
+static inline void
+elfos_asm_declare_object_name(FILE *file, const char *name, tree decl)
+{
+  HOST_WIDE_INT size;
+
+  /* For template static data member instantiations or
+     inline fn local statics and their guard variables, use
+     gnu_unique_object so that they will be combined even under
+     RTLD_LOCAL.  Don't use gnu_unique_object for typeinfo,
+     vtables and other read-only artificial decls.  */
+  if (USE_GNU_UNIQUE_OBJECT && DECL_ONE_ONLY (decl)
+      && (!DECL_ARTIFICIAL (decl) || !TREE_READONLY (decl)))
+    ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "gnu_unique_object");
+  else
+    ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "object");
+
+  size_directive_output = 0;
+  if (!flag_inhibit_size_directive
+      && (decl) && DECL_SIZE (decl))
+    {
+      size_directive_output = 1;
+      size = tree_to_uhwi (DECL_SIZE_UNIT (decl));
+      ASM_OUTPUT_SIZE_DIRECTIVE (file, name, size);
+    }
+  ASM_OUTPUT_LABEL (file, name);
+}
+
 /* Output the size directive for a decl in rest_of_decl_compilation
    in the case where we did not do so before the initializer.
    Once we find the error_mark_node, we know that the value of
@@ -345,24 +346,27 @@
 
 #undef ASM_FINISH_DECLARE_OBJECT
 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END)\
-  do                                                           \
-    {                                                          \
-      const char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0);  \
-      HOST_WIDE_INT size;                                      \
-                                                               \
-      if (!flag_inhibit_size_directive                         \
-         && DECL_SIZE (DECL)                                   \
-         && ! AT_END && TOP_LEVEL                              \
-         && DECL_INITIAL (DECL) == error_mark_node             \
-         && !size_directive_output)                            \
-       {                                                       \
-         size_directive_output = 1;                            \
-         size = tree_to_uhwi (DECL_SIZE_UNIT (DECL));          \
-         ASM_OUTPUT_SIZE_DIRECTIVE (FILE, name, size);         \
-       }                                                       \
-    }                                                          \
-  while (0)
+  elfos_asm_finish_declare_object (FILE, DECL, TOP_LEVEL, AT_END)
 
+static inline void
+elfos_asm_finish_declare_object (FILE *file, tree decl,
+                                int top_level, int at_end)
+{
+  const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
+  HOST_WIDE_INT size;
+
+  if (!flag_inhibit_size_directive
+      && DECL_SIZE (decl)
+      && !at_end && top_level
+      && DECL_INITIAL (decl) == error_mark_node
+      && !size_directive_output)
+    {
+      size_directive_output = 1;
+      size = tree_to_uhwi (DECL_SIZE_UNIT (decl));
+      ASM_OUTPUT_SIZE_DIRECTIVE (file, name, size);
+    }
+}
+
 /* This is how to declare the size of a function.  */
 #ifndef ASM_DECLARE_FUNCTION_SIZE
 #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)           \

build/gengtype  \
                    -S ../../gcc-trunk/gcc -I gtyp-input.list -w tmp-gtype.state
g++ -std=gnu++98 -c   -g -DIN_GCC     -fno-exceptions -fno-rtti 
-fasynchronous-unwind-tables -Wall -Wextra -Wno-narrowing -Wwrite-strings 
-Wcast-qual -Wno-format -Wmissing-format-attribute -Woverloaded-virtual 
-pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings 
-fno-common  -DHAVE_CONFIG_H  -DGENERATOR_FILE -fno-PIE -I. -Ibuild 
-I../../gcc-trunk/gcc -I../../gcc-trunk/gcc/build 
-I../../gcc-trunk/gcc/../include  -I../../gcc-trunk/gcc/../libcpp/include  \
                -o build/gencheck.o ../../gcc-trunk/gcc/gencheck.c
In file included from ./tm.h:30:0,
                 from ../../gcc-trunk/gcc/gencheck.c:23:
../../gcc-trunk/gcc/config/elfos.h: In function ‘void 
elfos_asm_declare_object_name(FILE*, const char*, tree)’:
../../gcc-trunk/gcc/config/elfos.h:324:51: error: ‘DECL_ONE_ONLY’ was not 
declared in this scope
   if (USE_GNU_UNIQUE_OBJECT && DECL_ONE_ONLY (decl)
                                                   ^
../../gcc-trunk/gcc/config/elfos.h:325:33: error: ‘DECL_ARTIFICIAL’ was not 
declared in this scope
       && (!DECL_ARTIFICIAL (decl) || !TREE_READONLY (decl)))
                                 ^
../../gcc-trunk/gcc/config/elfos.h:325:58: error: ‘TREE_READONLY’ was not 
declared in this scope
       && (!DECL_ARTIFICIAL (decl) || !TREE_READONLY (decl)))
                                                          ^
../../gcc-trunk/gcc/config/elfos.h:326:63: error: ‘ASM_OUTPUT_TYPE_DIRECTIVE’ 
was not declared in this scope
     ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "gnu_unique_object");
                                                               ^
../../gcc-trunk/gcc/config/elfos.h:328:52: error: ‘ASM_OUTPUT_TYPE_DIRECTIVE’ 
was not declared in this scope
     ASM_OUTPUT_TYPE_DIRECTIVE (file, name, "object");
                                                    ^
../../gcc-trunk/gcc/config/elfos.h:330:3: error: ‘size_directive_output’ was 
not declared in this scope
   size_directive_output = 0;
   ^
../../gcc-trunk/gcc/config/elfos.h:332:35: error: ‘DECL_SIZE’ was not declared 
in this scope
       && (decl) && DECL_SIZE (decl))
                                   ^
../../gcc-trunk/gcc/config/elfos.h:335:48: error: ‘DECL_SIZE_UNIT’ was not 
declared in this scope
       size = tree_to_uhwi (DECL_SIZE_UNIT (decl));
                                                ^
../../gcc-trunk/gcc/config/elfos.h:335:49: error: ‘tree_to_uhwi’ was not 
declared in this scope
       size = tree_to_uhwi (DECL_SIZE_UNIT (decl));
                                                 ^
../../gcc-trunk/gcc/config/elfos.h:336:50: error: ‘ASM_OUTPUT_SIZE_DIRECTIVE’ 
was not declared in this scope
       ASM_OUTPUT_SIZE_DIRECTIVE (file, name, size);
                                                  ^
../../gcc-trunk/gcc/config/elfos.h:338:31: error: ‘ASM_OUTPUT_LABEL’ was not 
declared in this scope
   ASM_OUTPUT_LABEL (file, name);
                               ^
../../gcc-trunk/gcc/config/elfos.h: In function ‘void 
elfos_asm_finish_declare_object(FILE*, tree, int, int)’:
../../gcc-trunk/gcc/config/elfos.h:355:48: error: ‘DECL_RTL’ was not declared 
in this scope
   const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
                                                ^
../../gcc-trunk/gcc/config/elfos.h:355:52: error: ‘XEXP’ was not declared in 
this scope
   const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
                                                    ^
../../gcc-trunk/gcc/config/elfos.h:355:56: error: ‘XSTR’ was not declared in 
this scope
   const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
                                                        ^
../../gcc-trunk/gcc/config/elfos.h:359:25: error: ‘DECL_SIZE’ was not declared 
in this scope
       && DECL_SIZE (decl)
                         ^
../../gcc-trunk/gcc/config/elfos.h:361:28: error: ‘DECL_INITIAL’ was not 
declared in this scope
       && DECL_INITIAL (decl) == error_mark_node
                            ^
../../gcc-trunk/gcc/config/elfos.h:361:33: error: ‘error_mark_node’ was not 
declared in this scope
       && DECL_INITIAL (decl) == error_mark_node
                                 ^
../../gcc-trunk/gcc/config/elfos.h:362:11: error: ‘size_directive_output’ was 
not declared in this scope
       && !size_directive_output)
           ^
../../gcc-trunk/gcc/config/elfos.h:365:48: error: ‘DECL_SIZE_UNIT’ was not 
declared in this scope
       size = tree_to_uhwi (DECL_SIZE_UNIT (decl));
                                                ^
../../gcc-trunk/gcc/config/elfos.h:365:49: error: ‘tree_to_uhwi’ was not 
declared in this scope
       size = tree_to_uhwi (DECL_SIZE_UNIT (decl));
                                                 ^
../../gcc-trunk/gcc/config/elfos.h:366:50: error: ‘ASM_OUTPUT_SIZE_DIRECTIVE’ 
was not declared in this scope
       ASM_OUTPUT_SIZE_DIRECTIVE (file, name, size);
                                                  ^


Now I don't know how to fix that easily.


Bernd.

Reply via email to