[clang] 20ba079 - [StaticAnalyzer] Don't use Optional::create (NFC)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 25 15:39:07 PST 2022
Author: Kazu Hirata
Date: 2022-11-25T15:38:53-08:00
New Revision: 20ba079dda7be1a72d64cebc9f55d909bf29f6c1
URL: https://github.com/llvm/llvm-project/commit/20ba079dda7be1a72d64cebc9f55d909bf29f6c1
DIFF: https://github.com/llvm/llvm-project/commit/20ba079dda7be1a72d64cebc9f55d909bf29f6c1.diff
LOG: [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
Added:
Modified:
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
index 4528dbc0cc36..f99ef04584a7 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -480,9 +480,8 @@ ProgramStateRef ExprEngine::setIndexOfElementToConstruct(
Optional<unsigned> ExprEngine::getPendingInitLoop(ProgramStateRef State,
const CXXConstructExpr *E,
const LocationContext *LCtx) {
-
- return Optional<unsigned>::create(
- State->get<PendingInitLoop>({E, LCtx->getStackFrame()}));
+ const unsigned *V = State->get<PendingInitLoop>({E, LCtx->getStackFrame()});
+ return V ? Optional(*V) : std::nullopt;
}
ProgramStateRef ExprEngine::removePendingInitLoop(ProgramStateRef State,
@@ -509,9 +508,9 @@ Optional<unsigned>
ExprEngine::getIndexOfElementToConstruct(ProgramStateRef State,
const CXXConstructExpr *E,
const LocationContext *LCtx) {
-
- return Optional<unsigned>::create(
- State->get<IndexOfElementToConstruct>({E, LCtx->getStackFrame()}));
+ const unsigned *V =
+ State->get<IndexOfElementToConstruct>({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<unsigned>::create(
- State->get<PendingArrayDestruction>(LCtx->getStackFrame()));
+ const unsigned *V =
+ State->get<PendingArrayDestruction>(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<SVal>::create(State->get<ObjectsUnderConstruction>(Key));
+ const SVal *V = State->get<ObjectsUnderConstruction>(Key);
+ return V ? Optional(*V) : std::nullopt;
}
ProgramStateRef
More information about the cfe-commits
mailing list