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]

RFA: PATCH: PR target/39545: structures with zero-length array passed/returned inconsistently


Since flexible array member in struct is ignored when passing and
returning, we should never count it.  This patch fixes it with an ABI
change warning. If it is OK, I will provide a few testcase.

Thanks.


H.J.
---
2009-03-24  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/39545
	* config/i386/i386.c (classify_argument): Ignore flexible array
	member in struct and warn ABI change.

Index: gcc/config/i386/i386.c
===================================================================
--- gcc/config/i386/i386.c	(revision 145000)
+++ gcc/config/i386/i386.c	(working copy)
@@ -4865,9 +4865,9 @@ classify_argument (enum machine_mode mod
     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
   int words = (bytes + (bit_offset % 64) / 8 + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
 
-  /* Variable sized entities are always passed/returned in memory.  */
+  /* Variable sized entities should never get here.  */
   if (bytes < 0)
-    return 0;
+    gcc_unreachable ();
 
   if (mode != VOIDmode
       && targetm.calls.must_pass_in_stack (mode, type))
@@ -4923,6 +4923,22 @@ classify_argument (enum machine_mode mod
 		    }
 		  else
 		    {
+		      /* Variable sized member is ignored.  */
+		      if (TYPE_MODE (TREE_TYPE (field)) == BLKmode
+			  && int_size_in_bytes (TREE_TYPE (field)) < 0)
+			{
+			  static bool warned;
+			  
+			  if (!warned && warn_psabi)
+			    {
+			      warned = true;
+			      inform (input_location,
+				      "The ABI of passing struct with"
+				      " a flexible array member has"
+				      " changed in GCC 4.4");
+			    }
+			  continue;
+			}
 		      num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
 					       TREE_TYPE (field), subclasses,
 					       (int_bit_position (field)


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