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,20 @@ 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+ if (IM.allInitialized ())
744+ return Lifetime::Started;
745+ return getArray ().getLifetime ();
746+ }
747+
748+ return IM->isElementAlive (getIndex ()) ? Lifetime::Started
749+ : Lifetime::Ended;
750+ }
751+
734752 return getInlineDesc ()->LifeState ;
735753 }
736754
@@ -739,6 +757,17 @@ class Pointer {
739757 return ;
740758 if (BS.Base < sizeof (InlineDescriptor))
741759 return ;
760+
761+ if (inArray ()) {
762+ const Descriptor *Desc = getFieldDesc ();
763+ InitMapPtr &IM = getInitMap ();
764+ if (!IM.hasInitMap ())
765+ IM.setInitMap (new InitMap (Desc->getNumElems (), IM.allInitialized ()));
766+
767+ IM->endElementLifetime (getIndex ());
768+ return ;
769+ }
770+
742771 getInlineDesc ()->LifeState = Lifetime::Ended;
743772 }
744773
@@ -747,6 +776,18 @@ class Pointer {
747776 return ;
748777 if (BS.Base < sizeof (InlineDescriptor))
749778 return ;
779+
780+ if (inArray ()) {
781+ InitMapPtr &IM = getInitMap ();
782+ if (!IM.hasInitMap ()) {
783+ const Descriptor *Desc = getFieldDesc ();
784+ IM.setInitMap (new InitMap (Desc->getNumElems (), IM.allInitialized ()));
785+ }
786+
787+ IM->startElementLifetime (getIndex ());
788+ return ;
789+ }
790+
750791 getInlineDesc ()->LifeState = Lifetime::Started;
751792 }
752793
@@ -791,7 +832,6 @@ class Pointer {
791832 friend class DeadBlock ;
792833 friend class MemberPointer ;
793834 friend class InterpState ;
794- friend struct InitMap ;
795835 friend class DynamicAllocator ;
796836 friend class Program ;
797837
@@ -838,6 +878,8 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Pointer &P) {
838878 OS << ' ' ;
839879 if (const Descriptor *D = P.getFieldDesc ())
840880 D->dump (OS);
881+ if (P.isArrayElement ())
882+ OS << " index " << P.getIndex ();
841883 return OS;
842884}
843885
0 commit comments