[ASTimporter] Remove decl from lookup only if it has decl context
authorBalazs Benics <balazs.benics@sigmatechnology.se>
Tue, 18 May 2021 07:43:20 +0000 (09:43 +0200)
committerBalazs Benics <balazs.benics@sigmatechnology.se>
Tue, 18 May 2021 07:43:20 +0000 (09:43 +0200)
commit88ee91cd87794813f4394f82d2c693c8d766e1d2
treee2807c8727c2c2e1ec04ddbe3ef5f08c063955fe
parentbbea361039c11dc2e6e281c80fa8aa569f1c7c2d
[ASTimporter] Remove decl from lookup only if it has decl context

In the case of TypedefDecls we set the DeclContext after we imported it.
It turns out, it could lead to null pointer dereferences during the
cleanup part of a failed import.

This patch demonstrates this issue and fixes it by checking if the
DeclContext is available or not.

Reviewed By: shafik

Differential Revision: https://reviews.llvm.org/D102640
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp