@@ -36,22 +36,23 @@ class TypeInfo;
3636// / This data structure holds everything needed to emit debug info
3737// / for a type.
3838class DebugTypeInfo {
39+ protected:
3940 // / The type we need to emit may be different from the type
4041 // / mentioned in the Decl, for example, stripped of qualifiers.
4142 TypeBase *Type = nullptr ;
4243 // / Needed to determine the size of basic types and to determine
4344 // / the storage type for undefined variables.
4445 llvm::Type *StorageType = nullptr ;
45- Size size = Size( 0 ) ;
46- Alignment align = Alignment() ;
46+ Optional< Size> size;
47+ Alignment align;
4748 bool DefaultAlignment = true ;
4849 bool IsMetadataType = false ;
4950
5051public:
5152 DebugTypeInfo () = default ;
52- DebugTypeInfo (swift::Type Ty, llvm::Type *StorageTy, Size SizeInBytes,
53- Alignment AlignInBytes, bool HasDefaultAlignment ,
54- bool IsMetadataType);
53+ DebugTypeInfo (swift::Type Ty, llvm::Type *StorageTy,
54+ Optional<Size> SizeInBytes, Alignment AlignInBytes ,
55+ bool HasDefaultAlignment, bool IsMetadataType);
5556
5657 // / Create type for a local variable.
5758 static DebugTypeInfo getLocalVariable (VarDecl *Decl,
@@ -92,24 +93,44 @@ class DebugTypeInfo {
9293 }
9394
9495 llvm::Type *getStorageType () const {
95- assert ((StorageType || size. isZero ()) &&
96- " only defined types may have a size" );
96+ if (size && size-> isZero ())
97+ assert (StorageType && " only defined types may have a size" );
9798 return StorageType;
9899 }
99- Size getSize () const { return size; }
100+ Optional< Size> getSize () const { return size; }
100101 void setSize (Size NewSize) { size = NewSize; }
101102 Alignment getAlignment () const { return align; }
102103 bool isNull () const { return Type == nullptr ; }
103104 bool isForwardDecl () const { return StorageType == nullptr ; }
104105 bool isMetadataType () const { return IsMetadataType; }
105106 bool hasDefaultAlignment () const { return DefaultAlignment; }
106-
107+
107108 bool operator ==(DebugTypeInfo T) const ;
108109 bool operator !=(DebugTypeInfo T) const ;
109110#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
110111 LLVM_DUMP_METHOD void dump () const ;
111112#endif
112113};
114+
115+ // / A DebugTypeInfo with a defined size (that may be 0).
116+ class CompletedDebugTypeInfo : public DebugTypeInfo {
117+ CompletedDebugTypeInfo (DebugTypeInfo DbgTy) : DebugTypeInfo(DbgTy) {}
118+ public:
119+ static Optional<CompletedDebugTypeInfo> get (DebugTypeInfo DbgTy) {
120+ if (!DbgTy.getSize ())
121+ return {};
122+ return CompletedDebugTypeInfo (DbgTy);
123+ }
124+
125+ static Optional<CompletedDebugTypeInfo>
126+ getFromTypeInfo (swift::Type Ty, const TypeInfo &Info) {
127+ return CompletedDebugTypeInfo::get (
128+ DebugTypeInfo::getFromTypeInfo (Ty, Info));
129+ }
130+
131+ Size::int_type getSizeValue () const { return size.getValue ().getValue (); }
132+ };
133+
113134}
114135}
115136
0 commit comments