[cfe-dev] [analyzer] Retrieving macro expansions in the plist output
Kristóf Umann via cfe-dev
cfe-dev at lists.llvm.org
Fri Aug 17 05:09:42 PDT 2018
Hi!
I'm currently trying to implement a new node in the plist output that would
show the expansion of a macro, like this:
void setToNull(int **vptr) {
*vptr = nullptr;
}
void print(void*);
#define TO_NULL(x) \
setToNull(x)
#define DOES_NOTHING(x) \
{ \
int b; \
b = 5; \
} \
print(x)
#define DEREF(x) \
DOES_NOTHING(x); \
*x
void f() {
int *a = new int(5);
TO_NULL(&a);
DEREF(a) = 5;
}
For this code, two PathDiagnosticMacroPieces should be generated, and a
message like this should be displayed:
Expanding macro 'TO_NULL' to 'print(&a); setToNull(&a)'
Expanding macro 'DEREF' to '{ int sajt; sajt = 5; } print(a); *a'
I've made some progress on this issue, but here are the problems I faced.
Currently, HTML file generation supports macro expansions fairly well,
however, the code that achieves this seems to be held together by sheer
luck:
https://clang.llvm.org/doxygen/namespaceclang_1_1html.html#a3283736376c3e436ff65975acdb1d399
As I understand it, the entire file is re-lexed and preprocessed, during
which macro expansions are added to the HTML file. I attempted to reuse the
code here without having to re-lex everything, but so far my efforts lead
to little success. I also found that any modification of this code quickly
leads to instabilities -- although this part of Clang is somewhat of a
mystery to me just yet, so I'd concede to this being my fault.
I also fear that since HTML output is not as used as other outputs, and
could lack vigorous testing, it could be crash-prone.
Do you know any way of obtaining the expansion of a macro expression that
doesn't involve such abusement of the preprocessor? Something like this
would be ideal:
SourceLocation Loc = /* PathDiagnosticMacroPiece location */;
Preproc.getMacroExpansionForExpression(Loc));
Cheers,
Kristóf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180817/aff48822/attachment.html>
More information about the cfe-dev
mailing list