[llvm-bugs] [Bug 31050] New: False positive warning of -Waddress-of-packed-member

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Nov 17 16:46:55 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=31050

            Bug ID: 31050
           Summary: False positive warning of -Waddress-of-packed-member
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: yunlian at chromium.org
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

#include <stdio.h>

typedef struct __attribute__ ((packed, aligned(4)))
{
    short a;
    short b;
    int     c;
} A;

int main() {
    A s;
    s.c = 0;
    int* ptr = &s.c;
    printf("%d", *ptr);
    return 0;
}


Struct A is explictly requested to be aligned to 4 bytes. Therefore, A.c is
also aligned to 4 bytes. 

However clang incorrectly complains:

taking address of packed member 'c' of class or structure 'A' may result in an
unaligned pointer value
      [-Waddress-of-packed-member]
    int* ptr = &s.c;

Thanks,

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20161118/f2a7fa4d/attachment.html>


More information about the llvm-bugs mailing list