Patchwork [4.5] ObjC/C++ back-port of fix for PR32052

login
register
mail settings
Submitter IainS
Date June 8, 2010, 12:21 p.m.
Message ID <86B92522-4BD6-4C4B-954A-FEF26BD92C5B@sandoe-acoustics.co.uk>
Download mbox | patch
Permalink /patch/54965/
State New
Headers show

Comments

IainS - June 8, 2010, 12:21 p.m.
tested on i686-apple-darwin9, i6868-pc-linux-gnu.
OK for 4.5?
Iain

gcc/objc/ChangeLog:

  	Backport from mainline:

	PR objc++/32052
	* objc-act.c (encode_aggregate_within): Encode structure tags
	with template args for ObjC++.

gcc/testsuite/ChangeLog:

	Backport from mainline:

	PR objc++/32052
	* obj-c++.dg/encode-2.mm: Remove XFAIL. Add test for anonymous
	structure and nested declarations.
	* obj-c++.dg/encode-3.mm:  Remove XFAIL. Add test for anonymous
	structure and nested declarations.  Reduce header clutter.
	* objc.dg/encode-10.m: New.
	* objc.dg/encode-11.m: New.
IainS - June 10, 2010, 12:35 p.m.
On 8 Jun 2010, at 13:21, IainS wrote:

> gcc/objc/ChangeLog:
>
> 	Backport from mainline:
>
> 	PR objc++/32052
> 	* objc-act.c (encode_aggregate_within): Encode structure tags
> 	with template args for ObjC++.
>
> gcc/testsuite/ChangeLog:
>
> 	Backport from mainline:
>
> 	PR objc++/32052
> 	* obj-c++.dg/encode-2.mm: Remove XFAIL. Add test for anonymous
> 	structure and nested declarations.
> 	* obj-c++.dg/encode-3.mm:  Remove XFAIL. Add test for anonymous
> 	structure and nested declarations.  Reduce header clutter.
> 	* objc.dg/encode-10.m: New.
> 	* objc.dg/encode-11.m: New.
>
> <160426-4-5-PR32052-diff.txt>

applied to 4.5 release branch as r160541.
Iain

Patch

Index: gcc/objc/objc-act.c
===================================================================
--- gcc/objc/objc-act.c	(revision 160426)
+++ gcc/objc/objc-act.c	(working copy)
@@ -8120,15 +8120,21 @@  encode_aggregate_within (tree type, int curtype, i
 
   /* Encode the struct/union tag name, or '?' if a tag was
      not provided.  Typedef aliases do not qualify.  */
+#ifdef OBJCPLUS
+  /* For compatibility with the NeXT runtime, ObjC++ encodes template
+     args as a composite struct tag name. */
   if (name && TREE_CODE (name) == IDENTIFIER_NODE
-#ifdef OBJCPLUS
       /* Did this struct have a tag?  */
-      && !TYPE_WAS_ANONYMOUS (type)
-#endif
-      )
+      && !TYPE_WAS_ANONYMOUS (type))
     obstack_grow (&util_obstack,
+		  decl_as_string (type, TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME),
+		  strlen (decl_as_string (type, TFF_DECL_SPECIFIERS | TFF_UNQUALIFIED_NAME)));
+#else
+  if (name && TREE_CODE (name) == IDENTIFIER_NODE)
+    obstack_grow (&util_obstack,
 		  IDENTIFIER_POINTER (name),
 		  strlen (IDENTIFIER_POINTER (name)));
+#endif
   else
     obstack_1grow (&util_obstack, '?');
 
Index: gcc/testsuite/objc.dg/encode-10.m
===================================================================
--- gcc/testsuite/objc.dg/encode-10.m	(revision 0)
+++ gcc/testsuite/objc.dg/encode-10.m	(revision 0)
@@ -0,0 +1,19 @@ 
+/* { dg-do compile } */
+
+typedef struct Vec {
+ double x, y;
+ int z;
+} xyz_t ;
+
+typedef struct {
+  float fscalar;
+  double dscalar;
+  xyz_t dv;
+  int iscalar;
+} anonymous;
+
+const char *enc = @encode(xyz_t);
+const char *enc2 = @encode(anonymous);
+
+/* { dg-final { scan-assembler "{Vec=ddi}" } }  */
+/* { dg-final { scan-assembler "{?=fd{Vec=ddi}i}" } }  */
Index: gcc/testsuite/objc.dg/encode-11.m
===================================================================
--- gcc/testsuite/objc.dg/encode-11.m	(revision 0)
+++ gcc/testsuite/objc.dg/encode-11.m	(revision 0)
@@ -0,0 +1,43 @@ 
+/* { dg-do run } */
+
+extern void abort (void);
+extern int strcmp (const char *, const char *);
+
+typedef struct Vec {
+ double xv[10], yv[5];
+ float fscal;
+ int z;
+} xyz_t ;
+
+typedef struct {
+  float fscalar;
+  double dscalar;
+  xyz_t dv;
+  int iscalar;
+  long ln;
+  long long lln;
+} anonymous;
+
+const char *enc = @encode(xyz_t);
+const char *enc2 = @encode(anonymous);
+
+#ifdef __LP64__
+#define L "q"
+#else
+#define L "l"
+#endif
+
+int main(void) {
+  const char *encode = @encode(long);
+
+  if (strcmp (encode, L))
+    abort ();
+    
+  if (strcmp (enc, "{Vec=[10d][5d]fi}"))
+     abort ();
+
+  if (strcmp (enc2, "{?=fd{Vec=[10d][5d]fi}i" L "q}"))
+    abort ();
+
+  return 0;
+}
Index: gcc/testsuite/obj-c++.dg/encode-2.mm
===================================================================
--- gcc/testsuite/obj-c++.dg/encode-2.mm	(revision 160426)
+++ gcc/testsuite/obj-c++.dg/encode-2.mm	(working copy)
@@ -6,9 +6,21 @@  struct Vec {
  int z;
 };
 
+typedef struct {
+  Vec<double> dvec;
+  Vec<float> fvec;
+  float fscalar;
+  double dscalar;
+  Vec<char> chVec;
+  int iscalar;
+} anonymous;
+
 Vec<double> dd;
+
 const char *enc = @encode(Vec<float>);
 const char *enc2 = @encode(Vec<double>);
+const char *enc3 = @encode(anonymous);
 
-/* { dg-final { scan-assembler "{Vec<float>=ffi}" { xfail "*-*-*" } } } PR32052 */
-/* { dg-final { scan-assembler "{Vec<double>=ddi}" { xfail "*-*-*" } } } PR32052 */
+/* { dg-final { scan-assembler "{Vec<float>=ffi}" } }  */
+/* { dg-final { scan-assembler "{Vec<double>=ddi}" } }  */
+/* { dg-final { scan-assembler "{?={Vec<double>=ddi}{Vec<float>=ffi}fd{Vec<char>=cci}i}" } }  */
Index: gcc/testsuite/obj-c++.dg/encode-3.mm
===================================================================
--- gcc/testsuite/obj-c++.dg/encode-3.mm	(revision 160426)
+++ gcc/testsuite/obj-c++.dg/encode-3.mm	(working copy)
@@ -1,18 +1,30 @@ 
-/* { dg-do run { xfail { "*-*-*" } } } PR32052 */
+/* { dg-do run } */
 
-#include <stdlib.h>
-#include <string.h>
+extern "C" {
+extern void abort (void);
+extern int strcmp (const char *, const char *);
+}
 
 template <class T>
 struct Vec {
- T x, y;
- long z;
- long long zz;
+  T x, y;
+  long z;
+  long long zz;
 };
 
-Vec<double> dd;
+typedef struct {
+  float fscalar;
+  double dv[10];
+  int iscalar;
+  long z;
+  long long zz;
+  Vec<const char> cv;
+} anonymous;
+
+//Vec<double> dd;
 const char *enc = @encode(Vec<float>);
 const char *enc2 = @encode(Vec<double>);
+const char *enc3 = @encode(anonymous);
 
 #ifdef __LP64__
 #define L "q"
@@ -32,5 +44,8 @@  int main(void) {
   if (strcmp (enc2, "{Vec<double>=dd" L "q}"))
     abort();
 
+  if (strcmp (enc3, "{?=f[10d]i" L "q{Vec<const char>=rcrc" L "q}}"))
+    abort();
+
   return 0;
 }