[cfe-commits] r167363 - in /cfe/trunk: include/clang/Parse/Parser.h lib/Parse/ParseStmt.cpp

Lang Hames lhames at gmail.com
Sat Nov 3 22:16:50 PDT 2012


Good catch. Test case added in r167369.

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.

- Lang.


On Sat, Nov 3, 2012 at 3:34 PM, Chandler Carruth <chandlerc at google.com>wrote:

> On Sat, Nov 3, 2012 at 3:29 PM, Lang Hames <lhames at gmail.com> wrote:
> > Author: lhames
> > Date: Sat Nov  3 17:29:05 2012
> > New Revision: 167363
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=167363&view=rev
> > Log:
> > Support interleaving of other pragmas with FP_CONTRACT at the beginning
> of a
> > compound statement.
> >
> > Modified:
> >     cfe/trunk/include/clang/Parse/Parser.h
> >     cfe/trunk/lib/Parse/ParseStmt.cpp
>
> Test case please!
>
> >
> > Modified: cfe/trunk/include/clang/Parse/Parser.h
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=167363&r1=167362&r2=167363&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/include/clang/Parse/Parser.h (original)
> > +++ cfe/trunk/include/clang/Parse/Parser.h Sat Nov  3 17:29:05 2012
> > @@ -1498,6 +1498,7 @@
> >    StmtResult ParseCompoundStatement(bool isStmtExpr = false);
> >    StmtResult ParseCompoundStatement(bool isStmtExpr,
> >                                      unsigned ScopeFlags);
> > +  void ParseCompoundStatementLeadingPragmas();
> >    StmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
> >    bool ParseParenExprOrCondition(ExprResult &ExprResult,
> >                                   Decl *&DeclResult,
> >
> > Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=167363&r1=167362&r2=167363&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
> > +++ cfe/trunk/lib/Parse/ParseStmt.cpp Sat Nov  3 17:29:05 2012
> > @@ -706,6 +706,48 @@
> >    return ParseCompoundStatementBody(isStmtExpr);
> >  }
> >
> > +/// Parse any pragmas at the start of the compound expression. We
> handle these
> > +/// separately since some pragmas (FP_CONTRACT) must appear before any C
> > +/// statement in the compound, but may be intermingled with other
> pragmas.
> > +void Parser::ParseCompoundStatementLeadingPragmas() {
> > +  bool checkForPragmas = true;
> > +  while (checkForPragmas) {
> > +    switch (Tok.getKind()) {
> > +    case tok::annot_pragma_vis:
> > +      HandlePragmaVisibility();
> > +      break;
> > +    case tok::annot_pragma_pack:
> > +      HandlePragmaPack();
> > +      break;
> > +    case tok::annot_pragma_msstruct:
> > +      HandlePragmaMSStruct();
> > +      break;
> > +    case tok::annot_pragma_align:
> > +      HandlePragmaAlign();
> > +      break;
> > +    case tok::annot_pragma_weak:
> > +      HandlePragmaWeak();
> > +      break;
> > +    case tok::annot_pragma_weakalias:
> > +      HandlePragmaWeakAlias();
> > +      break;
> > +    case tok::annot_pragma_redefine_extname:
> > +      HandlePragmaRedefineExtname();
> > +      break;
> > +    case tok::annot_pragma_opencl_extension:
> > +      HandlePragmaOpenCLExtension();
> > +      break;
> > +    case tok::annot_pragma_fp_contract:
> > +      HandlePragmaFPContract();
> > +      break;
> > +    default:
> > +      checkForPragmas = false;
> > +      break;
> > +    }
> > +  }
>
> This seems rather brittle. Is there anything that will prevent it from
> becoming a bug every time someone adds a new pragma? Is there any way
> to factor things so that we get a compiler error or something here
> that indicates we might need to handle every pragma?
>
> What I'm thinking is a function that converts the pragma tokens to a
> pragma enum that we have some confidence people will update. Then we
> can have a covering enum switch here (and else where).
>
> -Chandler
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121103/96b90758/attachment.html>


More information about the cfe-commits mailing list