This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix bug in readability-uppercase-literal-suffix
ClosedPublic

Authored by carlosgalvezp on Sep 26 2021, 2:55 AM.

Details

Summary

Fixes https://bugs.llvm.org/show_bug.cgi?id=51790. The check triggers incorrectly with non-type template parameters.

A bisect determined that the bug was introduced here:
https://github.com/llvm/llvm-project/commit/ea2225a10be986d226e041d20d36dff17e78daed

Unfortunately that patch can no longer be reverted on top of the main branch, so add a fix instead. Add a unit test to avoid regression in the future.

Diff Detail

Event Timeline

carlosgalvezp created this revision.Sep 26 2021, 2:55 AM
carlosgalvezp requested review of this revision.Sep 26 2021, 2:55 AM

I personally think this fix should happen when doing the match, not when analyzing the matches. This is my first patch to LLVM and I'm not knowledgeable in AST so I don't really know how to go about that :) Please come with suggestions if there's a better way to do this!

Thank you for the fix!

clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
137–138
clang-tools-extra/test/clang-tidy/checkers/readability-uppercase-literal-suffix-integer.cpp
286

Can you add a // CHECK-MESSAGES-NOT: line to the places where we used to diagnose but no longer do? That helps make the test more explicit.

Another test to add is a nontype template parameter whose identifier ends in a digit just before the i. e.g., foo1i

Fixed review comments

carlosgalvezp marked 2 inline comments as done.Sep 27 2021, 6:40 AM
carlosgalvezp retitled this revision from [clang-tidy] Fix bug 51790 in readability-uppercase-literal-suffix to [clang-tidy] Fix bug in readability-uppercase-literal-suffix.Sep 27 2021, 6:56 AM
carlosgalvezp edited the summary of this revision. (Show Details)
aaron.ballman accepted this revision.Sep 27 2021, 10:41 AM

LGTM, thank you! Would you like me to commit on your behalf? If so, please let me know what name and email address you'd like me to use for patch attribution in git.

This revision is now accepted and ready to land.Sep 27 2021, 10:41 AM

Awesome, thanks a lot for the review! :) Sure, you can use the following to commit on my behalf, since I don't think I have such permissions:

Carlos Galvez
carlosgalvezp@gmail.com

Awesome, thanks a lot for the review! :) Sure, you can use the following to commit on my behalf, since I don't think I have such permissions:

Carlos Galvez
carlosgalvezp@gmail.com

Thanks! I've commit on your behalf in b2a2c38349a18b89b04d342632d5ea02f86dfdd6.

carlosgalvezp added a comment.EditedSep 27 2021, 11:14 AM

Super, thanks! It went really smooth :)

Newbie question: I noticed that [clang-tidy] is no longer part of the commit message, I thought the intention was to keep it to more easily glance through the commit history?

Super, thanks! It went really smooth :)

Newbie question: I noticed that [clang-tidy] is no longer part of the commit message, I thought the intention was to keep it to more easily glance through the commit history?

We usually put [project] markings in the subject so it's easier for code reviewers to know what PRs are in an area of interest to them, and I suppose I could keep them as part of the commit message. But the commit message "title" is supposed to be concise (I hear 50 characters is a common measure for it), so I usually remove the [project] marker reflexively to keep the title of the commit brief.

Btw, this patch failed some bots because of a missing #include which I've added in ef0f728abe6ec43f2f75082c9b47ec7fade2ead2.

Thanks for the clarification, makes sense! I got the notification about the build failure, thanks for fixing. I actually added it in the first place but then noticed that checkers typically didn't include any STL header so I thought maybe there was a restriction on their usage or something. The code compiled just fine when running the "clang-check-tools" target. Good to know for the next time :)

PS: I've also reported the build errors in pre-merge, maybe they would have caught it earlier.