This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Support implicit parameters in path note
ClosedPublic

Authored by jkorous on Sep 13 2022, 4:00 PM.

Details

Summary

showBRParamDiagnostics assumed stores happen only via function parameters while that can also happen via implicit parameters like 'self' or 'this'.
The regression test caused a failed assert in the original cast to ParmVarDecl.

rdar://99687986

Diff Detail

Event Timeline

jkorous created this revision.Sep 13 2022, 4:00 PM
Herald added a project: Restricted Project. · View Herald Transcript
jkorous requested review of this revision.Sep 13 2022, 4:00 PM

@NoQ I tried to tease out a note that would allow me to test 'this' as well but didn't find any such situation.
Shall I just remove that case?

NoQ added a comment.Sep 13 2022, 6:12 PM

Thanks nice!!

That's right, this cannot be hit there because it's not represented by VarRegion (but by a CXXThisRegion). It's also a slightly different story because this, unlike self, cannot be reassigned mid-way.

clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
1384

This looks like an llvm_unreachable() to me.

clang/test/Analysis/path-notes-impl-param.m
24

It's usually a good idea to write down these warnings even if they aren't being tested. We want the programmers to revisit the test every time they break at least one of the notes, and then visually confirm that the updated report makes sense *as a whole*.

jkorous added inline comments.Sep 16 2022, 3:03 PM
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
1384

Do I understand correctly that would crash in a release build?
https://llvm.org/doxygen/Support_2ErrorHandling_8h_source.html#l00143

Wouldn't not-printing any parameter-kind-specific message be better?

If we want to get awareness of these cases we could just use assert.

clang/test/Analysis/path-notes-impl-param.m
24

Got it! I aimed for the test to be specific and didn't realize the consistency aspect.

jkorous updated this revision to Diff 460921.Sep 16 2022, 4:45 PM

Check for specific diagnostics in the test.

jkorous marked an inline comment as not done.Sep 16 2022, 4:45 PM
NoQ added inline comments.Sep 19 2022, 7:45 PM
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
1384

Aha yeah, I was thinking like, the usual thing where we handle all the cases and then have a compile-time warning if something else can happen, so unreachable will be verified at compile time and won't actually be hit on switch branches.

But I agree that listing all the cases isn't very productive in this case. So yeah, let's just assert that it's a self.

But now that you listed all the cases, we should probably talk about ObjCCmd (it's spelled as _cmd in any ObjC method and resolves to the selector of that method). The selector pointer in any stack frame is usually brand new, it doesn't make sense to track it into the outside world. So I suspect that we should assert that it can't be encountered here. Unless we called a function by variable selector?... I don't think we model that yet, and even if so, I can't think of a checker that would warn in such case (if that selector is nil or undefined, there's no stack frame to pop back from; if the selector is constrained to nil inside the current stack frame, there's no reason to track it further). So let's assert that this never happens.

jkorous updated this revision to Diff 461945.Sep 21 2022, 10:38 AM

Remove mention of other implicit parameter kinds.

jkorous added inline comments.Sep 21 2022, 10:40 AM
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
1384

Shall we just make it an if checking for self pointer kind?

NoQ accepted this revision.Sep 21 2022, 4:31 PM

Ok LGTM!

clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
1384

Either way is fine I guess. One way or another, if the message isn't good enough we'll probably find out.

This revision is now accepted and ready to land.Sep 21 2022, 4:31 PM
This revision was landed with ongoing or failed builds.Sep 21 2022, 5:27 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 21 2022, 5:27 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript