This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: preserve parameter attributes during C++ decl smashing


H.J. Lu wrote:
On Tue, Apr 28, 2009 at 3:40 PM, Mark Mitchell <mark@codesourcery.com> wrote:
If we emit a definition of "f", I don't think we should emit it as weak.
 AFAIK, it only makes sense for a symbol to be weak when we are emitted
a reference to it, not a definition of it.  But, that's not really a
question about merging attributes; the same question applies to:

__attribute__((weak)) void f(int i) { ... }


Try


# readelf -s --wide libstdc++.a| grep WEAK

on Linux. You may find many weak definitions.



Here is an updated version of the patch that always merges the attributes. I found that I needed to set the attributes on both the 'old' and the 'new' declaration because it was unpredictable which set of PARM_DECL nodes would be used in the result of merging the FUNCTION_DECLs.


I'm not sure if it's OK to share the DECL_ATTRIBUTES(...) properties like that, so please check that out specifically in reviewing the patch. Let me know if anything else is needed--this is my first submission to gcc-patches.

--
Dave
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -1920,6 +1920,17 @@ duplicate_decls (tree newdecl, tree oldd
 
   if (TREE_CODE (newdecl) == FUNCTION_DECL)
     {
+      /* Merge parameter attributes. */
+      tree oldarg, newarg;
+      for (oldarg = DECL_ARGUMENTS(olddecl), 
+             newarg = DECL_ARGUMENTS(newdecl);
+           oldarg && newarg;
+           oldarg = TREE_CHAIN(oldarg), newarg = TREE_CHAIN(newarg)) {
+        DECL_ATTRIBUTES (newarg)
+          = (*targetm.merge_decl_attributes) (oldarg, newarg);
+        DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
+      }
+
       if (DECL_TEMPLATE_INSTANTIATION (olddecl)
 	  && !DECL_TEMPLATE_INSTANTIATION (newdecl))
 	{

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]