I refer to the source code version at GitHub - llvm-mirror/clang: Mirror kept for legacy. Moved to https://github.com/llvm/llvm-project,
function Preprocessor::HandlePragmaDirective at Lex/Pragma.cpp:127.
I've installed a pragma callback via Preprocessor::addPPCallbacks. The callback
function just stores the text of the pragma line. For this I use Preprocessor::Lex
and Preprocessor::getSpelling, which works fine.
Since the pragma line has to be handled normally afterwards, I start in my callback with
Preprocessor::EnableBacktrackAtThisPos and call Preprocessor::Backtrack before returning.
This works as long as the pragma is known and somehow parsed and handled at line 139.
If it is not handled there, then the parser has to move to Tok::eod, which is actually achieved at line 144.
However this doesn't work in my case, since EnableBacktrackAtThisPos enters the caching mode, but
Backtrack doesn't leave it. Then CurPPLexer is 0 and the next pragma token is lexed as part of the
program (and compilation will normally fail).
I guess that's a bug.
I've tried LookAhead instead of Lex and backtracking, but this fails too for the same reason. Now I am
out of ideas how to work around this bug.
Has anyone a hint?
Thanks in advance