@@ -131,7 +131,10 @@ raw_ostream &operator<<(raw_ostream &OS, const ParamInfo &P) {
131
131
// / size can not be statically determined.
132
132
uint64_t getStaticAllocaAllocationSize (const AllocaInst *AI) {
133
133
const DataLayout &DL = AI->getModule ()->getDataLayout ();
134
- uint64_t Size = DL.getTypeAllocSize (AI->getAllocatedType ());
134
+ TypeSize TS = DL.getTypeAllocSize (AI->getAllocatedType ());
135
+ if (TS.isScalable ())
136
+ return 0 ;
137
+ uint64_t Size = TS.getFixedSize ();
135
138
if (AI->isArrayAllocation ()) {
136
139
auto C = dyn_cast<ConstantInt>(AI->getArraySize ());
137
140
if (!C)
@@ -211,7 +214,9 @@ class StackSafetyLocalAnalysis {
211
214
212
215
ConstantRange offsetFromAlloca (Value *Addr, const Value *AllocaPtr);
213
216
ConstantRange getAccessRange (Value *Addr, const Value *AllocaPtr,
214
- uint64_t AccessSize);
217
+ ConstantRange SizeRange);
218
+ ConstantRange getAccessRange (Value *Addr, const Value *AllocaPtr,
219
+ TypeSize Size);
215
220
ConstantRange getMemIntrinsicAccessRange (const MemIntrinsic *MI, const Use &U,
216
221
const Value *AllocaPtr);
217
222
@@ -244,9 +249,9 @@ StackSafetyLocalAnalysis::offsetFromAlloca(Value *Addr,
244
249
return Offset;
245
250
}
246
251
247
- ConstantRange StackSafetyLocalAnalysis::getAccessRange (Value *Addr,
248
- const Value *AllocaPtr,
249
- uint64_t AccessSize ) {
252
+ ConstantRange
253
+ StackSafetyLocalAnalysis::getAccessRange (Value *Addr, const Value *AllocaPtr,
254
+ ConstantRange SizeRange ) {
250
255
if (!SE.isSCEVable (Addr->getType ()))
251
256
return UnknownRange;
252
257
@@ -255,12 +260,20 @@ ConstantRange StackSafetyLocalAnalysis::getAccessRange(Value *Addr,
255
260
256
261
ConstantRange AccessStartRange =
257
262
SE.getUnsignedRange (Expr).zextOrTrunc (PointerSize);
258
- ConstantRange SizeRange = getRange (0 , AccessSize);
259
263
ConstantRange AccessRange = AccessStartRange.add (SizeRange);
260
264
assert (!AccessRange.isEmptySet ());
261
265
return AccessRange;
262
266
}
263
267
268
+ ConstantRange StackSafetyLocalAnalysis::getAccessRange (Value *Addr,
269
+ const Value *AllocaPtr,
270
+ TypeSize Size) {
271
+ ConstantRange SizeRange = Size.isScalable ()
272
+ ? ConstantRange::getFull (PointerSize)
273
+ : getRange (0 , Size.getFixedSize ());
274
+ return getAccessRange (Addr, AllocaPtr, SizeRange);
275
+ }
276
+
264
277
ConstantRange StackSafetyLocalAnalysis::getMemIntrinsicAccessRange (
265
278
const MemIntrinsic *MI, const Use &U, const Value *AllocaPtr) {
266
279
if (auto MTI = dyn_cast<MemTransferInst>(MI)) {
@@ -274,7 +287,8 @@ ConstantRange StackSafetyLocalAnalysis::getMemIntrinsicAccessRange(
274
287
// Non-constant size => unsafe. FIXME: try SCEV getRange.
275
288
if (!Len)
276
289
return UnknownRange;
277
- ConstantRange AccessRange = getAccessRange (U, AllocaPtr, Len->getZExtValue ());
290
+ ConstantRange AccessRange =
291
+ getAccessRange (U, AllocaPtr, getRange (0 , Len->getZExtValue ()));
278
292
return AccessRange;
279
293
}
280
294
0 commit comments