This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][NFC] Refactor AnalysisConsumer::getModeForDecl()
ClosedPublic

Authored by steakhal on Nov 23 2021, 7:26 AM.

Details

Summary

I just read this part of the code, and I found the nested ifs less readable.

Diff Detail

Event Timeline

steakhal created this revision.Nov 23 2021, 7:26 AM
steakhal requested review of this revision.Nov 23 2021, 7:26 AM

I should note that I compared this on multiple projects to the baseline version and no runtime nor reports changed.
So, this is purely a cosmetic change.

martong accepted this revision.Nov 23 2021, 7:50 AM

LGTM!

This revision is now accepted and ready to land.Nov 23 2021, 7:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 29 2021, 1:39 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ASDenysPetrov added inline comments.Nov 29 2021, 3:31 AM
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
599–603

Why don't just leave this snippet as it was but add const SourceLocation Loc instead of re-assigning SL? Your construction made me stumbled for a while. As this patch is meant to bring readability, I wouldn't like to see such a code-trick. I see your intention to hide SL but IMO let compiler do this for us. See suggested.

steakhal added inline comments.Nov 29 2021, 5:48 AM
clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
599–603

Hm, you are probably right. The main idea was to reduce the number of unrelated declarations in the scope by nesting them into the calculation of the important ones.
However, we could relax in this case. I agree that would be even better.