question/problem about parsing pragma's following a function definition

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

question/problem about parsing pragma's following a function definition

Hans Wennborg via cfe-dev

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
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: question/problem about parsing pragma's following a function definition

Hans Wennborg via cfe-dev
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.

Thanks,
--Serge


On Thu, Jan 23, 2020 at 4:53 AM Blower, Melanie I via cfe-dev <[hidden email]> 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
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev