[PATCH] D105451: [clang] Fix crash when there is an invalid declaration with flag -Wcast-align

Queen Dela Cruz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 6 16:49:58 PDT 2021


qdelacru updated this revision to Diff 356836.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105451/new/

https://reviews.llvm.org/D105451

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/warn-cast-align.c


Index: clang/test/Sema/warn-cast-align.c
===================================================================
--- clang/test/Sema/warn-cast-align.c
+++ clang/test/Sema/warn-cast-align.c
@@ -67,3 +67,11 @@
 FnTy test5(void) {
   return (FnTy)&func5;
 }
+
+void test6() {
+  struct {
+    int hello;
+    doesnotexist world; // expected-error {{unknown type name 'doesnotexist'}}
+  } foo;
+  void **repro = (void **)&foo.hello; // expected-warning {{cast from 'int *' to 'void **' increases required alignment from 4 to 8}}
+}
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14475,7 +14475,8 @@
   case Stmt::MemberExprClass: {
     auto *ME = cast<MemberExpr>(E);
     auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
-    if (!FD || FD->getType()->isReferenceType())
+    if (!FD || FD->getType()->isReferenceType() ||
+        FD->getParent()->isInvalidDecl())
       break;
     Optional<std::pair<CharUnits, CharUnits>> P;
     if (ME->isArrow())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105451.356836.patch
Type: text/x-patch
Size: 1089 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210706/b4ca5d84/attachment.bin>


More information about the cfe-commits mailing list