[PATCH] D23657: Remove some false positives when taking the address of packed members

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 4 09:16:13 PDT 2016


arphaman added a comment.

Thanks for working on this!

This patch fixes a couple of our internal warnings that shouldn't be presented. I included a code sample that reproduces our warnings,  would you mind adding some code to the test case that's similar to the sample below?

  typedef	struct {
    uint32_t msgh_bits;
    uint32_t msgh_size;
    int32_t msgh_voucher_port;
    int32_t msgh_id;
  } S10Header;
  
  typedef struct {
      uint32_t t;
      uint64_t m;
      uint32_t p;
      union {
          struct {
              uint32_t a;
              double z;
          } __attribute__ ((aligned (8), packed)) a;
          struct {
              uint32_t b;
              double z;
              uint32_t a;
          } __attribute__ ((aligned (8), packed)) b;
      };
  } __attribute__ ((aligned (8), packed)) S10Data;
  
  typedef struct {
    S10Header hdr;
    uint32_t size;
    uint8_t count;
    S10Data data[] __attribute__ ((aligned (8)));
  } __attribute__ ((aligned (8), packed)) S10;
  
  void foo(S10Header *hdr);
  void bar(S10 *s) {
    foo(&s->hdr); // No warning expected.
  }

Btw, slightly off-topic, but I noticed that the declaration `DiagnoseMisalignedMembers` in the header has a doc comment that violates the 80 chars rule. I committed a fix in r283228.


https://reviews.llvm.org/D23657





More information about the cfe-commits mailing list