[llvm-branch-commits] [clang] a71877e - [clang] Do not crash when CXXRecordDecl has a non-CXXRecordDecl base.

Adam Czachorowski via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 14 12:32:39 PST 2021


Author: Adam Czachorowski
Date: 2021-01-14T21:20:06+01:00
New Revision: a71877edfbb7094584f6d20d93f6091e7d374024

URL: https://github.com/llvm/llvm-project/commit/a71877edfbb7094584f6d20d93f6091e7d374024
DIFF: https://github.com/llvm/llvm-project/commit/a71877edfbb7094584f6d20d93f6091e7d374024.diff

LOG: [clang] Do not crash when CXXRecordDecl has a non-CXXRecordDecl base.

This can happen on some invalid code, like the included test case.

Differential Revision: https://reviews.llvm.org/D94704

Added: 
    

Modified: 
    clang/lib/Sema/SemaDeclCXX.cpp
    clang/test/SemaTemplate/temp_class_spec.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 27679ac6f8d3..8bfaa46162bc 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -5520,8 +5520,9 @@ Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
 
   // Bases.
   for (const auto &Base : ClassDecl->bases()) {
-    // Bases are always records in a well-formed non-dependent class.
     const RecordType *RT = Base.getType()->getAs<RecordType>();
+    if (!RT)
+      continue;
 
     // Remember direct virtual bases.
     if (Base.isVirtual()) {

diff  --git a/clang/test/SemaTemplate/temp_class_spec.cpp b/clang/test/SemaTemplate/temp_class_spec.cpp
index 8a07fd7292c2..f92c52e9624e 100644
--- a/clang/test/SemaTemplate/temp_class_spec.cpp
+++ b/clang/test/SemaTemplate/temp_class_spec.cpp
@@ -361,3 +361,17 @@ namespace PR6181 {
   };
   
 }
+
+// Check that we do not crash on invalid code that leads to invalid base.
+namespace {
+template <typename X>
+class Foo {};
+
+template <int Y>
+class Bar;
+
+template <typename Z>
+class Bar<0> : public Foo<Z> { // expected-error{{partial specialization of 'Bar' does not use any of its template parameters}}
+  Bar() : Foo<Z>() {}
+};
+} // namespace


        


More information about the llvm-branch-commits mailing list