1515
1616#include " Descriptor.h"
1717#include " FunctionPointer.h"
18+ #include " InitMap.h"
1819#include " InterpBlock.h"
1920#include " clang/AST/ComparisonCategories.h"
2021#include " clang/AST/Decl.h"
@@ -721,6 +722,9 @@ class Pointer {
721722 // / Like isInitialized(), but for primitive arrays.
722723 bool isElementInitialized (unsigned Index) const ;
723724 bool allElementsInitialized () const ;
725+ bool allElementsAlive () const ;
726+ bool isElementAlive (unsigned Index) const ;
727+
724728 // / Activats a field.
725729 void activate () const ;
726730 // / Deactivates an entire strurcutre.
@@ -731,6 +735,16 @@ class Pointer {
731735 return Lifetime::Started;
732736 if (BS.Base < sizeof (InlineDescriptor))
733737 return Lifetime::Started;
738+
739+ if (inArray () && !isArrayRoot ()) {
740+ InitMapPtr &IM = getInitMap ();
741+
742+ if (!IM.hasInitMap ())
743+ return getArray ().getLifetime ();
744+ return IM->isElementAlive (getIndex ()) ? Lifetime::Started
745+ : Lifetime::Ended;
746+ }
747+
734748 return getInlineDesc ()->LifeState ;
735749 }
736750
@@ -739,6 +753,17 @@ class Pointer {
739753 return ;
740754 if (BS.Base < sizeof (InlineDescriptor))
741755 return ;
756+
757+ if (inArray ()) {
758+ const Descriptor *Desc = getFieldDesc ();
759+ InitMapPtr &IM = getInitMap ();
760+ if (!IM.hasInitMap ())
761+ IM.setInitMap (new InitMap (Desc->getNumElems (), IM.allInitialized ()));
762+
763+ IM->endElementLifetime (getIndex ());
764+ return ;
765+ }
766+
742767 getInlineDesc ()->LifeState = Lifetime::Ended;
743768 }
744769
@@ -747,6 +772,18 @@ class Pointer {
747772 return ;
748773 if (BS.Base < sizeof (InlineDescriptor))
749774 return ;
775+
776+ if (inArray ()) {
777+ InitMapPtr &IM = getInitMap ();
778+ if (!IM.hasInitMap ()) {
779+ const Descriptor *Desc = getFieldDesc ();
780+ IM.setInitMap (new InitMap (Desc->getNumElems (), IM.allInitialized ()));
781+ }
782+
783+ IM->startElementLifetime (getIndex ());
784+ return ;
785+ }
786+
750787 getInlineDesc ()->LifeState = Lifetime::Started;
751788 }
752789
@@ -791,7 +828,6 @@ class Pointer {
791828 friend class DeadBlock ;
792829 friend class MemberPointer ;
793830 friend class InterpState ;
794- friend struct InitMap ;
795831 friend class DynamicAllocator ;
796832 friend class Program ;
797833
@@ -838,6 +874,8 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Pointer &P) {
838874 OS << ' ' ;
839875 if (const Descriptor *D = P.getFieldDesc ())
840876 D->dump (OS);
877+ if (P.isArrayElement ())
878+ OS << " index " << P.getIndex ();
841879 return OS;
842880}
843881
0 commit comments