D59466 wants to analyse the Stmt, and ExceptionEscapeCheck does not
have that as a possible entry point.
This simplifies addition of Stmt analysis entry point.
Details
Diff Detail
- Repository
- rCTE Clang Tools Extra
Event Timeline
Why not having normal overloads? The analysis for Stmt is implemented with the private methods. Explicit template specialization is a bit overkill and so easily understood (but not too complex in this case either).l
The alternative is to add something like:
ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::analyze(const Stmt *Stmt) { ExceptionInfo ExceptionList; llvm::SmallSet<const FunctionDecl *, 32> CallStack; ExceptionList = throwsException(Func, CallStack); if (ExceptionList.getBehaviour() == State::NotThrowing || ExceptionList.getBehaviour() == State::Unknown) return ExceptionList; // Remove all ignored exceptions from the list of exceptions that can be // thrown. ExceptionList.filterIgnoredExceptions(IgnoredExceptions, IgnoreBadAlloc); return ExceptionList; }
.. which ends up duplicating all of the boilerplate (blacklist in particular)
from ExceptionAnalyzer::analyze(const FunctionDecl *Func).
Looks like pointless code duplication that is easily avoidable.
Looks like pointless code duplication that is easily avoidable.
True, but I would prefer the refactoring to be private then (so the template stuff with the boilerplate) and a simple overloading interface dispatching to the templated stuff.
In the end I think the public interface is cleaner, easier to understand and not so easily misused (as the template would accept everything in principle, and SFINAE would be worse).
Keep templated function out of the public interface.
Right. That looks a bit better. Works for me, thank you!
clang-tidy/utils/ExceptionAnalyzer.cpp | ||
---|---|---|
226 | Please bikeshed on the name. I don't think this one is good. |
clang-tidy/utils/ExceptionAnalyzer.cpp | ||
---|---|---|
226 | Hmm, analyzeGeneric, analyzeGeneral, abstractAnalysis, analyzeAbstract, something good in these? Given its private its not too important either ;) |
clang-tidy/utils/ExceptionAnalyzer.cpp | ||
---|---|---|
208 | I'd suggest to make it a non-template and call it also analyzeImpl() and return ExceptionInfo by value. | |
226 | I'd suggest to simplify by changing analyzeBoilerplate() into a non-template, into this specifically: ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::filterIgnoredExceptions(ExceptionInfo ExceptionList) { if (ExceptionList.getBehaviour() == State::NotThrowing || ExceptionList.getBehaviour() == State::Unknown) return ExceptionList; // Remove all ignored exceptions from the list of exceptions that can be // thrown. ExceptionList.filterIgnoredExceptions(IgnoredExceptions, IgnoreBadAlloc); return ExceptionList; } And then call it in analyze(): ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::analyze(const FunctionDecl *Func) { return filterIgnoredExceptions(analyzeImpl(Func)); } |
Address some nits.
clang-tidy/utils/ExceptionAnalyzer.cpp | ||
---|---|---|
226 | Hmm not really. |
clang-tidy/utils/ExceptionAnalyzer.cpp | ||
---|---|---|
226 |
... and tests should catch it. No big drama. Anyway, it is not as important. I do think however that complicating the code this way is not worth the benefit. |
@gribozavr thank you for the review!
@baloghadamsoftware any comments?
clang-tidy/utils/ExceptionAnalyzer.cpp | ||
---|---|---|
226 | That is kind of the point. The test would catch it if they would already exist. |
clang-tidy/utils/ExceptionAnalyzer.cpp | ||
---|---|---|
226 |
Not really -- the new entry point can skip calling analyzeDispatch (and roll its own analysis) just like it can skip calling filterIgnoredException(). |
clang-tidy/utils/ExceptionAnalyzer.cpp | ||
---|---|---|
226 | Yep. I'm just hoping that that would look more out-of-place/be more noticeable than omitting some intermediate call. |
I'm gonna go with post-commit review here, if @baloghadamsoftware will have any notes, although this now looks rather uncontroversial.
I'd suggest to make it a non-template and call it also analyzeImpl() and return ExceptionInfo by value.