Bug 28373 - C code gives "unaligned access"
Summary: C code gives "unaligned access"
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: regression (show other bugs)
Version: 4.1.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-13 20:26 UTC by Kate Minola
Modified: 2006-07-13 22:44 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kate Minola 2006-07-13 20:26:37 UTC
/*  gcc-4.1.1 gives "unaligned access" on alphaev68-dec-osf5.1b
    regression from gcc-3.4.4

% gcc -v
Using built-in specs.
Target: alphaev68-dec-osf5.1b
Configured with: /usr/local/gcc-4.1.1/src/gcc-4.1.1/configure
--enable-languages=c --prefix=/usr/local/gcc-4.1.1/alpha-OSF1-V5
Thread model: posix
gcc version 4.1.1
%
%
gcc -o foo foo.c
% foo
Unaligned access pid=141992 <foo> va=0x11fffbffc pc=0x12000115c ra=0x1200011a0 inst=0x
9d420000
% 
*/

typedef struct
{
    double    d;
} aa;

int foo(v)
aa *v;
{
    v->d = (double) 1;

  return 0;
}

int main()
{
    int cc[1];
    int i1;
    int i2;
    int i3;
    int i4;
    int i5;
    int i6;
    int i7;   /* if remove this line, then no problem! */

    foo(cc);  /* says "unaligned access" */

    return 0;
}
Comment 1 Falk Hueffner 2006-07-13 20:58:52 UTC
The conversion from int* to aa* is only defined if the pointer is correctly
aligned. Even if it was correctly aligned, dereferencing this pointer is 
undefined behavior (see -Wstrict-aliasing documentation). So this is not a gcc
bug.
Comment 2 Andrew Pinski 2006-07-13 22:44:56 UTC
More than that:
    int cc[1];
    foo(cc);  /* says "unaligned access" */
int foo(v)
aa *v;

You are also violating C aliasing rules and also violating an even more fundental problem in that the struct aa will not fit in cc.