Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are the tutorials up-to-date? (Clang version is 20.0.0git) #114711

Open
bobhairgrove opened this issue Nov 3, 2024 · 11 comments
Open

Are the tutorials up-to-date? (Clang version is 20.0.0git) #114711

bobhairgrove opened this issue Nov 3, 2024 · 11 comments
Assignees
Labels
clang Clang issues not falling into any other category documentation good first issue https://github.com/llvm/llvm-project/contribute

Comments

@bobhairgrove
Copy link

Nothing written here seems to work for me: https://clang.llvm.org/docs/LibASTMatchersTutorial.html

In my previous post, I describe my frustrating experience building LLVM and Clang from latest sources. After having finally successfully built and installed everything after following a different tutorial found on the LLVM homepage, I went back to the LibASTMatcher tutorial to see if I could continue with the steps starting after the ninja install command (which should be sudo ninja install).

I didn't have ccmake installed (had to run sudo apt install cmake-curses-gui), so I did that. But I could not figure out where I needed to run this from since the tutorial installed everything immediately under $HOME and assumes that whoever is trying to use this tutorial would do the same. However, it seems that the step mentioned is to use clang to (re)compile LLVM using Clang, which isn't really necessary.

Then I went to this tutorial and tried to compile the very first example (using TEST() and EXPECT_TRUE(). It doesn't compile, unfortunately, but nothing written there gives me a hint about what is going on. Compiling with g++ should work, but here is the output:

// contents of "main.cpp":
#include "clang/Tooling/Tooling.h"

TEST(runToolOnCode, CanSyntaxCheckCode) {
  // runToolOnCode returns whether the action was correctly run over the
  // given code.
  EXPECT_TRUE(runToolOnCode(std::make_unique<clang::SyntaxOnlyAction>(), "class X {};"));
}

Output:

bob@bobs-laptop:~/code/LibToolingProject$ g++ -c main.cpp
main.cpp:3:5: error: expected constructor, destructor, or type conversion before ‘(’ token
    3 | TEST(runToolOnCode, CanSyntaxCheckCode) {
      |     ^

I know that TEST and EXPECT_TRUE are macros defined by Google test framework, but assume that they are somehow pulled in by the Tooling.h header. But perhaps not?

Why do the tutorial writers assume that certain tools are already installed without even mentioning the dependencies? Since all of these tutorials are located on the official LLVM and Clang websites, one would assume that they would be better organized and tested...

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Nov 3, 2024
@efriedma-quic
Copy link
Collaborator

There are some in-tree users of Tooling.h in clang-tools-extra you can use as reference (which are known to build because they're part of normal builds).

I agree it probably doesn't make sense to bootstrap clang in the directions in LibASTMatchersTutorial.rst . You could, anyway, but the gap between a random system compiler and a newly built clang is much smaller than it used to be.

It's very easy for the tutorial files to fall out of date, especially when the tutorial doesn't correspond to some in-tree code. The files in question are clang/docs/LibASTMatchersTutorial.rst and clang/docs/LibTooling.rst in the LLVM tree; patches to clarify would be welcome.

@efriedma-quic efriedma-quic added the good first issue https://github.com/llvm/llvm-project/contribute label Nov 4, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 4, 2024

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. Check that no other contributor has already been assigned to this issue. If you believe that no one is actually working on it despite an assignment, ping the person. After one week without a response, the assignee may be changed.
  2. In the comments of this issue, request for it to be assigned to you, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
  3. Fix the issue locally.
  4. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  5. Create a Git commit.
  6. Run git clang-format HEAD~1 to format your changes.
  7. Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.

If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.

@llvmbot
Copy link
Member

llvmbot commented Nov 4, 2024

@llvm/issue-subscribers-good-first-issue

Author: None (bobhairgrove)

Nothing written here seems to work for me: https://clang.llvm.org/docs/LibASTMatchersTutorial.html

In my previous post, I describe my frustrating experience building LLVM and Clang from latest sources. After having finally successfully built and installed everything after following a different tutorial found on the LLVM homepage, I went back to the LibASTMatcher tutorial to see if I could continue with the steps starting after the ninja install command (which should be sudo ninja install).

I didn't have ccmake installed (had to run sudo apt install cmake-curses-gui), so I did that. But I could not figure out where I needed to run this from since the tutorial installed everything immediately under $HOME and assumes that whoever is trying to use this tutorial would do the same. However, it seems that the step mentioned is to use clang to (re)compile LLVM using Clang, which isn't really necessary.

Then I went to this tutorial and tried to compile the very first example (using TEST() and EXPECT_TRUE(). It doesn't compile, unfortunately, but nothing written there gives me a hint about what is going on. Compiling with g++ should work, but here is the output:

// contents of "main.cpp":
#include "clang/Tooling/Tooling.h"

TEST(runToolOnCode, CanSyntaxCheckCode) {
  // runToolOnCode returns whether the action was correctly run over the
  // given code.
  EXPECT_TRUE(runToolOnCode(std::make_unique&lt;clang::SyntaxOnlyAction&gt;(), "class X {};"));
}

Output:

bob@<!-- -->bobs-laptop:~/code/LibToolingProject$ g++ -c main.cpp
main.cpp:3:5: error: expected constructor, destructor, or type conversion before ‘(’ token
    3 | TEST(runToolOnCode, CanSyntaxCheckCode) {
      |     ^

I know that TEST and EXPECT_TRUE are macros defined by Google test framework, but assume that they are somehow pulled in by the Tooling.h header. But perhaps not?

Why do the tutorial writers assume that certain tools are already installed without even mentioning the dependencies? Since all of these tutorials are located on the official LLVM and Clang websites, one would assume that they would be better organized and tested...

@shrey1605
Copy link

Hi,
I would like to work on this. Can someone please assign this to me? Thank you.

@siya100
Copy link
Contributor

siya100 commented Jan 14, 2025

hey @bobhairgrove can you assign this issue to me

@erichkeane
Copy link
Collaborator

Woops, sorry for the noise! Didn't realize this was assigned so recently.

@siya100
Copy link
Contributor

siya100 commented Jan 16, 2025

can you assign again

@erichkeane
Copy link
Collaborator

can you assign again

You are, I undid it/reassigned immediately.

@siya100
Copy link
Contributor

siya100 commented Jan 16, 2025

ok thank you i'll update you soon about my progress

@erichkeane
Copy link
Collaborator

ok thank you i'll update you soon about my progress

No worries! Sorry about the noise, I'm working through cleaning up 'assigned but no progress in a while' and this somehow got into my query despite being assigned recently.

@siya100
Copy link
Contributor

siya100 commented Jan 26, 2025

should the configuraton of llvm and clang should also be changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category documentation good first issue https://github.com/llvm/llvm-project/contribute
Projects
None yet
Development

No branches or pull requests

7 participants