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]

patch for C++ parser bug with function attributes


The attached GCC patch fixes a previously reported problem with function
attributes (see http://gcc.gnu.org/ml/gcc-bugs/1999-07/msg00835.html). 
The patch is relative to 2.95.2.  I have not checked any recent
development versions to see if the bug is already fixed, but neither
have I been able to find any patches for this in the patch mailing list
archive.

Whether you use my patch or someone else's, please fix this!  This bug
is rather serious in the Mingw environment where the standard header
files declare lots of functions with attributes.

-- 
Bob Wilson                      Tel: (408) 327-7312
Tensilica, Inc.                 Fax: (408) 986-8919
3255-6 Scott Blvd.              email: bwilson@tensilica.com
Santa Clara, CA 95054
This patch fixes a bug in the C++ front end that causes attributes,
such as "stdcall" in the Mingw environment, to be added onto existing
type nodes instead of creating new type variants.  One symptom of this
is that STL breaks in the Mingw environment if a file includes
<windows.h>.

diff -ur gcc-2.95.2/gcc/cp/decl.c gcc/cp/decl.c
--- gcc-2.95.2/gcc/cp/decl.c	Sun Aug  8 17:28:33 1999
+++ gcc/cp/decl.c	Tue Jan 23 11:21:15 2001
@@ -10263,7 +10263,16 @@
 	ignore_attrs = 0;
       else if (inner_attrs)
 	{
-	  decl_attributes (type, inner_attrs, NULL_TREE);
+	  /* Create a dummy decl to pass to decl_attributes.  The
+	     attributes will be added to a variant of type, and this
+	     new variant type can be retrieved from the dummy decl.
+	     Passing type directly causes the attributes to be added
+	     to type, which is wrong because type may be used
+	     elsewhere without attributes. */
+
+	  tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
+	  decl_attributes (dummy, inner_attrs, NULL_TREE);
+	  type = TREE_TYPE (dummy);
 	  inner_attrs = NULL_TREE;
 	}
 
@@ -10966,7 +10975,18 @@
   if (inner_attrs)
     {
       if (! ignore_attrs)
-	decl_attributes (type, inner_attrs, NULL_TREE);
+	{
+	  /* Create a dummy decl to pass to decl_attributes.  The
+	     attributes will be added to a variant of type, and this
+	     new variant type can be retrieved from the dummy decl.
+	     Passing type directly causes the attributes to be added
+	     to type, which is wrong because type may be used
+	     elsewhere without attributes. */
+
+	  tree dummy = build_decl (TYPE_DECL, NULL_TREE, type);
+	  decl_attributes (dummy, inner_attrs, NULL_TREE);
+	  type = TREE_TYPE (dummy);
+	}
       else if (attrlist)
 	TREE_VALUE (attrlist) = chainon (inner_attrs, TREE_VALUE (attrlist));
       else

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