[clang] [AST] Iterate redecls starting from the canonical one in getRawCommentsForAnyRedecl() (PR #108475)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 15 22:50:37 PDT 2024


HighCommander4 wrote:

> Buildkite is showing the test `Clang :: Index/comment-to-html-xml-conversion.cpp` failing. Will investigate.

I've been investigating this failure. It's caused by a slight change of behaviour of `ASTContext::getFullComment()` on explicit function template specializations, such as:

```c++
/// Aaa.
template<typename T, typename U>
void foo(T aaa, U bbb);

/// Bbb.
template<>
void foo(int aaa, int bbb);
```

While the correct comment (`// Bbb.`) is found for the explicit specialization, the returned `FullComment`'s `DeclInfo` does not have its [`TemplateKind`](https://searchfox.org/llvm/rev/3ae71d154e5dfb5e5a5d27b3699b27ce2b55f44d/clang/include/clang/AST/Comment.h#1047) set to `TemplateSpecialization` as expected.

This is in turn because the [code that sets this](https://searchfox.org/llvm/rev/3ae71d154e5dfb5e5a5d27b3699b27ce2b55f44d/clang/lib/AST/Comment.cpp#238-243) is conditioned on `FunctionDecl::getNumTemplateParameterLists() != 0`.

When `getRawCommentForAnyRedecl()` is called on the `FunctionDecl` for the explicit specialization (whose `getNumTemplateParameterLists()` returns 1), it previously returned the input `FunctionDecl` in its `OriginalDecl` out-parameter, but as a result of my change, it now returns the input decl's canonical decl, whose `getNumTemplateParameterLists()` returns 0, and it's this latter decl that ends up in the check mentioned above.

I'm not familiar enough with the AST modeling of template specializations to say what is going wrong here... @gribozavr as the author of the [mentioned check](https://searchfox.org/llvm/rev/3ae71d154e5dfb5e5a5d27b3699b27ce2b55f44d/clang/lib/AST/Comment.cpp#238-243), any advice would be appreciated.

https://github.com/llvm/llvm-project/pull/108475


More information about the cfe-commits mailing list