Index: llvm/include/llvm/Analysis/TargetLibraryInfo.h =================================================================== --- llvm/include/llvm/Analysis/TargetLibraryInfo.h +++ llvm/include/llvm/Analysis/TargetLibraryInfo.h @@ -392,6 +392,13 @@ return Attribute::None; } + /// Add an integer extension attribute to the specified argument of F. + void setArgExtAttr(Function *F, unsigned ArgNo, bool Signed = true) const { + Attribute::AttrKind ExtAttr = getExtAttrForI32Param(Signed); + if (ExtAttr != Attribute::None && !F->hasParamAttribute(ArgNo, ExtAttr)) + F->addParamAttr(ArgNo, ExtAttr); + } + /// Returns extension attribute kind to be used for i32 return values /// corresponding to C-level int or unsigned int. May be zeroext, signext, /// or none. Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp =================================================================== --- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -3376,13 +3376,17 @@ // Add Hint to entry Args and create call EnterArgs.push_back(HintInst); RTFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_critical_with_hint); + // TLI.setArgExtAttr(RTFn, 1, false); + // TLI.setArgExtAttr(RTFn, 3, false); } else { RTFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_critical); + // TLI.setArgExtAttr(RTFn, 1, false); } Instruction *EntryCall = Builder.CreateCall(RTFn, EnterArgs); Function *ExitRTLFn = getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_end_critical); + // TLI.setArgExtAttr(ExitRTLFn, 1, false); Instruction *ExitCall = Builder.CreateCall(ExitRTLFn, Args); return EmitOMPInlinedRegion(OMPD, EntryCall, ExitCall, BodyGenCB, FiniCB, Index: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -708,7 +708,7 @@ private: friend struct FunctionStackPoisoner; - void initializeCallbacks(Module &M); + void initializeCallbacks(Module &M, const TargetLibraryInfo *TLI); bool LooksLikeCodeInBug11395(Instruction *I); bool GlobalIsLinkerInitialized(GlobalVariable *G); @@ -2475,7 +2475,7 @@ return true; } -void AddressSanitizer::initializeCallbacks(Module &M) { +void AddressSanitizer::initializeCallbacks(Module &M, const TargetLibraryInfo *TLI) { IRBuilder<> IRB(*C); // Create __asan_report* callbacks. // IsWrite, TypeSize and Exp are encoded in the function name. @@ -2495,10 +2495,20 @@ AsanErrorCallbackSized[AccessIsWrite][Exp] = M.getOrInsertFunction( kAsanReportErrorTemplate + ExpStr + TypeStr + "_n" + EndingStr, FunctionType::get(IRB.getVoidTy(), Args2, false)); + if (Exp) { + Function *F = + cast(AsanErrorCallbackSized[AccessIsWrite][Exp].getCallee()); + TLI->setArgExtAttr(F, 2, false); + } AsanMemoryAccessCallbackSized[AccessIsWrite][Exp] = M.getOrInsertFunction( ClMemoryAccessCallbackPrefix + ExpStr + TypeStr + "N" + EndingStr, FunctionType::get(IRB.getVoidTy(), Args2, false)); + if (Exp) { + Function *F = cast( + AsanMemoryAccessCallbackSized[AccessIsWrite][Exp].getCallee()); + TLI->setArgExtAttr(F, 2, false); + } for (size_t AccessSizeIndex = 0; AccessSizeIndex < kNumberOfAccessSizes; AccessSizeIndex++) { @@ -2507,11 +2517,23 @@ M.getOrInsertFunction( kAsanReportErrorTemplate + ExpStr + Suffix + EndingStr, FunctionType::get(IRB.getVoidTy(), Args1, false)); + if (Exp) { + Function *F = + cast(AsanErrorCallback[AccessIsWrite][Exp][AccessSizeIndex] + .getCallee()); + TLI->setArgExtAttr(F, 2, false); + } AsanMemoryAccessCallback[AccessIsWrite][Exp][AccessSizeIndex] = M.getOrInsertFunction( ClMemoryAccessCallbackPrefix + ExpStr + Suffix + EndingStr, FunctionType::get(IRB.getVoidTy(), Args1, false)); + if (Exp) { + Function *F = + cast(AsanMemoryAccessCallback[AccessIsWrite][Exp] + [AccessSizeIndex].getCallee()); + TLI->setArgExtAttr(F, 2, false); + } } } } @@ -2529,6 +2551,7 @@ AsanMemset = M.getOrInsertFunction(MemIntrinCallbackPrefix + "memset", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IRB.getInt32Ty(), IntptrTy); + TLI->setArgExtAttr(cast(AsanMemset.getCallee()), 1); AsanHandleNoReturnFunc = M.getOrInsertFunction(kAsanHandleNoReturnName, IRB.getVoidTy()); @@ -2653,7 +2676,7 @@ LLVM_DEBUG(dbgs() << "ASAN instrumenting:\n" << F << "\n"); - initializeCallbacks(*F.getParent()); + initializeCallbacks(*F.getParent(), TLI); FunctionStateRAII CleanupObj(this); Index: llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -1022,10 +1022,11 @@ }; FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false); AttributeList AL; - if (auto AK = TLI->getExtAttrForI32Param(false)) + if (auto AK = TLI->getExtAttrForI32Param(false)) { + AL = AL.addParamAttribute(*Ctx, 1, AK); AL = AL.addParamAttribute(*Ctx, 2, AK); - FunctionCallee Res = M->getOrInsertFunction("llvm_gcda_start_file", FTy, AL); - return Res; + } + return M->getOrInsertFunction("llvm_gcda_start_file", FTy, AL); } FunctionCallee GCOVProfiler::getEmitFunctionFunc(const TargetLibraryInfo *TLI) { @@ -1041,7 +1042,7 @@ AL = AL.addParamAttribute(*Ctx, 1, AK); AL = AL.addParamAttribute(*Ctx, 2, AK); } - return M->getOrInsertFunction("llvm_gcda_emit_function", FTy); + return M->getOrInsertFunction("llvm_gcda_emit_function", FTy, AL); } FunctionCallee GCOVProfiler::getEmitArcsFunc(const TargetLibraryInfo *TLI) { Index: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -542,9 +542,9 @@ friend struct VarArgSystemZHelper; void initializeModule(Module &M); - void initializeCallbacks(Module &M); - void createKernelApi(Module &M); - void createUserspaceApi(Module &M); + void initializeCallbacks(Module &M, const TargetLibraryInfo &TLI); + void createKernelApi(Module &M, const TargetLibraryInfo &TLI); + void createUserspaceApi(Module &M, const TargetLibraryInfo &TLI); /// True if we're compiling the Linux kernel. bool CompileKernel; @@ -733,7 +733,7 @@ } /// Create KMSAN API callbacks. -void MemorySanitizer::createKernelApi(Module &M) { +void MemorySanitizer::createKernelApi(Module &M, const TargetLibraryInfo &TLI) { IRBuilder<> IRB(*C); // These will be initialized in insertKmsanPrologue(). @@ -747,6 +747,7 @@ WarningFn = M.getOrInsertFunction("__msan_warning", IRB.getVoidTy(), IRB.getInt32Ty()); + TLI.setArgExtAttr(cast(WarningFn.getCallee()), 0, false); // Requests the per-task context state (kmsan_context_state*) from the // runtime library. MsanContextStateTy = StructType::get( @@ -797,7 +798,7 @@ } /// Insert declarations for userspace-specific functions and globals. -void MemorySanitizer::createUserspaceApi(Module &M) { +void MemorySanitizer::createUserspaceApi(Module &M, const TargetLibraryInfo &TLI) { IRBuilder<> IRB(*C); // Create the callback. @@ -808,6 +809,7 @@ : "__msan_warning_with_origin_noreturn"; WarningFn = M.getOrInsertFunction(WarningFnName, IRB.getVoidTy(), IRB.getInt32Ty()); + TLI.setArgExtAttr(cast(WarningFn.getCallee()), 0, false); } else { StringRef WarningFnName = Recover ? "__msan_warning" : "__msan_warning_noreturn"; @@ -852,6 +854,9 @@ MaybeWarningFn[AccessSizeIndex] = M.getOrInsertFunction( FunctionName, AttributeList::get(*C, MaybeWarningFnAttrs), IRB.getVoidTy(), IRB.getIntNTy(AccessSize * 8), IRB.getInt32Ty()); + if (AccessSize * 8 <= 32) + TLI.setArgExtAttr(cast(MaybeWarningFn[AccessSizeIndex].getCallee()), 0, false); + TLI.setArgExtAttr(cast(MaybeWarningFn[AccessSizeIndex].getCallee()), 1, false); FunctionName = "__msan_maybe_store_origin_" + itostr(AccessSize); SmallVector, 2> MaybeStoreOriginFnAttrs; @@ -863,6 +868,9 @@ FunctionName, AttributeList::get(*C, MaybeStoreOriginFnAttrs), IRB.getVoidTy(), IRB.getIntNTy(AccessSize * 8), IRB.getInt8PtrTy(), IRB.getInt32Ty()); + if (AccessSize * 8 <= 32) + TLI.setArgExtAttr(cast(MaybeStoreOriginFn[AccessSizeIndex].getCallee()), 0, false); + TLI.setArgExtAttr(cast(MaybeStoreOriginFn[AccessSizeIndex].getCallee()), 2, false); } MsanSetAllocaOriginWithDescriptionFn = M.getOrInsertFunction( @@ -876,7 +884,7 @@ } /// Insert extern declaration of runtime-provided functions and globals. -void MemorySanitizer::initializeCallbacks(Module &M) { +void MemorySanitizer::initializeCallbacks(Module &M, const TargetLibraryInfo &TLI) { // Only do this once. if (CallbacksInitialized) return; @@ -886,9 +894,11 @@ // instrumentation. MsanChainOriginFn = M.getOrInsertFunction("__msan_chain_origin", IRB.getInt32Ty(), IRB.getInt32Ty()); + TLI.setArgExtAttr(cast(MsanChainOriginFn.getCallee()), 0, false); MsanSetOriginFn = M.getOrInsertFunction("__msan_set_origin", IRB.getVoidTy(), IRB.getInt8PtrTy(), IntptrTy, IRB.getInt32Ty()); + TLI.setArgExtAttr(cast(MsanSetOriginFn.getCallee()), 2, false); MemmoveFn = M.getOrInsertFunction("__msan_memmove", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IntptrTy); @@ -898,15 +908,16 @@ MemsetFn = M.getOrInsertFunction("__msan_memset", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IRB.getInt32Ty(), IntptrTy); + TLI.setArgExtAttr(cast(MemsetFn.getCallee()), 1); MsanInstrumentAsmStoreFn = M.getOrInsertFunction("__msan_instrument_asm_store", IRB.getVoidTy(), PointerType::get(IRB.getInt8Ty(), 0), IntptrTy); if (CompileKernel) { - createKernelApi(M); + createKernelApi(M, TLI); } else { - createUserspaceApi(M); + createUserspaceApi(M, TLI); } CallbacksInitialized = true; } @@ -1135,7 +1146,7 @@ // It's easier to remove unreachable blocks than deal with missing shadow. removeUnreachableBlocks(F); - MS.initializeCallbacks(*F.getParent()); + MS.initializeCallbacks(*F.getParent(), TLI); FnPrologueEnd = IRBuilder<>(F.getEntryBlock().getFirstNonPHI()) .CreateIntrinsic(Intrinsic::donothing, {}, {}); Index: llvm/lib/Transforms/Utils/BuildLibCalls.cpp =================================================================== --- llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -1237,13 +1237,6 @@ return Changed; } -static void setArgExtAttr(Function &F, unsigned ArgNo, - const TargetLibraryInfo &TLI, bool Signed = true) { - Attribute::AttrKind ExtAttr = TLI.getExtAttrForI32Param(Signed); - if (ExtAttr != Attribute::None && !F.hasParamAttribute(ArgNo, ExtAttr)) - F.addParamAttr(ArgNo, ExtAttr); -} - // Modeled after X86TargetLowering::markLibCallAttributes. static void markRegisterParameterAttributes(Function *F) { if (!F->arg_size() || F->isVarArg()) @@ -1301,7 +1294,7 @@ switch (TheLibFunc) { case LibFunc_fputc: case LibFunc_putchar: - setArgExtAttr(*F, 0, TLI); + TLI.setArgExtAttr(F, 0); break; case LibFunc_ldexp: case LibFunc_ldexpf: @@ -1309,10 +1302,10 @@ case LibFunc_memchr: case LibFunc_memrchr: case LibFunc_strchr: - setArgExtAttr(*F, 1, TLI); + TLI.setArgExtAttr(F, 1); break; case LibFunc_memccpy: - setArgExtAttr(*F, 2, TLI); + TLI.setArgExtAttr(F, 2); break; // These are functions that are known to not need any argument extension