public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/24178]  New: GCC 4.0/4.1 generates code that produces unaligned access exceptions
@ 2005-10-03 18:36 tsv at solvo dot ru
  2005-10-03 19:03 ` [Bug middle-end/24178] " pinskia at gcc dot gnu dot org
                   ` (21 more replies)
  0 siblings, 22 replies; 23+ messages in thread
From: tsv at solvo dot ru @ 2005-10-03 18:36 UTC (permalink / raw)
  To: gcc-bugs

gcc version 4.0.1 20050727 (Red Hat 4.0.1-5)
gcc version 4.0.2
GNU C version 4.1.0 20050927 (experimental) (alpha-unknown-linux-gnu)

All tested versions generate the same wrong code for the following testcase
(EV4/EV5 only with -O2 optimization):
#include <stdio.h>
#include <stddef.h>

typedef struct Foo
{
   void *p1;
   long p2;
   void *p3;
   unsigned char p4;
   char p5[3];
} Foo;

#ifdef __DECC
#undef offsetof
#define offsetof(TYPE, MEMBER) ((char *)(&(((TYPE *)0)-> MEMBER )))
#endif


void foo(const char *fn)
{
   Foo *p;

   p = (Foo *)(fn - offsetof(Foo, p5));
   p->p4 = 1;
}

int main(int argc, char **argv)
{
   Foo p;
#if defined(__alpha__) && defined(__linux__)
# include <asm/sysinfo.h>
# include <asm/unistd.h>

   unsigned int buf[2] =
     {
         SSIN_UACPROC, UAC_SIGBUS | UAC_NOPRINT
     };
   syscall(__NR_osf_setsysinfo, SSI_NVPAIRS, buf, 1, 0, 0, 0);
#endif

   printf("Offset - %d\n", offsetof(Foo, p5));

   foo(p.p5);
}

The assembler for the function "foo" is:
        .globl foo
        .ent foo
$foo..ng:
foo:
        .frame $30,0,$26,0
        .prologue 0
        ldah $2,256($31)
        ldl $1,-4($16)
        zapnot $1,247,$1
        bis $1,$2,$2
        stl $2,-4($16)
        ret $31,($26),1
        .end foo

The offset of "p5" member is 25 bytes, but compiler thinks that "p5" is aligned
in "foo" function and issue "ldl" on unaligned address.
DECC compiler generates "ldl $1, -1($16)" instruction.

It might be not very good coding practice, but it taken from Mozilla source.

Thank you.


-- 
           Summary: GCC 4.0/4.1 generates code that produces unaligned
                    access exceptions
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tsv at solvo dot ru
 GCC build triplet: alpha-*-linux-gnu
  GCC host triplet: alpha-*-linux-gnu
GCC target triplet: alpha-*-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24178


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2010-08-06 20:00 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-03 18:36 [Bug c/24178] New: GCC 4.0/4.1 generates code that produces unaligned access exceptions tsv at solvo dot ru
2005-10-03 19:03 ` [Bug middle-end/24178] " pinskia at gcc dot gnu dot org
2005-10-03 20:48 ` falk at debian dot org
2005-10-04  5:59 ` tsv at solvo dot ru
2005-10-04  7:32 ` falk at debian dot org
2005-10-04  7:36 ` [Bug middle-end/24178] [4.0/4.1 regression] " falk at debian dot org
2005-10-14 13:30 ` tsv at solvo dot ru
2005-10-15 15:04 ` falk at debian dot org
2005-10-22 21:59 ` pinskia at gcc dot gnu dot org
2005-10-22 22:42 ` falk at debian dot org
2005-10-23 18:22 ` tsv at solvo dot ru
2005-10-23 18:29 ` [Bug target/24178] " pinskia at gcc dot gnu dot org
2005-10-30 23:32 ` pinskia at gcc dot gnu dot org
2005-11-02  7:13 ` rth at gcc dot gnu dot org
2005-11-02  7:43 ` rth at gcc dot gnu dot org
2005-11-02 18:20 ` rth at gcc dot gnu dot org
2005-11-02 22:26 ` tsv at solvo dot ru
2005-11-03  0:33 ` rth at gcc dot gnu dot org
2005-11-03  0:34 ` rth at gcc dot gnu dot org
2010-08-06 19:33 ` ubizjak at gmail dot com
2010-08-06 19:44 ` [Bug target/24178] [4.6 Regression] " ubizjak at gmail dot com
2010-08-06 19:46 ` [Bug target/24178] [4.0/4.1 regression] " rguenth at gcc dot gnu dot org
2010-08-06 20:00 ` ubizjak at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).