[PATCH] D136018: [Clang] Fix crash when checking misaligned member with dependent type
Jun Zhang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 18 06:07:07 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
junaire marked an inline comment as done.
Closed by commit rG2946b252993d: [Clang] Fix crash when checking misaligned member with dependent type (authored by junaire).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D136018/new/
https://reviews.llvm.org/D136018
Files:
clang/lib/Sema/SemaChecking.cpp
clang/test/SemaCXX/misaligned-member-with-depdent-type.cpp
Index: clang/test/SemaCXX/misaligned-member-with-depdent-type.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/misaligned-member-with-depdent-type.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct __attribute__((packed)) {
+ unsigned options;
+ template <typename T>
+ void getOptions() {
+ (T *)&options;
+ }
+ template <typename U>
+ void getOptions2() {
+ (U)&options;
+ }
+} s;
+
+struct __attribute__((packed)) { // expected-error {{anonymous structs and classes must be class members}}
+ unsigned options ;
+ template <typename T> getOptions() // expected-error {{a type specifier is required for all declarations}}
+ {
+ (T *) & options;
+ }
+};
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -17387,15 +17387,15 @@
void Sema::DiscardMisalignedMemberAddress(const Type *T, Expr *E) {
E = E->IgnoreParens();
- if (!T->isPointerType() && !T->isIntegerType())
+ if (!T->isPointerType() && !T->isIntegerType() && !T->isDependentType())
return;
if (isa<UnaryOperator>(E) &&
cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf) {
auto *Op = cast<UnaryOperator>(E)->getSubExpr()->IgnoreParens();
if (isa<MemberExpr>(Op)) {
- auto MA = llvm::find(MisalignedMembers, MisalignedMember(Op));
+ auto *MA = llvm::find(MisalignedMembers, MisalignedMember(Op));
if (MA != MisalignedMembers.end() &&
- (T->isIntegerType() ||
+ (T->isDependentType() || T->isIntegerType() ||
(T->isPointerType() && (T->getPointeeType()->isIncompleteType() ||
Context.getTypeAlignInChars(
T->getPointeeType()) <= MA->Alignment))))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136018.468510.patch
Type: text/x-patch
Size: 1914 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221018/52942bad/attachment.bin>
More information about the cfe-commits
mailing list