[clang] f0084c3 - [AST][RecoveryExpr] Fix a crash: don't attach error-type base specifiers.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 24 01:14:12 PDT 2020


Author: Haojian Wu
Date: 2020-06-24T10:13:46+02:00
New Revision: f0084c3bcbc2f2e17ab1a24d19ac6738eb4c4263

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

LOG: [AST][RecoveryExpr] Fix a crash: don't attach error-type base specifiers.

Summary:
otherwise we'll run into code path which expects a good base specifiers,
and lead to crashes.

The crash only occurs in template instantiations (in non-template case,
the bad base specifiers are dropped during parsing.)

crash stacktrace:

```
clang: llvm-project/clang/lib/Sema/SemaInit.cpp:7864: clang::ExprResult clang::InitializationSequence::Perform(clang::Sema &, const clang::InitializedEntity &, const clang::InitializationKind &, clang::MultiExprArg, clang::QualType *): Assertion `Kind.getKind() == InitializationKind::IK_Copy || Kind.isExplicitCast() || Kind.getKind() == InitializationKind::IK_DirectList' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
```

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: cfe-commits

Tags: #clang

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

Added: 
    clang/test/SemaCXX/invalid-template-base-specifier.cpp

Modified: 
    clang/lib/Sema/SemaDeclCXX.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 5e849a190760..a2ada2053534 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -2426,7 +2426,10 @@ Sema::CheckBaseSpecifier(CXXRecordDecl *Class,
                          TypeSourceInfo *TInfo,
                          SourceLocation EllipsisLoc) {
   QualType BaseType = TInfo->getType();
-
+  if (BaseType->containsErrors()) {
+    // Already emitted a diagnostic when parsing the error type.
+    return nullptr;
+  }
   // C++ [class.union]p1:
   //   A union shall not have base classes.
   if (Class->isUnion()) {

diff  --git a/clang/test/SemaCXX/invalid-template-base-specifier.cpp b/clang/test/SemaCXX/invalid-template-base-specifier.cpp
new file mode 100644
index 000000000000..a788cdb859eb
--- /dev/null
+++ b/clang/test/SemaCXX/invalid-template-base-specifier.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -frecovery-ast -verify %s
+
+bool Foo(int *); // expected-note {{candidate function not viable}}
+
+template <typename T>
+struct Crash : decltype(Foo(T())) { // expected-error {{no matching function for call to 'Foo'}}
+  Crash(){};
+};
+
+void test() { Crash<int>(); } // expected-note {{in instantiation of template class}}


        


More information about the cfe-commits mailing list