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]

[Bug c/40305] New: strict aliasing and inlining


The following code (attaching preprocessed one) crashes with gcc 4.3.3 and gcc
4.4.1 (20090529).

Adding noinline attribute to pop() avoids the crash.

Declaring pop(strict foo *f, void** a) as pop(strict foo *f, int **a) avoids
the crash.

Adding -fno-strict-aliasing avoids the crash.

I'm not sure it does breaks strict aliasing (not the same as casting a "void*"
to a "int*" and dereferencing it). gcc does not prints any warning about strict
aliasing.

Compiled with "gcc-4.4.1 -o out test.c -O3", ran with "./out".

#include <string.h>
#include <assert.h>

struct foo {
        int *a;
        void **top;
        void *storage[1];
};

void crash(struct foo *f);

int main() {
        struct foo f;
        int i = 0;

        memset(&f, 0, sizeof(f));

        f.top = &f.storage[1];
        f.a = &i;

        crash(&f);

        assert(f.top == &f.storage[0]);
        assert(f.a == f.storage[0]);
        assert(f.a == NULL);
}

void pop(struct foo *f, void **a) {
        *a = *(--f->top);
}       

__attribute__((noinline))
void crash(struct foo *f) {

        while (f->a) {
                pop(f, (void**)&f->a);
        }       
}


-- 
           Summary: strict aliasing and inlining
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: arnaud dot lb at gmail dot com
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


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


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