This is an archive of the discontinued LLVM Phabricator instance.

[clang] Pass the NamedDecl* instead of the DeclarationName into many diagnostics.
ClosedPublic

Authored by riccibruno on Jul 27 2020, 6:56 AM.

Details

Summary

Background:

There are two related argument types which can be sent into a diagnostic to display the name of an entity: DeclarationName (ak_declarationname) or NamedDecl * (ak_nameddecl) (there is also ak_identifierinfo for IdentifierInfo *, but we are not concerned with it here).

A DeclarationName in a diagnostic will just be streamed to the output, which will directly result in a call to DeclarationName::print.

A NamedDecl * in a diagnostic will also ultimately result in a call to DeclarationName::print, but with two customisation points along the way.

The first customisation point is NamedDecl::getNameForDiagnostic which is overloaded by FunctionDecl, ClassTemplateSpecializationDecl and VarTemplateSpecializationDecl to print the template arguments if any.

The second customisation point is NamedDecl::printName. By default it just streams the stored DeclarationName into the output but it can be customised to provide a user-friendly name for an entity. It is currently overloaded by DecompositionDecl and MSGuidDecl.

What this patch does:

For many diagnostics a DeclarationName is used instead of the NamedDecl *. This bypasses the two customisation points mentioned above. This patches fix this for diagnostics in Sema.cpp, SemaCast.cpp, SemaChecking.cpp, SemaDecl.cpp, SemaDeclAttr.cpp, SemaDecl.cpp, SemaOverload.cpp and SemaStmt.cpp.

I have only modified diagnostics where I could construct a test-case which demonstrates that the change is appropriate (either with this patch or the next one).

Diff Detail

Event Timeline

riccibruno created this revision.Jul 27 2020, 6:56 AM
erichkeane accepted this revision.Jul 27 2020, 7:04 AM

I looked through the code changes, and they all seem quite mechanical. I believe they are all correct.

After reading through the test changes, I believe that this change is strictly an improvement thanks to printing the template arguments. Therefore, I don't believe I know of any way that htis is controversial.

That said, because I'm approving so quickly after submission, please give at least a few hours before committing to give the other reviewers a chance to take a look.

This revision is now accepted and ready to land.Jul 27 2020, 7:04 AM

I looked through the code changes, and they all seem quite mechanical. I believe they are all correct.

After reading through the test changes, I believe that this change is strictly an improvement thanks to printing the template arguments. Therefore, I don't believe I know of any way that htis is controversial.

That said, because I'm approving so quickly after submission, please give at least a few hours before committing to give the other reviewers a chance to take a look.

I will. Thanks for the review!

aaron.ballman accepted this revision.Jul 27 2020, 9:15 AM

The changes LGTM but it seems like there may be some formatting issues with the patch (or the lint tool is acting up).

The changes LGTM but it seems like there may be some formatting issues with the patch (or the lint tool is acting up).

Looks like the bot is right this time. Thanks!

This revision was landed with ongoing or failed builds.Jul 28 2020, 2:36 AM
This revision was automatically updated to reflect the committed changes.