diff --git a/llvm/include/llvm/Transforms/Utils/BuildLibCalls.h b/llvm/include/llvm/Transforms/Utils/BuildLibCalls.h --- a/llvm/include/llvm/Transforms/Utils/BuildLibCalls.h +++ b/llvm/include/llvm/Transforms/Utils/BuildLibCalls.h @@ -47,104 +47,115 @@ /// pointer. Ptr is required to be some pointer type, and the return value has /// 'intptr_t' type. Value *emitStrLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL, - const TargetLibraryInfo *TLI); + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the strdup function to the builder, for the specified /// pointer. Ptr is required to be some pointer type, and the return value has /// 'i8*' type. - Value *emitStrDup(Value *Ptr, IRBuilderBase &B, const TargetLibraryInfo *TLI); + Value *emitStrDup(Value *Ptr, IRBuilderBase &B, const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the strnlen function to the builder, for the specified /// pointer. Ptr is required to be some pointer type, MaxLen must be of size_t /// type, and the return value has 'intptr_t' type. Value *emitStrNLen(Value *Ptr, Value *MaxLen, IRBuilderBase &B, - const DataLayout &DL, const TargetLibraryInfo *TLI); + const DataLayout &DL, const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the strchr function to the builder, for the specified /// pointer and character. Ptr is required to be some pointer type, and the /// return value has 'i8*' type. Value *emitStrChr(Value *Ptr, char C, IRBuilderBase &B, - const TargetLibraryInfo *TLI); + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the strncmp function to the builder. Value *emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, - const DataLayout &DL, const TargetLibraryInfo *TLI); + const DataLayout &DL, const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the strcpy function to the builder, for the specified /// pointer arguments. Value *emitStrCpy(Value *Dst, Value *Src, IRBuilderBase &B, - const TargetLibraryInfo *TLI); + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the stpcpy function to the builder, for the specified /// pointer arguments. Value *emitStpCpy(Value *Dst, Value *Src, IRBuilderBase &B, - const TargetLibraryInfo *TLI); + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the strncpy function to the builder, for the specified /// pointer arguments and length. Value *emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, - const TargetLibraryInfo *TLI); + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the stpncpy function to the builder, for the specified /// pointer arguments and length. Value *emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, - const TargetLibraryInfo *TLI); + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the __memcpy_chk function to the builder. This expects that /// the Len and ObjSize have type 'intptr_t' and Dst/Src are pointers. Value *emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize, IRBuilderBase &B, const DataLayout &DL, - const TargetLibraryInfo *TLI); + const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the memchr function. This assumes that Ptr is a pointer, /// Val is an i32 value, and Len is an 'intptr_t' value. Value *emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B, - const DataLayout &DL, const TargetLibraryInfo *TLI); + const DataLayout &DL, const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the memcmp function. Value *emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, - const DataLayout &DL, const TargetLibraryInfo *TLI); + const DataLayout &DL, const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the bcmp function. Value *emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, - const DataLayout &DL, const TargetLibraryInfo *TLI); + const DataLayout &DL, const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the memccpy function. Value *emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len, - IRBuilderBase &B, const TargetLibraryInfo *TLI); + IRBuilderBase &B, const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the snprintf function. Value *emitSNPrintf(Value *Dest, Value *Size, Value *Fmt, ArrayRef Args, IRBuilderBase &B, - const TargetLibraryInfo *TLI); + const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the sprintf function. Value *emitSPrintf(Value *Dest, Value *Fmt, ArrayRef VariadicArgs, - IRBuilderBase &B, const TargetLibraryInfo *TLI); + IRBuilderBase &B, const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the strcat function. Value *emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B, - const TargetLibraryInfo *TLI); + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the strlcpy function. Value *emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, - const TargetLibraryInfo *TLI); + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the strlcat function. Value *emitStrLCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, - const TargetLibraryInfo *TLI); + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the strncat function. Value *emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, - const TargetLibraryInfo *TLI); + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the vsnprintf function. Value *emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList, - IRBuilderBase &B, const TargetLibraryInfo *TLI); + IRBuilderBase &B, const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the vsprintf function. Value *emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList, IRBuilderBase &B, - const TargetLibraryInfo *TLI); + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo = AAMDNodes()); /// Emit a call to the unary function named 'Name' (e.g. 'floor'). This /// function is known to take a single of type matching 'Op' and returns one diff --git a/llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h b/llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h --- a/llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h +++ b/llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h @@ -223,7 +223,7 @@ // Helper methods Value *emitStrLenMemCpy(Value *Src, Value *Dst, uint64_t Len, - IRBuilderBase &B); + IRBuilderBase &B, const AAMDNodes &AATags); void classifyArgUse(Value *Val, Function *F, bool IsFloat, SmallVectorImpl &SinCalls, SmallVectorImpl &CosCalls, diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp --- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -928,7 +928,7 @@ ArrayRef ParamTypes, ArrayRef Operands, IRBuilderBase &B, const TargetLibraryInfo *TLI, - bool IsVaArgs = false) { + bool IsVaArgs = false, const AAMDNodes &AAInfo = AAMDNodes()) { if (!TLI->has(TheLibFunc)) return nullptr; @@ -941,70 +941,72 @@ if (const Function *F = dyn_cast(Callee.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); + CI->setAAMetadata(AAInfo); return CI; } Value *llvm::emitStrLen(Value *Ptr, IRBuilderBase &B, const DataLayout &DL, - const TargetLibraryInfo *TLI) { + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo) { LLVMContext &Context = B.GetInsertBlock()->getContext(); return emitLibCall(LibFunc_strlen, DL.getIntPtrType(Context), - B.getInt8PtrTy(), castToCStr(Ptr, B), B, TLI); + B.getInt8PtrTy(), castToCStr(Ptr, B), B, TLI, false, AAInfo); } Value *llvm::emitStrDup(Value *Ptr, IRBuilderBase &B, - const TargetLibraryInfo *TLI) { + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo) { return emitLibCall(LibFunc_strdup, B.getInt8PtrTy(), B.getInt8PtrTy(), - castToCStr(Ptr, B), B, TLI); + castToCStr(Ptr, B), B, TLI, false, AAInfo); } Value *llvm::emitStrChr(Value *Ptr, char C, IRBuilderBase &B, - const TargetLibraryInfo *TLI) { + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo) { Type *I8Ptr = B.getInt8PtrTy(); Type *I32Ty = B.getInt32Ty(); return emitLibCall(LibFunc_strchr, I8Ptr, {I8Ptr, I32Ty}, - {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, B, TLI); + {castToCStr(Ptr, B), ConstantInt::get(I32Ty, C)}, B, TLI, false, AAInfo); } Value *llvm::emitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, - const DataLayout &DL, const TargetLibraryInfo *TLI) { + const DataLayout &DL, const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo) { LLVMContext &Context = B.GetInsertBlock()->getContext(); return emitLibCall( LibFunc_strncmp, B.getInt32Ty(), {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)}, - {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI); + {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI, false, AAInfo); } Value *llvm::emitStrCpy(Value *Dst, Value *Src, IRBuilderBase &B, - const TargetLibraryInfo *TLI) { + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo) { Type *I8Ptr = B.getInt8PtrTy(); return emitLibCall(LibFunc_strcpy, I8Ptr, {I8Ptr, I8Ptr}, - {castToCStr(Dst, B), castToCStr(Src, B)}, B, TLI); + {castToCStr(Dst, B), castToCStr(Src, B)}, B, TLI, false, AAInfo); } Value *llvm::emitStpCpy(Value *Dst, Value *Src, IRBuilderBase &B, - const TargetLibraryInfo *TLI) { + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo) { Type *I8Ptr = B.getInt8PtrTy(); return emitLibCall(LibFunc_stpcpy, I8Ptr, {I8Ptr, I8Ptr}, - {castToCStr(Dst, B), castToCStr(Src, B)}, B, TLI); + {castToCStr(Dst, B), castToCStr(Src, B)}, B, TLI, false, AAInfo); } Value *llvm::emitStrNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, - const TargetLibraryInfo *TLI) { + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo) { Type *I8Ptr = B.getInt8PtrTy(); return emitLibCall(LibFunc_strncpy, I8Ptr, {I8Ptr, I8Ptr, Len->getType()}, - {castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI); + {castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI, false, AAInfo); } Value *llvm::emitStpNCpy(Value *Dst, Value *Src, Value *Len, IRBuilderBase &B, - const TargetLibraryInfo *TLI) { + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo) { Type *I8Ptr = B.getInt8PtrTy(); return emitLibCall(LibFunc_stpncpy, I8Ptr, {I8Ptr, I8Ptr, Len->getType()}, - {castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI); + {castToCStr(Dst, B), castToCStr(Src, B), Len}, B, TLI, false, AAInfo); } Value *llvm::emitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize, IRBuilderBase &B, const DataLayout &DL, - const TargetLibraryInfo *TLI) { + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo) { if (!TLI->has(LibFunc_memcpy_chk)) return nullptr; @@ -1023,105 +1025,112 @@ if (const Function *F = dyn_cast(MemCpy.getCallee()->stripPointerCasts())) CI->setCallingConv(F->getCallingConv()); + CI->setAAMetadata(AAInfo); return CI; } Value *llvm::emitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilderBase &B, - const DataLayout &DL, const TargetLibraryInfo *TLI) { + const DataLayout &DL, const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo) { LLVMContext &Context = B.GetInsertBlock()->getContext(); return emitLibCall( LibFunc_memchr, B.getInt8PtrTy(), {B.getInt8PtrTy(), B.getInt32Ty(), DL.getIntPtrType(Context)}, - {castToCStr(Ptr, B), Val, Len}, B, TLI); + {castToCStr(Ptr, B), Val, Len}, B, TLI, false, AAInfo); } Value *llvm::emitMemCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, - const DataLayout &DL, const TargetLibraryInfo *TLI) { + const DataLayout &DL, const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo) { LLVMContext &Context = B.GetInsertBlock()->getContext(); return emitLibCall( LibFunc_memcmp, B.getInt32Ty(), {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)}, - {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI); + {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI, false, AAInfo); } Value *llvm::emitBCmp(Value *Ptr1, Value *Ptr2, Value *Len, IRBuilderBase &B, - const DataLayout &DL, const TargetLibraryInfo *TLI) { + const DataLayout &DL, const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo) { LLVMContext &Context = B.GetInsertBlock()->getContext(); return emitLibCall( LibFunc_bcmp, B.getInt32Ty(), {B.getInt8PtrTy(), B.getInt8PtrTy(), DL.getIntPtrType(Context)}, - {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI); + {castToCStr(Ptr1, B), castToCStr(Ptr2, B), Len}, B, TLI, false, AAInfo); } Value *llvm::emitMemCCpy(Value *Ptr1, Value *Ptr2, Value *Val, Value *Len, - IRBuilderBase &B, const TargetLibraryInfo *TLI) { + IRBuilderBase &B, const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo) { return emitLibCall( LibFunc_memccpy, B.getInt8PtrTy(), {B.getInt8PtrTy(), B.getInt8PtrTy(), B.getInt32Ty(), Len->getType()}, - {Ptr1, Ptr2, Val, Len}, B, TLI); + {Ptr1, Ptr2, Val, Len}, B, TLI, false, AAInfo); } Value *llvm::emitSNPrintf(Value *Dest, Value *Size, Value *Fmt, ArrayRef VariadicArgs, IRBuilderBase &B, - const TargetLibraryInfo *TLI) { + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo) { SmallVector Args{castToCStr(Dest, B), Size, castToCStr(Fmt, B)}; Args.insert(Args.end(), VariadicArgs.begin(), VariadicArgs.end()); return emitLibCall(LibFunc_snprintf, B.getInt32Ty(), {B.getInt8PtrTy(), Size->getType(), B.getInt8PtrTy()}, - Args, B, TLI, /*IsVaArgs=*/true); + Args, B, TLI, /*IsVaArgs=*/true, AAInfo); } Value *llvm::emitSPrintf(Value *Dest, Value *Fmt, ArrayRef VariadicArgs, IRBuilderBase &B, - const TargetLibraryInfo *TLI) { + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo) { SmallVector Args{castToCStr(Dest, B), castToCStr(Fmt, B)}; Args.insert(Args.end(), VariadicArgs.begin(), VariadicArgs.end()); return emitLibCall(LibFunc_sprintf, B.getInt32Ty(), {B.getInt8PtrTy(), B.getInt8PtrTy()}, Args, B, TLI, - /*IsVaArgs=*/true); + /*IsVaArgs=*/true, AAInfo); } Value *llvm::emitStrCat(Value *Dest, Value *Src, IRBuilderBase &B, - const TargetLibraryInfo *TLI) { + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo) { return emitLibCall(LibFunc_strcat, B.getInt8PtrTy(), {B.getInt8PtrTy(), B.getInt8PtrTy()}, - {castToCStr(Dest, B), castToCStr(Src, B)}, B, TLI); + {castToCStr(Dest, B), castToCStr(Src, B)}, B, TLI, false, AAInfo); } Value *llvm::emitStrLCpy(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, - const TargetLibraryInfo *TLI) { + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo) { return emitLibCall(LibFunc_strlcpy, Size->getType(), {B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()}, - {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI); + {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI, false, AAInfo); } Value *llvm::emitStrLCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, - const TargetLibraryInfo *TLI) { + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo) { return emitLibCall(LibFunc_strlcat, Size->getType(), {B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()}, - {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI); + {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI, false, AAInfo); } Value *llvm::emitStrNCat(Value *Dest, Value *Src, Value *Size, IRBuilderBase &B, - const TargetLibraryInfo *TLI) { + const TargetLibraryInfo *TLI, const AAMDNodes &AAInfo) { return emitLibCall(LibFunc_strncat, B.getInt8PtrTy(), {B.getInt8PtrTy(), B.getInt8PtrTy(), Size->getType()}, - {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI); + {castToCStr(Dest, B), castToCStr(Src, B), Size}, B, TLI, false, AAInfo); } Value *llvm::emitVSNPrintf(Value *Dest, Value *Size, Value *Fmt, Value *VAList, - IRBuilderBase &B, const TargetLibraryInfo *TLI) { + IRBuilderBase &B, const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo) { return emitLibCall( LibFunc_vsnprintf, B.getInt32Ty(), {B.getInt8PtrTy(), Size->getType(), B.getInt8PtrTy(), VAList->getType()}, - {castToCStr(Dest, B), Size, castToCStr(Fmt, B), VAList}, B, TLI); + {castToCStr(Dest, B), Size, castToCStr(Fmt, B), VAList}, B, TLI, false, AAInfo); } Value *llvm::emitVSPrintf(Value *Dest, Value *Fmt, Value *VAList, - IRBuilderBase &B, const TargetLibraryInfo *TLI) { + IRBuilderBase &B, const TargetLibraryInfo *TLI, + const AAMDNodes &AAInfo) { return emitLibCall(LibFunc_vsprintf, B.getInt32Ty(), {B.getInt8PtrTy(), B.getInt8PtrTy(), VAList->getType()}, - {castToCStr(Dest, B), castToCStr(Fmt, B), VAList}, B, TLI); + {castToCStr(Dest, B), castToCStr(Fmt, B), VAList}, B, TLI, false, AAInfo); } /// Append a suffix to the function name according to the type of 'Op'. diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -246,14 +246,16 @@ if (Len == 0) return Dst; - return emitStrLenMemCpy(Src, Dst, Len, B); + AAMDNodes AATags; + CI->getAAMetadata(AATags); + return emitStrLenMemCpy(Src, Dst, Len, B, AATags); } Value *LibCallSimplifier::emitStrLenMemCpy(Value *Src, Value *Dst, uint64_t Len, - IRBuilderBase &B) { + IRBuilderBase &B, const AAMDNodes &AATags) { // We need to find the end of the destination string. That's where the // memory is to be moved to. We just generate a call to strlen. - Value *DstLen = emitStrLen(Dst, B, DL, TLI); + Value *DstLen = emitStrLen(Dst, B, DL, TLI, AATags); if (!DstLen) return nullptr; @@ -266,7 +268,8 @@ // concatenation for us. Make a memcpy to copy the nul byte with align = 1. B.CreateMemCpy( CpyDst, Align(1), Src, Align(1), - ConstantInt::get(DL.getIntPtrType(Src->getContext()), Len + 1)); + ConstantInt::get(DL.getIntPtrType(Src->getContext()), Len + 1), + false, AATags.TBAA, nullptr, AATags.Scope, AATags.NoAlias); return Dst; } @@ -308,9 +311,11 @@ if (Len < SrcLen) return nullptr; + AAMDNodes AATags; + CI->getAAMetadata(AATags); // strncat(x, s, c) -> strcat(x, s) // s is constant so the strcat can be optimized further. - return emitStrLenMemCpy(Src, Dst, SrcLen, B); + return emitStrLenMemCpy(Src, Dst, SrcLen, B, AATags); } Value *LibCallSimplifier::optimizeStrChr(CallInst *CI, IRBuilderBase &B) { @@ -319,6 +324,9 @@ Value *SrcStr = CI->getArgOperand(0); annotateNonNullBasedOnAccess(CI, 0); + AAMDNodes AATags; + CI->getAAMetadata(AATags); + // If the second operand is non-constant, see if we can compute the length // of the input string and turn this into memchr. ConstantInt *CharC = dyn_cast(CI->getArgOperand(1)); @@ -333,7 +341,7 @@ return emitMemChr(SrcStr, CI->getArgOperand(1), // include nul. ConstantInt::get(DL.getIntPtrType(CI->getContext()), Len), - B, DL, TLI); + B, DL, TLI, AATags); } // Otherwise, the character is a constant, see if the first argument is @@ -341,7 +349,7 @@ StringRef Str; if (!getConstantStringInfo(SrcStr, Str)) { if (CharC->isZero()) // strchr(p, 0) -> p + strlen(p) - if (Value *StrLen = emitStrLen(SrcStr, B, DL, TLI)) + if (Value *StrLen = emitStrLen(SrcStr, B, DL, TLI, AATags)) return B.CreateGEP(B.getInt8Ty(), SrcStr, StrLen, "strchr"); return nullptr; } @@ -370,8 +378,11 @@ StringRef Str; if (!getConstantStringInfo(SrcStr, Str)) { // strrchr(s, 0) -> strchr(s, 0) - if (CharC->isZero()) - return emitStrChr(SrcStr, '\0', B, TLI); + if (CharC->isZero()) { + AAMDNodes AATags; + CI->getAAMetadata(AATags); + return emitStrChr(SrcStr, '\0', B, TLI, AATags); + } return nullptr; } @@ -415,11 +426,13 @@ if (Len2) annotateDereferenceableBytes(CI, 1, Len2); + AAMDNodes AATags; + CI->getAAMetadata(AATags); if (Len1 && Len2) { return emitMemCmp(Str1P, Str2P, ConstantInt::get(DL.getIntPtrType(CI->getContext()), std::min(Len1, Len2)), - B, DL, TLI); + B, DL, TLI, AATags); } // strcmp to memcmp @@ -428,13 +441,13 @@ return emitMemCmp( Str1P, Str2P, ConstantInt::get(DL.getIntPtrType(CI->getContext()), Len2), B, DL, - TLI); + TLI, AATags); } else if (HasStr1 && !HasStr2) { if (canTransformToMemCmp(CI, Str2P, Len1, DL)) return emitMemCmp( Str1P, Str2P, ConstantInt::get(DL.getIntPtrType(CI->getContext()), Len1), B, DL, - TLI); + TLI, AATags); } annotateNonNullBasedOnAccess(CI, {0, 1}); @@ -460,8 +473,10 @@ if (Length == 0) // strncmp(x,y,0) -> 0 return ConstantInt::get(CI->getType(), 0); + AAMDNodes AATags; + CI->getAAMetadata(AATags); if (Length == 1) // strncmp(x,y,1) -> memcmp(x,y,1) - return emitMemCmp(Str1P, Str2P, Size, B, DL, TLI); + return emitMemCmp(Str1P, Str2P, Size, B, DL, TLI, AATags); StringRef Str1, Str2; bool HasStr1 = getConstantStringInfo(Str1P, Str1); @@ -496,14 +511,14 @@ return emitMemCmp( Str1P, Str2P, ConstantInt::get(DL.getIntPtrType(CI->getContext()), Len2), B, DL, - TLI); + TLI, AATags); } else if (HasStr1 && !HasStr2) { Len1 = std::min(Len1, Length); if (canTransformToMemCmp(CI, Str2P, Len1, DL)) return emitMemCmp( Str1P, Str2P, ConstantInt::get(DL.getIntPtrType(CI->getContext()), Len1), B, DL, - TLI); + TLI, AATags); } return nullptr; @@ -515,8 +530,11 @@ uint64_t SrcLen = GetStringLength(Src); if (SrcLen && Size) { annotateDereferenceableBytes(CI, 0, SrcLen); - if (SrcLen <= Size->getZExtValue() + 1) - return emitStrDup(Src, B, TLI); + if (SrcLen <= Size->getZExtValue() + 1) { + AAMDNodes AATags; + CI->getAAMetadata(AATags); + return emitStrDup(Src, B, TLI, AATags); + } } return nullptr; @@ -535,11 +553,14 @@ else return nullptr; + AAMDNodes AATags; + CI->getAAMetadata(AATags); // We have enough information to now generate the memcpy call to do the // copy for us. Make a memcpy to copy the nul byte with align = 1. CallInst *NewCI = B.CreateMemCpy(Dst, Align(1), Src, Align(1), - ConstantInt::get(DL.getIntPtrType(CI->getContext()), Len)); + ConstantInt::get(DL.getIntPtrType(CI->getContext()), Len), + false, AATags.TBAA, nullptr, AATags.Scope, AATags.NoAlias); NewCI->setAttributes(CI->getAttributes()); return Dst; } @@ -547,8 +568,10 @@ Value *LibCallSimplifier::optimizeStpCpy(CallInst *CI, IRBuilderBase &B) { Function *Callee = CI->getCalledFunction(); Value *Dst = CI->getArgOperand(0), *Src = CI->getArgOperand(1); + AAMDNodes AATags; + CI->getAAMetadata(AATags); if (Dst == Src) { // stpcpy(x,x) -> x+strlen(x) - Value *StrLen = emitStrLen(Src, B, DL, TLI); + Value *StrLen = emitStrLen(Src, B, DL, TLI, AATags); return StrLen ? B.CreateInBoundsGEP(B.getInt8Ty(), Dst, StrLen) : nullptr; } @@ -566,7 +589,8 @@ // We have enough information to now generate the memcpy call to do the // copy for us. Make a memcpy to copy the nul byte with align = 1. - CallInst *NewCI = B.CreateMemCpy(Dst, Align(1), Src, Align(1), LenV); + CallInst *NewCI = B.CreateMemCpy(Dst, Align(1), Src, Align(1), LenV, + false, AATags.TBAA, nullptr, AATags.Scope, AATags.NoAlias); NewCI->setAttributes(CI->getAttributes()); return DstEnd; } @@ -599,9 +623,12 @@ return nullptr; } + AAMDNodes AATags; + CI->getAAMetadata(AATags); if (SrcLen == 0) { // strncpy(x, "", y) -> memset(align 1 x, '\0', y) - CallInst *NewCI = B.CreateMemSet(Dst, B.getInt8('\0'), Size, Align(1)); + CallInst *NewCI = B.CreateMemSet(Dst, B.getInt8('\0'), Size, Align(1), + false, AATags.TBAA, AATags.Scope, AATags.NoAlias); AttrBuilder ArgAttrs(CI->getAttributes().getParamAttributes(0)); NewCI->setAttributes(NewCI->getAttributes().addParamAttributes( CI->getContext(), 0, ArgAttrs)); @@ -625,7 +652,8 @@ Type *PT = Callee->getFunctionType()->getParamType(0); // strncpy(x, s, c) -> memcpy(align 1 x, align 1 s, c) [s and c are constant] CallInst *NewCI = B.CreateMemCpy(Dst, Align(1), Src, Align(1), - ConstantInt::get(DL.getIntPtrType(PT), Len)); + ConstantInt::get(DL.getIntPtrType(PT), Len), + false, AATags.TBAA, nullptr, AATags.Scope, AATags.NoAlias); NewCI->setAttributes(CI->getAttributes()); return Dst; } @@ -757,8 +785,11 @@ } // strpbrk(s, "a") -> strchr(s, 'a') - if (HasS2 && S2.size() == 1) - return emitStrChr(CI->getArgOperand(0), S2[0], B, TLI); + if (HasS2 && S2.size() == 1) { + AAMDNodes AATags; + CI->getAAMetadata(AATags); + return emitStrChr(CI->getArgOperand(0), S2[0], B, TLI, AATags); + } return nullptr; } @@ -813,8 +844,11 @@ } // strcspn(s, "") -> strlen(s) - if (HasS2 && S2.empty()) - return emitStrLen(CI->getArgOperand(0), B, DL, TLI); + if (HasS2 && S2.empty()) { + AAMDNodes AATags; + CI->getAAMetadata(AATags); + return emitStrLen(CI->getArgOperand(0), B, DL, TLI, AATags); + } return nullptr; } @@ -824,13 +858,15 @@ if (CI->getArgOperand(0) == CI->getArgOperand(1)) return B.CreateBitCast(CI->getArgOperand(0), CI->getType()); + AAMDNodes AATags; + CI->getAAMetadata(AATags); // fold strstr(a, b) == a -> strncmp(a, b, strlen(b)) == 0 if (isOnlyUsedInEqualityComparison(CI, CI->getArgOperand(0))) { - Value *StrLen = emitStrLen(CI->getArgOperand(1), B, DL, TLI); + Value *StrLen = emitStrLen(CI->getArgOperand(1), B, DL, TLI, AATags); if (!StrLen) return nullptr; Value *StrNCmp = emitStrNCmp(CI->getArgOperand(0), CI->getArgOperand(1), - StrLen, B, DL, TLI); + StrLen, B, DL, TLI, AATags); if (!StrNCmp) return nullptr; for (auto UI = CI->user_begin(), UE = CI->user_end(); UI != UE;) { @@ -868,7 +904,7 @@ // fold strstr(x, "y") -> strchr(x, 'y'). if (HasStr2 && ToFindStr.size() == 1) { - Value *StrChr = emitStrChr(CI->getArgOperand(0), ToFindStr[0], B, TLI); + Value *StrChr = emitStrChr(CI->getArgOperand(0), ToFindStr[0], B, TLI, AATags); return StrChr ? B.CreateBitCast(StrChr, CI->getType()) : nullptr; } @@ -1082,7 +1118,9 @@ Value *LHS = CI->getArgOperand(0); Value *RHS = CI->getArgOperand(1); Value *Size = CI->getArgOperand(2); - return emitBCmp(LHS, RHS, Size, B, DL, TLI); + AAMDNodes AATags; + CI->getAAMetadata(AATags); + return emitBCmp(LHS, RHS, Size, B, DL, TLI, AATags); } return nullptr; @@ -1098,9 +1136,13 @@ if (isa(CI)) return nullptr; + AAMDNodes AATags; + CI->getAAMetadata(AATags); // memcpy(x, y, n) -> llvm.memcpy(align 1 x, align 1 y, n) CallInst *NewCI = B.CreateMemCpy(CI->getArgOperand(0), Align(1), - CI->getArgOperand(1), Align(1), Size); + CI->getArgOperand(1), Align(1), Size, + false, AATags.TBAA, AATags.TBAAStruct, + AATags.Scope, AATags.NoAlias); NewCI->setAttributes(CI->getAttributes()); return CI->getArgOperand(0); } @@ -1125,11 +1167,15 @@ return nullptr; } + AAMDNodes AATags; + CI->getAAMetadata(AATags); + // Wrap arg 'c' of type int to char size_t Pos = SrcStr.find(StopChar->getSExtValue() & 0xFF); if (Pos == StringRef::npos) { if (N->getZExtValue() <= SrcStr.size()) { - B.CreateMemCpy(Dst, Align(1), Src, Align(1), CI->getArgOperand(3)); + B.CreateMemCpy(Dst, Align(1), Src, Align(1), CI->getArgOperand(3), + false, AATags.TBAA, nullptr, AATags.Scope, AATags.NoAlias); return Constant::getNullValue(CI->getType()); } return nullptr; @@ -1138,7 +1184,8 @@ Value *NewN = ConstantInt::get(N->getType(), std::min(uint64_t(Pos + 1), N->getZExtValue())); // memccpy -> llvm.memcpy - B.CreateMemCpy(Dst, Align(1), Src, Align(1), NewN); + B.CreateMemCpy(Dst, Align(1), Src, Align(1), NewN, + false, AATags.TBAA, nullptr, AATags.Scope, AATags.NoAlias); return Pos + 1 <= N->getZExtValue() ? B.CreateInBoundsGEP(B.getInt8Ty(), Dst, NewN) : Constant::getNullValue(CI->getType()); @@ -1147,9 +1194,12 @@ Value *LibCallSimplifier::optimizeMemPCpy(CallInst *CI, IRBuilderBase &B) { Value *Dst = CI->getArgOperand(0); Value *N = CI->getArgOperand(2); + AAMDNodes AATags; + CI->getAAMetadata(AATags); // mempcpy(x, y, n) -> llvm.memcpy(align 1 x, align 1 y, n), x + n CallInst *NewCI = - B.CreateMemCpy(Dst, Align(1), CI->getArgOperand(1), Align(1), N); + B.CreateMemCpy(Dst, Align(1), CI->getArgOperand(1), Align(1), N, + false, AATags.TBAA, nullptr, AATags.Scope, AATags.NoAlias); NewCI->setAttributes(CI->getAttributes()); return B.CreateInBoundsGEP(B.getInt8Ty(), Dst, N); } @@ -1160,9 +1210,12 @@ if (isa(CI)) return nullptr; + AAMDNodes AATags; + CI->getAAMetadata(AATags); // memmove(x, y, n) -> llvm.memmove(align 1 x, align 1 y, n) CallInst *NewCI = B.CreateMemMove(CI->getArgOperand(0), Align(1), - CI->getArgOperand(1), Align(1), Size); + CI->getArgOperand(1), Align(1), Size, + false, AATags.TBAA, AATags.Scope, AATags.NoAlias); NewCI->setAttributes(CI->getAttributes()); return CI->getArgOperand(0); } @@ -1220,9 +1273,12 @@ if (auto *Calloc = foldMallocMemset(CI, B)) return Calloc; + AAMDNodes AATags; + CI->getAAMetadata(AATags); // memset(p, v, n) -> llvm.memset(align 1 p, v, n) Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(), false); - CallInst *NewCI = B.CreateMemSet(CI->getArgOperand(0), Val, Size, Align(1)); + CallInst *NewCI = B.CreateMemSet(CI->getArgOperand(0), Val, Size, Align(1), + false, AATags.TBAA, AATags.Scope, AATags.NoAlias); NewCI->setAttributes(CI->getAttributes()); return CI->getArgOperand(0); } @@ -2453,6 +2509,8 @@ if (!getConstantStringInfo(CI->getArgOperand(1), FormatStr)) return nullptr; + AAMDNodes AATags; + CI->getAAMetadata(AATags); // If we just have a format string (nothing else crazy) transform it. if (CI->getNumArgOperands() == 2) { // Make sure there's no % in the constant array. We could try to handle @@ -2464,7 +2522,8 @@ B.CreateMemCpy( CI->getArgOperand(0), Align(1), CI->getArgOperand(1), Align(1), ConstantInt::get(DL.getIntPtrType(CI->getContext()), - FormatStr.size() + 1)); // Copy the null byte. + FormatStr.size() + 1), // Copy the null byte. + false, AATags.TBAA, nullptr, AATags.Scope, AATags.NoAlias); return ConstantInt::get(CI->getType(), FormatStr.size()); } @@ -2496,17 +2555,18 @@ if (CI->use_empty()) // sprintf(dest, "%s", str) -> strcpy(dest, str) - return emitStrCpy(CI->getArgOperand(0), CI->getArgOperand(2), B, TLI); + return emitStrCpy(CI->getArgOperand(0), CI->getArgOperand(2), B, TLI, AATags); uint64_t SrcLen = GetStringLength(CI->getArgOperand(2)); if (SrcLen) { B.CreateMemCpy( CI->getArgOperand(0), Align(1), CI->getArgOperand(2), Align(1), - ConstantInt::get(DL.getIntPtrType(CI->getContext()), SrcLen)); + ConstantInt::get(DL.getIntPtrType(CI->getContext()), SrcLen), + false, AATags.TBAA, nullptr, AATags.Scope, AATags.NoAlias); // Returns total number of characters written without null-character. return ConstantInt::get(CI->getType(), SrcLen - 1); } else if (Value *V = emitStpCpy(CI->getArgOperand(0), CI->getArgOperand(2), - B, TLI)) { + B, TLI, AATags)) { // sprintf(dest, "%s", str) -> stpcpy(dest, str) - dest Value *PtrDiff = B.CreatePtrDiff(V, CI->getArgOperand(0)); return B.CreateIntCast(PtrDiff, CI->getType(), false); @@ -2518,13 +2578,14 @@ if (OptForSize) return nullptr; - Value *Len = emitStrLen(CI->getArgOperand(2), B, DL, TLI); + Value *Len = emitStrLen(CI->getArgOperand(2), B, DL, TLI, AATags); if (!Len) return nullptr; Value *IncLen = B.CreateAdd(Len, ConstantInt::get(Len->getType(), 1), "leninc"); B.CreateMemCpy(CI->getArgOperand(0), Align(1), CI->getArgOperand(2), - Align(1), IncLen); + Align(1), IncLen, + false, AATags.TBAA, nullptr, AATags.Scope, AATags.NoAlias); // The sprintf result is the unincremented number of bytes in the string. return B.CreateIntCast(Len, CI->getType(), false); @@ -2581,6 +2642,8 @@ if (!getConstantStringInfo(CI->getArgOperand(2), FormatStr)) return nullptr; + AAMDNodes AATags; + CI->getAAMetadata(AATags); // If we just have a format string (nothing else crazy) transform it. if (CI->getNumArgOperands() == 3) { // Make sure there's no % in the constant array. We could try to handle @@ -2598,7 +2661,8 @@ B.CreateMemCpy( CI->getArgOperand(0), Align(1), CI->getArgOperand(2), Align(1), ConstantInt::get(DL.getIntPtrType(CI->getContext()), - FormatStr.size() + 1)); // Copy the null byte. + FormatStr.size() + 1), + false, AATags.TBAA, nullptr, AATags.Scope, AATags.NoAlias); // Copy the null byte. return ConstantInt::get(CI->getType(), FormatStr.size()); } @@ -2638,7 +2702,8 @@ return nullptr; B.CreateMemCpy(CI->getArgOperand(0), Align(1), CI->getArgOperand(3), - Align(1), ConstantInt::get(CI->getType(), Str.size() + 1)); + Align(1), ConstantInt::get(CI->getType(), Str.size() + 1), + false, AATags.TBAA, nullptr, AATags.Scope, AATags.NoAlias); // The snprintf result is the unincremented number of bytes in the string. return ConstantInt::get(CI->getType(), Str.size()); @@ -2811,8 +2876,11 @@ Value *LibCallSimplifier::optimizeBCopy(CallInst *CI, IRBuilderBase &B) { // bcopy(src, dst, n) -> llvm.memmove(dst, src, n) + AAMDNodes AATags; + CI->getAAMetadata(AATags); return B.CreateMemMove(CI->getArgOperand(1), Align(1), CI->getArgOperand(0), - Align(1), CI->getArgOperand(2)); + Align(1), CI->getArgOperand(2), + false, AATags.TBAA, AATags.Scope, AATags.NoAlias); } bool LibCallSimplifier::hasFloatVersion(StringRef FuncName) { @@ -3246,9 +3314,12 @@ Value *FortifiedLibCallSimplifier::optimizeMemCpyChk(CallInst *CI, IRBuilderBase &B) { if (isFortifiedCallFoldable(CI, 3, 2)) { + AAMDNodes AATags; + CI->getAAMetadata(AATags); CallInst *NewCI = B.CreateMemCpy(CI->getArgOperand(0), Align(1), CI->getArgOperand(1), - Align(1), CI->getArgOperand(2)); + Align(1), CI->getArgOperand(2), + false, AATags.TBAA, AATags.TBAAStruct, AATags.Scope, AATags.NoAlias); NewCI->setAttributes(CI->getAttributes()); return CI->getArgOperand(0); } @@ -3258,9 +3329,12 @@ Value *FortifiedLibCallSimplifier::optimizeMemMoveChk(CallInst *CI, IRBuilderBase &B) { if (isFortifiedCallFoldable(CI, 3, 2)) { + AAMDNodes AATags; + CI->getAAMetadata(AATags); CallInst *NewCI = B.CreateMemMove(CI->getArgOperand(0), Align(1), CI->getArgOperand(1), - Align(1), CI->getArgOperand(2)); + Align(1), CI->getArgOperand(2), + false, AATags.TBAA, AATags.Scope, AATags.NoAlias); NewCI->setAttributes(CI->getAttributes()); return CI->getArgOperand(0); } @@ -3273,8 +3347,11 @@ if (isFortifiedCallFoldable(CI, 3, 2)) { Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(), false); + AAMDNodes AATags; + CI->getAAMetadata(AATags); CallInst *NewCI = B.CreateMemSet(CI->getArgOperand(0), Val, - CI->getArgOperand(2), Align(1)); + CI->getArgOperand(2), Align(1), + false, AATags.TBAA, AATags.Scope, AATags.NoAlias); NewCI->setAttributes(CI->getAttributes()); return CI->getArgOperand(0); } @@ -3288,9 +3365,11 @@ Value *Dst = CI->getArgOperand(0), *Src = CI->getArgOperand(1), *ObjSize = CI->getArgOperand(2); + AAMDNodes AATags; + CI->getAAMetadata(AATags); // __stpcpy_chk(x,x,...) -> x+strlen(x) if (Func == LibFunc_stpcpy_chk && !OnlyLowerUnknownSize && Dst == Src) { - Value *StrLen = emitStrLen(Src, B, DL, TLI); + Value *StrLen = emitStrLen(Src, B, DL, TLI, AATags); return StrLen ? B.CreateInBoundsGEP(B.getInt8Ty(), Dst, StrLen) : nullptr; } @@ -3301,9 +3380,9 @@ // string lengths for varying. if (isFortifiedCallFoldable(CI, 2, None, 1)) { if (Func == LibFunc_strcpy_chk) - return emitStrCpy(Dst, Src, B, TLI); + return emitStrCpy(Dst, Src, B, TLI, AATags); else - return emitStpCpy(Dst, Src, B, TLI); + return emitStpCpy(Dst, Src, B, TLI, AATags); } if (OnlyLowerUnknownSize) @@ -3318,7 +3397,7 @@ Type *SizeTTy = DL.getIntPtrType(CI->getContext()); Value *LenV = ConstantInt::get(SizeTTy, Len); - Value *Ret = emitMemCpyChk(Dst, Src, LenV, ObjSize, B, DL, TLI); + Value *Ret = emitMemCpyChk(Dst, Src, LenV, ObjSize, B, DL, TLI, AATags); // If the function was an __stpcpy_chk, and we were able to fold it into // a __memcpy_chk, we still need to return the correct end pointer. if (Ret && Func == LibFunc_stpcpy_chk) @@ -3328,9 +3407,12 @@ Value *FortifiedLibCallSimplifier::optimizeStrLenChk(CallInst *CI, IRBuilderBase &B) { - if (isFortifiedCallFoldable(CI, 1, None, 0)) + if (isFortifiedCallFoldable(CI, 1, None, 0)) { + AAMDNodes AATags; + CI->getAAMetadata(AATags); return emitStrLen(CI->getArgOperand(0), B, CI->getModule()->getDataLayout(), - TLI); + TLI, AATags); + } return nullptr; } @@ -3338,12 +3420,14 @@ IRBuilderBase &B, LibFunc Func) { if (isFortifiedCallFoldable(CI, 3, 2)) { + AAMDNodes AATags; + CI->getAAMetadata(AATags); if (Func == LibFunc_strncpy_chk) return emitStrNCpy(CI->getArgOperand(0), CI->getArgOperand(1), - CI->getArgOperand(2), B, TLI); + CI->getArgOperand(2), B, TLI, AATags); else return emitStpNCpy(CI->getArgOperand(0), CI->getArgOperand(1), - CI->getArgOperand(2), B, TLI); + CI->getArgOperand(2), B, TLI, AATags); } return nullptr; @@ -3351,9 +3435,12 @@ Value *FortifiedLibCallSimplifier::optimizeMemCCpyChk(CallInst *CI, IRBuilderBase &B) { - if (isFortifiedCallFoldable(CI, 4, 3)) + if (isFortifiedCallFoldable(CI, 4, 3)) { + AAMDNodes AATags; + CI->getAAMetadata(AATags); return emitMemCCpy(CI->getArgOperand(0), CI->getArgOperand(1), - CI->getArgOperand(2), CI->getArgOperand(3), B, TLI); + CI->getArgOperand(2), CI->getArgOperand(3), B, TLI, AATags); + } return nullptr; } @@ -3362,8 +3449,10 @@ IRBuilderBase &B) { if (isFortifiedCallFoldable(CI, 3, 1, None, 2)) { SmallVector VariadicArgs(CI->arg_begin() + 5, CI->arg_end()); + AAMDNodes AATags; + CI->getAAMetadata(AATags); return emitSNPrintf(CI->getArgOperand(0), CI->getArgOperand(1), - CI->getArgOperand(4), VariadicArgs, B, TLI); + CI->getArgOperand(4), VariadicArgs, B, TLI, AATags); } return nullptr; @@ -3373,8 +3462,10 @@ IRBuilderBase &B) { if (isFortifiedCallFoldable(CI, 2, None, None, 1)) { SmallVector VariadicArgs(CI->arg_begin() + 4, CI->arg_end()); + AAMDNodes AATags; + CI->getAAMetadata(AATags); return emitSPrintf(CI->getArgOperand(0), CI->getArgOperand(3), VariadicArgs, - B, TLI); + B, TLI, AATags); } return nullptr; @@ -3382,53 +3473,71 @@ Value *FortifiedLibCallSimplifier::optimizeStrCatChk(CallInst *CI, IRBuilderBase &B) { - if (isFortifiedCallFoldable(CI, 2)) - return emitStrCat(CI->getArgOperand(0), CI->getArgOperand(1), B, TLI); + if (isFortifiedCallFoldable(CI, 2)) { + AAMDNodes AATags; + CI->getAAMetadata(AATags); + return emitStrCat(CI->getArgOperand(0), CI->getArgOperand(1), B, TLI, AATags); + } return nullptr; } Value *FortifiedLibCallSimplifier::optimizeStrLCat(CallInst *CI, IRBuilderBase &B) { - if (isFortifiedCallFoldable(CI, 3)) + if (isFortifiedCallFoldable(CI, 3)) { + AAMDNodes AATags; + CI->getAAMetadata(AATags); return emitStrLCat(CI->getArgOperand(0), CI->getArgOperand(1), - CI->getArgOperand(2), B, TLI); + CI->getArgOperand(2), B, TLI, AATags); + } return nullptr; } Value *FortifiedLibCallSimplifier::optimizeStrNCatChk(CallInst *CI, IRBuilderBase &B) { - if (isFortifiedCallFoldable(CI, 3)) + if (isFortifiedCallFoldable(CI, 3)) { + AAMDNodes AATags; + CI->getAAMetadata(AATags); return emitStrNCat(CI->getArgOperand(0), CI->getArgOperand(1), - CI->getArgOperand(2), B, TLI); + CI->getArgOperand(2), B, TLI, AATags); + } return nullptr; } Value *FortifiedLibCallSimplifier::optimizeStrLCpyChk(CallInst *CI, IRBuilderBase &B) { - if (isFortifiedCallFoldable(CI, 3)) + if (isFortifiedCallFoldable(CI, 3)) { + AAMDNodes AATags; + CI->getAAMetadata(AATags); return emitStrLCpy(CI->getArgOperand(0), CI->getArgOperand(1), - CI->getArgOperand(2), B, TLI); + CI->getArgOperand(2), B, TLI, AATags); + } return nullptr; } Value *FortifiedLibCallSimplifier::optimizeVSNPrintfChk(CallInst *CI, IRBuilderBase &B) { - if (isFortifiedCallFoldable(CI, 3, 1, None, 2)) + if (isFortifiedCallFoldable(CI, 3, 1, None, 2)) { + AAMDNodes AATags; + CI->getAAMetadata(AATags); return emitVSNPrintf(CI->getArgOperand(0), CI->getArgOperand(1), - CI->getArgOperand(4), CI->getArgOperand(5), B, TLI); + CI->getArgOperand(4), CI->getArgOperand(5), B, TLI, AATags); + } return nullptr; } Value *FortifiedLibCallSimplifier::optimizeVSPrintfChk(CallInst *CI, IRBuilderBase &B) { - if (isFortifiedCallFoldable(CI, 2, None, None, 1)) + if (isFortifiedCallFoldable(CI, 2, None, None, 1)) { + AAMDNodes AATags; + CI->getAAMetadata(AATags); return emitVSPrintf(CI->getArgOperand(0), CI->getArgOperand(3), - CI->getArgOperand(4), B, TLI); + CI->getArgOperand(4), B, TLI, AATags); + } return nullptr; }