@@ -161,6 +161,15 @@ VarHoldsBytesOfStorVarPlus(to, load, storVar, startByte, newLow, high):-
161
161
newLow = maxKeptByte - startByte,
162
162
HighBytesMaskOp(var, to, maskLen).
163
163
164
+ // Note: This is usually an intermediary case, to restore it to some storage bytes.
165
+ // It could potentially lead to FPs, but not having it would introduce FNs, to revisit
166
+ // That's the reason it's more restrictive (it will keep the bytes of the previous var is they are all kept)
167
+ VarHoldsBytesOfStorVarPlus(to, load, storVar, startByte, low, high):-
168
+ VarHoldsBytesOfStorVarPlus(var, load, storVar, startByte, low, high),
169
+ width = high - low,
170
+ ByteMaskOpKeepRange(var, to, [keepLow, keepHigh]),
171
+ keepLow <= startByte, keepHigh >= startByte + width.
172
+
164
173
VarHoldsBytesOfStorVarFinal(var, load, storVar, low, high):-
165
174
VarHoldsBytesOfStorVar(var, load, storVar, low, high),
166
175
!VarFlowsFromSLOADToSSTORE(var, storVar), // Could potentially be restrictive for rare cases in optimized code
@@ -227,13 +236,34 @@ ConstWrittenToBytesOfStorVar(var, val, store, store, construct, 0, 31):-
227
236
val != "0x0".
228
237
// !SLOADOfConstruct(_, construct, _).
229
238
239
+ // FailedMergedStorageModelingReason(storVar, stmt, stmt2, [low, high], [otherLow, otherHigh]),
240
+ // FailedMergedStorageModeling(storVar):-
241
+ // AnyLoadStoreStorVarBytes(stmt, storVar, low, high),
242
+ // AnyLoadStoreStorVarBytes(stmt2, storVar, otherLow, otherHigh), otherLow = otherLow, otherHigh = otherHigh, // NOWARN
243
+ // (low != otherLow ; high != otherHigh),
244
+ // ( (low < otherLow , otherLow < high) ; (low < otherHigh, otherHigh < high) ).
245
+
230
246
FailedMergedStorageModelingReason(storVar, stmt, stmt2, [low, high], [otherLow, otherHigh]),
231
247
FailedMergedStorageModeling(storVar):-
232
248
AnyLoadStoreStorVarBytes(stmt, storVar, low, high),
233
- AnyLoadStoreStorVarBytes(stmt2, storVar, otherLow, otherHigh), otherLow = otherLow, otherHigh = otherHigh, // NOWARN
234
- ( low != otherLow ; high != otherHigh) ,
249
+ AnyLoadStoreStorVarBytes(stmt2, storVar, otherLow, otherHigh),
250
+ low != otherLow, high != otherHigh,
235
251
( (low < otherLow , otherLow < high) ; (low < otherHigh, otherHigh < high) ).
236
252
253
+ FailedMergedStorageModelingReason(storVar, stmt, stmt2, [low, high], [otherLow, high]),
254
+ FailedMergedStorageModeling(storVar):-
255
+ AnyLoadStoreStorVarBytes(stmt, storVar, low, high),
256
+ AnyLoadStoreStorVarBytes(stmt2, storVar, otherLow, high),
257
+ low != otherLow,
258
+ low < otherLow , otherLow < high.
259
+
260
+ // FailedMergedStorageModelingReason(storVar, stmt, stmt2, [low, high], [otherLow, otherHigh]),
261
+ // FailedMergedStorageModeling(storVar):-
262
+ // AnyLoadStoreStorVarBytes(stmt, storVar, low, high),
263
+ // AnyLoadStoreStorVarBytes(stmt2, storVar, otherLow, otherHigh), otherLow = otherLow, otherHigh = otherHigh, // NOWARN
264
+ // (low != otherLow ; high != otherHigh),
265
+ // ( (low < otherLow , otherLow < high) ; (low < otherHigh, otherHigh < high) ).
266
+
237
267
LoadOrStoreToStoreVar(stmt, construct):-
238
268
InitialStorageStmtToIndexAndConstruct(stmt, "ACCESS", _, construct).
239
269
@@ -556,6 +586,15 @@ VarHoldsBytesOfStorVar(to, store, storVar, 0, 0):-
556
586
Statement_Uses(store, storedVar, 1),
557
587
BooleanCast(storedVar, to).
558
588
589
+
590
+ .decl NormalizeStorageVarByteLimits(storvVar: StorageConstruct, inByteLow: number, inByteHigh: number, actualByteLow: number, actualByteHigh: number)
591
+ DEBUG_OUTPUT(NormalizeStorageVarByteLimits)
592
+
593
+ NormalizeStorageVarByteLimits(storVar, low, high, low, actualHigh):-
594
+ AnyLoadStoreStorVarBytes(_, storVar, low, high),
595
+ actualHigh = max otherHigh :AnyLoadStoreStorVarBytes(_, storVar, low, otherHigh).
596
+
597
+
559
598
/**
560
599
Top-Level Global Variables
561
600
*/
@@ -604,7 +643,9 @@ LoadGlobalVariable(stmt, v, var):-
604
643
SuccessfulMergedStorageModeling($Variable($Constant(storVar))),
605
644
SLOADOfConst(_, storVar, _), // ensure it's a global variable
606
645
VarHoldsBytesOfStorVarFinal(_, _, $Variable($Constant(storVar)), low, high),
607
- VarHoldsBytesOfStorVar(var, _, $Variable($Constant(storVar)), low, high),
646
+ // perhaps we need to add new instruction here
647
+ NormalizeStorageVarByteLimits($Variable($Constant(storVar)), low, high, actualLow, actualHigh),
648
+ VarHoldsBytesOfStorVar(var, _, $Variable($Constant(storVar)), actualLow, actualHigh),
608
649
Statement_Defines(stmt, var, 0),
609
650
(low != 0 ; high != 31),
610
651
v = MERGED_STORAGE_VAR(storVar, low, high).
@@ -622,13 +663,24 @@ StoreGlobalVariable(store, v, writtenVar):-
622
663
SuccessfulMergedStorageModeling($Variable($Constant(storVar))),
623
664
SSTOREToConst(_, storVar, _), // ensure it's a global variable
624
665
VarWrittenToBytesOfStorVarFinal(writtenVar, store, $Variable($Constant(storVar)), byteLow, byteHigh),
625
- v = MERGED_STORAGE_VAR(storVar, byteLow, byteHigh).
666
+ NormalizeStorageVarByteLimits($Variable($Constant(storVar)), byteLow, byteHigh, actualLow, actualHigh),
667
+ ProcessedStorageVariable($Variable($Constant(storVar)), $TightlyPackedVariable($Constant(storVar), actualLow, actualHigh)),
668
+ v = MERGED_STORAGE_VAR(storVar, actualLow, actualHigh).
669
+
670
+ StoreGlobalVariable(store, storVar, writtenVar):-
671
+ SuccessfulMergedStorageModeling($Variable($Constant(storVar))),
672
+ SSTOREToConst(_, storVar, _), // ensure it's a global variable
673
+ VarWrittenToBytesOfStorVarFinal(writtenVar, store, $Variable($Constant(storVar)), byteLow, byteHigh),
674
+ NormalizeStorageVarByteLimits($Variable($Constant(storVar)), byteLow, byteHigh, 0, 31),
675
+ ProcessedStorageVariable($Variable($Constant(storVar)), $Variable($Constant(storVar))).
626
676
627
677
StoreGlobalVariable(store, v, constVar):-
628
678
SuccessfulMergedStorageModeling($Variable($Constant(storVar))),
629
679
SSTOREToConst(_, storVar, _), // ensure it's a global variable
630
680
ConstWrittenToBytesOfStorVarProcessed(constVar, _, store, _, $Variable($Constant(storVar)), byteLow, byteHigh),
631
- v = MERGED_STORAGE_VAR(storVar, byteLow, byteHigh).
681
+ NormalizeStorageVarByteLimits($Variable($Constant(storVar)), byteLow, byteHigh, actualLow, actualHigh),
682
+ ProcessedStorageVariable($Variable($Constant(storVar)), $TightlyPackedVariable($Constant(storVar), actualLow, actualHigh)),
683
+ v = MERGED_STORAGE_VAR(storVar, actualLow, actualHigh).
632
684
633
685
634
686
StorageVariableInfo(storVar, storVar, 0, 31):-
@@ -649,15 +701,17 @@ ProcessedStorageVariable(construct, construct):-
649
701
VarHoldsBytesOfStorVarFinal(_, _, construct, 0, 31)
650
702
).
651
703
652
- ProcessedStorageVariable(storageVar, $TightlyPackedVariable(parentCons, byteLow, byteHigh )):-
704
+ ProcessedStorageVariable(storageVar, $TightlyPackedVariable(parentCons, actualLow, actualHigh )):-
653
705
SuccessfulMergedStorageModeling(storageVar),
654
706
storageVar = $Variable(parentCons),
655
707
(
656
708
ConstWrittenToUnreadBytesOfStorVar(_, _, _, storageVar, byteLow, byteHigh);
657
709
VarWrittenToBytesOfStorVarFinal(_, _, storageVar, byteLow, byteHigh);
658
710
VarHoldsBytesOfStorVarFinal(_, _, storageVar, byteLow, byteHigh)
659
711
),
660
- byteHigh - byteLow != 31.
712
+ NormalizeStorageVarByteLimits(storageVar, byteLow, byteHigh, actualLow, actualHigh),
713
+ byteHigh - byteLow != 31,
714
+ actualHigh - actualLow != 31.
661
715
662
716
// If an array element is never loaded or stored directly (i.e. it is only copied via loops)
663
717
// We consider it non merged. Maybe this isn't the right aproach, review.
@@ -670,6 +724,7 @@ StorageVariablePacksNVars(storageVar, numberOfVars):-
670
724
numberOfVars = count : ProcessedStorageVariable(storageVar, _),
671
725
numberOfVars > 1.
672
726
727
+ // Does this need to be fixed for the (cons, cons) case
673
728
ConstWrittenToBytesOfStorVarProcessed(constVar, const, store, load, $Variable(parentCons), byteLow, byteHigh):-
674
729
ConstWrittenToBytesOfStorVar(constVar, const, store, load, $Variable(parentCons), byteLow, byteHigh),
675
730
ProcessedStorageVariable($Variable(parentCons), $TightlyPackedVariable(parentCons, byteLow, byteHigh)).
0 commit comments