]> granicus.if.org Git - clang/commitdiff
Ignore pointers to incomplete types when diagnosing misaligned addresses
authorRoger Ferrer Ibanez <roger.ferreribanez@arm.com>
Thu, 7 Dec 2017 09:23:50 +0000 (09:23 +0000)
committerRoger Ferrer Ibanez <roger.ferreribanez@arm.com>
Thu, 7 Dec 2017 09:23:50 +0000 (09:23 +0000)
This is a fix for PR35509 in which we crash because we attempt to compute the
alignment of an incomplete type.

Differential Revision: https://reviews.llvm.org/D40895

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@320017 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/SemaCXX/address-packed.cpp

index cdf162da6d118199997e62fd89c969368f2be926..6dec8d1730130070a37cc9333879e6002f1b25a7 100644 (file)
@@ -12399,8 +12399,9 @@ void Sema::DiscardMisalignedMemberAddress(const Type *T, Expr *E) {
                           MisalignedMember(Op));
       if (MA != MisalignedMembers.end() &&
           (T->isIntegerType() ||
-           (T->isPointerType() &&
-            Context.getTypeAlignInChars(T->getPointeeType()) <= MA->Alignment)))
+           (T->isPointerType() && (T->getPointeeType()->isIncompleteType() ||
+                                   Context.getTypeAlignInChars(
+                                       T->getPointeeType()) <= MA->Alignment))))
         MisalignedMembers.erase(MA);
     }
   }
index 308c4858cd5088292f3a23a5639b8ca150f336fc..f0d1496fd8928614ebb9994aa7c5169a60c5481e 100644 (file)
@@ -112,3 +112,12 @@ void g1() {
   S<float> s3;
   s3.get(); // expected-note {{in instantiation of member function 'S<float>::get'}}
 }
+
+// PR35509
+typedef long L1;
+struct Incomplete;
+struct S2 {
+  L1 d;
+  Incomplete *e() const;
+} __attribute__((packed));
+Incomplete *S2::e() const { return (Incomplete *)&d; } // no-warning