On Wed, Apr 13, 2005 at 01:55:07PM -0700, James E Wilson wrote:
> Martin Koegler wrote:
> >          tree type = TREE_TYPE (*node);
> >          tree attr = tree_cons (name, args, TYPE_ATTRIBUTES (type));
> >          tree newtype = build_type_attribute_variant (type, attr);
> >          TYPE_MAIN_VARIANT (newtype) = TYPE_MAIN_VARIANT (type);
> >          TREE_TYPE (*node) = newtype;
> 
> You shouldn't be trying to build your own types in a machine dependent 
> attribute handler function.  The compiler's type system is determined by 
> front-ends mainly, and some middle-end infrastructure, and isn't your 
> domain to mess with.  This stuff is subject to change, at which point 
> your code may break.
> 
> There are a number of subtleties in the type system relating to arrays, 
> so it isn't surprising that you are having trouble with them.  For 
> instance, you can't apply some kinds of type modifiers to array types, 
> they have to be applied to the array element types instead.
> 
> I think the problem with your code is that you are setting 
> TYPE_MAIN_VARIANT to point at the original type.  TYPE_MAIN_VARIANT is 
> only supposed to be used in the presence of type qualifiers like const 
> and volatile, to point at the unqualified type.  But you have no type 
> qualifiers here, and hence TYPE_MAIN_VARIANT should point at itself.

I changed the attribute handler to only return NULL_TREE in any case, but
the result is still the same (using the same gcc core).

The problem seems to be, that in the code
          gen_type_die (type, context_die);

          /* We have to get the type_main_variant here (and pass that to the
             `lookup_type_die' routine) because the ..._TYPE node we have
             might simply be a *copy* of some original type node (where the
             copy was created to help us keep track of typedef names) and
             that copy might have a different TYPE_UID from the original
             ..._TYPE node.  */
          if (TREE_CODE (type) != VECTOR_TYPE)
            mod_type_die = lookup_type_die (type_main_variant (type));

gen_type_type does not change TYPE_SYMTAB_DIE(type), so the following lookup 
fails
(type has the same value as type_main_variant (type)).

gen_type_die does the following in this case:
gen_type_die calls gen_decl_die (TYPE_NAME (type), context_die). gen_decl_die 
calls
gen_typedef_die passing TYPE_NAME(type) (which is the GROUP9_T).
gen_typedef_die immediatly returns, because this type has already been written.

Here dumps of the types, while compiling 
typedef unsigned char GROUP9_T[3];
typedef GROUP9_T EGROUP9_T __attribute ((eeprom));

with dwarf2 debugging output.

When calling, the attribute handler, the type looks so:

Breakpoint 1, m68hc05_handle_eeprom_attribute (node=0xb7f51220, 
name=0xb7f74bc8, args=0x0, flags=0, no_add_attrs=0xbff60c8b "")
    at ../.././gcc/config/m68hc05/m68hc05.c:1690
1690      return NULL_TREE;
(gdb) call debug_tree(*node)
 <array_type 0xb7f14e58 GROUP9_T
    type <integer_type 0xb7f081b0 unsigned char asm_written public unsigned QI
        size <integer_cst 0xb7eff0f0 constant invariant 8>
        unit size <integer_cst 0xb7eff108 constant invariant 1>
        align 8 symtab -1208530080 alias set -1 precision 8 min <integer_cst 
0xb7eff168 0> max <integer_cst 0xb7eff180 255>
        pointer_to_this <pointer_type 0xb7f140d8>>
    BLK
    size <integer_cst 0xb7eff0c0 type <integer_type 0xb7f080d8 bit_size_type> 
constant invariant 24>
    unit size <integer_cst 0xb7eff018 type <integer_type 0xb7f0806c short 
unsigned int> constant invariant 3>
    align 8 symtab -1208567256 alias set -1
    domain <integer_type 0xb7f08000
        type <integer_type 0xb7f0806c short unsigned int public unsigned 
sizetype HI
            size <integer_cst 0xb7eff1f8 constant invariant 16>
            unit size <integer_cst 0xb7eff210 constant invariant 2>
            align 8 symtab -1208530132 alias set -1 precision 16 min 
<integer_cst 0xb7eff240 0> max <integer_cst 0xb7eff1e0 65535>>
        HI size <integer_cst 0xb7eff1f8 16> unit size <integer_cst 0xb7eff210 2>
        align 8 symtab 0 alias set -1 precision 16 min <integer_cst 0xb7eff090 
0> max <integer_cst 0xb7eff210 2>>>

In modified_type_die, the qualified type looks so:
(gdb) call debug_tree(qualified_type)
 <array_type 0xb7f51288 GROUP9_T
    type <integer_type 0xb7f081b0 unsigned char asm_written public unsigned QI
        size <integer_cst 0xb7eff0f0 constant invariant 8>
        unit size <integer_cst 0xb7eff108 constant invariant 1>
        align 8 symtab -1208530080 alias set -1 precision 8 min <integer_cst 
0xb7eff168 0> max <integer_cst 0xb7eff180 255>
        pointer_to_this <pointer_type 0xb7f140d8>>
    BLK
    size <integer_cst 0xb7eff0c0 type <integer_type 0xb7f080d8 bit_size_type> 
constant invariant 24>
    unit size <integer_cst 0xb7eff018 type <integer_type 0xb7f0806c short 
unsigned int> constant invariant 3>
    align 8 symtab 0 alias set -1
    attributes <tree_list 0xb7f77438
        purpose <identifier_node 0xb7f74bc8 eeprom>>
    domain <integer_type 0xb7f08000
        type <integer_type 0xb7f0806c short unsigned int public unsigned 
sizetype HI
            size <integer_cst 0xb7eff1f8 constant invariant 16>
            unit size <integer_cst 0xb7eff210 constant invariant 2>
            align 8 symtab -1208530132 alias set -1 precision 16 min 
<integer_cst 0xb7eff240 0> max <integer_cst 0xb7eff1e0 65535>>
        HI size <integer_cst 0xb7eff1f8 16> unit size <integer_cst 0xb7eff210 2>
        align 8 symtab 0 alias set -1 precision 16 min <integer_cst 0xb7eff090 
0> max <integer_cst 0xb7eff210 2>>>

The typename of the type looks:
(gdb) call debug_tree(type_name)
 <type_decl 0xb7f146c0 GROUP9_T
    type <array_type 0xb7f14e58 GROUP9_T
        type <integer_type 0xb7f081b0 unsigned char asm_written public unsigned 
QI
            size <integer_cst 0xb7eff0f0 constant invariant 8>
            unit size <integer_cst 0xb7eff108 constant invariant 1>
            align 8 symtab -1208530080 alias set -1 precision 8 min 
<integer_cst 0xb7eff168 0> max <integer_cst 0xb7eff180 255>
            pointer_to_this <pointer_type 0xb7f140d8>>
        BLK
        size <integer_cst 0xb7eff0c0 constant invariant 24>
        unit size <integer_cst 0xb7eff018 constant invariant 3>
        align 8 symtab -1208567256 alias set -1
        domain <integer_type 0xb7f08000 type <integer_type 0xb7f0806c short 
unsigned int>
            HI
            size <integer_cst 0xb7eff1f8 constant invariant 16>
            unit size <integer_cst 0xb7eff210 constant invariant 2>
            align 8 symtab 0 alias set -1 precision 16 min <integer_cst 
0xb7eff090 0> max <integer_cst 0xb7eff210 2>>>
    asm_written VOID file x.c line 1
    align 1
    result <array_type 0xb7f11144 type <integer_type 0xb7f081b0 unsigned char>
        asm_written BLK size <integer_cst 0xb7eff0c0 24> unit size <integer_cst 
0xb7eff018 3>
        align 8 symtab -1208530236 alias set -1 domain <integer_type 
0xb7f08000>>>

DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)) is
 <array_type 0xb7f11144
    type <integer_type 0xb7f081b0 unsigned char asm_written public unsigned QI
        size <integer_cst 0xb7eff0f0 constant invariant 8>
        unit size <integer_cst 0xb7eff108 constant invariant 1>
        align 8 symtab -1208530080 alias set -1 precision 8 min <integer_cst 
0xb7eff168 0> max <integer_cst 0xb7eff180 255>
        pointer_to_this <pointer_type 0xb7f140d8>>
    asm_written BLK
    size <integer_cst 0xb7eff0c0 type <integer_type 0xb7f080d8 bit_size_type> 
constant invariant 24>
    unit size <integer_cst 0xb7eff018 type <integer_type 0xb7f0806c short 
unsigned int> constant invariant 3>
    align 8 symtab -1208530236 alias set -1
    domain <integer_type 0xb7f08000
        type <integer_type 0xb7f0806c short unsigned int public unsigned 
sizetype HI
            size <integer_cst 0xb7eff1f8 constant invariant 16>
            unit size <integer_cst 0xb7eff210 constant invariant 2>
            align 8 symtab -1208530132 alias set -1 precision 16 min 
<integer_cst 0xb7eff240 0> max <integer_cst 0xb7eff1e0 65535>>
        HI size <integer_cst 0xb7eff1f8 16> unit size <integer_cst 0xb7eff210 2>
        align 8 symtab 0 alias set -1 precision 16 min <integer_cst 0xb7eff090 
0> max <integer_cst 0xb7eff210 2>>>

The TYPE_MAIN_VARIANT is:
(gdb) call debug_tree(type->type.main_variant)
 <array_type 0xb7f51288 GROUP9_T
    type <integer_type 0xb7f081b0 unsigned char asm_written public unsigned QI
        size <integer_cst 0xb7eff0f0 constant invariant 8>
        unit size <integer_cst 0xb7eff108 constant invariant 1>
        align 8 symtab -1208530080 alias set -1 precision 8 min <integer_cst 
0xb7eff168 0> max <integer_cst 0xb7eff180 255>
        pointer_to_this <pointer_type 0xb7f140d8>>
    BLK
    size <integer_cst 0xb7eff0c0 type <integer_type 0xb7f080d8 bit_size_type> 
constant invariant 24>
    unit size <integer_cst 0xb7eff018 type <integer_type 0xb7f0806c short 
unsigned int> constant invariant 3>
    align 8 symtab 0 alias set -1
    attributes <tree_list 0xb7f77438
        purpose <identifier_node 0xb7f74bc8 eeprom>>
    domain <integer_type 0xb7f08000
        type <integer_type 0xb7f0806c short unsigned int public unsigned 
sizetype HI
            size <integer_cst 0xb7eff1f8 constant invariant 16>
            unit size <integer_cst 0xb7eff210 constant invariant 2>
            align 8 symtab -1208530132 alias set -1 precision 16 min 
<integer_cst 0xb7eff240 0> max <integer_cst 0xb7eff1e0 65535>>
        HI size <integer_cst 0xb7eff1f8 16> unit size <integer_cst 0xb7eff210 2>
        align 8 symtab 0 alias set -1 precision 16 min <integer_cst 0xb7eff090 
0> max <integer_cst 0xb7eff210 2>>>

mfg Martin Kögler
[EMAIL PROTECTED]
PS: Please CC me on replies.

Reply via email to