clang: ../../clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp:1261: {anonymous}::MacroExpansionInfo getMacroExpansionInfo(const {anonymous}::MacroParamMap&, clang::SourceLocation, const clang::Preprocessor&): Assertion `TheTok.is(tok::r_paren) && "Expanded macro argument acquisition failed! After the end of the loop" " this token should be ')'!"' failed.
Besides this, I've observed that the handwritten macro expansion in plist diagnostics is non-conformant. There are several examples where it produces the wrong expansion.
Such as for this:
void clang_analyzer_warnIfReached();
#define retArg(x) x
#define retArgUnclosed retArg(clang_analyzer_warnIfReached()
#define BB CC
#define applyInt BB(int)
#define CC(x) retArgUnclosed
void unbalancedMacros() {
applyInt );
}
#define expandArgUnclosedCommaExpr(x) (x, clang_analyzer_warnIfReached(), 1
#define f expandArgUnclosedCommaExpr
void unbalancedMacros2() {
int x = f(f(1)) )); // note the 'extra' rparens.
}
The code contains no typos, the parens are deliberately not matching at each context.
Besides these bugs, I'm expecting many more - even crashing ones.
Might fuzzing could help with resolving the crashes, but that wouldn't help to make it conformant.
I'm currently investigating how difficult it would be to use the clang's preprocessor to achieve correct macro expansions.
But I suspect that aquiring the state of the PP at the macro expansion location might be difficult.
Extended Description
Here is the minimal repro (attached patch file):
Analyzer call (debug build):
Assertion triggered:
Relevant part of the backtrace:
Full trace attached.
Besides this, I've observed that the handwritten macro expansion in plist diagnostics is non-conformant. There are several examples where it produces the wrong expansion. Such as for this:
The code:
The code contains no typos, the parens are deliberately not matching at each context.
Besides these bugs, I'm expecting many more - even crashing ones. Might fuzzing could help with resolving the crashes, but that wouldn't help to make it conformant. I'm currently investigating how difficult it would be to use the clang's preprocessor to achieve correct macro expansions. But I suspect that aquiring the state of the PP at the macro expansion location might be difficult.
I've also read some discussion about this on the cfe-dev mailing list as '[cfe-dev] [analyzer] Retrieving macro expansions in the plist output' (http://lists.llvm.org/pipermail/cfe-dev/2018-September/059226.html).