@@ -310,30 +310,12 @@ static inline void UpgradeAllocasToMallocs(Function *NewF,
310
310
IntegerType::get (AI->getContext (), 64 ),
311
311
AI->getAlignment ()))}));
312
312
313
- #if LLVM_VERSION_MAJOR >= 14
314
- if (ConstantInt *size = dyn_cast<ConstantInt>(CI->getOperand (0 ))) {
315
- CI->addDereferenceableRetAttr (size->getLimitedValue ());
316
- #if !defined(FLANG) && !defined(ROCM)
317
- AttrBuilder B (CI->getContext ());
318
- #else
319
- AttrBuilder B;
320
- #endif
321
- B.addDereferenceableOrNullAttr (size->getLimitedValue ());
322
- CI->setAttributes (
323
- CI->getAttributes ().addRetAttributes (CI->getContext (), B));
324
- }
325
- CI->addAttributeAtIndex (AttributeList::ReturnIndex, Attribute::NoAlias);
326
- CI->addAttributeAtIndex (AttributeList::ReturnIndex, Attribute::NonNull);
327
- #else
328
- if (ConstantInt *size = dyn_cast<ConstantInt>(CI->getOperand (0 ))) {
329
- CI->addDereferenceableAttr (llvm::AttributeList::ReturnIndex,
330
- size->getLimitedValue ());
331
- CI->addDereferenceableOrNullAttr (llvm::AttributeList::ReturnIndex,
332
- size->getLimitedValue ());
333
- }
334
- CI->addAttribute (AttributeList::ReturnIndex, Attribute::NoAlias);
335
- CI->addAttribute (AttributeList::ReturnIndex, Attribute::NonNull);
336
- #endif
313
+ auto PT0 = cast<PointerType>(rep->getType ());
314
+ auto PT1 = cast<PointerType>(AI->getType ());
315
+ if (PT0->getAddressSpace () != PT1->getAddressSpace ())
316
+ rep = B.CreateAddrSpaceCast (rep,
317
+ PointerType::get (PT0->getPointerElementType (),
318
+ PT1->getAddressSpace ()));
337
319
assert (rep->getType () == AI->getType ());
338
320
AI->replaceAllUsesWith (rep);
339
321
AI->eraseFromParent ();
0 commit comments