[Lldb-commits] [lldb] [lldb] Fix crash when adding members to an "incomplete" type (PR #102116)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 7 04:59:42 PDT 2024


Michael137 wrote:

> > LGTM, thanks!
> > So the actual problem is that the ASTImporter will only copy over the definition to the destination decl if the source decl `isCompleteDefinition`. So then when we tried to add the typedef decl to the `CXXRecordDecl` that the ASTImporter created for `A`, it would try to query its definition which didn't get copied over (cause we only ever started the definition for `A`, but nothing completed it, especially since it had no external storage), and hence we assert.
> 
> No, the problem was that `A` was stuck in this half-complete state, where we've begun -- but not finished -- it's definition, and it also didn't have an external ast source which could complete it (because we've already tried completing it, and CompleteTypeFromDWARF has cleared the "external" flag). AFAICT, the ast importer is just not prepared to handle this situation. The crash happened when it tried to query some property (probably to copy it over) of the source Decl, and this crashed because the decl didn't have the DefinitionData field set up.

Yea agreed. I was just curious where exactly the difference in the ASTImporter codepath came from with/without the patch. And it looks like without completing the definition, we lose the `DefinitionData` during the import process. What I meant was: we do always allocate `DefinitionData` for `A` in `PrepareContextToRecieveMembers`, but when we imported/copied the decl for `A::X` into the expression AST, the ASTImporter didn't import the definition for `A` because the `isCompleteDefinition` bit wasn't set (which happens [here](https://github.com/llvm/llvm-project/blob/f05e8186a439cf538f383dfbde68eca364a5acec/clang/lib/AST/ASTImporter.cpp#L3322-L3324)). With this patch, we make sure that the call to `ImportDefinition` happens before we try adding the `TypedefDecl` to the `A` context.

https://github.com/llvm/llvm-project/pull/102116


More information about the lldb-commits mailing list