svn commit: r301817 - stable/10/contrib/gcc

Pedro F. Giffuni pfg at FreeBSD.org
Fri Jun 10 22:07:19 UTC 2016


Author: pfg
Date: Fri Jun 10 22:07:17 2016
New Revision: 301817
URL: https://svnweb.freebsd.org/changeset/base/301817

Log:
  MFC r300301, r300319:
  GCC: Add support for named initializers for anonymous structs/unions.
  
  This is a C11 feature that is starting to get used in places such as Mesa.
  This implementation takes a different approach to upstream and is
  therefore not covered by GPLv3.
  
  Obtained from:	OpenBSD (CVS rev. 1.2)

Modified:
  stable/10/contrib/gcc/c-typeck.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/contrib/gcc/c-typeck.c
==============================================================================
--- stable/10/contrib/gcc/c-typeck.c	Fri Jun 10 21:47:37 2016	(r301816)
+++ stable/10/contrib/gcc/c-typeck.c	Fri Jun 10 22:07:17 2016	(r301817)
@@ -6041,6 +6041,7 @@ set_init_index (tree first, tree last)
 void
 set_init_label (tree fieldname)
 {
+  tree anon = NULL_TREE;
   tree tail;
 
   if (set_designator (0))
@@ -6058,19 +6059,39 @@ set_init_label (tree fieldname)
   for (tail = TYPE_FIELDS (constructor_type); tail;
        tail = TREE_CHAIN (tail))
     {
+      if (DECL_NAME (tail) == NULL_TREE
+	  && (TREE_CODE (TREE_TYPE (tail)) == RECORD_TYPE
+	      || TREE_CODE (TREE_TYPE (tail)) == UNION_TYPE))
+	{
+	  anon = lookup_field (tail, fieldname);
+	  if (anon)
+	    break;
+	}
+
       if (DECL_NAME (tail) == fieldname)
 	break;
     }
 
   if (tail == 0)
     error ("unknown field %qE specified in initializer", fieldname);
-  else
+
+  while (tail)
     {
       constructor_fields = tail;
       designator_depth++;
       designator_erroneous = 0;
       if (constructor_range_stack)
 	push_range_stack (NULL_TREE);
+
+      if (anon)
+	{
+	  if (set_designator (0))
+	    return;
+	  tail = TREE_VALUE(anon);
+	  anon = TREE_CHAIN(anon);
+	}
+      else
+	tail = NULL_TREE;
     }
 }
 



More information about the svn-src-all mailing list