[cfe-dev] C source code instrumentation with libclang

Matthieu Eyraud via cfe-dev cfe-dev at lists.llvm.org
Fri Jan 15 02:01:10 PST 2021


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210115/c3a1d3cd/attachment-0001.html>


More information about the cfe-dev mailing list