@@ -61,6 +61,32 @@ static cl::opt<bool> StackSafetyRun("stack-safety-run", cl::init(false),
61
61
62
62
namespace {
63
63
64
+ // Check if we should bailout for such ranges.
65
+ bool isUnsafe (const ConstantRange &R) {
66
+ return R.isEmptySet () || R.isFullSet () || R.isUpperSignWrapped ();
67
+ }
68
+
69
+ ConstantRange addOverflowNever (const ConstantRange &L, const ConstantRange &R) {
70
+ assert (!L.isSignWrappedSet ());
71
+ assert (!R.isSignWrappedSet ());
72
+ if (L.signedAddMayOverflow (R) !=
73
+ ConstantRange::OverflowResult::NeverOverflows)
74
+ return ConstantRange::getFull (L.getBitWidth ());
75
+ ConstantRange Result = L.add (R);
76
+ assert (!Result.isSignWrappedSet ());
77
+ return Result;
78
+ }
79
+
80
+ ConstantRange unionNoWrap (const ConstantRange &L, const ConstantRange &R) {
81
+ assert (!L.isSignWrappedSet ());
82
+ assert (!R.isSignWrappedSet ());
83
+ auto Result = L.unionWith (R);
84
+ // Two non-wrapped sets can produce wrapped.
85
+ if (Result.isSignWrappedSet ())
86
+ Result = ConstantRange::getFull (Result.getBitWidth ());
87
+ return Result;
88
+ }
89
+
64
90
// / Describes use of address in as a function call argument.
65
91
template <typename CalleeTy> struct CallInfo {
66
92
// / Function being called.
@@ -93,11 +119,7 @@ template <typename CalleeTy> struct UseInfo {
93
119
94
120
UseInfo (unsigned PointerSize) : Range{PointerSize, false } {}
95
121
96
- void updateRange (const ConstantRange &R) {
97
- assert (!R.isUpperSignWrapped ());
98
- Range = Range.unionWith (R);
99
- assert (!Range.isUpperSignWrapped ());
100
- }
122
+ void updateRange (const ConstantRange &R) { Range = unionNoWrap (Range, R); }
101
123
};
102
124
103
125
template <typename CalleeTy>
@@ -108,18 +130,6 @@ raw_ostream &operator<<(raw_ostream &OS, const UseInfo<CalleeTy> &U) {
108
130
return OS;
109
131
}
110
132
111
- // Check if we should bailout for such ranges.
112
- bool isUnsafe (const ConstantRange &R) {
113
- return R.isEmptySet () || R.isFullSet () || R.isUpperSignWrapped ();
114
- }
115
-
116
- ConstantRange addOverflowNever (const ConstantRange &L, const ConstantRange &R) {
117
- if (L.signedAddMayOverflow (R) !=
118
- ConstantRange::OverflowResult::NeverOverflows)
119
- return ConstantRange (L.getBitWidth (), true );
120
- return L.add (R);
121
- }
122
-
123
133
// / Calculate the allocation size of a given alloca. Returns empty range
124
134
// in case of confution.
125
135
ConstantRange getStaticAllocaSizeRange (const AllocaInst &AI) {
@@ -515,7 +525,7 @@ bool StackSafetyDataFlowAnalysis<CalleeTy>::updateOneUse(UseInfo<CalleeTy> &US,
515
525
if (UpdateToFullSet)
516
526
US.Range = UnknownRange;
517
527
else
518
- US.Range = US. Range . unionWith (CalleeRange);
528
+ US.updateRange (CalleeRange);
519
529
}
520
530
}
521
531
return Changed;
0 commit comments