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]

Fix PR43116: ICE when using attributes


Hi,

the problem manifests in the c++ frontend, but actually is a generic bug 
in applying attributes.  Some attributes change a function type, when we 
give a pointer to a function type we apply the attributes to the pointed 
to type, and then rebuild a pointer type from that.  That's all fine, 
except that we need to retain the qualifiers of the original pointer type, 
to not silently change a "const T *x" into a "T' *x".

Regstrapping on x86_64-linux (all langs+ada) in progress.  Okay if that 
passes?


Ciao,
Michael.
-- 
	PR c++/43116
	* attribs.c (decl_attributes): When rebuilding a function pointer
	type use the same qualifiers as the original pointer type.

testsuite/
	* g++.dg/other/pr43116.C: New testcase.

Index: attribs.c
===================================================================
--- attribs.c	(revision 157567)
+++ attribs.c	(working copy)
@@ -286,6 +286,7 @@ decl_attributes (tree *node, tree attrib
       tree *anode = node;
       const struct attribute_spec *spec = lookup_attribute_spec (name);
       bool no_add_attrs = 0;
+      int fn_ptr_quals = 0;
       tree fn_ptr_tmp = NULL_TREE;
 
       if (spec == NULL)
@@ -353,6 +354,7 @@ decl_attributes (tree *node, tree attrib
 		 This would all be simpler if attributes were part of the
 		 declarator, grumble grumble.  */
 	      fn_ptr_tmp = TREE_TYPE (*anode);
+	      fn_ptr_quals = TYPE_QUALS (*anode);
 	      anode = &fn_ptr_tmp;
 	      flags &= ~(int) ATTR_FLAG_TYPE_IN_PLACE;
 	    }
@@ -449,6 +451,8 @@ decl_attributes (tree *node, tree attrib
 	  /* Rebuild the function pointer type and put it in the
 	     appropriate place.  */
 	  fn_ptr_tmp = build_pointer_type (fn_ptr_tmp);
+	  if (fn_ptr_quals)
+	    fn_ptr_tmp = build_qualified_type (fn_ptr_tmp, fn_ptr_quals);
 	  if (DECL_P (*node))
 	    TREE_TYPE (*node) = fn_ptr_tmp;
 	  else
Index: testsuite/g++.dg/other/pr43116.C
===================================================================
--- testsuite/g++.dg/other/pr43116.C	(revision 0)
+++ testsuite/g++.dg/other/pr43116.C	(revision 0)
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+extern "C" int rpl_open (const char *filename, int flags, ...) __attribute__
+((__nonnull__ (1)));
+
+namespace gnulib
+{
+    int (*const open) (const char *filename, int flags, ...) __attribute__
+	((__nonnull__ (1))) = rpl_open;
+}


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