Skip to content

Commit 1bfb3e6

Browse files
authored
Merge pull request swiftlang#62499 from adrian-prantl/102367872
Add an assertion that verifies the size of cached debug info types.
2 parents 5666e1d + 0f4429b commit 1bfb3e6

28 files changed

+203
-199
lines changed

lib/IRGen/DebugTypeInfo.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ static bool hasDefaultAlignment(swift::Type Ty) {
4747
}
4848

4949
DebugTypeInfo DebugTypeInfo::getFromTypeInfo(swift::Type Ty, const TypeInfo &TI,
50+
IRGenModule &IGM,
5051
bool IsFragmentTypeInfo) {
5152
Optional<Size::int_type> SizeInBits;
5253
llvm::Type *StorageType = TI.getStorageType();
53-
if (TI.isFixedSize()) {
54+
if (StorageType->isSized())
55+
SizeInBits = IGM.DataLayout.getTypeSizeInBits(StorageType);
56+
else if (TI.isFixedSize()) {
5457
const FixedTypeInfo &FixTy = *cast<const FixedTypeInfo>(&TI);
5558
Size::int_type Size = FixTy.getFixedSize().getValue() * 8;
5659
SizeInBits = Size;
@@ -63,6 +66,7 @@ DebugTypeInfo DebugTypeInfo::getFromTypeInfo(swift::Type Ty, const TypeInfo &TI,
6366

6467
DebugTypeInfo DebugTypeInfo::getLocalVariable(VarDecl *Decl, swift::Type Ty,
6568
const TypeInfo &Info,
69+
IRGenModule &IGM,
6670
bool IsFragmentTypeInfo) {
6771

6872
auto DeclType = Decl->getInterfaceType();
@@ -77,7 +81,7 @@ DebugTypeInfo DebugTypeInfo::getLocalVariable(VarDecl *Decl, swift::Type Ty,
7781
// the type hasn't been mucked with by an optimization pass.
7882
auto *Type = Sugared->isEqual(RealType) ? DeclType.getPointer()
7983
: RealType.getPointer();
80-
return getFromTypeInfo(Type, Info, IsFragmentTypeInfo);
84+
return getFromTypeInfo(Type, Info, IGM, IsFragmentTypeInfo);
8185
}
8286

8387
DebugTypeInfo DebugTypeInfo::getGlobalMetadata(swift::Type Ty,
@@ -120,7 +124,7 @@ DebugTypeInfo DebugTypeInfo::getGlobal(SILGlobalVariable *GV,
120124
Type = DeclType.getPointer();
121125
}
122126
auto &TI = IGM.getTypeInfoForUnlowered(Type);
123-
DebugTypeInfo DbgTy = getFromTypeInfo(Type, TI, false);
127+
DebugTypeInfo DbgTy = getFromTypeInfo(Type, TI, IGM, false);
124128
assert(FragmentStorageType && "FragmentStorageType is a nullptr");
125129
assert(!DbgTy.isContextArchetype() &&
126130
"type of global variable cannot be an archetype");
@@ -163,7 +167,7 @@ DebugTypeInfo DebugTypeInfo::getObjCClass(ClassDecl *theClass,
163167
DebugTypeInfo DebugTypeInfo::getErrorResult(swift::Type Ty,
164168
IRGenModule &IGM) {
165169
auto &TI = IGM.getTypeInfoForUnlowered(Ty);
166-
DebugTypeInfo DbgTy = getFromTypeInfo(Ty, TI, false);
170+
DebugTypeInfo DbgTy = getFromTypeInfo(Ty, TI, IGM, false);
167171
return DbgTy;
168172
}
169173

@@ -195,7 +199,8 @@ LLVM_DUMP_METHOD void DebugTypeInfo::dump() const {
195199
if (SizeInBits)
196200
llvm::errs() << "SizeInBits " << *SizeInBits << " ";
197201
llvm::errs() << "Alignment " << Align.getValue() << "] ";
198-
getType()->dump(llvm::errs());
202+
if (auto *Type = getType())
203+
Type->dump(llvm::errs());
199204

200205
if (FragmentStorageType) {
201206
llvm::errs() << "FragmentStorageType=";

lib/IRGen/DebugTypeInfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class DebugTypeInfo {
6161

6262
/// Create type for a local variable.
6363
static DebugTypeInfo getLocalVariable(VarDecl *Decl, swift::Type Ty,
64-
const TypeInfo &Info,
64+
const TypeInfo &Info, IRGenModule &IGM,
6565
bool IsFragmentTypeInfo);
6666
/// Create type for global type metadata.
6767
static DebugTypeInfo getGlobalMetadata(swift::Type Ty, llvm::Type *StorageTy,
@@ -75,6 +75,7 @@ class DebugTypeInfo {
7575

7676
/// Create a standalone type from a TypeInfo object.
7777
static DebugTypeInfo getFromTypeInfo(swift::Type Ty, const TypeInfo &Info,
78+
IRGenModule &IGM,
7879
bool IsFragmentTypeInfo);
7980
/// Global variables.
8081
static DebugTypeInfo getGlobal(SILGlobalVariable *GV,
@@ -111,7 +112,6 @@ class DebugTypeInfo {
111112
return SizeIsFragmentSize ? llvm::None : SizeInBits;
112113
}
113114
Optional<Size::int_type> getRawSizeInBits() const { return SizeInBits; }
114-
void setSizeInBits(Size::int_type NewSize) { SizeInBits = NewSize; }
115115
Alignment getAlignment() const { return Align; }
116116
bool isNull() const { return Type == nullptr; }
117117
bool isForwardDecl() const { return FragmentStorageType == nullptr; }
@@ -139,9 +139,9 @@ class CompletedDebugTypeInfo : public DebugTypeInfo {
139139
}
140140

141141
static Optional<CompletedDebugTypeInfo>
142-
getFromTypeInfo(swift::Type Ty, const TypeInfo &Info) {
142+
getFromTypeInfo(swift::Type Ty, const TypeInfo &Info, IRGenModule &IGM) {
143143
return CompletedDebugTypeInfo::get(
144-
DebugTypeInfo::getFromTypeInfo(Ty, Info, /*IsFragment*/ false));
144+
DebugTypeInfo::getFromTypeInfo(Ty, Info, IGM, /*IsFragment*/ false));
145145
}
146146

147147
Size::int_type getSizeInBits() const { return *SizeInBits; }

0 commit comments

Comments
 (0)