Bug 32970 - [4.3 Regression] C++ frontend can not handle vector pointer constant parameter
Summary: [4.3 Regression] C++ frontend can not handle vector pointer constant parameter
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.3.0
: P1 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2007-08-02 18:37 UTC by Sa Liu
Modified: 2007-08-17 06:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.1
Known to fail: 4.3.0
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sa Liu 2007-08-02 18:37:19 UTC
When compiling a function with parameter of a pointer to a vector constant 
type, the compiler calls a recursive function and is not able to get out. 

Concretely, in gcc/cp/mangle.c file, in function write_type:

  if (write_CV_qualifiers_for_type (type) > 0)
    /* If TYPE was CV-qualified, we just wrote the qualifiers; now
       mangle the unqualified type.  The recursive call is needed here
       since both the qualified and unqualified types are substitution
       candidates.  */
    write_type (TYPE_MAIN_VARIANT (type));

But TYPE_MAIN_VARIANT (type) has been set as type itself in gcc/tree.c 
function make_node_stat:
   case tcc_type:
        ...
      TYPE_MAIN_VARIANT (t) = t;

Therefor the write_type function runs into a dead recursion.

The bug was detected on spu, and the same error appears on PowerPC and Intel too.

The following is a test case on Intel:

void bar(
    int __attribute__((vector_size(16))) * a,
    int __attribute__((vector_size(16))) * const b);

int instance(void)
{
   int __attribute__((vector_size(16))) a[1], b[1];

   bar(a, b);
}
Comment 1 Janis Johnson 2007-08-06 23:15:10 UTC
A regression hunt of mainline on powerpc-linux identified the following patch, where the compiler went from compiling in a reasonable time to taking more than three seconds for the submitter's testcase:

    r117696 | bonzini | 2006-10-13 15:59:03 +0000 (Fri, 13 Oct 2006)

    http://gcc.gnu.org/viewcvs?view=rev&rev=117696
Comment 2 Sa Liu 2007-08-07 11:31:17 UTC
Is this really a regression from 4.1.1? 
I got the same error on 4.1.1, before the patch r117696 was applied.
Comment 3 Janis Johnson 2007-08-07 23:17:22 UTC
It compiles quickly for me with GCC 4.1.1 for powerpc64-linux and with a 4.1.1 cross compiler for i686-linux.  Is your 4.1.1 compiler from FSF sources, or might it have additional backports?
Comment 4 Sa Liu 2007-08-08 13:38:24 UTC
Okey, I have a Red Hat GCC 4.1.1, which might be different from the FSF one.
Comment 5 Sa Liu 2007-08-10 10:13:10 UTC
This patch can fix the problem:

Index: gcc/tree.c
===================================================================
--- gcc.orig/tree.c
+++ gcc/tree.c
@@ -7609,8 +7609,11 @@ reconstruct_complex_type (tree type, tre
   else
     return bottom;
 
-  TYPE_READONLY (outer) = TYPE_READONLY (type);
-  TYPE_VOLATILE (outer) = TYPE_VOLATILE (type);
+  if  (TYPE_READONLY (type))
+    build_qualified_type(outer, TYPE_QUAL_CONST);
+
+  if (TYPE_VOLATILE (type))
+    build_qualified_type(outer, TYPE_QUAL_VOLATILE);
 
   return outer;
 }
Comment 6 Ulrich Weigand 2007-08-12 23:35:59 UTC
Changing component to middle-end as the problem is not actually in the C++ front-end.
Comment 7 Ulrich Weigand 2007-08-12 23:43:05 UTC
Sa's patch isn't quite correct as it ignores the result of
the build_qualified_type call.  The following patch should
fix that:

diff -urNp toolchain/gcc.orig/gcc/tree.c toolchain/gcc/gcc/tree.c
--- toolchain/gcc.orig/gcc/tree.c       2007-08-12 15:57:05.442520932 +0200
+++ toolchain/gcc/gcc/tree.c    2007-08-12 16:07:42.516093968 +0200
@@ -6554,10 +6554,7 @@ reconstruct_complex_type (tree type, tre
   else
     return bottom;

-  TYPE_READONLY (outer) = TYPE_READONLY (type);
-  TYPE_VOLATILE (outer) = TYPE_VOLATILE (type);
-
-  return outer;
+  return build_qualified_type (outer, TYPE_QUALS (type));
 }

 /* Returns a vector tree node given a mode (integer, vector, or BLKmode) and
Comment 8 Ben Elliston 2007-08-17 05:24:42 UTC
Subject: Bug 32970

Author: bje
Date: Fri Aug 17 05:24:24 2007
New Revision: 127578

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=127578
Log:
	PR middle-end/32970
gcc/
	* tree.c (reconstruct_complex_type): For a pointer to a vector,
	use build_qualified_type to retain qualifiers of the base type.
testsuite/
	* g++.dg/ext/altivec-14.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/ext/altivec-14.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree.c

Comment 9 Ben Elliston 2007-08-17 06:49:03 UTC
Fixed in r127578.