[PATCH] D99165: [clang] Fix a crash on checkDestructorReference.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 23 03:27:16 PDT 2021


hokein created this revision.
hokein added a reviewer: sammccall.
hokein requested review of this revision.
Herald added a project: clang.

The LookupDestructor requires a complete class definition, the
callside (checkDesturctorReference) didnt't guarantee that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99165

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp


Index: clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp
===================================================================
--- clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp
+++ clang/test/SemaCXX/cxx0x-initializer-aggregates.cpp
@@ -133,3 +133,11 @@
 namespace PR24816 {
   struct { int i; } ne = {{0, 1}}; // expected-error{{excess elements in scalar initializer}}
 }
+
+namespace no_crash {
+template <class T>
+class Foo {};
+void test(int foo) {
+  Foo<int> array[foo] = {0}; // expected-error {{variable-sized object may not be initialized}}
+}
+}
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -1831,6 +1831,8 @@
   auto *CXXRD = ElementType->getAsCXXRecordDecl();
   if (!CXXRD)
     return false;
+  if (!CXXRD->isCompleteDefinition())
+    return false;
 
   CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(CXXRD);
   SemaRef.CheckDestructorAccess(Loc, Destructor,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99165.332592.patch
Type: text/x-patch
Size: 1016 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210323/b7c7eedd/attachment.bin>


More information about the cfe-commits mailing list