Tidy check behavior often depends on language and/or clang-tidy options. This revision allows a user of TranformerClangTidyCheck to pass rule _generator_ in place of a rule, where the generator takes both the language and clang-tidy options. Additionally, the generator returns an Optional to allow for the case where the check is deemed irrelevant/disable based on those options.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Thanks for the review!
clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp | ||
---|---|---|
33 ↗ | (On Diff #204581) | I think not, but please correct me if I'm wrong (and clearly I should add a comment explaining this): in order to get meaningful results from getLangOpts and Options, we need the ClangTidyCheck() constructor to have been called. If we were to dispatch, it would look like: : TransformerClangTidyCheck(MakeRule(getLangOpts(), Options), Name, Context) {} which, if I understand correctly, means that MakeRule will access that data _before_ the check object is properly initialized. That said, I can factor out the assertion into a method to avoid the redundancy. WDYT? |
clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp | ||
---|---|---|
33 ↗ | (On Diff #204581) | You're right. I don't think it is necessary to factor out the assertion -- up to you. |
Adjust comments in test.
clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp | ||
---|---|---|
33 ↗ | (On Diff #204581) | Decided not to factor. |
clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp | ||
---|---|---|
92 ↗ | (On Diff #206258) | Would adding -std=c99 to ExtraArgs, and setting Filename to input.c work? |
clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp | ||
---|---|---|
92 ↗ | (On Diff #206258) | No, nothing seems to work. I can't find a way to ever set bits in LangOptions. I'm rather confused why that's the case... |
clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp | ||
---|---|---|
92 ↗ | (On Diff #206258) | I found the answer: getLangOpts() is not guaranteed to work at check-creation time. This makes sense, since a single check may be run against many different files. I'd say its a flaw in the API though since it seems like a feature of the check, when its really a feature of the file. We should update the API to warn about this and possibly improve it to avoid the confusion. I'll update the code to save the std::function and invoke at registerMatchers() time instead. |
clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp | ||
---|---|---|
92 ↗ | (On Diff #206258) | Never mind my previous point -- this only holds for the particular way that runCheckOnCode is implemented (which is arguably a bug). For the real clang tidy, LangOpts is a feature of the tool invocation and is therefore constant across the lifetime of the check. I will send a change to runCheckOnCode that fixes this -- that is, ensures LangOpts is set *before* the Check is constructed, and then this will work correctly. |
clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp | ||
---|---|---|
69 ↗ | (On Diff #206510) | "Objective-C" (with a dash) |