Search code examples
clanglibclang

libclang not emitting certain AST nodes


I'm using the go-clang library to parse the following C file: aac.c. For some reason when I run the file through clang and dump the AST, I don't get AST output for certain functions. For example, the C file contains a forward declaration of aac_ioctl_send_raw_srb and the actual definition later on in the file.

Given this I was expecting to see two AST nodes in the output but only one FuncDecl (the forward declaration) is dumped:

clang -Xclang -ast-dump -fsyntax-only aac.c | grep "aac_ioctl_send_raw_srb" | wc -l
aac.c:38:10: fatal error: 'opt_aac.h' file not found
#include "opt_aac.h"
         ^
1 error generated.
       1 <--- wc output

(Ignoring the error)

I get the same result using the go-clang library to parse the C file from within my own application. Is there any explanation for why the definition is not dumped?


Solution

  • I got some help in #llvm IRC and someone suggested that the errors actually are causing the issue. Even though other nodes are being emitted, LLVM may just be ignoring ones that it thinks require information that reside in the missing #includes.

    I fixed the include paths and sure enough the nodes I was looking for were emitted.