This is an archive of the discontinued LLVM Phabricator instance.

[Wdocumentation] fixes an assertion failure with typedefed function and block pointer
ClosedPublic

Authored by Mordante on Aug 24 2019, 10:18 AM.

Details

Summary

The assertion happens when compiling with -Wdocumentation with variable declaration to a typedefed function pointer. I not too familiar with the ObjC syntax but first two tests assert without this patch.

Fixes https://bugs.llvm.org/show_bug.cgi?id=42844

Diff Detail

Repository
rL LLVM

Event Timeline

Mordante created this revision.Aug 24 2019, 10:18 AM
gribozavr added inline comments.Aug 25 2019, 10:14 AM
clang/lib/AST/Comment.cpp
151 ↗(On Diff #217023)

Why is the new functionality turned off sometimes? It seems to me that we always want to look through typedefs.

Mordante marked 2 inline comments as done.Aug 25 2019, 11:07 AM
Mordante added inline comments.
clang/lib/AST/Comment.cpp
151 ↗(On Diff #217023)

Setting testTypedefTypeLoc to true breaks a unit test in test/Sema/warn-documentation.cpp:358

typedef int (*test_not_function_like_typedef1)(int aaa);

// expected-warning@+1 {{'\param' command used in a comment that is not attached to a function declaration}}
/// \param aaa Meow.                                                            
typedef test_not_function_like_typedef1 test_not_function_like_typedef2;

and its corresponding test using a using instead of typedef. This has been introduced in:

commit 49fdf8d3f5e114e6f8b49fde29a30b0eaaa3c5dd
Author: Dmitri Gribenko <gribozavr@gmail.com>
Date:   Sat Sep 15 21:13:36 2012 +0000

    Comment parsing: don't treat typedef to a typedef to a function as a
    'function-like' type that can be annotated with \param.
    
    Thanks to Eli Friedman for noticing!
    
    llvm-svn: 163985

I'm not sure whether or not we should allow this typedef documentation. I just tested with Doxygen. It doesn't complain and shows the parameter documentation for test_not_function_like_typedef2. So on that basis we could remove this expected-warning and testTypedefTypeLoc.

What do you think?

gribozavr added inline comments.Aug 25 2019, 11:25 AM
clang/lib/AST/Comment.cpp
151 ↗(On Diff #217023)

Thanks for the explanation. I can't find the context for that decision, and the commit description does not explain the reason either.

It is really a policy decision -- when introducing a comment for function return value and arguments, should the declaration include the said return value and arguments, or can they be visible through a typedef?

Thinking about it, my inclination is to say that comments for the return value and arguments should be present on the declaration that introduces them. Otherwise, it is breaking an abstraction barrier.

WDYT?

Mordante marked 3 inline comments as done.Aug 30 2019, 10:17 AM
Mordante added inline comments.
clang/lib/AST/Comment.cpp
151 ↗(On Diff #217023)

(I just noticed I forgot to submit this comment.)

I tend to agree. However Doxygen accepts the code, but Doxygen doesn't seem to validate whether parameters exist.
So I wonder whether we do our users a service by warning about code that Doxygen properly handles. On that basis I think we can allow it.

We could add an extra warning in the pedantic group and let the user decide whether or not she thinks it warrants a warning.

I think that would be the best solution: accept the comment but allow the user to opt-in on a warning.

gribozavr added inline comments.Aug 30 2019, 11:49 AM
clang/lib/AST/Comment.cpp
151 ↗(On Diff #217023)

Doxygen and C++ both allow a lot of dubious stuff. That can't be a reason to avoid producing a warning -- we would have no warnings if that was the bar.

I think what we should discuss is, what is the use case for adding a \returns command in this position -- and how is documenting parameters not a use case. If there is a valid use case, how common it is in real world.

Mordante updated this revision to Diff 218264.Sep 1 2019, 8:24 AM
Mordante marked an inline comment as done.

As discussed on IRC no longer allow \return on a typedef'ed type. This is consistent with \param.

  • Reverts all prior changes in lib/AST/Comment.cpp
  • Adds extra tests in Sema::isFunctionOrBlockPointerVarLikeDecl
  • Updates unit tests
gribozavr accepted this revision.Sep 2 2019, 1:30 AM

LGTM, but could you also verify that references are not an issue?

using D = void();
D &d = ...; ///< \return none
This revision is now accepted and ready to land.Sep 2 2019, 1:30 AM
Mordante updated this revision to Diff 218377.Sep 2 2019, 9:24 AM

Adds extra unit tests for references.

Thanks for the review.

using D = void();
D &d = ...; ///< \return none

Is no issue, I added tests for it.

Can you commit the code for me?

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 2 2019, 11:24 AM