diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Analysis/MemoryBuiltins.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Analysis/MemoryBuiltins.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/contrib/llvm-project/llvm/lib/Analysis/MemoryBuiltins.cpp b/contrib/llvm-project/llvm/lib/Analysis/MemoryBuiltins.cpp index 0b61b1c0eabd..5dda96a2ca94 100644 --- a/contrib/llvm-project/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/contrib/llvm-project/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -72,6 +72,7 @@ struct AllocFnsTy { // know which functions are nounwind, noalias, nocapture parameters, etc. static const std::pair<LibFunc, AllocFnsTy> AllocationFnData[] = { {LibFunc_malloc, {MallocLike, 1, 0, -1}}, + {LibFunc_vec_malloc, {MallocLike, 1, 0, -1}}, {LibFunc_valloc, {MallocLike, 1, 0, -1}}, {LibFunc_Znwj, {OpNewLike, 1, 0, -1}}, // new(unsigned int) {LibFunc_ZnwjRKSt9nothrow_t, {MallocLike, 2, 0, -1}}, // new(unsigned int, nothrow) @@ -103,7 +104,9 @@ static const std::pair<LibFunc, AllocFnsTy> AllocationFnData[] = { {LibFunc_msvc_new_array_longlong_nothrow, {MallocLike, 2, 0, -1}}, // new[](unsigned long long, nothrow) {LibFunc_aligned_alloc, {AlignedAllocLike, 2, 1, -1}}, {LibFunc_calloc, {CallocLike, 2, 0, 1}}, + {LibFunc_vec_calloc, {CallocLike, 2, 0, 1}}, {LibFunc_realloc, {ReallocLike, 2, 1, -1}}, + {LibFunc_vec_realloc, {ReallocLike, 2, 1, -1}}, {LibFunc_reallocf, {ReallocLike, 2, 1, -1}}, {LibFunc_strdup, {StrDupLike, 1, -1, -1}}, {LibFunc_strndup, {StrDupLike, 2, 1, -1}} @@ -378,9 +381,8 @@ PointerType *llvm::getMallocType(const CallInst *CI, unsigned NumOfBitCastUses = 0; // Determine if CallInst has a bitcast use. - for (Value::const_user_iterator UI = CI->user_begin(), E = CI->user_end(); - UI != E;) - if (const BitCastInst *BCI = dyn_cast<BitCastInst>(*UI++)) { + for (const User *U : CI->users()) + if (const BitCastInst *BCI = dyn_cast<BitCastInst>(U)) { MallocType = cast<PointerType>(BCI->getDestTy()); NumOfBitCastUses++; } @@ -566,8 +568,16 @@ Value *llvm::lowerObjectSizeCall(IntrinsicInst *ObjectSize, Value *UseZero = Builder.CreateICmpULT(SizeOffsetPair.first, SizeOffsetPair.second); ResultSize = Builder.CreateZExtOrTrunc(ResultSize, ResultType); - return Builder.CreateSelect(UseZero, ConstantInt::get(ResultType, 0), - ResultSize); + Value *Ret = Builder.CreateSelect( + UseZero, ConstantInt::get(ResultType, 0), ResultSize); + + // The non-constant size expression cannot evaluate to -1. + if (!isa<Constant>(SizeOffsetPair.first) || + !isa<Constant>(SizeOffsetPair.second)) + Builder.CreateAssumption( + Builder.CreateICmpNE(Ret, ConstantInt::get(ResultType, -1))); + + return Ret; } } @@ -676,13 +686,14 @@ SizeOffsetType ObjectSizeOffsetVisitor::visitAllocaInst(AllocaInst &I) { } SizeOffsetType ObjectSizeOffsetVisitor::visitArgument(Argument &A) { + Type *MemoryTy = A.getPointeeInMemoryValueType(); // No interprocedural analysis is done at the moment. - if (!A.hasPassPointeeByValueAttr()) { + if (!MemoryTy|| !MemoryTy->isSized()) { ++ObjectVisitorArgument; return unknown(); } - PointerType *PT = cast<PointerType>(A.getType()); - APInt Size(IntTyBits, DL.getTypeAllocSize(PT->getElementType())); + + APInt Size(IntTyBits, DL.getTypeAllocSize(MemoryTy)); return std::make_pair(align(Size, A.getParamAlignment()), Zero); } |