[cxx-interop] Fix reverse interop crash when using raw modules

Some fields in the AST are cached values that are populated lazily. We
should not use those values directly as in case they are not yet
computed we get back null pointers. Use ASTContext instead which can
call the slow path if the cache is not yet populated.

rdar://132746445
This commit is contained in:
Gabor Horvath
2024-08-06 16:20:55 +01:00
parent da61cd6c66
commit 0276d46718
2 changed files with 14 additions and 14 deletions

View File

@@ -284,11 +284,10 @@ public:
if (!isa<clang::TypeDecl>(typeDecl->getClangDecl()))
return;
// Get the underlying clang type from a type alias decl or record decl.
auto clangType =
clang::QualType(
cast<clang::TypeDecl>(typeDecl->getClangDecl())->getTypeForDecl(),
0)
.getCanonicalType();
auto clangDecl = typeDecl->getClangDecl();
auto clangType = clangDecl->getASTContext()
.getTypeDeclType(cast<clang::TypeDecl>(clangDecl))
.getCanonicalType();
if (!isa<clang::RecordType>(clangType.getTypePtr()))
return;
auto it = seenClangTypes.insert(clangType.getTypePtr());