diff options
author | Kazu Hirata <kazu@google.com> | 2022-12-02 19:43:04 -0800 |
---|---|---|
committer | Kazu Hirata <kazu@google.com> | 2022-12-02 19:43:04 -0800 |
commit | 19aff0f37dd68ee51e78b764c0ce629ae73d1eef (patch) | |
tree | 07403086631814ae1ff7742c8c6dac4fb67b5088 /llvm/lib/Analysis/MemoryBuiltins.cpp | |
parent | fef3a16aeab660d0789c592985993bd68b51f517 (diff) | |
download | llvm-19aff0f37dd68ee51e78b764c0ce629ae73d1eef.zip llvm-19aff0f37dd68ee51e78b764c0ce629ae73d1eef.tar.gz llvm-19aff0f37dd68ee51e78b764c0ce629ae73d1eef.tar.bz2 |
[Analysis] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated. The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.
This is part of an effort to migrate from llvm::Optional to
std::optional:
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
Diffstat (limited to 'llvm/lib/Analysis/MemoryBuiltins.cpp')
-rw-r--r-- | llvm/lib/Analysis/MemoryBuiltins.cpp | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp index 9deb966..2d0a3e1 100644 --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -177,12 +177,12 @@ getAllocationDataForFunction(const Function *Callee, AllocType AllocTy, // Don't perform a slow TLI lookup, if this function doesn't return a pointer // and thus can't be an allocation function. if (!Callee->getReturnType()->isPointerTy()) - return None; + return std::nullopt; // Make sure that the function is available. LibFunc TLIFn; if (!TLI || !TLI->getLibFunc(*Callee, TLIFn) || !TLI->has(TLIFn)) - return None; + return std::nullopt; const auto *Iter = find_if( AllocationFnData, [TLIFn](const std::pair<LibFunc, AllocFnsTy> &P) { @@ -190,11 +190,11 @@ getAllocationDataForFunction(const Function *Callee, AllocType AllocTy, }); if (Iter == std::end(AllocationFnData)) - return None; + return std::nullopt; const AllocFnsTy *FnData = &Iter->second; if ((FnData->AllocTy & AllocTy) != FnData->AllocTy) - return None; + return std::nullopt; // Check function prototype. int FstParam = FnData->FstParam; @@ -210,7 +210,7 @@ getAllocationDataForFunction(const Function *Callee, AllocType AllocTy, FTy->getParamType(SndParam)->isIntegerTy(32) || FTy->getParamType(SndParam)->isIntegerTy(64))) return *FnData; - return None; + return std::nullopt; } static Optional<AllocFnsTy> getAllocationData(const Value *V, AllocType AllocTy, @@ -219,7 +219,7 @@ static Optional<AllocFnsTy> getAllocationData(const Value *V, AllocType AllocTy, if (const Function *Callee = getCalledFunction(V, IsNoBuiltinCall)) if (!IsNoBuiltinCall) return getAllocationDataForFunction(Callee, AllocTy, TLI); - return None; + return std::nullopt; } static Optional<AllocFnsTy> @@ -230,7 +230,7 @@ getAllocationData(const Value *V, AllocType AllocTy, if (!IsNoBuiltinCall) return getAllocationDataForFunction( Callee, AllocTy, &GetTLI(const_cast<Function &>(*Callee))); - return None; + return std::nullopt; } static Optional<AllocFnsTy> getAllocationSize(const Value *V, @@ -239,7 +239,7 @@ static Optional<AllocFnsTy> getAllocationSize(const Value *V, const Function *Callee = getCalledFunction(V, IsNoBuiltinCall); if (!Callee) - return None; + return std::nullopt; // Prefer to use existing information over allocsize. This will give us an // accurate AllocTy. @@ -250,7 +250,7 @@ static Optional<AllocFnsTy> getAllocationSize(const Value *V, Attribute Attr = Callee->getFnAttribute(Attribute::AllocSize); if (Attr == Attribute()) - return None; + return std::nullopt; std::pair<unsigned, std::optional<unsigned>> Args = Attr.getAllocSizeArgs(); @@ -402,7 +402,7 @@ llvm::getAllocSize(const CallBase *CB, const TargetLibraryInfo *TLI, // allocsize. The code structure could stand to be cleaned up a bit. Optional<AllocFnsTy> FnData = getAllocationSize(CB, TLI); if (!FnData) - return None; + return std::nullopt; // Get the index type for this address space, results and intermediate // computations are performed at that width. @@ -413,14 +413,14 @@ llvm::getAllocSize(const CallBase *CB, const TargetLibraryInfo *TLI, if (FnData->AllocTy == StrDupLike) { APInt Size(IntTyBits, GetStringLength(Mapper(CB->getArgOperand(0)))); if (!Size) - return None; + return std::nullopt; // Strndup limits strlen. if (FnData->FstParam > 0) { const ConstantInt *Arg = dyn_cast<ConstantInt>(Mapper(CB->getArgOperand(FnData->FstParam))); if (!Arg) - return None; + return std::nullopt; APInt MaxSize = Arg->getValue().zext(IntTyBits); if (Size.ugt(MaxSize)) @@ -432,11 +432,11 @@ llvm::getAllocSize(const CallBase *CB, const TargetLibraryInfo *TLI, const ConstantInt *Arg = dyn_cast<ConstantInt>(Mapper(CB->getArgOperand(FnData->FstParam))); if (!Arg) - return None; + return std::nullopt; APInt Size = Arg->getValue(); if (!CheckedZextOrTrunc(Size, IntTyBits)) - return None; + return std::nullopt; // Size is determined by just 1 parameter. if (FnData->SndParam < 0) @@ -444,16 +444,16 @@ llvm::getAllocSize(const CallBase *CB, const TargetLibraryInfo *TLI, Arg = dyn_cast<ConstantInt>(Mapper(CB->getArgOperand(FnData->SndParam))); if (!Arg) - return None; + return std::nullopt; APInt NumElems = Arg->getValue(); if (!CheckedZextOrTrunc(NumElems, IntTyBits)) - return None; + return std::nullopt; bool Overflow; Size = Size.umul_ov(NumElems, Overflow); if (Overflow) - return None; + return std::nullopt; return Size; } @@ -529,7 +529,7 @@ Optional<FreeFnsTy> getFreeFunctionDataForFunction(const Function *Callee, return P.first == TLIFn; }); if (Iter == std::end(FreeFnData)) - return None; + return std::nullopt; return Iter->second; } @@ -538,7 +538,7 @@ Optional<StringRef> llvm::getAllocationFamily(const Value *I, bool IsNoBuiltin; const Function *Callee = getCalledFunction(I, IsNoBuiltin); if (Callee == nullptr || IsNoBuiltin) - return None; + return std::nullopt; LibFunc TLIFn; if (TLI && TLI->getLibFunc(*Callee, TLIFn) && TLI->has(TLIFn)) { @@ -557,7 +557,7 @@ Optional<StringRef> llvm::getAllocationFamily(const Value *I, if (Attr.isValid()) return Attr.getValueAsString(); } - return None; + return std::nullopt; } /// isLibFreeFunction - Returns true if the function is a builtin free() |