public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Make TARGET_INSERT_ATTRIBUTES work in C++.
@ 2010-12-09 20:33 Dave Korn
  0 siblings, 0 replies; only message in thread
From: Dave Korn @ 2010-12-09 20:33 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 1600 bytes --]


    Hi list,

  cplus_decl_attributes(), in cp/decl2.c, is a wrapper that the C++ FE puts
around calls to the core attribs.c#decl_attributes() function in order to
handle templates.  It contains what appears to be a bit of premature
optimisation: if there are no attributes to be added to the decl, it returns
early rather than calling through to the core decl_attributes() function.
This looks like an effort to avoid wasted cpu cycles, but in fact it misses
out at least one important bit of processing that the core routine performs:
calling the TARGET_INSERT_ATTRIBUTES hook.  This means that any backend that
(for example) uses the insert_attributes hook to implement pragmas should find
that they don't work on any C++ declarations except those which also have
explicitly-specified attributes on them.

  The attached patch just removes the early exits and allows the underlying
core routine to have a chance to call the hook no matter what.  Bootstrapped
and tested on x86_64-unknown-linux-gnu without regressions.  I'll be needing
this functionality, once it's working again, to fix some bugs with the windows
backends' dllim/export attributes.

gcc/cp/ChangeLog:

2010-12-09  Dave Korn  <...

	* decl2.c (cplus_decl_attributes): Don't exit early but instead always
	call decl_attributes() (and implicitly TARGET_INSERT_ATTRIBUTES).

  OK?

  (BTW, while doing this, I noticed that there's a call in
cp/decl.c#grokdeclarator() directly to the core decl_attributes() function
that doesn't go via the cplus_decl_attributes() wrapper - is it supposed to be
that way?)

    cheers,
      DaveK


[-- Attachment #2: cxx-attribs-fix.diff --]
[-- Type: text/x-c, Size: 962 bytes --]

Index: gcc/cp/decl2.c
===================================================================
--- gcc/cp/decl2.c	(revision 167484)
+++ gcc/cp/decl2.c	(working copy)
@@ -1269,8 +1269,7 @@ void
 cplus_decl_attributes (tree *decl, tree attributes, int flags)
 {
   if (*decl == NULL_TREE || *decl == void_type_node
-      || *decl == error_mark_node
-      || attributes == NULL_TREE)
+      || *decl == error_mark_node)
     return;
 
   if (processing_template_decl)
@@ -1279,13 +1278,13 @@ cplus_decl_attributes (tree *decl, tree attributes
 	return;
 
       save_template_attributes (&attributes, decl);
-      if (attributes == NULL_TREE)
-	return;
     }
 
   if (TREE_CODE (*decl) == TEMPLATE_DECL)
     decl = &DECL_TEMPLATE_RESULT (*decl);
 
+  /* Even if ATTRIBUTES is null, we must call this in order to
+     give the TARGET_INSERT_ATTRIBUTES hook a chance to run.  */
   decl_attributes (decl, attributes, flags);
 
   if (TREE_CODE (*decl) == TYPE_DECL)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-12-09 19:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-09 20:33 [PATCH] Make TARGET_INSERT_ATTRIBUTES work in C++ Dave Korn

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