This is an archive of the discontinued LLVM Phabricator instance.

[Diagnostic] Clarify -Winfinite-recursion message
Needs ReviewPublic

Authored by Codesbyusman on Jun 14 2022, 8:59 AM.

Diff Detail

Event Timeline

Codesbyusman created this revision.Jun 14 2022, 8:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 14 2022, 8:59 AM
Codesbyusman requested review of this revision.Jun 14 2022, 8:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 14 2022, 8:59 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaron.ballman added a subscriber: aaron.ballman.

Thank you for looking into this! I'm adding a few more reviewers for awareness.

clang/include/clang/Basic/DiagnosticSemaKinds.td
63

A few things:

  • Diagnostics in Clang are not intended to be grammatically correct, so they don't start with a capital letter or end with a trailing full stop (so if this wording was kept, you should use in order instead of In order).
  • While this is a cute way to get the point across, we want the diagnostic to help guide the user as to why their code is wrong so they have the best chance to fix the issue.

I think the original wording isn't too bad here because it's lexically associated with the function definition itself (so the "this function" is clear in situ), but I do think "will call itself" is a bit awkward. Perhaps "this function is called recursively on all paths through the function", but I don't feel strongly either.

clang/test/SemaCXX/warn-infinite-recursion.cpp
11

It looks like you formatted the whole file -- we typically try to have the only changes in the patch be specifically about the changes driving the patch, instead of mixing several fixes together into one patch. While it seems a bit less efficient than it could be, having a clean separation eases maintenance burdens for us. If we need to revert a patch for some reason, we don't lose potentially good changes along with the bad ones. But also, it makes it more clear if we need to do a git-blame as to why changes were introduced.

You should revert the formatting-specific changes in the file so that the only differences are the functional ones.

erichkeane added inline comments.Jun 14 2022, 10:49 AM
clang/include/clang/Basic/DiagnosticSemaKinds.td
63

I like the suggestion by Aaron here, "function %0 is called recursively through all paths through %0" (or the function). Perhaps the double %0 is a touch of a recursion joke as well :)

aaron.ballman added inline comments.Jun 14 2022, 10:51 AM
clang/include/clang/Basic/DiagnosticSemaKinds.td
63

TBH, I'd probably skip the %0 because the warning is issued on the same line as the function definition itself, so the name should already be obvious to the user.

This diagnostic doesn't currently handle mutually recursive functions, and I kind of worry that adding %0 implies we support that case when we don't.

Codesbyusman added inline comments.Jun 14 2022, 12:28 PM
clang/include/clang/Basic/DiagnosticSemaKinds.td
63

"this function is called recursively on all paths through the function" is good. what you say which will be more better as the "all paths through this function will call itself" is also ok.

63

if i am not wrong it is indicating the infinite recursion as no base case. can we prompt user in some a decent manner that the base case is missing. i.e. including some phrase in "this function is called recursively on all paths through the function" that shows base case was missing or this would be a bad idea? any suggestions.

clang/test/SemaCXX/warn-infinite-recursion.cpp
11

my bad, didn't notice, on save formatter was enabled. I will revert it. By the way nice advice. Thank you

erichkeane added inline comments.Jun 14 2022, 12:30 PM
clang/include/clang/Basic/DiagnosticSemaKinds.td
63

I think I'd like the first one, the location data alone is pretty annoying in many cases.

erichkeane added inline comments.Jun 14 2022, 12:48 PM
clang/include/clang/Basic/DiagnosticSemaKinds.td
63

I think I'd like the first one, the location data alone is pretty annoying in many cases.

Spoke with Aaron offline, our policy is to just use the names when it is ambiguous/helpful in a way that knowing the line is not. I'm not a huge fan of the policy, but am not going to lobby it here, feel free to use one of hte below suggestions.

aaron.ballman added inline comments.Jun 14 2022, 12:53 PM
clang/include/clang/Basic/DiagnosticSemaKinds.td
63

Spoke with Aaron offline, our policy is to just use the names when it is ambiguous/helpful in a way that knowing the line is not. I'm not a huge fan of the policy, but am not going to lobby it here, feel free to use one of hte below suggestions.

FWIW, my feelings are not super strongly held (and it's possible this isn't "policy" so much as "the way some folks do things"), so if @Codesbyusman decides he wants to use %0 to name the function in the diagnostic or not, that's fine by me also. The only bit I definitely feel strongly about is not repeating the function name in the diagnostic and avoiding an implication that the diagnostic works for detecting mutual recursion. So I'd be fine with function %0 is called recursively on all paths through the function

xgupta resigned from this revision.Nov 29 2022, 7:50 PM