This is an archive of the discontinued LLVM Phabricator instance.

[Analyzer] Bugfix for CheckerRegistry
ClosedPublic

Authored by baloghadamsoftware on Mar 9 2020, 5:15 AM.

Details

Summary

CheckerRegistry registers a checker either if it is excplicitly enabled or it is a dependency of an explicitly enabled checker and is not explicitly disabled. In both cases it is also important that the checker should be registered (shoudRegisterXXX() returns true).

Currently there is a bug here: if the dependenct checker is not explicitly disabled it is registered regardless of whether it should be registered. This patch fixes this bug.

Diff Detail

Event Timeline

If we disable the dependency of a checker explicitly I think we should at least emit a warning.

If we disable the dependency of a checker explicitly I think we should at least emit a warning.

I agree, but I do not thik that this should be part of this patch. This is only a small bugfix.

I looked in the unittests directory but could not find tests for dependency handling. @Szelethus, feel free to commandeer this patch if you know how to test it.

If we disable the dependency of a checker explicitly I think we should at least emit a warning.

I agree, but I do not thik that this should be part of this patch. This is only a small bugfix.

Oof. We wanted to do that for a long time but there were compatibility concerns -- in any case, we totally could emit an error at least when -analyzer-config-compatibility-mode is false and for newer checkers and a warning for older ones.

I distinctively remember a lot of concerns being raised around this. @dcoughlin, @NoQ, how does what I suggested here sound like?

I looked in the unittests directory but could not find tests for dependency handling. @Szelethus, feel free to commandeer this patch if you know how to test it.

This should be the thing you're looking for: clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp. It might be a good idea to wait for me to land D67335 first, though :)

I am not sure if I would call this a bugfix. Enabling a checker without one of its dependency will potentially cause the checker to misbehave. I am uncomfortable changing the current behavior to a more dangerous one without any diagnostics. Including the diagnostic with this patch should not make this too big.

I am not sure if I would call this a bugfix. Enabling a checker without one of its dependency will potentially cause the checker to misbehave. I am uncomfortable changing the current behavior to a more dangerous one without any diagnostics. Including the diagnostic with this patch should not make this too big.

This is a bugfix. The current behavior is wrong due to a mistake. A checker is registered which should not and this may cause crashes.

I am not sure if I would call this a bugfix. Enabling a checker without one of its dependency will potentially cause the checker to misbehave. I am uncomfortable changing the current behavior to a more dangerous one without any diagnostics. Including the diagnostic with this patch should not make this too big.

This is a bugfix. The current behavior is wrong due to a mistake. A checker is registered which should not and this may cause crashes.

Oh, sorry. I misunderstood the description. My bad. In this case I am ok with having the diagnostic in a separate patch.

Szelethus added a comment.EditedMar 9 2020, 8:51 AM

The thing to note here is checkers that are isDisabled() won't get enabled, only if they are isEnabled() as well :)

Please add a unit test, otherwise LGTM. I just landed D67335, so it should be easy to do.

Szelethus added inline comments.Mar 10 2020, 4:32 AM
clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
85

How about Unsatisfied checker dependency.?

92

Isn't this overkill? The test above test only the output, but don't outright cause a crash.

111–112

Same thing.

143

I don't think this is checking what you're looking for -- the test should be whether Diag is an empty string, while runCheckerOnCode returns true when the tool (the static analyzer, in this case) terminates successfully, even if it doesn't work the way we expect it to.

baloghadamsoftware marked an inline comment as done.Mar 10 2020, 5:02 AM
baloghadamsoftware added inline comments.
clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
143

There could be hundreds of alternative approaches, but this test exactly simulates the real-world problem: the checker crashes because it should not be registered. Of course, I tried the test without the bugfix and it fails as it should because the tool terminates unsuccessfully if the prerequisite checker is registered.

Szelethus added inline comments.Mar 10 2020, 9:13 AM
clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
143

This is still confusing. Please check the string, that should contain what you need and nothing else, and the asserts could be removed as a result -- it shouldn't be more then 5 lines.

Updated according to the comments.

baloghadamsoftware marked 4 inline comments as done.Mar 17 2020, 12:29 PM
Szelethus accepted this revision.Mar 18 2020, 4:39 AM

LGTM, thanks!

This revision is now accepted and ready to land.Mar 18 2020, 4:39 AM
This revision was automatically updated to reflect the committed changes.