This is the mail archive of the gcc-bugs@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]

[Bug c++/41201] #pragma GCC target ("sse2") doesn't alter __SSE2__ in C++ (as it does in C)


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41201

Dave Korn <davek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2010.12.08 14:10:43
                 CC|                            |davek at gcc dot gnu.org
         AssignedTo|unassigned at gcc dot       |davek at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1

--- Comment #6 from Dave Korn <davek at gcc dot gnu.org> 2010-12-08 14:10:43 UTC ---
I stumbled into the underlying cause of this bug while working on
dllimport/dllexport attributes.  It turns out that the TARGET_INSERT_ATTRIBUTES
hook is broken in C++, because of a bit of premature optimisation in the
routine gcc/cp/decl2.c#cplus_decl_attributes().  This is a C++-specific wrapper
round the core compiler's gcc/attribs.c#decl_attributes() which takes care of
deferred attribute handling for templates:

/* Like decl_attributes, but handle C++ complexity.  */

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)
    return;

  if (processing_template_decl)
    {
      if (check_for_bare_parameter_packs (attributes))
    return;

      save_template_attributes (&attributes, decl);
      if (attributes == NULL_TREE)
    return;
    }

  if (TREE_CODE (*decl) == TEMPLATE_DECL)
    decl = &DECL_TEMPLATE_RESULT (*decl);

  decl_attributes (decl, attributes, flags);

  if (TREE_CODE (*decl) == TYPE_DECL)
    SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (*decl), TREE_TYPE (*decl));
}

  The early exits when attributes == NULL_TREE are (I suppose) intended to save
the time taken calling decl_attributes when there aren't any attributes to be
added to the newly-created decl, but it has the side-effect of bypassing the
call that decl_attributes makes to TARGET_INSERT_ATTRIBUTES.  The consequence
is that the default/target/pragma-derived attributes don't get inserted onto
any decls in C++ - except for decls that have some explicit attributes
specified!

  I'm going to be testing this fix as part of a larger patch over the next
couple of days, perhaps others would like to give it a try on their platforms:


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)


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