@@ -393,10 +393,12 @@ bool AVarBoundsInfo::addAssignment(BoundsKey L, BoundsKey R) {
393
393
// dependency and never will be able to find the bounds for the return
394
394
// value.
395
395
if (L != R)
396
- ProgVarGraph.addEdge (R, L);
396
+ ProgVarGraph.addUniqueEdge (R, L);
397
397
} else {
398
- ProgVarGraph.addEdge (L, R);
399
- ProgVarGraph.addEdge (R, L);
398
+ ProgVarGraph.addUniqueEdge (R, L);
399
+ ProgramVar *PV = getProgramVar (R);
400
+ if (!(PV && PV->IsNumConstant ()))
401
+ ProgVarGraph.addUniqueEdge (L, R);
400
402
}
401
403
return true ;
402
404
}
@@ -712,7 +714,45 @@ bool AvarBoundsInference::inferPossibleBounds(BoundsKey K, ABounds *SB,
712
714
}
713
715
}
714
716
715
- return RetVal;
717
+ // All constants are reachable!
718
+ if (SBVar->IsNumConstant ()) {
719
+ PotK.insert (FromVarK);
720
+ }
721
+
722
+ // Get all bounds key that are equivalent to FromVarK
723
+ std::set<BoundsKey> AllFKeys;
724
+ AllFKeys.clear ();
725
+ AllFKeys.insert (FromVarK);
726
+
727
+ for (auto CurrVarK : AllFKeys) {
728
+ // Find all the in scope variables reachable from the CurrVarK
729
+ // bounds variable.
730
+ ScopeVisitor TV (DstScope, PotK, BI->PVarInfo ,
731
+ BI->PointerBoundsKey );
732
+ BKGraph.visitBreadthFirst (CurrVarK, [&TV](BoundsKey BK) {
733
+ TV.visitBoundsKey (BK);
734
+ });
735
+ }
736
+
737
+ // This is to get all the constants that are assigned to the variables
738
+ // reachable from FromVarK.
739
+ if (!SBVar->IsNumConstant ()) {
740
+ std::set<BoundsKey> ReachableCons;
741
+ std::set<BoundsKey> Pre;
742
+ for (auto CK : PotK) {
743
+ Pre.clear ();
744
+ BKGraph.getPredecessors (CK, Pre);
745
+ for (auto T : Pre) {
746
+ auto *TVar = BI->getProgramVar (T);
747
+ if (TVar->IsNumConstant ()) {
748
+ ReachableCons.insert (T);
749
+ }
750
+ }
751
+ }
752
+ PotK.insert (ReachableCons.begin (), ReachableCons.end ());
753
+ }
754
+
755
+ return !PotK.empty ();
716
756
}
717
757
718
758
bool AvarBoundsInference::getRelevantBounds (std::set<BoundsKey> &RBKeys,
@@ -1065,11 +1105,10 @@ bool AVarBoundsInfo::performFlowAnalysis(ProgramInfo *PI) {
1065
1105
// Any thing changed? which means bounds of a variable changed
1066
1106
// Which means we need to recompute the flow based bounds for
1067
1107
// all arrays that have flow based bounds.
1068
- if (keepHighestPriorityBounds (ArrPointerBoundsKey)) {
1069
- // Remove flow inferred bounds, if exist for all the array pointers.
1070
- for (auto TBK : ArrPointerBoundsKey)
1071
- removeBounds (TBK, FlowInferred);
1072
- }
1108
+ keepHighestPriorityBounds (ArrPointerBoundsKey);
1109
+ // Remove flow inferred bounds, if exist for all the array pointers.
1110
+ for (auto TBK : ArrPointerBoundsKey)
1111
+ removeBounds (TBK, FlowInferred);
1073
1112
1074
1113
// Next, get the ARR pointers that has bounds.
1075
1114
// These are pointers with bounds.
0 commit comments