[llvm-bugs] [Bug 22821] usage of pointers to packed struct members should trigger warning

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Aug 17 00:34:31 PDT 2016


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

Roger Ferrer Ibanez <roger.ferreribanez at arm.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from Roger Ferrer Ibanez <roger.ferreribanez at arm.com> ---
clang does not accept #pragma pack but instead uses __attribute__((packed)).
The example above could be rewritten as


#include <stdio.h>
typedef struct __attribute__((packed)) A { int v; } unaligned;
void print(int *x) { printf("%d\n", *x); }
void test1(unaligned *p) { print(&(p->v)); }
void test2(unaligned *p) {
  int *x = &(p->v);
  printf("%d\n", *x);
}

As of https://reviews.llvm.org/rL278483 clang diagnoses this case

clang -c prova.c -Wall
prova.c:5:36: warning: taking address of packed member 'v' of class or
structure 'A' may result in an unaligned pointer value
[-Waddress-of-packed-member]
void test1(unaligned *p) { print(&(p->v)); }
                                   ^~~~
prova.c:7:14: warning: taking address of packed member 'v' of class or
structure 'A' may result in an unaligned pointer value
[-Waddress-of-packed-member]
  int *x = &(p->v);
             ^~~~
2 warnings generated.

So I think we can consider this ticket as fixed

-- 
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/20160817/8010289b/attachment.html>


More information about the llvm-bugs mailing list