From 20ba079dda7be1a72d64cebc9f55d909bf29f6c1 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Fri, 25 Nov 2022 15:38:53 -0800 Subject: [PATCH] [StaticAnalyzer] Don't use Optional::create (NFC) Note that std::optional does not offer create(). 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 --- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp index 4528dbc..f99ef04 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -480,9 +480,8 @@ ProgramStateRef ExprEngine::setIndexOfElementToConstruct( Optional ExprEngine::getPendingInitLoop(ProgramStateRef State, const CXXConstructExpr *E, const LocationContext *LCtx) { - - return Optional::create( - State->get({E, LCtx->getStackFrame()})); + const unsigned *V = State->get({E, LCtx->getStackFrame()}); + return V ? Optional(*V) : std::nullopt; } ProgramStateRef ExprEngine::removePendingInitLoop(ProgramStateRef State, @@ -509,9 +508,9 @@ Optional ExprEngine::getIndexOfElementToConstruct(ProgramStateRef State, const CXXConstructExpr *E, const LocationContext *LCtx) { - - return Optional::create( - State->get({E, LCtx->getStackFrame()})); + const unsigned *V = + State->get({E, LCtx->getStackFrame()}); + return V ? Optional(*V) : std::nullopt; } ProgramStateRef @@ -529,8 +528,9 @@ ExprEngine::getPendingArrayDestruction(ProgramStateRef State, const LocationContext *LCtx) { assert(LCtx && "LocationContext shouldn't be null!"); - return Optional::create( - State->get(LCtx->getStackFrame())); + const unsigned *V = + State->get(LCtx->getStackFrame()); + return V ? Optional(*V) : std::nullopt; } ProgramStateRef ExprEngine::setPendingArrayDestruction( @@ -599,7 +599,8 @@ ExprEngine::getObjectUnderConstruction(ProgramStateRef State, const ConstructionContextItem &Item, const LocationContext *LC) { ConstructedObjectKey Key(Item, LC->getStackFrame()); - return Optional::create(State->get(Key)); + const SVal *V = State->get(Key); + return V ? Optional(*V) : std::nullopt; } ProgramStateRef -- 2.7.4