Questions tagged [clang-ast-matchers]

67 questions
1
vote
0 answers

clang-tooling: How to check if a field is an incomplete type on construction?

I want to write a matcher, which excludes classes containing incomplete types like: std::unique_ptr, but it is not identified as one, because it is a template type (I think so). Does anyone know how to circumvent this? Minimal…
1
vote
1 answer

Matching variadic template arguments using an AST Matcher

I have the following sample code. template T add(T first, Args... rest) { return first + add(rest...); } int add(int a, int b) { return a + b; } When I run it through clang-check -ast-dump, I get the following…
1
vote
1 answer

Clang MatchResult has no AST nodes bound?

I'm writing my first AST Matcher to detect pointer-to-integral conversions but the size of the BoundedNodes in the MatchResult is 0. How is this possible? Why would the AST Matcher call my callback even with an empty MatchResult? Is it possible for…
Adriaan Jacobs
  • 309
  • 2
  • 9
1
vote
0 answers

How to expose ImplicitCastExpr node in clang Python bindings?

I have C code: int func4b(float *x, int (*fp)(int *hello, float *goodbye)); int hello(int *x, float *y) { return 0; } void callerb() { float x=6.0; func4b(&x, &hello); // This is line 28 } clang-12 -cc1 -ast-dump t2_calls.c provides: …
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
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
0 answers

Clang AST Matchers: is it possible filter based on count?

I was trying to write a simple clang-tidy checker that will check for constructor that is calling fopen() more than once. For that I was tying to match the constructor with more than one fopen() calls. My indention is to find potential memory leak…
vrnithinkumar
  • 1,273
  • 1
  • 11
  • 29
1
vote
1 answer

Clang AST Matchers: how to find function body from a function declaration?

I was trying to write a simple clang-tidy checker that will check for constructor that is calling fopen() more than once. My indention is to find potential memory leak in case any exception happens in the second fopen() call. class Dummy_file { …
vrnithinkumar
  • 1,273
  • 1
  • 11
  • 29
1
vote
1 answer

ASTMatcher for class instance with Initialization and the member function call

I'm having difficulty getting the ASTMatcher for the following entities. The first one is the instance of a class. Vec v1(1.0,1.0,1.0); Vec v2(2.0,2.0,2.0); Ideally, I can have a matcher that can match both instances. The second is to capture the…
isPrime
  • 151
  • 1
  • 10
1
vote
0 answers

FunctionDecl: How do I get the as-written unqualified-id of a function?

I have been able to write a Clang AST matcher that gives me FunctionDecl instances. However, I am observing cases where getNameAsString substitutes as-written template parameter types with type-parameter-N-M. For example, in the following…
fbrereto
  • 35,429
  • 19
  • 126
  • 178
1
vote
0 answers

How to find the parent initialization of a variable of a function using clang ast?

Hi so I'm able to match function calls using ASTMatchers. But I need to find the statement where one of the parameters of this function has been initialized. How do I do that? int main(){ char* str = "abcde"; char dest[19]; size_t len =…
1
vote
1 answer

In a clang plugin, how do you see whether there was an error compiling the translation unit?

I want my clang plugin to not actually do anything if there was an error compiling the code for the AST my plugin is going to run on. However, I can't figure out what object contains the list of errors generated during compilation. Is there…
xaxxon
  • 19,189
  • 5
  • 50
  • 80
1
vote
1 answer

How to get underly cxxRecordDecl from typedefDecl

I have a piece of code: typedef struct S1{ int a; int b; } S, *PS; I can get following AST with clang-check: | |-CXXRecordDecl 0x3dfde48 col:16 implicit struct S1 | |-FieldDecl 0x3dfdef8 col:9 a 'int' | -FieldDecl 0x3dfdf58
thisEric
  • 486
  • 7
  • 18
1
vote
1 answer

what does the line/col mean in clang ast dump

I am confused with the clang ast-dump outout, what does the line and col mean? Thanks `-FunctionDecl 0xa853e98 line:33:5 main 'int (void)' -CompoundStmt 0xa87f018 |-DeclStmt 0xa87e808
thisEric
  • 486
  • 7
  • 18
1
vote
1 answer

How find BlockDecl nodes in Clang AST using AST Matcher?

I need to find self references in blocks (Objective C). And I'm using Clang AST Matchers for this. The matcher to find all self references I've created is below: declRefExpr(to(varDecl(hasName("self"))) Now I need to apply this matcher for blocks…
Yulia
  • 1,087
  • 9
  • 16