<div dir="ltr">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.<div><br></div><div>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.<br><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Thanks,<br>--Serge<br></div></div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 23, 2020 at 4:53 AM Blower, Melanie I via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US">
<div class="gmail-m_1943797202636056663WordSection1">
<p class="MsoNormal">I’m working on a patch to add a new pragma.  <a href="https://reviews.llvm.org/D72841" target="_blank">
https://reviews.llvm.org/D72841</a><u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">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:<u></u><u></u></p>
<p class="MsoNormal">(Actions.getCurScope()->getParent() == nullptr)<u></u><u></u></p>
<p class="MsoNormal">I also tried<u></u><u></u></p>
<p class="MsoNormal">(Actions.CurContext->isTranslationUnit())<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">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<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">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 <u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Void f() {<u></u><u></u></p>
<p class="MsoNormal">Do stuff;<u></u><u></u></p>
<p class="MsoNormal">}<u></u><u></u></p>
<p class="MsoNormal">#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.
<u></u><u></u></p>
</div>
</div>

_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>