This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Add Zircon module to clang-tidy
ClosedPublic

Authored by juliehockett on Mar 9 2018, 5:45 PM.

Details

Summary

Adding a Zircon module to clang-tidy for checks specific to the Zircon kernel, with a checker to fuchsia-zx (for zircon) to flag instances where specific objects are temporarily created.

Diff Detail

Event Timeline

juliehockett created this revision.Mar 9 2018, 5:45 PM
Eugene.Zelenko added inline comments.
clang-tidy/fuchsia/ZxTemporaryObjectsCheck.cpp
24 ↗(On Diff #137885)

Please include STLExtras.h and string.

clang-tidy/fuchsia/ZxTemporaryObjectsCheck.h
31 ↗(On Diff #137885)

This contradict documentation which claims that default is empty.

docs/ReleaseNotes.rst
81

I think you could omit second statement.

docs/clang-tidy/checks/fuchsia-zx-temporary-objects.rst
38 ↗(On Diff #137885)

Please use 2 spaces indentation and 80 characters limit. Continuation should be indented too.

aaron.ballman added inline comments.Mar 12 2018, 1:03 PM
clang-tidy/fuchsia/FuchsiaTidyModule.cpp
44 ↗(On Diff #137885)

Do we want a zircon module instead? I'm wondering about people who enable modules by doing fuchsia-* and whether or not they would expect this check (and others for zircon) to be enabled.

clang-tidy/fuchsia/ZxTemporaryObjectsCheck.cpp
46 ↗(On Diff #137885)

Elide braces.

47 ↗(On Diff #137885)

I think this could be stated more clearly as "creating a temporary object of type %0 is prohibited" and pass in the temporary type. That will also help the user to identify what type is problematic in something like: f(good_temp{}, bad_temp{}, good_temp{});. I'm not tied to printing the type, but "misuse" suggests there's a better way to use the temporary object, which I don't think is a correct interpretation.

clang-tidy/fuchsia/ZxTemporaryObjectsCheck.h
20 ↗(On Diff #137885)

Construction instead of constructing?

juliehockett marked 8 inline comments as done.
juliehockett retitled this revision from [clang-tidy] Add Fuchsia checker for temporary objects to [clang-tidy] Add Zircon module to clang-tidy.
juliehockett edited the summary of this revision. (Show Details)

Moved check to new Zircon module, fixed comments

aaron.ballman added inline comments.Mar 13 2018, 1:06 PM
clang-tidy/tool/ClangTidyMain.cpp
527

You can go ahead and commit this change directly to trunk, no need to roll it in to this patch (since it's an unrelated drive-by). No review necessary.

clang-tidy/zircon/TemporaryObjectsCheck.cpp
32

Full stop at the end of comments (here and elsewhere).

52

You can skip the call to getQualifiedNameAsString(); the diagnostics engine will handle it properly.

clang-tidy/zircon/TemporaryObjectsCheck.h
22–23

I think the "Takes the list" sentence could be made more clear as "The list of disallowed temporary object types is configurable.", but you could probably just drop the sentence entirely as well.

docs/clang-tidy/checks/list.rst
93

Can you keep this list alphabetical?

docs/clang-tidy/index.rst
78

s/Zercon/Zircon

juliehockett marked 6 inline comments as done.

Addressing comments

Eugene.Zelenko added inline comments.Mar 13 2018, 2:38 PM
docs/ReleaseNotes.rst
77

Please sort new checks in alphabetical order.

I dreamed up some test cases that may or may not make sense. I think they boil down to a few things:

  • Does inheriting from a prohibited type still diagnose when the derived type is used to construct a temporary?
  • Should it still be prohibited if the temporary type is being returned?
clang-tidy/zircon/ZirconTidyModule.cpp
30

Can you add a bit of vertical whitespace before this comment?

test/clang-tidy/zircon-temporary-objects.cpp
83

Some additional test cases:

template <typename Ty>
Ty make_ty() { return Ty{}; }

// Call make_ty<> with two types: one allowed and one disallowed; I assume only the disallowed triggers the diagnostic.

struct Bingo : NS::Bar {}; // Not explicitly disallowed

void f() {
  Bingo{}; // Should this diagnose because it inherits from Bar?
}

// Assuming derived classes diagnose if the base is prohibited:
template <typename Ty>
struct Quux : Ty {};

void f() {
  Quux<NS::Bar>{}; // Diagnose
  Quux<Bar>{}; // Fine?
}
juliehockett marked 3 inline comments as done.

Addomg tests amd fixing documentation

aaron.ballman added inline comments.Mar 13 2018, 6:13 PM
test/clang-tidy/zircon-temporary-objects.cpp
87

Why? I thought Bar was allowed, but NS::Bar was prohibited?

96

The documentation should explicitly call this out, as it's different than I would have expected (I was assuming the derived classes would inherit the prohibition).

108–109

The comments here seem amiss.

juliehockett marked 3 inline comments as done.

Fixing tests and updating docs

aaron.ballman added inline comments.Mar 14 2018, 11:04 AM
clang-tidy/zircon/TemporaryObjectsCheck.cpp
52

This doesn't seem to be done?

docs/clang-tidy/checks/zircon-temporary-objects.rst
37–38

Can you hoist this into the exposition as well? It seems sufficiently important to warrant calling out in something other than an example.

juliehockett added inline comments.Mar 14 2018, 11:08 AM
clang-tidy/fuchsia/FuchsiaTidyModule.cpp
44 ↗(On Diff #137885)

We definitely can -- it would be nice to have the additional separation (so that non-zircon parts of fuchsia don't need to explicitly disable checks.

test/clang-tidy/zircon-temporary-objects.cpp
83

For the inheritance ones, Quux would have to be explicitly included in the list in order to be triggered by the checker (to avoid over-diagnosing), so in this case no warnings should be generated.

87

Artifact of passing in the decl instead of the fully-qualified name string -- the automatic to-string method generates just the unqualified name.

aaron.ballman added inline comments.Mar 14 2018, 11:15 AM
clang-tidy/zircon/TemporaryObjectsCheck.cpp
52

Ah, I see why now. You should change to %q0 (and drop the existing single quotes) and then get rid of getQualifiedNameAsString().

juliehockett marked 2 inline comments as done.

Updating decl passed to warning string

juliehockett marked 3 inline comments as done.

Updating docs.

Fixing a typo sorry

aaron.ballman accepted this revision.Mar 14 2018, 4:10 PM

LGTM with some minor documentation nits.

docs/clang-tidy/checks/zircon-temporary-objects.rst
7

Nit: the docs conflate objects and types somewhat. The configuration specifies prohibited types, and objects of that type are the problem. How about: If the object should be flagged, the fully qualified type name must be explicitly passed to the check.

36–37

Same problem here. How about: "This check matches temporary objects without regard for inheritance and so a prohibited base class type does not similarly prohibit derived class types."

This revision is now accepted and ready to land.Mar 14 2018, 4:10 PM
This revision was automatically updated to reflect the committed changes.
juliehockett marked 2 inline comments as done.