Skip to content

Commit 10b4bd0

Browse files
committed
Drop the CachedMacroValue class
1 parent 5eb1d22 commit 10b4bd0

File tree

2 files changed

+7
-24
lines changed

2 files changed

+7
-24
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,6 @@ Nullability getNullabilityAnnotation(QualType Type);
7373
/// returned.
7474
std::optional<int> tryExpandAsInteger(StringRef Macro, const Preprocessor &PP);
7575

76-
class CachedMacroValue {
77-
public:
78-
CachedMacroValue(StringRef MacroSpelling, const Preprocessor &PP)
79-
: MacroValueOrFailure(tryExpandAsInteger(MacroSpelling, PP)) {}
80-
explicit CachedMacroValue(int ConcreteValue)
81-
: MacroValueOrFailure(ConcreteValue) {}
82-
83-
int valueOr(int Default) const {
84-
return MacroValueOrFailure.value_or(Default);
85-
}
86-
bool hasValue() const { return MacroValueOrFailure.has_value(); }
87-
int value() const { return MacroValueOrFailure.value(); }
88-
89-
private:
90-
std::optional<int> MacroValueOrFailure;
91-
};
92-
9376
class OperatorKind {
9477
union {
9578
BinaryOperatorKind Bin;

clang/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ enum class OpenVariant {
4040
OpenAt
4141
};
4242

43-
static CachedMacroValue getCreateFlagValue(const ASTContext &Ctx,
44-
const Preprocessor &PP) {
45-
CachedMacroValue MacroVal("O_CREAT", PP);
46-
if (MacroVal.hasValue())
43+
static std::optional<int> getCreateFlagValue(const ASTContext &Ctx,
44+
const Preprocessor &PP) {
45+
std::optional<int> MacroVal = tryExpandAsInteger("O_CREAT", PP);
46+
if (MacroVal.has_value())
4747
return MacroVal;
4848

4949
// If we failed, fall-back to known values.
5050
if (Ctx.getTargetInfo().getTriple().getVendor() == llvm::Triple::Apple)
51-
return CachedMacroValue{0x0200};
51+
return {0x0200};
5252
return MacroVal;
5353
}
5454

@@ -61,7 +61,7 @@ class UnixAPIMisuseChecker : public Checker<check::PreCall> {
6161
const BugType BT_pthreadOnce{this, "Improper use of 'pthread_once'",
6262
categories::UnixAPI};
6363
const BugType BT_ArgumentNull{this, "NULL pointer", categories::UnixAPI};
64-
const CachedMacroValue Val_O_CREAT;
64+
const std::optional<int> Val_O_CREAT;
6565

6666
ProgramStateRef
6767
EnsurePtrNotNull(SVal PtrVal, const Expr *PtrExpr, CheckerContext &C,
@@ -262,7 +262,7 @@ void UnixAPIMisuseChecker::CheckOpenVariant(CheckerContext &C,
262262
return;
263263
}
264264

265-
if (!Val_O_CREAT.hasValue()) {
265+
if (!Val_O_CREAT.has_value()) {
266266
return;
267267
}
268268

0 commit comments

Comments
 (0)