C source code instrumentation with libclang

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

C source code instrumentation with libclang

Deep Majumder via cfe-dev
Hello !
I am currently investigating tools for C instrumentation for the purpose of
coverage analysis.
The tricky aspect of it definitely seems to be how to deal with the
preprocessing phase.
There is mostly one question that comes to my mind, and after a bit of
research (on this mailing list) I did not find a satisfying answer.

Let's say I want to support multiple compilers.
I don't think I can preprocess the sources with the other compiler, then
parse them with clang, and even
if this would be possible, I think I would be losing too much information
about macro expansion for example. So I will probably need to configure the
Clang preprocessor to modify where it looks for the include files, to use
the one of the compiler in use. Though, I fear having parsing problem with
this approach (the included code might be compiler-specific or might call
some built-ins that clang does not provide, as they mention  here
<https://urldefense.com/v3/__http://clang-developers.42468.n3.nabble.com/clangd-libclang-how-to-emulate-other-compilers-td4060396.html__;!!DZ3fjg!oYyNZWy85HqnM8DKf4CNyQxWHu22NpNC9b6dGCqoXU_Qz6hfLcijImHULzajXvwovos$ >
).
I also fear that running a different preprocessor (clang's) than the one of
the compiler in use may result in altering the program semantics (does every
preprocessor implements macro expansion the same way?).

By any chance, do you have any idea how existing coverage tools may deal
with this matter? Are there corner cases where instrumentation may be
slightly off because of that?

Thank you if you took the time to read / answer

Matthieu Eyraud

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev