================
@@ -1154,6 +1154,21 @@ auto buildDiagnoseMatchSwitch(
// lot of duplicated work (e.g. string comparisons), consider providing APIs
// that avoid it through memoization.
auto IgnorableOptional = ignorableOptional(Options);
+ if (Options.IgnoreValueCalls) {
+ // Only diagnose operator-based unwraps. Value calls are ignored.
+ return CFGMatchSwitchBuilder<
+ const Environment,
+ llvm::SmallVector<UncheckedOptionalAccessDiagnostic>>()
+ // optional::operator*, optional::operator->
+ .CaseOfCFGStmt<CallExpr>(valueOperatorCall(IgnorableOptional),
+ [](const CallExpr *E,
+ const MatchFinder::MatchResult &,
+ const Environment &Env) {
+ return diagnoseUnwrapCall(E->getArg(0),
Env);
+ })
----------------
vbvictor wrote:
We shouldn't duplicate code here.
We should first add case with `*, ->` and save temporary builder variable. Then
`if (!IgnoreValueCalls)` add case with `value`. In the end, call `.Build()`.
See that build returns himself
https://github.com/llvm/llvm-project/blob/d4b41b9de091b39525fdf3fcbf1b86a3895fbc48/clang/include/clang/Analysis/FlowSensitive/CFGMatchSwitch.h#L47-L53
https://github.com/llvm/llvm-project/pull/167209
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits