LibTooling is a library to support writing standalone tools based on Clang.
Questions tagged [libtooling]
152 questions
2
votes
1 answer
CLang Libtooling: fetching datatype of a variable inside clang::VarDecl, clang::FieldDecl or clang::ParmVarDecl
I am working on CLang 3.5. I am trying to fetch info about variables declared in a C++ project.
How can I fetch datatype or qualified class name of a variable in a clang::VarDecl, clang::FieldDecl or clang::ParmVarDecl object? I tried to find a…

Prakhar Mishra
- 1,586
- 4
- 28
- 52
1
vote
1 answer
clang libtooling: PPCallbacks only for defines in main source file
I want to retrieve macro names within a source file but avoid the ones that are defined within included header files.
Right now I am using
PPCallbacks::MacroDefined
to get the macro token.
Is there a way to skip this callback when defined macro…

Bhushan
- 354
- 9
- 25
1
vote
0 answers
use-after-poison error on libtooling example
When testing libtooling example(https://clang.llvm.org/docs/RAVFrontendAction.html) of clang with address-sanitizer, I've encountered use-after-poison error.
I've used following source codes and instructions to test it. I'm using prebuilt version of…

backrankrook
- 11
- 2
1
vote
0 answers
Get the SourceRange of explicit template instantiations using clang AST library
In the following c++ source file:
1 //file my_func.cpp
2 void template foo(Bar& bar) {
3 // some code
4 }
5 template void foo(double&);
I want to get the beginning and the end of the explicit instantiation of the function…

mpeschke
- 308
- 3
- 11
1
vote
0 answers
Clang indexing doesn't detect C++20 ConceptDecls
I'm having trouble getting Clang's IndexingAction to detect
clang::ConceptDecls.
I have a minimum working example that initializes
an IndexingAction and runs it over some test code that contains two
ConceptDecls. I've verified that the frontend…

John V.
- 21
- 1
1
vote
0 answers
LibTooling: create compilation database on the fly from compiler command line
I would like to make a LibTooling tool that takes precisely the same compilation string as clang. For example
clang a.c -O3 b.c -I/myinclude -DMY_DEFINE c.c. Should be replaced by my-tool a.c -O3 b.c -I/myinclude -DMY_DEFINE c.c
Officially suggested…
user8044236
1
vote
0 answers
Map Clang AST from LibTooling to AST in OCaml
I'm looking for a way to map C++ ASTs, produced by Clang, to another AST in OCaml. Currently I'm using clangml to do this, which is a great library that provides bindings from libclang to OCaml.
However, I need access to the Clang's preprocessor and…

Niels
- 11
- 2
1
vote
1 answer
clang AST Matcher: Whats the best way to match the current Matcher over hasParent()
I am trying to search for ifStmts, which aren't an else if. To accomplish that, I want to test if the Stmt has a Parent, which is not an ifStmt(hasElse(ifStmt(equals())))
The following obviously does not work, but I could not find a…

Fabian Keßler
- 563
- 3
- 12
1
vote
1 answer
How to remove error limit in Clang Libtooling?
I made C/C++ source code modification tool using Clang Libtooling. I ran into the following error while executing my tool on test programs.
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
But I would like…

lkarus
- 36
- 5
1
vote
1 answer
How to pass arguments to ASTFrontendAction
Is there a way I can pass constructor arguments to classes inheriting from clang::ASTFrontendAction in programs based on libtooling? All examples I have found online look something like this:
int main() {
ClangTool Tool(...);
return…

Peter
- 2,919
- 1
- 16
- 35
1
vote
1 answer
Clang AST Libtooling: How to print Array identifier on AST Matching
My code that I tried is below:
if(const ArraySubscriptExpr *array = Result.Nodes.getNodeAs("array"))
{
llvm::outs() << array->getBase() <<'\n';
}
getBase() should print the array identifier, but it is printing…
1
vote
0 answers
Clang Assertion failed: Ran out of source locations
I have a utility that uses Clang's LibTooling framework to parse the AST and perform static code analysis. I am using LLVM and Clang v10.0.
Recently I observed that the utility never finishes parsing the AST of a particular file. On debugging, I…

asumang
- 673
- 1
- 6
- 11
1
vote
1 answer
Parsing comments with clang AST
I would like to parse customized tag with clang AST. Here is a simple illustration of my compilation unit input.
#include
int main() {
// \my-tags tag_A, tag_B
printf("helloworld");
return 0;
}
How can I get those tags after…

posutsai
- 31
- 1
- 6
1
vote
1 answer
how to match all return stmt from cxxMethodDecl node
I want to find all the methods which params is reference type,
to add some codes before all return stmt.
Here is my code:
Matcher.addMatcher(cxxMethodDecl().bind("r"), &HandlerForReturn);
const CXXMethodDecl *re =…

mccxj
- 17
- 5
1
vote
1 answer
Expression size in AST is incorrect for member access
Suppose that I have the following code:
struct S {
int abcd = 0;
};
int main() {
S s;
return s.abcd;
}
The corresponding AST part:
-FunctionDecl 0x563ddd3a3e20 line:5:5 main 'int ()'
`-CompoundStmt 0x563ddd3a4570

Nikita Petrenko
- 1,068
- 1
- 7
- 10