[cfe-dev] question/problem about parsing pragma's following a function definition

Blower, Melanie I via cfe-dev cfe-dev at lists.llvm.org
Wed Jan 22 13:53:36 PST 2020


I'm working on a patch to add a new pragma.  https://reviews.llvm.org/D72841

Some forms of the pragma are only allowed at file scope.  When parsing the pragma I used this expression to test if at file scope:
(Actions.getCurScope()->getParent() == nullptr)
I also tried
(Actions.CurContext->isTranslationUnit())

Both methods failed to recognize that the token following the end of the function body is at file scope.  In the debugger I can see that after the pragma parsing is complete, there is a call to ConsumeBrace which has been called in turn by consumeClose<ParseCompoundStatementBody<ParseFunctionStatementBody

So this means that the function body isn't closed up until after all the following pragma's have been parsed. Is this the right way to do things or should the function be closed when the brace is seen?  It's surprising to me. Thanks in advance for any insight -Melanie

Void f() {
Do stuff;
}
#pragma float_control(push) <<< The push pragma should only appear at file scope but the function scope hasn't been closed when the pragma is parsed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200122/bb190fa4/attachment.html>


More information about the cfe-dev mailing list