[lldb] Complete return types of CXXMethodDecls to prevent crashing due to covariant...
authorRaphael Isemann <teemperor@gmail.com>
Wed, 29 Jan 2020 08:07:55 +0000 (09:07 +0100)
committerRaphael Isemann <teemperor@gmail.com>
Wed, 29 Jan 2020 08:08:35 +0000 (09:08 +0100)
commita5fb2e371ec2b585ca56cbc1a116912aabe347d3
treebeeb057910dd2f8022df33b8a934270161b7c947
parenta497e1b5ea7a681ef1b40b5c11f411bfe0e807d0
[lldb] Complete return types of CXXMethodDecls to prevent crashing due to covariant return types

Summary:
Currently we crash in Clang's CodeGen when we call functions with covariant return types with this assert:
```
Assertion failed: (DD && "queried property of class with no definition"), function data, file clang/include/clang/AST/DeclCXX.h, line 433.
```
when calling `clang::CXXRecordDecl::isDerivedFrom` from the `ItaniumVTableBuilder`.

Clang seems to assume that the underlying record decls of covariant return types are already completed.
This is true during a normal Clang invocation as there the type checker will complete both decls when
checking if the overloaded function is valid (i.e., the return types are covariant).

When we minimally import our AST into the expression in LLDB we don't do this type checking (which
would complete the record decls) and we end up trying to access the invalid record decls from CodeGen
which makes us trigger the assert.

This patch just completes the underlying types of ptr/ref return types of virtual function so that the
underlying records are complete and we behave as Clang expects us to do.

Fixes rdar://38048657

Reviewers: lhames, shafik

Reviewed By: shafik

Subscribers: abidh, JDevlieghere, lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D73024
lldb/packages/Python/lldbsuite/test/lang/cpp/covariant-return-types/Makefile [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/lang/cpp/covariant-return-types/TestCovariantReturnTypes.py [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/lang/cpp/covariant-return-types/main.cpp [new file with mode: 0644]
lldb/source/Symbol/ClangASTImporter.cpp