Skip to content

Commit a3fb234

Browse files
committed
[BasicAA] Return std::optional from getObjectSize() (NFC)
Prefer this over UnknownSize, especially once the return value switches to something other than uint64_t.
1 parent 324d1bb commit a3fb234

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,18 @@ bool BasicAAResult::invalidate(Function &Fn, const PreservedAnalyses &PA,
101101
//===----------------------------------------------------------------------===//
102102

103103
/// Returns the size of the object specified by V or UnknownSize if unknown.
104-
static uint64_t getObjectSize(const Value *V, const DataLayout &DL,
105-
const TargetLibraryInfo &TLI,
106-
bool NullIsValidLoc,
107-
bool RoundToAlign = false) {
104+
static std::optional<uint64_t> getObjectSize(const Value *V,
105+
const DataLayout &DL,
106+
const TargetLibraryInfo &TLI,
107+
bool NullIsValidLoc,
108+
bool RoundToAlign = false) {
108109
uint64_t Size;
109110
ObjectSizeOpts Opts;
110111
Opts.RoundToAlign = RoundToAlign;
111112
Opts.NullIsUnknownSize = NullIsValidLoc;
112113
if (getObjectSize(V, Size, DL, &TLI, Opts))
113114
return Size;
114-
return MemoryLocation::UnknownSize;
115+
return std::nullopt;
115116
}
116117

117118
/// Returns true if we can prove that the object specified by V is smaller than
@@ -151,10 +152,10 @@ static bool isObjectSmallerThan(const Value *V, uint64_t Size,
151152

152153
// This function needs to use the aligned object size because we allow
153154
// reads a bit past the end given sufficient alignment.
154-
uint64_t ObjectSize = getObjectSize(V, DL, TLI, NullIsValidLoc,
155-
/*RoundToAlign*/ true);
155+
std::optional<uint64_t> ObjectSize = getObjectSize(V, DL, TLI, NullIsValidLoc,
156+
/*RoundToAlign*/ true);
156157

157-
return ObjectSize != MemoryLocation::UnknownSize && ObjectSize < Size;
158+
return ObjectSize && *ObjectSize < Size;
158159
}
159160

160161
/// Return the minimal extent from \p V to the end of the underlying object,
@@ -182,8 +183,9 @@ static uint64_t getMinimalExtentFrom(const Value &V,
182183
/// Returns true if we can prove that the object specified by V has size Size.
183184
static bool isObjectSize(const Value *V, uint64_t Size, const DataLayout &DL,
184185
const TargetLibraryInfo &TLI, bool NullIsValidLoc) {
185-
uint64_t ObjectSize = getObjectSize(V, DL, TLI, NullIsValidLoc);
186-
return ObjectSize != MemoryLocation::UnknownSize && ObjectSize == Size;
186+
std::optional<uint64_t> ObjectSize =
187+
getObjectSize(V, DL, TLI, NullIsValidLoc);
188+
return ObjectSize && *ObjectSize == Size;
187189
}
188190

189191
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)