Author: rogfer01 Date: Thu Dec 7 01:23:50 2017 New Revision: 320017 URL: http://llvm.org/viewvc/llvm-project?rev=320017&view=rev Log: 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 Modified: cfe/trunk/lib/Sema/SemaChecking.cpp cfe/trunk/test/SemaCXX/address-packed.cpp Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=320017&r1=320016&r2=320017&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Dec 7 01:23:50 2017 @@ -12399,8 +12399,9 @@ void Sema::DiscardMisalignedMemberAddres 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); } } Modified: cfe/trunk/test/SemaCXX/address-packed.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/address-packed.cpp?rev=320017&r1=320016&r2=320017&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/address-packed.cpp (original) +++ cfe/trunk/test/SemaCXX/address-packed.cpp Thu Dec 7 01:23:50 2017 @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits