Bug 29436 - [4.0/4.1/4.2/4.3 Regression] ICE in modified_type_die
Summary: [4.0/4.1/4.2/4.3 Regression] ICE in modified_type_die
Status: RESOLVED DUPLICATE of bug 28834
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.1.1
: P1 normal
Target Milestone: 4.1.3
Assignee: Jason Merrill
URL:
Keywords: ice-on-valid-code
: 30628 32326 (view as bug list)
Depends on: 28834
Blocks:
  Show dependency treegraph
 
Reported: 2006-10-12 00:44 UTC by Albert Cahalan
Modified: 2008-02-07 19:17 UTC (History)
25 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 3.3.5 3.4.0 3.3.3 4.0.0 4.1.0 4.1.1 4.1.2 4.2.0
Last reconfirmed: 2007-11-02 13:50:43


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Albert Cahalan 2006-10-12 00:44:10 UTC
$ cat ice.c
typedef struct S {
        unsigned long flags;
}S_t;
struct dp {
        S_t c;
};
typedef S_t __attribute__((__may_alias__)) cmonkey;
static void handler(void *vp)
{
        struct dp *dp;
        cmonkey *cm = vp;
        dp->c = *cm;
}
$ gcc -m32 -std=gnu99 -W -Wall -g3 -c ice.c 
ice.c:7: internal compiler error: in modified_type_die, at dwarf2out.c:8463
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/ccakn2Ps.out file, please attach this to your bugreport.
$
Comment 1 Albert Cahalan 2006-10-12 01:20:41 UTC
Other ways to ICE gcc:

///////////////////////
typedef struct S {
        unsigned long flags;
}S_t;
typedef S_t __attribute__((__may_alias__)) cmonkey;
S_t *handler(void *vp)
{
        cmonkey *cm = vp;
        return cm;
}
////////////////////////
typedef struct S {
        unsigned long flags;
}S_t;
typedef S_t __attribute__((__may_alias__)) cmonkey;
S_t handler(void *vp)
{
        cmonkey *cm = vp;
        return *cm;
}
//////////////////////
typedef struct S {
        unsigned long flags;
}S_t;
typedef S_t __attribute__((__may_alias__)) cmonkey;
int handler(void *vp)
{
        S_t dp;
        cmonkey *cm = vp;
        dp = *cm;
}
///////////////////
typedef struct S {
        unsigned long flags;
}S_t;
typedef S_t __attribute__((__may_alias__)) cmonkey;
int handler(void *vp)
{
        S_t * dp;
        cmonkey *cm = vp;
        *dp = *cm;
}
////////////////////////

Besides a fix, I could use some workaround suggestions.
This itself is an attempted workaround for a suspected
bug involving memcpy, so that won't do.
Comment 2 Albert Cahalan 2006-10-12 01:25:51 UTC
Hey, I don't even need to use the types. The typedef alone
is enough to ICE gcc:

typedef struct S {
        unsigned long flags;
}S_t;
typedef S_t __attribute__((__may_alias__)) cmonkey;
int main(int argc, char *argv[]){
}
Comment 3 Andrew Pinski 2006-10-12 04:09:08 UTC
Confirmed, this is an user visable regression in that the code did not ICE in 3.2.3 even though the attribute is ignored.
Comment 4 Richard Biener 2006-10-17 09:37:35 UTC
I cannot reproduce this any longer with 4.2:

trunk-g/gcc> ./cc1 -quiet t.i -g3 -std=gnu99 -W -Wall -m32
t.i: In function 'handler':
t.i:12: error: incompatible types in assignment

though cc1plus ICEs (differently) now:

trunk-g/gcc> ./cc1plus -quiet t.i -g3 -std=gnu99 -W -Wall -m32
cc1plus: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
t.i: In function 'void handler(void*)':
t.i:11: error: invalid conversion from 'void*' to 'cmonkey*'
t.i:12: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

Starting program: /abuild/rguenther/trunk-g/gcc/cc1plus -quiet t.i -g3 -std=gnu99 -W -Wall -m32
cc1plus: warning: command line option "-std=gnu99" is valid for C/ObjC but not for C++
t.i: In function 'void handler(void*)':
t.i:11: error: invalid conversion from 'void*' to 'cmonkey*'

Program received signal SIGSEGV, Segmentation fault.
0x00000000005aa1b8 in decl_namespace_context (decl=0x2b8e53df20b0)
    at /space/rguenther/src/svn/trunk/gcc/cp/tree.c:1391
1391            decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl));
(gdb) print decl->type.main_variant->common.chain
$1 = (tree) 0x0
Comment 5 Richard Biener 2006-10-17 12:33:32 UTC
We're getting a type variant with the attribute created which shares TYPE_NAME which in turn points back to the wrong (un-attributed) type.  So we do not create a die for the attributed type.

This can be worked around with

Index: tree.c
===================================================================
*** tree.c      (revision 117822)
--- tree.c      (working copy)
*************** build_type_attribute_variant (tree ttype
*** 3310,3315 ****
--- 3310,3320 ----
  
        ntype = type_hash_canon (hashcode, ntype);
        ttype = build_qualified_type (ntype, TYPE_QUALS (ttype));
+       if (TYPE_NAME (ttype))
+       {
+           TYPE_NAME (ttype) = copy_node (TYPE_NAME (ttype));
+           TREE_TYPE (TYPE_NAME (ttype)) = ttype;
+       }
      }
  
    return ttype;

after which we have the same situation as currently on mainline (cc1plus
segfaults, cc1 is fine).

I guess something fixed this on the mainline - any idea what?
Comment 6 Richard Biener 2006-10-17 12:37:58 UTC
Janis, can you hunt this on the mainline?  I want to know at what point we changed
from the ICE in dwarf2out to issuing an error (for cc1).

Thanks!
Comment 7 Andrew Pinski 2006-10-17 15:31:28 UTC
(In reply to comment #6)
> Janis, can you hunt this on the mainline?  I want to know at what point we
> changed
> from the ICE in dwarf2out to issuing an error (for cc1).
We still ICE for the testcase in comment #2.
Comment 8 Albert Cahalan 2006-10-17 21:05:11 UTC
In case comment #4 was meant to imply that a non-ICE error is fine:

Please note that the crashing code is very nearly the __may_alias__ example given in the gcc documentation. The main difference is that I used a struct. This really needs to work for things like malloc arena headers, so the "t.i:12: error: incompatible types in assignment" and "t.i:11: error: invalid conversion from 'void*' to 'cmonkey*'" stuff is no good.
Comment 9 Albert Cahalan 2006-10-18 00:57:40 UTC
I did it again, but this time in splice_child_die.

$ gcc -g3 -Os -W -Wall -std=gnu99 jji.c
jji.c:3: warning: useless storage class specifier in empty declaration
jji.c:5: internal compiler error: in splice_child_die, at dwarf2out.c:5492
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/ccg46xph.out file, please attach this to yo
ur bugreport.
$ cat jji.c
typedef struct S {
        unsigned long flags;
};

typedef struct S __attribute__((__may_alias__)) cmonkey;

int main(int argc,char *argv[]){
        return 0;
}
$ 
Comment 10 Albert Cahalan 2006-10-18 01:01:23 UTC
An enum will crash it too. This one is in modified_type_die like the original.

$ gcc -g3 -Os -W -Wall -std=gnu99 kku.c
kku.c:3: internal compiler error: in modified_type_die, at dwarf2out.c:8463
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/ccksgAgj.out file, please attach this to your bugreport.
$ cat kku.c
typedef enum E {foo, bar} E;

typedef E __attribute__((__may_alias__)) cmonkey;

int main(int argc,char *argv[]){
        return 0;
}
$ 

Comment 11 Janis Johnson 2006-10-18 16:27:46 UTC
A regression hunt on powerpc-linux using the testcase from the submitter's description showed that it went from an ICE to an error with this patch:

    http://gcc.gnu.org/viewcvs?view=rev&rev=110925

    r110925 | geoffk | 2006-02-13 21:17:59 +0000 (Mon, 13 Feb 2006)

Let me know if other reghunts would be useful here.
Comment 12 Geoff Keating 2006-10-18 17:08:32 UTC
Isn't this a dup of bug 28834?
Comment 13 Andrew Pinski 2006-10-18 17:19:57 UTC
(In reply to comment #12)
> Isn't this a dup of bug 28834?

Related for sure, dup unknown at this point.
Comment 14 Richard Biener 2007-01-29 16:52:57 UTC
*** Bug 30628 has been marked as a duplicate of this bug. ***
Comment 15 Gabriel Dos Reis 2007-02-03 20:34:37 UTC
won't fix in GCC-4.0.x.  Adjusting milestone.
Comment 16 Andrew Pinski 2007-06-13 19:27:04 UTC
*** Bug 32326 has been marked as a duplicate of this bug. ***
Comment 17 Jason Merrill 2007-11-19 21:24:58 UTC
is a dup of 28834.

*** This bug has been marked as a duplicate of 28834 ***
Comment 18 Jason Merrill 2007-11-19 21:35:24 UTC
Subject: Bug 29436

Author: jason
Date: Mon Nov 19 21:35:13 2007
New Revision: 130297

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=130297
Log:
        PR debug/29436, c/32326
        * tree.c (build_type_attribute_qual_variant): Refuse to make
        a distinct copy of a struct/enum type.  Use build_distinct_type_copy.
        * doc/extend.texi (Type Attributes): Don't encourage people to add
        attributes to struct/enum types in a typedef.  Fix
        transparent_union example.

        * tree-inline.c (remap_type_1): Remove code that's redundant with
        remap_type.
        (build_duplicate_type): Set id.copy_decl.
        * c-common.c (handle_transparent_union_attribute): Simplify logic.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-common.c
    trunk/gcc/doc/extend.texi
    trunk/gcc/testsuite/gcc.c-torture/execute/mayalias-2.c
    trunk/gcc/testsuite/gcc.c-torture/execute/mayalias-3.c
    trunk/gcc/tree-inline.c
    trunk/gcc/tree.c