@@ -1689,7 +1689,10 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
16891689 uint64_t SizeOfByte = CI.getTargetInfo ().getCharWidth ();
16901690 // FIXME: SizeInBits is redundant with DbgTy, remove it.
16911691 auto *llvmty = IGM.getStorageTypeForUnlowered (DbgTy.getType ());
1692- uint64_t SizeInBits = llvmty->isSized () ? IGM.DataLayout .getTypeSizeInBits (llvmty) : 0 ;
1692+ std::optional<uint64_t > SizeInBitsOrNull;
1693+ if (llvmty->isSized ())
1694+ SizeInBitsOrNull = IGM.DataLayout .getTypeSizeInBits (llvmty);
1695+ uint64_t SizeInBits = SizeInBitsOrNull.value_or (0 );
16931696 unsigned AlignInBits = DbgTy.hasDefaultAlignment ()
16941697 ? 0
16951698 : DbgTy.getAlignment ().getValue () * SizeOfByte;
@@ -1790,7 +1793,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
17901793 SizeInBits, AlignInBits, Flags, nullptr ,
17911794 llvm::dwarf::DW_LANG_Swift, MangledName);
17921795 StringRef Name = Decl->getName ().str ();
1793- if (!DbgTy. getTypeSizeInBits () )
1796+ if (!SizeInBitsOrNull )
17941797 return DBuilder.createForwardDecl (
17951798 llvm::dwarf::DW_TAG_structure_type, MangledName, Scope, L.File ,
17961799 FwdDeclLine, llvm::dwarf::DW_LANG_Swift, 0 , AlignInBits);
@@ -2187,7 +2190,10 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
21872190 bool sanityCheckCachedType (DebugTypeInfo DbgTy, llvm::DIType *CachedType) {
21882191 if (DbgTy.isForwardDecl ())
21892192 return true ;
2190- auto SizeInBits = DbgTy.getTypeSizeInBits ();
2193+ auto *StorageType = IGM.getStorageTypeForUnlowered (DbgTy.getType ());
2194+ std::optional<uint64_t > SizeInBits;
2195+ if (StorageType->isSized ())
2196+ SizeInBits = IGM.DataLayout .getTypeSizeInBits (StorageType);
21912197 unsigned CachedSizeInBits = getSizeInBits (CachedType);
21922198 if ((SizeInBits && CachedSizeInBits != *SizeInBits) ||
21932199 (!SizeInBits && CachedSizeInBits)) {
0 commit comments