Skip to content

Commit ede97cb

Browse files
committed
Fix
1 parent 79693d6 commit ede97cb

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ struct UncheckedOptionalAccessModelOptions {
4848
bool IgnoreSmartPointerDereference = false;
4949

5050
/// In generating diagnostics, ignore calls to `optional::value()`.
51-
///
52-
/// Projects that intentionally use `value()` as a guarded access pattern may
53-
/// set this to true to suppress diagnostics for `value()` while continuing to
54-
/// diagnose UB-prone operator accesses (`operator*`, `operator->`).
5551
bool IgnoreValueCalls = false;
5652
};
5753

clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,26 +1155,30 @@ auto buildDiagnoseMatchSwitch(
11551155
// that avoid it through memoization.
11561156
const auto IgnorableOptional = ignorableOptional(Options);
11571157

1158-
auto Builder = CFGMatchSwitchBuilder<
1159-
const Environment,
1160-
llvm::SmallVector<UncheckedOptionalAccessDiagnostic>>()
1161-
.CaseOfCFGStmt<CallExpr>(
1162-
valueOperatorCall(IgnorableOptional),
1163-
[](const CallExpr *E, const MatchFinder::MatchResult &,
1164-
const Environment &Env) {
1165-
return diagnoseUnwrapCall(E->getArg(0), Env);
1166-
});
1167-
1168-
if (!Options.IgnoreValueCalls) {
1169-
return std::move(Builder)
1170-
.CaseOfCFGStmt<CXXMemberCallExpr>(
1171-
valueCall(IgnorableOptional),
1172-
[](const CXXMemberCallExpr *E, const MatchFinder::MatchResult &,
1173-
const Environment &Env) {
1174-
return diagnoseUnwrapCall(E->getImplicitObjectArgument(), Env);
1175-
})
1176-
.Build();
1177-
}
1158+
auto DiagBuilder =
1159+
CFGMatchSwitchBuilder<
1160+
const Environment,
1161+
llvm::SmallVector<UncheckedOptionalAccessDiagnostic>>()
1162+
// optional::operator*, optional::operator->
1163+
.CaseOfCFGStmt<CallExpr>(
1164+
valueOperatorCall(IgnorableOptional),
1165+
[](const CallExpr *E, const MatchFinder::MatchResult &,
1166+
const Environment &Env) {
1167+
return diagnoseUnwrapCall(E->getArg(0), Env);
1168+
});
1169+
1170+
auto Builder = Options.IgnoreValueCalls
1171+
? std::move(DiagBuilder)
1172+
: std::move(DiagBuilder)
1173+
// optional::value
1174+
.CaseOfCFGStmt<CXXMemberCallExpr>(
1175+
valueCall(IgnorableOptional),
1176+
[](const CXXMemberCallExpr *E,
1177+
const MatchFinder::MatchResult &,
1178+
const Environment &Env) {
1179+
return diagnoseUnwrapCall(
1180+
E->getImplicitObjectArgument(), Env);
1181+
});
11781182

11791183
return std::move(Builder).Build();
11801184
}

0 commit comments

Comments
 (0)