@@ -525,16 +525,11 @@ llvm::DIScope *IRGenDebugInfo::getOrCreateContext(DeclContext *DC) {
525
525
// A module may contain multiple files.
526
526
return getOrCreateContext (DC->getParent ());
527
527
case DeclContextKind::GenericTypeDecl: {
528
- auto CachedType = DITypeCache.find (
529
- cast<GenericTypeDecl>(DC)->getDeclaredType ().getPointer ());
530
- if (CachedType != DITypeCache.end ()) {
531
- // Verify that the information still exists.
532
- if (llvm::Metadata *Val = CachedType->second )
533
- return cast<llvm::DIType>(Val);
534
- }
528
+ auto *TyDecl = cast<GenericTypeDecl>(DC);
529
+ if (auto *DITy = getTypeOrNull (TyDecl->getDeclaredType ().getPointer ()))
530
+ return DITy;
535
531
536
532
// Create a Forward-declared type.
537
- auto *TyDecl = cast<NominalTypeDecl>(DC);
538
533
auto Loc = getDebugLoc (SM, TyDecl);
539
534
auto File = getOrCreateFile (Loc.Filename );
540
535
auto Line = Loc.Line ;
@@ -1707,21 +1702,27 @@ static bool canMangle(TypeBase *Ty) {
1707
1702
}
1708
1703
}
1709
1704
1710
- llvm::DIType *IRGenDebugInfo::getOrCreateType (DebugTypeInfo DbgTy) {
1711
- // Is this an empty type?
1712
- if (DbgTy.isNull ())
1713
- // We can't use the empty type as an index into DenseMap.
1714
- return createType (DbgTy, " " , TheCU, MainFile);
1715
-
1716
- // Look in the cache first.
1717
- auto CachedType = DITypeCache.find (DbgTy.getType ());
1705
+ llvm::DIType *IRGenDebugInfo::getTypeOrNull (TypeBase *Ty) {
1706
+ auto CachedType = DITypeCache.find (Ty);
1718
1707
if (CachedType != DITypeCache.end ()) {
1719
1708
// Verify that the information still exists.
1720
1709
if (llvm::Metadata *Val = CachedType->second ) {
1721
1710
auto DITy = cast<llvm::DIType>(Val);
1722
1711
return DITy;
1723
1712
}
1724
1713
}
1714
+ return nullptr ;
1715
+ }
1716
+
1717
+ llvm::DIType *IRGenDebugInfo::getOrCreateType (DebugTypeInfo DbgTy) {
1718
+ // Is this an empty type?
1719
+ if (DbgTy.isNull ())
1720
+ // We can't use the empty type as an index into DenseMap.
1721
+ return createType (DbgTy, " " , TheCU, MainFile);
1722
+
1723
+ // Look in the cache first.
1724
+ if (auto *DITy = getTypeOrNull (DbgTy.getType ()))
1725
+ return DITy;
1725
1726
1726
1727
// Second line of defense: Look up the mangled name. TypeBase*'s are
1727
1728
// not necessarily unique, but name mangling is too expensive to do
0 commit comments