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/43421] New: strict-aliasing warning from innocent code


Compiling the code below (with -O2 -Wall -std=c99, gcc 4.4.3) gives the warning

apa.c: In function 'f':
cc1: warning: dereferencing pointer '({anonymous})' does break strict-aliasing
rules
apa.c:9: note: initialized from here

which is both unhelpful and dubious - is the code really doing anything wrong
here?

static int g(const void *p) {
        int x;
        __builtin_memcpy(&x, p, sizeof x);
        return x;
}

struct s { char d[5]; };

int f(struct s ss) {
        int t = 0;
        for (int i = 0; i < 2; i++)
                t += g(ss.d);
        return t;
}


-- 
           Summary: strict-aliasing warning from innocent code
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mattiase at acm dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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