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

Serge Pavlov via cfe-dev cfe-dev at lists.llvm.org
Thu Jan 23 22:42:02 PST 2020

When parser consumes `}`, it tries to pump next available token. If it sees
a pragma, it tries to parse the pragma and convert it into an annotation
token. So `PragmaFloatControlHandler::HandlePragma` occurs in the scope of
the current function. It cannot be changed easily because after '}' is
consumed, the action `ActOnCompoundStmt` and `ActOnFinishFunctionBody`
should be executed and they require proper scope/context.

I would propose you to try moving the check into Sema, into the call of
`Sema::ActOnPragmaFloatControl`. It executes latter and CurContext must
already be updated.


On Thu, Jan 23, 2020 at 4:53 AM Blower, Melanie I via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> 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.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200124/605adc29/attachment.html>

More information about the cfe-dev mailing list