This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c/8023: Miscompilation of function grokdeclarator in c-decl.c at -O1 and above


>Number:         8023
>Category:       c
>Synopsis:       Miscompilation of function grokdeclarator in c-decl.c at -O1 and above
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Tue Sep 24 09:46:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Dave Anglin
>Release:        gcc 3.2 and 3.3 (experimental)
>Organization:
>Environment:
hppa64-hp-hpux11.00
>Description:
The following test program

  char short *x23;

should warn that a "long or short" was "specified with
char".  In trying to determine why the compiler doesn't
warn, I found that the variable specbits is treated in
inconsistently.

The type of specbits is int (32 bits) but it appears that
the compiler decides to treat it as a long (64 bits).  However,
there is a mixup in the subreg access.  In some cases, it
is accessed at offset 4 (correct) and in other cases it
is accessed at offset 0 (incorrect).

We have the following code and corresponding rtl at -O1
for the initialization of specbits at 387 of c-decl.c:

  specbits |= 1 << (int) i;

(note 511 510 512 ("grokdeclarator.c") 387)

(insn 512 511 513 0000000000000000 (set (reg:SI 215)
        (minus:SI (const_int 31 [0x1f])
            (subreg:SI (reg/v:DI 182) 4))) -1 (nil)
    (nil))

(insn 513 512 514 0000000000000000 (set (reg:SI 214)
        (ashift:SI (const_int 1 [0x1])
            (minus:SI (const_int 31 [0x1f])
                (reg:SI 215)))) -1 (nil)
    (expr_list:REG_EQUAL (ashift:SI (const_int 1 [0x1])
            (subreg:SI (reg/v:DI 182) 4))
        (nil)))

(insn 514 513 515 0000000000000000 (set (reg:SI 216)
        (ior:SI (reg:SI 214)
            (subreg/s:SI (reg/v:DI 74) 4))) -1 (nil)
    (nil))

(insn 515 514 516 0000000000000000 (set (reg/v:DI 74)
        (sign_extend:DI (reg:SI 216))) -1 (nil)
    (nil))

Then, up to line 478, specbits is accessed at offset 4
in DI 74, but a line 478

      if ((specbits & 1 << (int) RID_LONG)
          && (specbits & 1 << (int) RID_SHORT))
        error ("both long and short specified for `%s'", name);

the following rtl is generated

(note 882 881 883 ("grokdeclarator.c") 478)

(insn 883 882 884 0000000000000000 (set (reg:SI 328)
        (const_int 132 [0x84])) -1 (nil)
    (nil))

(insn 884 883 885 0000000000000000 (set (reg:SI 327)
        (and:SI (subreg:SI (reg/v:DI 74) 0)
            (reg:SI 328))) -1 (nil)
    (nil))

So, the generated assembly code ands SI 327 with the
high-order 32 bits instead of the low-order 32 bits
of DI 74.  This is why the proper warnings are not
being generated.

This doesn't appear to be a regression as 3.2 has the
same behavior as 3.3.  The code generated at -O0 is
ok.
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]