1818#include " support/Logger.h"
1919#include " support/TypeUtil.h"
2020
21- #include " llvm/ADT/None.h"
22- #include " llvm/ADT/Optional.h"
2321#include " llvm/ADT/STLExtras.h"
2422#include " llvm/ADT/SmallPtrSet.h"
2523#include " llvm/ADT/StringRef.h"
24+
2625#if LLVM_VERSION_MAJOR >= 12
2726#include " llvm/Analysis/ValueTracking.h" // llvm::findAllocaForValue
2827#else
3837#include " llvm/Support/raw_ostream.h"
3938
4039#include < cstddef>
40+ #include < optional>
4141
4242namespace typeart ::analysis {
4343
@@ -82,26 +82,26 @@ void MemOpVisitor::visitCallBase(llvm::CallBase& cb) {
8282 if (!collect_heap) {
8383 return ;
8484 }
85- const auto isInSet = [&](const auto & fMap ) -> llvm::Optional <MemOpKind> {
85+ const auto isInSet = [&](const auto & fMap ) -> std::optional <MemOpKind> {
8686 const auto * f = cb.getCalledFunction ();
8787 if (!f) {
8888 // TODO handle calls through, e.g., function pointers? - seems infeasible
8989 // LOG_INFO("Encountered indirect call, skipping.");
90- return None ;
90+ return {} ;
9191 }
9292 const auto name = f->getName ().str ();
9393
9494 const auto res = fMap .find (name);
9595 if (res != fMap .end ()) {
9696 return {(*res).second };
9797 }
98- return None ;
98+ return {} ;
9999 };
100100
101101 if (auto alloc_val = isInSet (mem_operations.allocs ())) {
102- visitMallocLike (cb, alloc_val.getValue ());
102+ visitMallocLike (cb, alloc_val.value ());
103103 } else if (auto dealloc_val = isInSet (mem_operations.deallocs ())) {
104- visitFreeLike (cb, dealloc_val.getValue ());
104+ visitFreeLike (cb, dealloc_val.value ());
105105 }
106106}
107107
@@ -216,8 +216,8 @@ llvm::Expected<ArrayCookieData> handlePaddedArrayCookie(const MallocGeps& geps,
216216 return {ArrayCookieData{*cookie_store, array_gep}};
217217}
218218
219- llvm::Optional <ArrayCookieData> handleArrayCookie (const MallocGeps& geps, MallocBcasts& bcasts,
220- BitCastInst*& primary_cast) {
219+ std::optional <ArrayCookieData> handleArrayCookie (const MallocGeps& geps, MallocBcasts& bcasts,
220+ BitCastInst*& primary_cast) {
221221 auto exit_on_error = llvm::ExitOnError{" Array Cookie Detection failed!" };
222222 if (geps.size () == 1 ) {
223223 return exit_on_error (handleUnpaddedArrayCookie (geps, bcasts, primary_cast));
@@ -232,7 +232,7 @@ llvm::Optional<ArrayCookieData> handleArrayCookie(const MallocGeps& geps, Malloc
232232 LOG_FATAL (err);
233233 exit_on_error ({error::make_string_error (err)});
234234 }
235- return llvm::None ;
235+ return {} ;
236236}
237237
238238void MemOpVisitor::visitMallocLike (llvm::CallBase& ci, MemOpKind k) {
@@ -253,12 +253,12 @@ void MemOpVisitor::visitFreeLike(llvm::CallBase& ci, MemOpKind k) {
253253 if (auto f = ci.getCalledFunction ()) {
254254 auto dkind = mem_operations.deallocKind (f->getName ());
255255 if (dkind) {
256- kind = dkind.getValue ();
256+ kind = dkind.value ();
257257 }
258258 }
259259
260260 auto gep = dyn_cast<GetElementPtrInst>(ci.getArgOperand (0 ));
261- auto array_cookie_gep = gep != nullptr ? llvm::Optional <llvm::GetElementPtrInst*>{gep} : llvm::None ;
261+ auto array_cookie_gep = gep != nullptr ? std::optional <llvm::GetElementPtrInst*>{gep} : std:: nullopt ;
262262 frees.emplace_back (FreeData{&ci, array_cookie_gep, kind, isa<InvokeInst>(ci)});
263263}
264264
0 commit comments