llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.8k stars 11.45k forks source link

Errors in AST matcher documentation/examples? #63748

Open higher-performance opened 1 year ago

higher-performance commented 1 year ago

I've noticed some of the AST matcher documentation seems to be wrong (likely outdated). For example, this

https://github.com/llvm/llvm-project/blob/399eb5632f4ad201bfe4f0bbe1f8ce302c711726/clang/docs/LibASTMatchersReference.html#L2331-L2339

claims that

template <typename T> class C {}; C<char> var;

is matched by

varDecl(hasTypeLoc(templateSpecializationTypeLoc(typeLoc())))

but that doesn't seem to be the case.

Could the document test cases be verified/updated?

I suspect it may be worthwhile to do this automatically as part of CI, rather than manually.

5chmidti commented 9 months ago

I have started working on this (testing the AST matcher docs) over the past week. It might take some time to create something that works, but I plan to post an RFC (if appropriate) once I have a working implementation to discuss what the implementation should look like before opening a pr to discuss details.

higher-performance commented 8 months ago

Thank you. I think I also discovered another one in the documentation of ignoringImplicit.

5chmidti commented 7 months ago

I thought I would give an update. My implementation works well, but there are is still a lot of things to do feature wise and re-checking the documentation a few more times. Here are some statistics from my generator:

Statistics:
        doxygen_blocks                :   515
        missing_tests                 :   220
        matcher_groups_without_matches:    33
        code_snippets                 :   309
        matches                       :   444
        matchers                      :   361
        tested_matchers               :   311
        skipped_objc                  :    16
        compile_failures              :    13
        skipped_cuda                  :     2

All the current 311 tested matchers pass, but one of my To-dos is checking if they actually test what they should :) One example would be the ignoringImplicit example, which I have deleted for now.

5chmidti commented 3 months ago

I've opened a pr with my changes which will test the documentation of AST matchers, and I added additional examples to matchers that did not have any.