Bug 28906 - [4.2 regression] rejects valid arrays
Summary: [4.2 regression] rejects valid arrays
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P1 blocker
Target Milestone: 4.2.0
Assignee: Andrew Pinski
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: ice-on-valid-code, patch, rejects-valid, wrong-code
: 28907 (view as bug list)
Depends on:
Blocks: 27184
  Show dependency treegraph
 
Reported: 2006-08-30 16:16 UTC by Martin Michlmayr
Modified: 2006-09-08 02:49 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-08-31 11:18:46


Attachments
test case (213 bytes, text/plain)
2006-08-30 16:16 UTC, Martin Michlmayr
Details
preprocessed source (28.62 KB, application/octet-stream)
2006-08-31 20:21 UTC, Martin Michlmayr
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Michlmayr 2006-08-30 16:16:16 UTC
Works gcc 4.2 20060806, fails with 20060823:


(sid)579:tbm@usurper: ~] /usr/lib/gcc-snapshot/bin/g++ -c texlive-t1rw.cc
texlive-t1rw.cc:19: error: conflicting declaration 'unsigned char Efont::Type1Reader::xvalue_store [257]'
texlive-t1rw.cc:5: error: 'Efont::Type1Reader::xvalue_store' has a previous declaration as 'unsigned char Efont::Type1Reader::xvalue_store [(sizeof (T) * want)]'
texlive-t1rw.cc:19: error: declaration of 'unsigned char Efont::Type1Reader::xvalue_store [(sizeof (T) * want)]' outside of class is not definition
texlive-t1rw.cc:19: internal compiler error: tree check: did not expect class 'type', have 'type' (template_type_parm) in contains_placeholder_p, at tree.c:2223
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 Martin Michlmayr 2006-08-30 16:16:48 UTC
Created attachment 12156 [details]
test case

Testcase from application "texlive-bin".
Comment 2 Andrew Pinski 2006-08-30 16:24:37 UTC
Reduced testcase:
extern unsigned char xvalue_store[];
bool reserve (int want)
{
  new unsigned char[want];
}
unsigned char xvalue_store[257];
----
I almost think this was casued by the patch to fix PR 27184.

Janis,
  Could you do a regression hunt on this bug?
Thanks,
Andrew
Comment 3 Andrew Pinski 2006-08-30 17:18:24 UTC
*** Bug 28907 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2006-08-30 17:20:45 UTC
This also causes wrong code:
extern char machineMain[];
void sort (long len)
{
  new char[100];
}
char machineMain[] = "main";
int main(void)
{
  if (sizeof(machineMain)!=sizeof("main"))
    __builtin_abort();
}
Comment 5 Andrew Pinski 2006-08-31 10:59:28 UTC
Yes this was casued by that patch.
Anyways we do:
1627          /* ??? The middle-end will error on us for building a VLA outside a
1628             function context.  Methinks that's not it's purvey.  So we'll do
1629             our own VLA layout later.  */
1630          vla_p = true;
(gdb) l
1631          full_type = build_cplus_array_type (type, NULL_TREE);
1632          index = convert (sizetype, nelts);
1633          index = size_binop (MINUS_EXPR, index, size_one_node);
1634          TYPE_DOMAIN (full_type) = build_index_type (index);

Which is the problem.  I will look into this further either this long weekend or later today.
Comment 6 Andrew Pinski 2006-08-31 11:06:19 UTC
Doing:
Index: init.c
===================================================================
--- init.c      (revision 116553)
+++ init.c      (working copy)
@@ -1628,7 +1628,7 @@ build_new_1 (tree placement, tree type,
         function context.  Methinks that's not it's purvey.  So we'll do
         our own VLA layout later.  */
       vla_p = true;
-      full_type = build_cplus_array_type (type, NULL_TREE);
+      full_type = copy_node (build_cplus_array_type (type, NULL_TREE));
       index = convert (sizetype, nelts);
       index = size_binop (MINUS_EXPR, index, size_one_node);
       TYPE_DOMAIN (full_type) = build_index_type (index);

Will fix the problem but I don't know if this is the correct fix.
Comment 7 Andrew Pinski 2006-08-31 11:18:35 UTC
Mine, we want/need to use build_distinct_type_copy instead but other than that it should be ok.
Comment 8 Martin Michlmayr 2006-08-31 20:10:50 UTC
Is this the same bug?

(sid)59:tbm@usurper: ~/delta/bin] /usr/lib/gcc-snapshot/bin/g++ -c  mini.c
mini.c:40: error: variable-size type declared outside of any function
mini.c:40: error: variable-size type declared outside of any function


Testcase:

extern "C"
{
  typedef long unsigned int size_t;
  extern size_t strlen (__const char *__s) throw () __attribute__ ((__pure__))
    __attribute__ ((__nonnull__ (1)));
  struct addrinfo
  {
  }
  _G_fpos64_t;
  typedef unsigned char cc_t;
}
extern char *hostname;
extern char NetTraceFile[];
void SetNetTrace (const char *);
typedef struct
{
}
Clocks;
char **genget (const char *, char **, int);
struct setlist
{
  const char *name;
  const char *help;
  void (*handler) (const char *);
  cc_t *charp;
};
static struct setlist Setlist[] = {
  {
     "tracefile", "file to write trace information to", SetNetTrace,
     (cc_t *) NetTraceFile}
};
static struct setlist *
getset (const char *name)
{
  return (struct setlist *) genget (name, (char **) Setlist,
                                    sizeof (struct setlist));
  char *hostp = __null;
    {
      hostname = new char[strlen (hostp) + 1];
    }
}
Comment 9 Martin Michlmayr 2006-08-31 20:21:04 UTC
Created attachment 12163 [details]
preprocessed source

Actually, can you please check when you get home if this is the same bug?
Comment 10 Andrew Pinski 2006-09-01 04:01:13 UTC
(In reply to comment #9)
> Actually, can you please check when you get home if this is the same bug?
Yes this is the same bug as my patch (which I am about to submut) fixes it.
Comment 11 Andrew Pinski 2006-09-01 04:49:27 UTC
I did not add a testcase for one that just ICE but I did add two testcases, one for the wrong code and one for the rejecting valid.  The ICE is because of templates which I don't feel like needing a testcase for that really since the other two should be enough to detect the problem in the future.  I also added a testcase to make sure that two seperate variables does change the shared incomplete shared type either.
Comment 12 patchapp@dberlin.org 2006-09-01 04:51:39 UTC
Subject: Bug number PR C++/28906

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-09/msg00007.html
Comment 13 Andrew Pinski 2006-09-08 02:49:20 UTC
Subject: Bug 28906

Author: pinskia
Date: Fri Sep  8 02:49:11 2006
New Revision: 116776

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116776
Log:
006-09-07  Andrew Pinski  <pinskia@physics.uc.edu>

        PR C++/28906
        * init.c (build_new_1): Build a distinct type copy
        for the array type that was returned from
        build_cplus_array_type.
2006-09-07  Andrew Pinski  <pinskia@physics.uc.edu>

        PR C++/28906
        * g++.dg/other/array3.C: New test.
        * g++.dg/other/array4.C: New test.
        * g++.dg/other/array5.C: New test.


Added:
    trunk/gcc/testsuite/g++.dg/other/array3.C
    trunk/gcc/testsuite/g++.dg/other/array4.C
    trunk/gcc/testsuite/g++.dg/other/array5.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/init.c
    trunk/gcc/testsuite/ChangeLog

Comment 14 Andrew Pinski 2006-09-08 02:49:51 UTC
Fixed.
Comment 15 Richard Biener 2006-10-17 08:27:37 UTC
Subject: Bug 28906

Author: rguenth
Date: Tue Oct 17 08:27:26 2006
New Revision: 117821

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117821
Log:
2006-10-17  Richard Guenther  <rguenther@suse.de>

        Backport from mainline:
        2006-09-07  Andrew Pinski  <pinskia@physics.uc.edu>

        PR C++/28906
        * init.c (build_new_1): Build a distinct type copy
        for the array type that was returned from
        build_cplus_array_type.

        * g++.dg/other/array3.C: New test.
        * g++.dg/other/array4.C: New test.
        * g++.dg/other/array5.C: New test.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/other/array3.C
      - copied unchanged from r116776, trunk/gcc/testsuite/g++.dg/other/array3.C
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/other/array4.C
      - copied unchanged from r116776, trunk/gcc/testsuite/g++.dg/other/array4.C
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/other/array5.C
      - copied unchanged from r116776, trunk/gcc/testsuite/g++.dg/other/array5.C
Modified:
    branches/gcc-4_1-branch/gcc/cp/ChangeLog
    branches/gcc-4_1-branch/gcc/cp/init.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog