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

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 30 17:42:32 PDT 2016


rsmith added inline comments.

================
Comment at: lib/Sema/SemaChecking.cpp:11054
@@ +11053,3 @@
+      auto AlignRecord = Context.getTypeAlignInChars(BaseType);
+      if ((RequiredAlignment > AlignRecord) ||
+          ((Context.toCharUnitsFromBits(
----------------
Suppose I have this:

  struct A { char c; int n; };
  struct __attribute__((packed)) B { A a; } b;
  char *p = &b.a.c;

Here, on the second iteration through this loop, it looks like you'll compute `RequiredAlignment == 4` (from `A`'s alignment of 4), with `AlignRecord == 1` (from the attribute), which would result in calling `Action`. This seems unnecessary, since we know we'll never diagnose this case, because the actual alignment of the field is (at least) the alignment of the original member `c`.


https://reviews.llvm.org/D23657





More information about the cfe-commits mailing list