Good catch. Test case added in r167369.<div><br></div><div>It is somewhat brittle, but it's an incremental improvement over what's there. I'll have a think about whether there's a safer way to do this.</div>
<div><br></div><div>- Lang.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Nov 3, 2012 at 3:34 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Sat, Nov 3, 2012 at 3:29 PM, Lang Hames <<a href="mailto:lhames@gmail.com">lhames@gmail.com</a>> wrote:<br>

> Author: lhames<br>
> Date: Sat Nov  3 17:29:05 2012<br>
> New Revision: 167363<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=167363&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=167363&view=rev</a><br>
> Log:<br>
> Support interleaving of other pragmas with FP_CONTRACT at the beginning of a<br>
> compound statement.<br>
><br>
> Modified:<br>
>     cfe/trunk/include/clang/Parse/Parser.h<br>
>     cfe/trunk/lib/Parse/ParseStmt.cpp<br>
<br>
</div>Test case please!<br>
<div><div class="h5"><br>
><br>
> Modified: cfe/trunk/include/clang/Parse/Parser.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=167363&r1=167362&r2=167363&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=167363&r1=167362&r2=167363&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/include/clang/Parse/Parser.h (original)<br>
> +++ cfe/trunk/include/clang/Parse/Parser.h Sat Nov  3 17:29:05 2012<br>
> @@ -1498,6 +1498,7 @@<br>
>    StmtResult ParseCompoundStatement(bool isStmtExpr = false);<br>
>    StmtResult ParseCompoundStatement(bool isStmtExpr,<br>
>                                      unsigned ScopeFlags);<br>
> +  void ParseCompoundStatementLeadingPragmas();<br>
>    StmtResult ParseCompoundStatementBody(bool isStmtExpr = false);<br>
>    bool ParseParenExprOrCondition(ExprResult &ExprResult,<br>
>                                   Decl *&DeclResult,<br>
><br>
> Modified: cfe/trunk/lib/Parse/ParseStmt.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=167363&r1=167362&r2=167363&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=167363&r1=167362&r2=167363&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/lib/Parse/ParseStmt.cpp (original)<br>
> +++ cfe/trunk/lib/Parse/ParseStmt.cpp Sat Nov  3 17:29:05 2012<br>
> @@ -706,6 +706,48 @@<br>
>    return ParseCompoundStatementBody(isStmtExpr);<br>
>  }<br>
><br>
> +/// Parse any pragmas at the start of the compound expression. We handle these<br>
> +/// separately since some pragmas (FP_CONTRACT) must appear before any C<br>
> +/// statement in the compound, but may be intermingled with other pragmas.<br>
> +void Parser::ParseCompoundStatementLeadingPragmas() {<br>
> +  bool checkForPragmas = true;<br>
> +  while (checkForPragmas) {<br>
> +    switch (Tok.getKind()) {<br>
> +    case tok::annot_pragma_vis:<br>
> +      HandlePragmaVisibility();<br>
> +      break;<br>
> +    case tok::annot_pragma_pack:<br>
> +      HandlePragmaPack();<br>
> +      break;<br>
> +    case tok::annot_pragma_msstruct:<br>
> +      HandlePragmaMSStruct();<br>
> +      break;<br>
> +    case tok::annot_pragma_align:<br>
> +      HandlePragmaAlign();<br>
> +      break;<br>
> +    case tok::annot_pragma_weak:<br>
> +      HandlePragmaWeak();<br>
> +      break;<br>
> +    case tok::annot_pragma_weakalias:<br>
> +      HandlePragmaWeakAlias();<br>
> +      break;<br>
> +    case tok::annot_pragma_redefine_extname:<br>
> +      HandlePragmaRedefineExtname();<br>
> +      break;<br>
> +    case tok::annot_pragma_opencl_extension:<br>
> +      HandlePragmaOpenCLExtension();<br>
> +      break;<br>
> +    case tok::annot_pragma_fp_contract:<br>
> +      HandlePragmaFPContract();<br>
> +      break;<br>
> +    default:<br>
> +      checkForPragmas = false;<br>
> +      break;<br>
> +    }<br>
> +  }<br>
<br>
</div></div>This seems rather brittle. Is there anything that will prevent it from<br>
becoming a bug every time someone adds a new pragma? Is there any way<br>
to factor things so that we get a compiler error or something here<br>
that indicates we might need to handle every pragma?<br>
<br>
What I'm thinking is a function that converts the pragma tokens to a<br>
pragma enum that we have some confidence people will update. Then we<br>
can have a covering enum switch here (and else where).<br>
<span class="HOEnZb"><font color="#888888"><br>
-Chandler<br>
</font></span></blockquote></div><br></div>