@@ -78,7 +78,10 @@ class APValue {
7878 typedef llvm::APFloat APFloat;
7979public:
8080 enum ValueKind {
81- Uninitialized,
81+ // / There is no such object (it's outside its lifetime).
82+ None,
83+ // / This object has an indeterminate value (C++ [basic.indet]).
84+ Indeterminate,
8285 Int,
8386 Float,
8487 FixedPoint,
@@ -231,58 +234,59 @@ class APValue {
231234 DataType Data;
232235
233236public:
234- APValue () : Kind(Uninitialized ) {}
235- explicit APValue (APSInt I) : Kind(Uninitialized ) {
237+ APValue () : Kind(None ) {}
238+ explicit APValue (APSInt I) : Kind(None ) {
236239 MakeInt (); setInt (std::move (I));
237240 }
238- explicit APValue (APFloat F) : Kind(Uninitialized ) {
241+ explicit APValue (APFloat F) : Kind(None ) {
239242 MakeFloat (); setFloat (std::move (F));
240243 }
241- explicit APValue (APFixedPoint FX) : Kind(Uninitialized ) {
244+ explicit APValue (APFixedPoint FX) : Kind(None ) {
242245 MakeFixedPoint (std::move (FX));
243246 }
244- explicit APValue (const APValue *E, unsigned N) : Kind(Uninitialized ) {
247+ explicit APValue (const APValue *E, unsigned N) : Kind(None ) {
245248 MakeVector (); setVector (E, N);
246249 }
247- APValue (APSInt R, APSInt I) : Kind(Uninitialized ) {
250+ APValue (APSInt R, APSInt I) : Kind(None ) {
248251 MakeComplexInt (); setComplexInt (std::move (R), std::move (I));
249252 }
250- APValue (APFloat R, APFloat I) : Kind(Uninitialized ) {
253+ APValue (APFloat R, APFloat I) : Kind(None ) {
251254 MakeComplexFloat (); setComplexFloat (std::move (R), std::move (I));
252255 }
253256 APValue (const APValue &RHS);
254- APValue (APValue &&RHS) : Kind(Uninitialized ) { swap (RHS); }
257+ APValue (APValue &&RHS) : Kind(None ) { swap (RHS); }
255258 APValue (LValueBase B, const CharUnits &O, NoLValuePath N,
256259 bool IsNullPtr = false )
257- : Kind(Uninitialized ) {
260+ : Kind(None ) {
258261 MakeLValue (); setLValue (B, O, N, IsNullPtr);
259262 }
260263 APValue (LValueBase B, const CharUnits &O, ArrayRef<LValuePathEntry> Path,
261264 bool OnePastTheEnd, bool IsNullPtr = false )
262- : Kind(Uninitialized ) {
265+ : Kind(None ) {
263266 MakeLValue (); setLValue (B, O, Path, OnePastTheEnd, IsNullPtr);
264267 }
265- APValue (UninitArray, unsigned InitElts, unsigned Size) : Kind(Uninitialized ) {
268+ APValue (UninitArray, unsigned InitElts, unsigned Size) : Kind(None ) {
266269 MakeArray (InitElts, Size);
267270 }
268- APValue (UninitStruct, unsigned B, unsigned M) : Kind(Uninitialized ) {
271+ APValue (UninitStruct, unsigned B, unsigned M) : Kind(None ) {
269272 MakeStruct (B, M);
270273 }
271274 explicit APValue (const FieldDecl *D, const APValue &V = APValue())
272- : Kind(Uninitialized ) {
275+ : Kind(None ) {
273276 MakeUnion (); setUnion (D, V);
274277 }
275278 APValue (const ValueDecl *Member, bool IsDerivedMember,
276- ArrayRef<const CXXRecordDecl*> Path) : Kind(Uninitialized ) {
279+ ArrayRef<const CXXRecordDecl*> Path) : Kind(None ) {
277280 MakeMemberPointer (Member, IsDerivedMember, Path);
278281 }
279282 APValue (const AddrLabelExpr* LHSExpr, const AddrLabelExpr* RHSExpr)
280- : Kind(Uninitialized ) {
283+ : Kind(None ) {
281284 MakeAddrLabelDiff (); setAddrLabelDiff (LHSExpr, RHSExpr);
282285 }
283286
284287 ~APValue () {
285- MakeUninit ();
288+ if (Kind != None && Kind != Indeterminate)
289+ DestroyDataAndMakeUninit ();
286290 }
287291
288292 // / Returns whether the object performed allocations.
@@ -296,7 +300,11 @@ class APValue {
296300 void swap (APValue &RHS);
297301
298302 ValueKind getKind () const { return Kind; }
299- bool isUninit () const { return Kind == Uninitialized; }
303+
304+ bool isAbsent () const { return Kind == None; }
305+ bool isIndeterminate () const { return Kind == Indeterminate; }
306+ bool hasValue () const { return Kind != None && Kind != Indeterminate; }
307+
300308 bool isInt () const { return Kind == Int; }
301309 bool isFloat () const { return Kind == Float; }
302310 bool isFixedPoint () const { return Kind == FixedPoint; }
@@ -536,56 +544,52 @@ class APValue {
536544
537545private:
538546 void DestroyDataAndMakeUninit ();
539- void MakeUninit () {
540- if (Kind != Uninitialized)
541- DestroyDataAndMakeUninit ();
542- }
543547 void MakeInt () {
544- assert (isUninit () && " Bad state change" );
548+ assert (isAbsent () && " Bad state change" );
545549 new ((void *)Data.buffer ) APSInt (1 );
546550 Kind = Int;
547551 }
548552 void MakeFloat () {
549- assert (isUninit () && " Bad state change" );
553+ assert (isAbsent () && " Bad state change" );
550554 new ((void *)(char *)Data.buffer ) APFloat (0.0 );
551555 Kind = Float;
552556 }
553557 void MakeFixedPoint (APFixedPoint &&FX) {
554- assert (isUninit () && " Bad state change" );
558+ assert (isAbsent () && " Bad state change" );
555559 new ((void *)(char *)Data.buffer ) APFixedPoint (std::move (FX));
556560 Kind = FixedPoint;
557561 }
558562 void MakeVector () {
559- assert (isUninit () && " Bad state change" );
563+ assert (isAbsent () && " Bad state change" );
560564 new ((void *)(char *)Data.buffer ) Vec ();
561565 Kind = Vector;
562566 }
563567 void MakeComplexInt () {
564- assert (isUninit () && " Bad state change" );
568+ assert (isAbsent () && " Bad state change" );
565569 new ((void *)(char *)Data.buffer ) ComplexAPSInt ();
566570 Kind = ComplexInt;
567571 }
568572 void MakeComplexFloat () {
569- assert (isUninit () && " Bad state change" );
573+ assert (isAbsent () && " Bad state change" );
570574 new ((void *)(char *)Data.buffer ) ComplexAPFloat ();
571575 Kind = ComplexFloat;
572576 }
573577 void MakeLValue ();
574578 void MakeArray (unsigned InitElts, unsigned Size);
575579 void MakeStruct (unsigned B, unsigned M) {
576- assert (isUninit () && " Bad state change" );
580+ assert (isAbsent () && " Bad state change" );
577581 new ((void *)(char *)Data.buffer ) StructData (B, M);
578582 Kind = Struct;
579583 }
580584 void MakeUnion () {
581- assert (isUninit () && " Bad state change" );
585+ assert (isAbsent () && " Bad state change" );
582586 new ((void *)(char *)Data.buffer ) UnionData ();
583587 Kind = Union;
584588 }
585589 void MakeMemberPointer (const ValueDecl *Member, bool IsDerivedMember,
586590 ArrayRef<const CXXRecordDecl*> Path);
587591 void MakeAddrLabelDiff () {
588- assert (isUninit () && " Bad state change" );
592+ assert (isAbsent () && " Bad state change" );
589593 new ((void *)(char *)Data.buffer ) AddrLabelDiffData ();
590594 Kind = AddrLabelDiff;
591595 }
0 commit comments