public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR c++/18121 and middle-end/17407
@ 2004-10-23 19:30 Andrew Pinski
  2004-10-24 12:29 ` Andrew Pinski
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Pinski @ 2004-10-23 19:30 UTC (permalink / raw)
  To: gcc-patches@gcc.gnu.org Patches

[-- Attachment #1: Type: text/plain, Size: 1021 bytes --]

Two related problems relating to code which was added to the code added
to the tree-ssa branch.  The problem was fixed in the wrong spot rather
than in the middle-end we fixed in the front-ends which caused 
C++/18121.
But since we could have a typedef so we don't layout the array type.
The way I fixed both problems is to revert the patch which fixed
PR middle-end/12920 and have build_array_type layout the type even if
the index_type is NULL.

OK? Bootstrapped and tested on powerpc-darwin.

Thanks,
Andrew Pinski

ChangeLog:

	* c-decl.c (grokdeclarator) <case cdk_array>: Remove the call
	layout_type as it is already done by build_array_type.
	* tree.c (build_array_type): Don't return early if index_type
	is NULL.  Just don't call iterative_hash_object on it.

cp/ChangeLog:
	* decl.c (grokdeclarator) <case cdk_array>: Remove the call
	layout_type as it is already done by create_array_type_for_decl.

testsuite/ChangeLog:
	* gcc.c-torture/compile/pr17407.c: New test.
	* g++.dg/template/array8.C: New test.




[-- Attachment #2: temp.diff.txt --]
[-- Type: text/plain, Size: 3599 bytes --]

Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.603
diff -u -p -r1.603 c-decl.c
--- c-decl.c	21 Oct 2004 16:29:48 -0000	1.603
+++ c-decl.c	23 Oct 2004 18:35:19 -0000
@@ -4133,14 +4189,9 @@ grokdeclarator (const struct c_declarato
 	       zero.  */
 	    if (size && integer_zerop (size))
 	      {
-		layout_type (type);
 		TYPE_SIZE (type) = bitsize_zero_node;
 		TYPE_SIZE_UNIT (type) = size_zero_node;
 	      }
-	    else if (declarator->kind == cdk_pointer)
-	      /* We can never complete an array type which is the
-	         target of a pointer, so go ahead and lay it out.  */
-	      layout_type (type);
 
 	    if (decl_context != PARM
 		&& (array_ptr_quals != TYPE_UNQUALIFIED
Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.439
diff -u -p -r1.439 tree.c
--- tree.c	21 Oct 2004 16:29:51 -0000	1.439
+++ tree.c	23 Oct 2004 18:35:49 -0000
@@ -4334,11 +4334,10 @@ build_array_type (tree elt_type, tree in
   TREE_TYPE (t) = elt_type;
   TYPE_DOMAIN (t) = index_type;
 
-  if (index_type == 0)
-    return t;
 
   hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
-  hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
+  if (index_type != 0)
+    hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
   t = type_hash_canon (hashcode, t);
 
   if (!COMPLETE_TYPE_P (t))
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1317
diff -u -p -r1.1317 decl.c
--- cp/decl.c	20 Oct 2004 16:20:39 -0000	1.1317
+++ cp/decl.c	23 Oct 2004 18:36:51 -0000
@@ -7214,13 +7214,6 @@ grokdeclarator (const cp_declarator *dec
 	case cdk_array:
 	  type = create_array_type_for_decl (dname, type,
 					     declarator->u.array.bounds);
-	  if (inner_declarator
-	      && (inner_declarator->kind == cdk_pointer
-		  || inner_declarator->kind == cdk_reference
-		  || inner_declarator->kind == cdk_ptrmem))
-	    /* We can never complete an array type which is the
-	       target of a pointer, so go ahead and lay it out.  */
-	    layout_type (type);
 	  break;
 
 	case cdk_function:
Index: testsuite/gcc.c-torture/compile/pr17407.c
===================================================================
RCS file: testsuite/gcc.c-torture/compile/pr17407.c
diff -N testsuite/gcc.c-torture/compile/pr17407.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.c-torture/compile/pr17407.c	21 Oct 2004 03:05:38 -0000
@@ -0,0 +1,15 @@
+typedef struct libxml_xpathCallback { 
+  void *ns_uri; 
+} libxml_xpathCallback; 
+ 
+typedef libxml_xpathCallback libxml_xpathCallbackArray[]; 
+ 
+libxml_xpathCallbackArray *libxml_xpathCallbacks; 
+
+void foo1(void);
+ 
+void 
+foo (void) 
+{ 
+  if ((*libxml_xpathCallbacks)[3].ns_uri != ((void *)0)) foo1(); 
+} 
Index: testsuite/g++.dg/template/array8.C
===================================================================
RCS file: testsuite/g++.dg/template/array8.C
diff -N testsuite/g++.dg/template/array8.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/g++.dg/template/array8.C	23 Oct 2004 18:52:24 -0000
@@ -0,0 +1,16 @@
+// PR c++/18121
+
+// We were trying to layout the array
+// type but since the type/value of A<N>::i
+// was not known at template declation type,
+// we were crashing
+
+template<int> struct A
+{
+    static int const i = 1;
+};
+
+template<int N> struct B
+{
+    typedef int (*p)[A<N>::i];
+};

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix PR c++/18121 and middle-end/17407
  2004-10-23 19:30 [PATCH] Fix PR c++/18121 and middle-end/17407 Andrew Pinski
@ 2004-10-24 12:29 ` Andrew Pinski
  2004-10-25  4:21   ` Mark Mitchell
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Pinski @ 2004-10-24 12:29 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc-patches@gcc.gnu.org Patches

[-- Attachment #1: Type: text/plain, Size: 1103 bytes --]


On Oct 23, 2004, at 3:04 PM, Andrew Pinski wrote:

> Two related problems relating to code which was added to the code added
> to the tree-ssa branch.  The problem was fixed in the wrong spot rather
> than in the middle-end we fixed in the front-ends which caused 
> C++/18121.
> But since we could have a typedef so we don't layout the array type.
> The way I fixed both problems is to revert the patch which fixed
> PR middle-end/12920 and have build_array_type layout the type even if
> the index_type is NULL.
>
> OK? Bootstrapped and tested on powerpc-darwin.
>
> Thanks,
> Andrew Pinski

Somehow I posted a previous patch which does not work, woops.

ChangeLog:

ChangeLog:

	* c-decl.c (grokdeclarator) <case cdk_array>: Remove the call
	layout_type as it is already done by build_array_type.
	* tree.c (build_array_type): Layout the type even

cp/ChangeLog:
	* decl.c (grokdeclarator) <case cdk_array>: Remove the call
	layout_type as it is already done by create_array_type_for_decl.

testsuite/ChangeLog:
	* gcc.c-torture/compile/pr17407.c: New test.
	* g++.dg/template/array8.C: New test.



[-- Attachment #2: temp.diff.txt --]
[-- Type: text/plain, Size: 3521 bytes --]

Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.439
diff -u -p -r1.439 tree.c
--- tree.c	21 Oct 2004 16:29:51 -0000	1.439
+++ tree.c	24 Oct 2004 03:22:39 -0000
@@ -4333,9 +4333,12 @@ build_array_type (tree elt_type, tree in
   t = make_node (ARRAY_TYPE);
   TREE_TYPE (t) = elt_type;
   TYPE_DOMAIN (t) = index_type;
-
+  
   if (index_type == 0)
-    return t;
+    {
+      layout_type (t);
+      return t;
+    }
 
   hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
   hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.603
diff -u -p -r1.603 c-decl.c
--- c-decl.c	21 Oct 2004 16:29:48 -0000	1.603
+++ c-decl.c	24 Oct 2004 03:22:54 -0000
@@ -4133,14 +4189,9 @@ grokdeclarator (const struct c_declarato
 	       zero.  */
 	    if (size && integer_zerop (size))
 	      {
-		layout_type (type);
 		TYPE_SIZE (type) = bitsize_zero_node;
 		TYPE_SIZE_UNIT (type) = size_zero_node;
 	      }
-	    else if (declarator->kind == cdk_pointer)
-	      /* We can never complete an array type which is the
-	         target of a pointer, so go ahead and lay it out.  */
-	      layout_type (type);
 
 	    if (decl_context != PARM
 		&& (array_ptr_quals != TYPE_UNQUALIFIED
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1317
diff -u -p -r1.1317 decl.c
--- cp/decl.c	20 Oct 2004 16:20:39 -0000	1.1317
+++ cp/decl.c	24 Oct 2004 03:23:13 -0000
@@ -7214,13 +7214,6 @@ grokdeclarator (const cp_declarator *dec
 	case cdk_array:
 	  type = create_array_type_for_decl (dname, type,
 					     declarator->u.array.bounds);
-	  if (inner_declarator
-	      && (inner_declarator->kind == cdk_pointer
-		  || inner_declarator->kind == cdk_reference
-		  || inner_declarator->kind == cdk_ptrmem))
-	    /* We can never complete an array type which is the
-	       target of a pointer, so go ahead and lay it out.  */
-	    layout_type (type);
 	  break;
 
 	case cdk_function:
Index: testsuite/gcc.c-torture/compile/pr17407.c
===================================================================
RCS file: testsuite/gcc.c-torture/compile/pr17407.c
diff -N testsuite/gcc.c-torture/compile/pr17407.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.c-torture/compile/pr17407.c	21 Oct 2004 03:05:38 -0000
@@ -0,0 +1,15 @@
+typedef struct libxml_xpathCallback { 
+  void *ns_uri; 
+} libxml_xpathCallback; 
+ 
+typedef libxml_xpathCallback libxml_xpathCallbackArray[]; 
+ 
+libxml_xpathCallbackArray *libxml_xpathCallbacks; 
+
+void foo1(void);
+ 
+void 
+foo (void) 
+{ 
+  if ((*libxml_xpathCallbacks)[3].ns_uri != ((void *)0)) foo1(); 
+} 
Index: testsuite/g++.dg/template/array8.C
===================================================================
RCS file: testsuite/g++.dg/template/array8.C
diff -N testsuite/g++.dg/template/array8.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/g++.dg/template/array8.C	23 Oct 2004 18:52:24 -0000
@@ -0,0 +1,16 @@
+// PR c++/18121
+
+// We were trying to layout the array
+// type but since the type/value of A<N>::i
+// was not known at template declation type,
+// we were crashing
+
+template<int> struct A
+{
+    static int const i = 1;
+};
+
+template<int N> struct B
+{
+    typedef int (*p)[A<N>::i];
+};

[-- Attachment #3: Type: text/plain, Size: 2 bytes --]




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix PR c++/18121 and middle-end/17407
  2004-10-24 12:29 ` Andrew Pinski
@ 2004-10-25  4:21   ` Mark Mitchell
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Mitchell @ 2004-10-25  4:21 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gcc-patches@gcc.gnu.org Patches

Andrew Pinski wrote:

>
> On Oct 23, 2004, at 3:04 PM, Andrew Pinski wrote:
>
>> Two related problems relating to code which was added to the code added
>> to the tree-ssa branch.  The problem was fixed in the wrong spot rather
>> than in the middle-end we fixed in the front-ends which caused 
>> C++/18121.
>> But since we could have a typedef so we don't layout the array type.
>> The way I fixed both problems is to revert the patch which fixed
>> PR middle-end/12920 and have build_array_type layout the type even if
>> the index_type is NULL.
>>
>> OK? Bootstrapped and tested on powerpc-darwin.
>
OK.

-- 
Mark Mitchell
CodeSourcery, LLC
(916) 791-8304
mark@codesourcery.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-10-25  3:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-23 19:30 [PATCH] Fix PR c++/18121 and middle-end/17407 Andrew Pinski
2004-10-24 12:29 ` Andrew Pinski
2004-10-25  4:21   ` Mark Mitchell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).