From e767a3be6ef2b4fc3d64155f9020b844d4bad61b Mon Sep 17 00:00:00 2001 From: Roger Ferrer Ibanez Date: Thu, 7 Dec 2017 09:23:50 +0000 Subject: [PATCH] Ignore pointers to incomplete types when diagnosing misaligned addresses 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 | 5 +++-- test/SemaCXX/address-packed.cpp | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index cdf162da6d..6dec8d1730 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -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); } } diff --git a/test/SemaCXX/address-packed.cpp b/test/SemaCXX/address-packed.cpp index 308c4858cd..f0d1496fd8 100644 --- a/test/SemaCXX/address-packed.cpp +++ b/test/SemaCXX/address-packed.cpp @@ -112,3 +112,12 @@ void g1() { S s3; s3.get(); // expected-note {{in instantiation of member function 'S::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 -- 2.50.1