That's awesome. Thanks Eli!<div><br></div><div>- Lang.<br><br><div class="gmail_quote">On Wed, Oct 3, 2012 at 7:47 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">thanks!<br>
<div class="HOEnZb"><div class="h5"><br>
On 3 October 2012 22:36, Eli Friedman <<a href="mailto:eli.friedman@gmail.com">eli.friedman@gmail.com</a>> wrote:<br>
> Author: efriedma<br>
> Date: Wed Oct 3 21:36:51 2012<br>
> New Revision: 165195<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=165195&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=165195&view=rev</a><br>
> Log:<br>
> Permanently end the whole "pragma got handled by the parser too early"<br>
> mess by handling all pragmas which the parser touches uniformly.<br>
> <rdar://problem/12248901>, etc.<br>
><br>
><br>
> Modified:<br>
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
> cfe/trunk/include/clang/Basic/TokenKinds.def<br>
> cfe/trunk/include/clang/Parse/Parser.h<br>
> cfe/trunk/include/clang/Sema/Sema.h<br>
> cfe/trunk/lib/Parse/ParsePragma.cpp<br>
> cfe/trunk/lib/Parse/ParsePragma.h<br>
> cfe/trunk/lib/Parse/ParseStmt.cpp<br>
> cfe/trunk/lib/Parse/Parser.cpp<br>
> cfe/trunk/lib/Sema/SemaAttr.cpp<br>
> cfe/trunk/test/CodeGen/fp-contract-pragma.cpp<br>
> cfe/trunk/test/Misc/warning-flags.c<br>
> cfe/trunk/test/Sema/pragma-pack-and-options-align.c<br>
><br>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=165195&r1=165194&r2=165195&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=165195&r1=165194&r2=165195&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)<br>
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Oct 3 21:36:51 2012<br>
> @@ -407,8 +407,6 @@<br>
> def err_parameters_retval_cannot_have_fp16_type : Error<<br>
> "%select{parameters|function return value}0 cannot have __fp16 type; did you forget * ?">;<br>
> def warn_enum_value_overflow : Warning<"overflow in enumeration value">;<br>
> -def warn_pragma_options_align_unsupported_option : Warning<<br>
> - "unsupported alignment option in '#pragma options align'">;<br>
> def warn_pragma_options_align_reset_failed : Warning<<br>
> "#pragma options align=reset failed: %0">;<br>
> def err_pragma_options_align_mac68k_target_unsupported : Error<<br>
><br>
> Modified: cfe/trunk/include/clang/Basic/TokenKinds.def<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=165195&r1=165194&r2=165195&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=165195&r1=165194&r2=165195&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/Basic/TokenKinds.def (original)<br>
> +++ cfe/trunk/include/clang/Basic/TokenKinds.def Wed Oct 3 21:36:51 2012<br>
> @@ -602,6 +602,41 @@<br>
> // handles them.<br>
> ANNOTATION(pragma_parser_crash)<br>
><br>
> +// Annotation for #pragma ms_struct...<br>
> +// The lexer produces these so that they only take effect when the parser<br>
> +// handles them.<br>
> +ANNOTATION(pragma_msstruct)<br>
> +<br>
> +// Annotation for #pragma align...<br>
> +// The lexer produces these so that they only take effect when the parser<br>
> +// handles them.<br>
> +ANNOTATION(pragma_align)<br>
> +<br>
> +// Annotation for #pragma weak id<br>
> +// The lexer produces these so that they only take effect when the parser<br>
> +// handles them.<br>
> +ANNOTATION(pragma_weak)<br>
> +<br>
> +// Annotation for #pragma weak id = id<br>
> +// The lexer produces these so that they only take effect when the parser<br>
> +// handles them.<br>
> +ANNOTATION(pragma_weakalias)<br>
> +<br>
> +// Annotation for #pragma redefine_extname...<br>
> +// The lexer produces these so that they only take effect when the parser<br>
> +// handles them.<br>
> +ANNOTATION(pragma_redefine_extname)<br>
> +<br>
> +// Annotation for #pragma STDC FP_CONTRACT...<br>
> +// The lexer produces these so that they only take effect when the parser<br>
> +// handles them.<br>
> +ANNOTATION(pragma_fp_contract)<br>
> +<br>
> +// Annotation for #pragma OPENCL EXTENSION...<br>
> +// The lexer produces these so that they only take effect when the parser<br>
> +// handles them.<br>
> +ANNOTATION(pragma_opencl_extension)<br>
> +<br>
> #undef ANNOTATION<br>
> #undef TESTING_KEYWORD<br>
> #undef OBJC2_AT_KEYWORD<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=165195&r1=165194&r2=165195&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=165195&r1=165194&r2=165195&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/Parse/Parser.h (original)<br>
> +++ cfe/trunk/include/clang/Parse/Parser.h Wed Oct 3 21:36:51 2012<br>
> @@ -441,6 +441,34 @@<br>
> /// #pragma pack...<br>
> void HandlePragmaPack();<br>
><br>
> + /// \brief Handle the annotation token produced for<br>
> + /// #pragma ms_struct...<br>
> + void HandlePragmaMSStruct();<br>
> +<br>
> + /// \brief Handle the annotation token produced for<br>
> + /// #pragma align...<br>
> + void HandlePragmaAlign();<br>
> +<br>
> + /// \brief Handle the annotation token produced for<br>
> + /// #pragma weak id...<br>
> + void HandlePragmaWeak();<br>
> +<br>
> + /// \brief Handle the annotation token produced for<br>
> + /// #pragma weak id = id...<br>
> + void HandlePragmaWeakAlias();<br>
> +<br>
> + /// \brief Handle the annotation token produced for<br>
> + /// #pragma redefine_extname...<br>
> + void HandlePragmaRedefineExtname();<br>
> +<br>
> + /// \brief Handle the annotation token produced for<br>
> + /// #pragma STDC FP_CONTRACT...<br>
> + void HandlePragmaFPContract();<br>
> +<br>
> + /// \brief Handle the annotation token produced for<br>
> + /// #pragma OPENCL EXTENSION...<br>
> + void HandlePragmaOpenCLExtension();<br>
> +<br>
> /// GetLookAheadToken - This peeks ahead N tokens and returns that token<br>
> /// without consuming any tokens. LookAhead(0) returns 'Tok', LookAhead(1)<br>
> /// returns the token after Tok, etc.<br>
><br>
> Modified: cfe/trunk/include/clang/Sema/Sema.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=165195&r1=165194&r2=165195&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=165195&r1=165194&r2=165195&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/Sema/Sema.h (original)<br>
> +++ cfe/trunk/include/clang/Sema/Sema.h Wed Oct 3 21:36:51 2012<br>
> @@ -6328,8 +6328,7 @@<br>
><br>
> /// ActOnPragmaOptionsAlign - Called on well formed \#pragma options align.<br>
> void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,<br>
> - SourceLocation PragmaLoc,<br>
> - SourceLocation KindLoc);<br>
> + SourceLocation PragmaLoc);<br>
><br>
> enum PragmaPackKind {<br>
> PPK_Default, // #pragma pack([n])<br>
><br>
> Modified: cfe/trunk/lib/Parse/ParsePragma.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=165195&r1=165194&r2=165195&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=165195&r1=165194&r2=165195&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Parse/ParsePragma.cpp (original)<br>
> +++ cfe/trunk/lib/Parse/ParsePragma.cpp Wed Oct 3 21:36:51 2012<br>
> @@ -40,7 +40,7 @@<br>
> struct PragmaPackInfo {<br>
> Sema::PragmaPackKind Kind;<br>
> IdentifierInfo *Name;<br>
> - Expr *Alignment;<br>
> + Token Alignment;<br>
> SourceLocation LParenLoc;<br>
> SourceLocation RParenLoc;<br>
> };<br>
> @@ -50,10 +50,107 @@<br>
> PragmaPackInfo *Info =<br>
> static_cast<PragmaPackInfo *>(Tok.getAnnotationValue());<br>
> SourceLocation PragmaLoc = ConsumeToken();<br>
> - Actions.ActOnPragmaPack(Info->Kind, Info->Name, Info->Alignment, PragmaLoc,<br>
> + ExprResult Alignment;<br>
> + if (Info->Alignment.is(tok::numeric_constant)) {<br>
> + Alignment = Actions.ActOnNumericConstant(Info->Alignment);<br>
> + if (Alignment.isInvalid())<br>
> + return;<br>
> + }<br>
> + Actions.ActOnPragmaPack(Info->Kind, Info->Name, Alignment.get(), PragmaLoc,<br>
> Info->LParenLoc, Info->RParenLoc);<br>
> }<br>
><br>
> +void Parser::HandlePragmaMSStruct() {<br>
> + assert(Tok.is(tok::annot_pragma_msstruct));<br>
> + Sema::PragmaMSStructKind Kind =<br>
> + static_cast<Sema::PragmaMSStructKind>(<br>
> + reinterpret_cast<uintptr_t>(Tok.getAnnotationValue()));<br>
> + Actions.ActOnPragmaMSStruct(Kind);<br>
> + ConsumeToken(); // The annotation token.<br>
> +}<br>
> +<br>
> +void Parser::HandlePragmaAlign() {<br>
> + assert(Tok.is(tok::annot_pragma_align));<br>
> + Sema::PragmaOptionsAlignKind Kind =<br>
> + static_cast<Sema::PragmaOptionsAlignKind>(<br>
> + reinterpret_cast<uintptr_t>(Tok.getAnnotationValue()));<br>
> + SourceLocation PragmaLoc = ConsumeToken();<br>
> + Actions.ActOnPragmaOptionsAlign(Kind, PragmaLoc);<br>
> +}<br>
> +<br>
> +void Parser::HandlePragmaWeak() {<br>
> + assert(Tok.is(tok::annot_pragma_weak));<br>
> + SourceLocation PragmaLoc = ConsumeToken();<br>
> + Actions.ActOnPragmaWeakID(Tok.getIdentifierInfo(), PragmaLoc,<br>
> + Tok.getLocation());<br>
> + ConsumeToken(); // The weak name.<br>
> +}<br>
> +<br>
> +void Parser::HandlePragmaWeakAlias() {<br>
> + assert(Tok.is(tok::annot_pragma_weakalias));<br>
> + SourceLocation PragmaLoc = ConsumeToken();<br>
> + IdentifierInfo *WeakName = Tok.getIdentifierInfo();<br>
> + SourceLocation WeakNameLoc = Tok.getLocation();<br>
> + ConsumeToken();<br>
> + IdentifierInfo *AliasName = Tok.getIdentifierInfo();<br>
> + SourceLocation AliasNameLoc = Tok.getLocation();<br>
> + ConsumeToken();<br>
> + Actions.ActOnPragmaWeakAlias(WeakName, AliasName, PragmaLoc,<br>
> + WeakNameLoc, AliasNameLoc);<br>
> +<br>
> +}<br>
> +<br>
> +void Parser::HandlePragmaRedefineExtname() {<br>
> + assert(Tok.is(tok::annot_pragma_redefine_extname));<br>
> + SourceLocation RedefLoc = ConsumeToken();<br>
> + IdentifierInfo *RedefName = Tok.getIdentifierInfo();<br>
> + SourceLocation RedefNameLoc = Tok.getLocation();<br>
> + ConsumeToken();<br>
> + IdentifierInfo *AliasName = Tok.getIdentifierInfo();<br>
> + SourceLocation AliasNameLoc = Tok.getLocation();<br>
> + ConsumeToken();<br>
> + Actions.ActOnPragmaRedefineExtname(RedefName, AliasName, RedefLoc,<br>
> + RedefNameLoc, AliasNameLoc);<br>
> +}<br>
> +<br>
> +void Parser::HandlePragmaFPContract() {<br>
> + assert(Tok.is(tok::annot_pragma_fp_contract));<br>
> + tok::OnOffSwitch OOS =<br>
> + static_cast<tok::OnOffSwitch>(<br>
> + reinterpret_cast<uintptr_t>(Tok.getAnnotationValue()));<br>
> + Actions.ActOnPragmaFPContract(OOS);<br>
> + ConsumeToken(); // The annotation token.<br>
> +}<br>
> +<br>
> +namespace {<br>
> + typedef llvm::PointerIntPair<IdentifierInfo *, 1, bool> OpenCLExtData;<br>
> +}<br>
> +<br>
> +void Parser::HandlePragmaOpenCLExtension() {<br>
> + assert(Tok.is(tok::annot_pragma_opencl_extension));<br>
> + OpenCLExtData data =<br>
> + OpenCLExtData::getFromOpaqueValue(Tok.getAnnotationValue());<br>
> + unsigned state = data.getInt();<br>
> + IdentifierInfo *ename = data.getPointer();<br>
> + SourceLocation NameLoc = Tok.getLocation();<br>
> + ConsumeToken(); // The annotation token.<br>
> +<br>
> + OpenCLOptions &f = Actions.getOpenCLOptions();<br>
> + // OpenCL 1.1 9.1: "The all variant sets the behavior for all extensions,<br>
> + // overriding all previously issued extension directives, but only if the<br>
> + // behavior is set to disable."<br>
> + if (state == 0 && ename->isStr("all")) {<br>
> +#define OPENCLEXT(nm) f.nm = 0;<br>
> +#include "clang/Basic/OpenCLExtensions.def"<br>
> + }<br>
> +#define OPENCLEXT(nm) else if (ename->isStr(#nm)) { f.nm = state; }<br>
> +#include "clang/Basic/OpenCLExtensions.def"<br>
> + else {<br>
> + PP.Diag(NameLoc, diag::warn_pragma_unknown_extension) << ename;<br>
> + return;<br>
> + }<br>
> +}<br>
> +<br>
> // #pragma GCC visibility comes in two variants:<br>
> // 'push' '(' [visibility] ')'<br>
> // 'pop'<br>
> @@ -130,13 +227,12 @@<br>
><br>
> Sema::PragmaPackKind Kind = Sema::PPK_Default;<br>
> IdentifierInfo *Name = 0;<br>
> - ExprResult Alignment;<br>
> + Token Alignment;<br>
> + Alignment.startToken();<br>
> SourceLocation LParenLoc = Tok.getLocation();<br>
> PP.Lex(Tok);<br>
> if (Tok.is(tok::numeric_constant)) {<br>
> - Alignment = Actions.ActOnNumericConstant(Tok);<br>
> - if (Alignment.isInvalid())<br>
> - return;<br>
> + Alignment = Tok;<br>
><br>
> PP.Lex(Tok);<br>
><br>
> @@ -165,9 +261,7 @@<br>
> PP.Lex(Tok);<br>
><br>
> if (Tok.is(tok::numeric_constant)) {<br>
> - Alignment = Actions.ActOnNumericConstant(Tok);<br>
> - if (Alignment.isInvalid())<br>
> - return;<br>
> + Alignment = Tok;<br>
><br>
> PP.Lex(Tok);<br>
> } else if (Tok.is(tok::identifier)) {<br>
> @@ -182,9 +276,7 @@<br>
> return;<br>
> }<br>
><br>
> - Alignment = Actions.ActOnNumericConstant(Tok);<br>
> - if (Alignment.isInvalid())<br>
> - return;<br>
> + Alignment = Tok;<br>
><br>
> PP.Lex(Tok);<br>
> }<br>
> @@ -219,7 +311,7 @@<br>
> new (Info) PragmaPackInfo();<br>
> Info->Kind = Kind;<br>
> Info->Name = Name;<br>
> - Info->Alignment = Alignment.release();<br>
> + Info->Alignment = Alignment;<br>
> Info->LParenLoc = LParenLoc;<br>
> Info->RParenLoc = RParenLoc;<br>
><br>
> @@ -265,12 +357,23 @@<br>
> << "ms_struct";<br>
> return;<br>
> }<br>
> - Actions.ActOnPragmaMSStruct(Kind);<br>
> +<br>
> + Token *Toks =<br>
> + (Token*) PP.getPreprocessorAllocator().Allocate(<br>
> + sizeof(Token) * 1, llvm::alignOf<Token>());<br>
> + new (Toks) Token();<br>
> + Toks[0].startToken();<br>
> + Toks[0].setKind(tok::annot_pragma_msstruct);<br>
> + Toks[0].setLocation(MSStructTok.getLocation());<br>
> + Toks[0].setAnnotationValue(reinterpret_cast<void*>(<br>
> + static_cast<uintptr_t>(Kind)));<br>
> + PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,<br>
> + /*OwnsTokens=*/false);<br>
> }<br>
><br>
> // #pragma 'align' '=' {'native','natural','mac68k','power','reset'}<br>
> // #pragma 'options 'align' '=' {'native','natural','mac68k','power','reset'}<br>
> -static void ParseAlignPragma(Sema &Actions, Preprocessor &PP, Token &FirstTok,<br>
> +static void ParseAlignPragma(Preprocessor &PP, Token &FirstTok,<br>
> bool IsOptions) {<br>
> Token Tok;<br>
><br>
> @@ -317,7 +420,6 @@<br>
> return;<br>
> }<br>
><br>
> - SourceLocation KindLoc = Tok.getLocation();<br>
> PP.Lex(Tok);<br>
> if (Tok.isNot(tok::eod)) {<br>
> PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol)<br>
> @@ -325,19 +427,29 @@<br>
> return;<br>
> }<br>
><br>
> - Actions.ActOnPragmaOptionsAlign(Kind, FirstTok.getLocation(), KindLoc);<br>
> + Token *Toks =<br>
> + (Token*) PP.getPreprocessorAllocator().Allocate(<br>
> + sizeof(Token) * 1, llvm::alignOf<Token>());<br>
> + new (Toks) Token();<br>
> + Toks[0].startToken();<br>
> + Toks[0].setKind(tok::annot_pragma_align);<br>
> + Toks[0].setLocation(FirstTok.getLocation());<br>
> + Toks[0].setAnnotationValue(reinterpret_cast<void*>(<br>
> + static_cast<uintptr_t>(Kind)));<br>
> + PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,<br>
> + /*OwnsTokens=*/false);<br>
> }<br>
><br>
> void PragmaAlignHandler::HandlePragma(Preprocessor &PP,<br>
> PragmaIntroducerKind Introducer,<br>
> Token &AlignTok) {<br>
> - ParseAlignPragma(Actions, PP, AlignTok, /*IsOptions=*/false);<br>
> + ParseAlignPragma(PP, AlignTok, /*IsOptions=*/false);<br>
> }<br>
><br>
> void PragmaOptionsHandler::HandlePragma(Preprocessor &PP,<br>
> PragmaIntroducerKind Introducer,<br>
> Token &OptionsTok) {<br>
> - ParseAlignPragma(Actions, PP, OptionsTok, /*IsOptions=*/true);<br>
> + ParseAlignPragma(PP, OptionsTok, /*IsOptions=*/true);<br>
> }<br>
><br>
> // #pragma unused(identifier)<br>
> @@ -426,7 +538,6 @@<br>
> void PragmaWeakHandler::HandlePragma(Preprocessor &PP,<br>
> PragmaIntroducerKind Introducer,<br>
> Token &WeakTok) {<br>
> - // FIXME: Should we be expanding macros here? My guess is no.<br>
> SourceLocation WeakLoc = WeakTok.getLocation();<br>
><br>
> Token Tok;<br>
> @@ -436,19 +547,20 @@<br>
> return;<br>
> }<br>
><br>
> - IdentifierInfo *WeakName = Tok.getIdentifierInfo(), *AliasName = 0;<br>
> - SourceLocation WeakNameLoc = Tok.getLocation(), AliasNameLoc;<br>
> + Token WeakName = Tok;<br>
> + bool HasAlias = false;<br>
> + Token AliasName;<br>
><br>
> PP.Lex(Tok);<br>
> if (Tok.is(tok::equal)) {<br>
> + HasAlias = true;<br>
> PP.Lex(Tok);<br>
> if (Tok.isNot(tok::identifier)) {<br>
> PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)<br>
> << "weak";<br>
> return;<br>
> }<br>
> - AliasName = Tok.getIdentifierInfo();<br>
> - AliasNameLoc = Tok.getLocation();<br>
> + AliasName = Tok;<br>
> PP.Lex(Tok);<br>
> }<br>
><br>
> @@ -457,11 +569,29 @@<br>
> return;<br>
> }<br>
><br>
> - if (AliasName) {<br>
> - Actions.ActOnPragmaWeakAlias(WeakName, AliasName, WeakLoc, WeakNameLoc,<br>
> - AliasNameLoc);<br>
> + if (HasAlias) {<br>
> + Token *Toks =<br>
> + (Token*) PP.getPreprocessorAllocator().Allocate(<br>
> + sizeof(Token) * 3, llvm::alignOf<Token>());<br>
> + Token &pragmaUnusedTok = Toks[0];<br>
> + pragmaUnusedTok.startToken();<br>
> + pragmaUnusedTok.setKind(tok::annot_pragma_weakalias);<br>
> + pragmaUnusedTok.setLocation(WeakLoc);<br>
> + Toks[1] = WeakName;<br>
> + Toks[2] = AliasName;<br>
> + PP.EnterTokenStream(Toks, 3,<br>
> + /*DisableMacroExpansion=*/true, /*OwnsTokens=*/false);<br>
> } else {<br>
> - Actions.ActOnPragmaWeakID(WeakName, WeakLoc, WeakNameLoc);<br>
> + Token *Toks =<br>
> + (Token*) PP.getPreprocessorAllocator().Allocate(<br>
> + sizeof(Token) * 2, llvm::alignOf<Token>());<br>
> + Token &pragmaUnusedTok = Toks[0];<br>
> + pragmaUnusedTok.startToken();<br>
> + pragmaUnusedTok.setKind(tok::annot_pragma_weak);<br>
> + pragmaUnusedTok.setLocation(WeakLoc);<br>
> + Toks[1] = WeakName;<br>
> + PP.EnterTokenStream(Toks, 2,<br>
> + /*DisableMacroExpansion=*/true, /*OwnsTokens=*/false);<br>
> }<br>
> }<br>
><br>
> @@ -479,17 +609,16 @@<br>
> return;<br>
> }<br>
><br>
> - IdentifierInfo *RedefName = Tok.getIdentifierInfo(), *AliasName = 0;<br>
> - SourceLocation RedefNameLoc = Tok.getLocation(), AliasNameLoc;<br>
> -<br>
> + Token RedefName = Tok;<br>
> PP.Lex(Tok);<br>
> +<br>
> if (Tok.isNot(tok::identifier)) {<br>
> PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)<br>
> << "redefine_extname";<br>
> return;<br>
> }<br>
> - AliasName = Tok.getIdentifierInfo();<br>
> - AliasNameLoc = Tok.getLocation();<br>
> +<br>
> + Token AliasName = Tok;<br>
> PP.Lex(Tok);<br>
><br>
> if (Tok.isNot(tok::eod)) {<br>
> @@ -498,8 +627,17 @@<br>
> return;<br>
> }<br>
><br>
> - Actions.ActOnPragmaRedefineExtname(RedefName, AliasName, RedefLoc,<br>
> - RedefNameLoc, AliasNameLoc);<br>
> + Token *Toks =<br>
> + (Token*) PP.getPreprocessorAllocator().Allocate(<br>
> + sizeof(Token) * 3, llvm::alignOf<Token>());<br>
> + Token &pragmaRedefTok = Toks[0];<br>
> + pragmaRedefTok.startToken();<br>
> + pragmaRedefTok.setKind(tok::annot_pragma_redefine_extname);<br>
> + pragmaRedefTok.setLocation(RedefLoc);<br>
> + Toks[1] = RedefName;<br>
> + Toks[2] = AliasName;<br>
> + PP.EnterTokenStream(Toks, 3,<br>
> + /*DisableMacroExpansion=*/true, /*OwnsTokens=*/false);<br>
> }<br>
><br>
><br>
> @@ -511,7 +649,17 @@<br>
> if (PP.LexOnOffSwitch(OOS))<br>
> return;<br>
><br>
> - Actions.ActOnPragmaFPContract(OOS);<br>
> + Token *Toks =<br>
> + (Token*) PP.getPreprocessorAllocator().Allocate(<br>
> + sizeof(Token) * 1, llvm::alignOf<Token>());<br>
> + new (Toks) Token();<br>
> + Toks[0].startToken();<br>
> + Toks[0].setKind(tok::annot_pragma_fp_contract);<br>
> + Toks[0].setLocation(Tok.getLocation());<br>
> + Toks[0].setAnnotationValue(reinterpret_cast<void*>(<br>
> + static_cast<uintptr_t>(OOS)));<br>
> + PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,<br>
> + /*OwnsTokens=*/false);<br>
> }<br>
><br>
> void<br>
> @@ -550,19 +698,23 @@<br>
> return;<br>
> }<br>
><br>
> - OpenCLOptions &f = Actions.getOpenCLOptions();<br>
> - // OpenCL 1.1 9.1: "The all variant sets the behavior for all extensions,<br>
> - // overriding all previously issued extension directives, but only if the<br>
> - // behavior is set to disable."<br>
> - if (state == 0 && ename->isStr("all")) {<br>
> -#define OPENCLEXT(nm) f.nm = 0;<br>
> -#include "clang/Basic/OpenCLExtensions.def"<br>
> - }<br>
> -#define OPENCLEXT(nm) else if (ename->isStr(#nm)) { f.nm = state; }<br>
> -#include "clang/Basic/OpenCLExtensions.def"<br>
> - else {<br>
> - PP.Diag(NameLoc, diag::warn_pragma_unknown_extension) << ename;<br>
> + PP.Lex(Tok);<br>
> + if (Tok.isNot(tok::eod)) {<br>
> + PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<<br>
> + "OPENCL EXTENSION";<br>
> return;<br>
> }<br>
> +<br>
> + OpenCLExtData data(ename, state);<br>
> + Token *Toks =<br>
> + (Token*) PP.getPreprocessorAllocator().Allocate(<br>
> + sizeof(Token) * 1, llvm::alignOf<Token>());<br>
> + new (Toks) Token();<br>
> + Toks[0].startToken();<br>
> + Toks[0].setKind(tok::annot_pragma_opencl_extension);<br>
> + Toks[0].setLocation(NameLoc);<br>
> + Toks[0].setAnnotationValue(data.getOpaqueValue());<br>
> + PP.EnterTokenStream(Toks, 1, /*DisableMacroExpansion=*/true,<br>
> + /*OwnsTokens=*/false);<br>
> }<br>
><br>
><br>
> Modified: cfe/trunk/lib/Parse/ParsePragma.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.h?rev=165195&r1=165194&r2=165195&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.h?rev=165195&r1=165194&r2=165195&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Parse/ParsePragma.h (original)<br>
> +++ cfe/trunk/lib/Parse/ParsePragma.h Wed Oct 3 21:36:51 2012<br>
> @@ -21,9 +21,8 @@<br>
> class Parser;<br>
><br>
> class PragmaAlignHandler : public PragmaHandler {<br>
> - Sema &Actions;<br>
> public:<br>
> - explicit PragmaAlignHandler(Sema &A) : PragmaHandler("align"), Actions(A) {}<br>
> + explicit PragmaAlignHandler() : PragmaHandler("align") {}<br>
><br>
> virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,<br>
> Token &FirstToken);<br>
> @@ -31,38 +30,31 @@<br>
><br>
> class PragmaGCCVisibilityHandler : public PragmaHandler {<br>
> public:<br>
> - explicit PragmaGCCVisibilityHandler(Sema &/*A*/)<br>
> - : PragmaHandler("visibility") {}<br>
> + explicit PragmaGCCVisibilityHandler() : PragmaHandler("visibility") {}<br>
><br>
> virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,<br>
> Token &FirstToken);<br>
> };<br>
><br>
> class PragmaOptionsHandler : public PragmaHandler {<br>
> - Sema &Actions;<br>
> public:<br>
> - explicit PragmaOptionsHandler(Sema &A) : PragmaHandler("options"),<br>
> - Actions(A) {}<br>
> + explicit PragmaOptionsHandler() : PragmaHandler("options") {}<br>
><br>
> virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,<br>
> Token &FirstToken);<br>
> };<br>
><br>
> class PragmaPackHandler : public PragmaHandler {<br>
> - Sema &Actions;<br>
> public:<br>
> - explicit PragmaPackHandler(Sema &A) : PragmaHandler("pack"),<br>
> - Actions(A) {}<br>
> + explicit PragmaPackHandler() : PragmaHandler("pack") {}<br>
><br>
> virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,<br>
> Token &FirstToken);<br>
> };<br>
><br>
> class PragmaMSStructHandler : public PragmaHandler {<br>
> - Sema &Actions;<br>
> public:<br>
> - explicit PragmaMSStructHandler(Sema &A) : PragmaHandler("ms_struct"),<br>
> - Actions(A) {}<br>
> + explicit PragmaMSStructHandler() : PragmaHandler("ms_struct") {}<br>
><br>
> virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,<br>
> Token &FirstToken);<br>
> @@ -70,48 +62,39 @@<br>
><br>
> class PragmaUnusedHandler : public PragmaHandler {<br>
> public:<br>
> - PragmaUnusedHandler(Sema &/*A*/)<br>
> - : PragmaHandler("unused") {}<br>
> + PragmaUnusedHandler() : PragmaHandler("unused") {}<br>
><br>
> virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,<br>
> Token &FirstToken);<br>
> };<br>
><br>
> class PragmaWeakHandler : public PragmaHandler {<br>
> - Sema &Actions;<br>
> public:<br>
> - explicit PragmaWeakHandler(Sema &A)<br>
> - : PragmaHandler("weak"), Actions(A) {}<br>
> + explicit PragmaWeakHandler() : PragmaHandler("weak") {}<br>
><br>
> virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,<br>
> Token &FirstToken);<br>
> };<br>
><br>
> class PragmaRedefineExtnameHandler : public PragmaHandler {<br>
> - Sema &Actions;<br>
> public:<br>
> - explicit PragmaRedefineExtnameHandler(Sema &A)<br>
> - : PragmaHandler("redefine_extname"), Actions(A) {}<br>
> + explicit PragmaRedefineExtnameHandler() : PragmaHandler("redefine_extname") {}<br>
><br>
> virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,<br>
> Token &FirstToken);<br>
> };<br>
><br>
> class PragmaOpenCLExtensionHandler : public PragmaHandler {<br>
> - Sema &Actions;<br>
> public:<br>
> - PragmaOpenCLExtensionHandler(Sema &A) :<br>
> - PragmaHandler("EXTENSION"), Actions(A) {}<br>
> + PragmaOpenCLExtensionHandler() : PragmaHandler("EXTENSION") {}<br>
> virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,<br>
> Token &FirstToken);<br>
> };<br>
><br>
><br>
> class PragmaFPContractHandler : public PragmaHandler {<br>
> - Sema &Actions;<br>
> public:<br>
> - PragmaFPContractHandler(Sema &A) :<br>
> - PragmaHandler("FP_CONTRACT"), Actions(A) {}<br>
> + PragmaFPContractHandler() : PragmaHandler("FP_CONTRACT") {}<br>
> virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,<br>
> Token &FirstToken);<br>
> };<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=165195&r1=165194&r2=165195&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=165195&r1=165194&r2=165195&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Parse/ParseStmt.cpp (original)<br>
> +++ cfe/trunk/lib/Parse/ParseStmt.cpp Wed Oct 3 21:36:51 2012<br>
> @@ -253,6 +253,16 @@<br>
> ProhibitAttributes(Attrs);<br>
> HandlePragmaPack();<br>
> return StmtEmpty();<br>
> +<br>
> + case tok::annot_pragma_fp_contract:<br>
> + ProhibitAttributes(Attrs);<br>
> + HandlePragmaFPContract();<br>
> + return StmtEmpty();<br>
> +<br>
> + case tok::annot_pragma_opencl_extension:<br>
> + ProhibitAttributes(Attrs);<br>
> + HandlePragmaOpenCLExtension();<br>
> + return StmtEmpty();<br>
> }<br>
><br>
> // If we reached this code, the statement must end in a semicolon.<br>
><br>
> Modified: cfe/trunk/lib/Parse/Parser.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=165195&r1=165194&r2=165195&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=165195&r1=165194&r2=165195&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Parse/Parser.cpp (original)<br>
> +++ cfe/trunk/lib/Parse/Parser.cpp Wed Oct 3 21:36:51 2012<br>
> @@ -60,35 +60,35 @@<br>
><br>
> // Add #pragma handlers. These are removed and destroyed in the<br>
> // destructor.<br>
> - AlignHandler.reset(new PragmaAlignHandler(actions));<br>
> + AlignHandler.reset(new PragmaAlignHandler());<br>
> PP.AddPragmaHandler(AlignHandler.get());<br>
><br>
> - GCCVisibilityHandler.reset(new PragmaGCCVisibilityHandler(actions));<br>
> + GCCVisibilityHandler.reset(new PragmaGCCVisibilityHandler());<br>
> PP.AddPragmaHandler("GCC", GCCVisibilityHandler.get());<br>
><br>
> - OptionsHandler.reset(new PragmaOptionsHandler(actions));<br>
> + OptionsHandler.reset(new PragmaOptionsHandler());<br>
> PP.AddPragmaHandler(OptionsHandler.get());<br>
><br>
> - PackHandler.reset(new PragmaPackHandler(actions));<br>
> + PackHandler.reset(new PragmaPackHandler());<br>
> PP.AddPragmaHandler(PackHandler.get());<br>
><br>
> - MSStructHandler.reset(new PragmaMSStructHandler(actions));<br>
> + MSStructHandler.reset(new PragmaMSStructHandler());<br>
> PP.AddPragmaHandler(MSStructHandler.get());<br>
><br>
> - UnusedHandler.reset(new PragmaUnusedHandler(actions));<br>
> + UnusedHandler.reset(new PragmaUnusedHandler());<br>
> PP.AddPragmaHandler(UnusedHandler.get());<br>
><br>
> - WeakHandler.reset(new PragmaWeakHandler(actions));<br>
> + WeakHandler.reset(new PragmaWeakHandler());<br>
> PP.AddPragmaHandler(WeakHandler.get());<br>
><br>
> - RedefineExtnameHandler.reset(new PragmaRedefineExtnameHandler(actions));<br>
> + RedefineExtnameHandler.reset(new PragmaRedefineExtnameHandler());<br>
> PP.AddPragmaHandler(RedefineExtnameHandler.get());<br>
><br>
> - FPContractHandler.reset(new PragmaFPContractHandler(actions));<br>
> + FPContractHandler.reset(new PragmaFPContractHandler());<br>
> PP.AddPragmaHandler("STDC", FPContractHandler.get());<br>
><br>
> if (getLangOpts().OpenCL) {<br>
> - OpenCLExtensionHandler.reset(new PragmaOpenCLExtensionHandler(actions));<br>
> + OpenCLExtensionHandler.reset(new PragmaOpenCLExtensionHandler());<br>
> PP.AddPragmaHandler("OPENCL", OpenCLExtensionHandler.get());<br>
><br>
> PP.AddPragmaHandler("OPENCL", FPContractHandler.get());<br>
> @@ -635,6 +635,27 @@<br>
> case tok::annot_pragma_pack:<br>
> HandlePragmaPack();<br>
> return DeclGroupPtrTy();<br>
> + case tok::annot_pragma_msstruct:<br>
> + HandlePragmaMSStruct();<br>
> + return DeclGroupPtrTy();<br>
> + case tok::annot_pragma_align:<br>
> + HandlePragmaAlign();<br>
> + return DeclGroupPtrTy();<br>
> + case tok::annot_pragma_weak:<br>
> + HandlePragmaWeak();<br>
> + return DeclGroupPtrTy();<br>
> + case tok::annot_pragma_weakalias:<br>
> + HandlePragmaWeakAlias();<br>
> + return DeclGroupPtrTy();<br>
> + case tok::annot_pragma_redefine_extname:<br>
> + HandlePragmaRedefineExtname();<br>
> + return DeclGroupPtrTy();<br>
> + case tok::annot_pragma_fp_contract:<br>
> + HandlePragmaFPContract();<br>
> + return DeclGroupPtrTy();<br>
> + case tok::annot_pragma_opencl_extension:<br>
> + HandlePragmaOpenCLExtension();<br>
> + return DeclGroupPtrTy();<br>
> case tok::semi:<br>
> ConsumeExtraSemi(OutsideFunction);<br>
> // TODO: Invoke action for top-level semicolon.<br>
><br>
> Modified: cfe/trunk/lib/Sema/SemaAttr.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=165195&r1=165194&r2=165195&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=165195&r1=165194&r2=165195&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Sema/SemaAttr.cpp (original)<br>
> +++ cfe/trunk/lib/Sema/SemaAttr.cpp Wed Oct 3 21:36:51 2012<br>
> @@ -136,23 +136,12 @@<br>
> }<br>
><br>
> void Sema::ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind,<br>
> - SourceLocation PragmaLoc,<br>
> - SourceLocation KindLoc) {<br>
> + SourceLocation PragmaLoc) {<br>
> if (PackContext == 0)<br>
> PackContext = new PragmaPackStack();<br>
><br>
> PragmaPackStack *Context = static_cast<PragmaPackStack*>(PackContext);<br>
><br>
> - // Reset just pops the top of the stack, or resets the current alignment to<br>
> - // default.<br>
> - if (Kind == Sema::POAK_Reset) {<br>
> - if (!Context->pop(0, /*IsReset=*/true)) {<br>
> - Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)<br>
> - << "stack empty";<br>
> - }<br>
> - return;<br>
> - }<br>
> -<br>
> switch (Kind) {<br>
> // For all targets we support native and natural are the same.<br>
> //<br>
> @@ -181,9 +170,13 @@<br>
> Context->setAlignment(PackStackEntry::kMac68kAlignmentSentinel);<br>
> break;<br>
><br>
> - default:<br>
> - Diag(PragmaLoc, diag::warn_pragma_options_align_unsupported_option)<br>
> - << KindLoc;<br>
> + case POAK_Reset:<br>
> + // Reset just pops the top of the stack, or resets the current alignment to<br>
> + // default.<br>
> + if (!Context->pop(0, /*IsReset=*/true)) {<br>
> + Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)<br>
> + << "stack empty";<br>
> + }<br>
> break;<br>
> }<br>
> }<br>
><br>
> Modified: cfe/trunk/test/CodeGen/fp-contract-pragma.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/fp-contract-pragma.cpp?rev=165195&r1=165194&r2=165195&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/fp-contract-pragma.cpp?rev=165195&r1=165194&r2=165195&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/CodeGen/fp-contract-pragma.cpp (original)<br>
> +++ cfe/trunk/test/CodeGen/fp-contract-pragma.cpp Wed Oct 3 21:36:51 2012<br>
> @@ -34,3 +34,15 @@<br>
> // CHECK: tail call float @llvm.fmuladd<br>
> return template_muladd<float>(a, b, c);<br>
> }<br>
> +<br>
> +template<typename T> class fp_contract_4 {<br>
> + float method(float a, float b, float c) {<br>
> + #pragma STDC FP_CONTRACT ON<br>
> + return a * b + c;<br>
> + #pragma STDC FP_CONTRACT OFF<br>
> + }<br>
> +};<br>
> +<br>
> +template class fp_contract_4<int>;<br>
> +// CHECK: _ZN13fp_contract_4IiE6methodEfff<br>
> +// CHECK: tail call float @llvm.fmuladd<br>
><br>
> Modified: cfe/trunk/test/Misc/warning-flags.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/warning-flags.c?rev=165195&r1=165194&r2=165195&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/warning-flags.c?rev=165195&r1=165194&r2=165195&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/Misc/warning-flags.c (original)<br>
> +++ cfe/trunk/test/Misc/warning-flags.c Wed Oct 3 21:36:51 2012<br>
> @@ -18,7 +18,7 @@<br>
><br>
> The list of warnings below should NEVER grow. It should gradually shrink to 0.<br>
><br>
> -CHECK: Warnings without flags (158):<br>
> +CHECK: Warnings without flags (157):<br>
> CHECK-NEXT: ext_delete_void_ptr_operand<br>
> CHECK-NEXT: ext_enum_friend<br>
> CHECK-NEXT: ext_expected_semi_decl_list<br>
> @@ -133,7 +133,6 @@<br>
> CHECK-NEXT: warn_pragma_extra_tokens_at_eol<br>
> CHECK-NEXT: warn_pragma_ms_struct<br>
> CHECK-NEXT: warn_pragma_options_align_reset_failed<br>
> -CHECK-NEXT: warn_pragma_options_align_unsupported_option<br>
> CHECK-NEXT: warn_pragma_options_expected_align<br>
> CHECK-NEXT: warn_pragma_pack_invalid_action<br>
> CHECK-NEXT: warn_pragma_pack_invalid_alignment<br>
><br>
> Modified: cfe/trunk/test/Sema/pragma-pack-and-options-align.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/pragma-pack-and-options-align.c?rev=165195&r1=165194&r2=165195&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/pragma-pack-and-options-align.c?rev=165195&r1=165194&r2=165195&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/Sema/pragma-pack-and-options-align.c (original)<br>
> +++ cfe/trunk/test/Sema/pragma-pack-and-options-align.c Wed Oct 3 21:36:51 2012<br>
> @@ -38,5 +38,16 @@<br>
> };<br>
> extern int a[sizeof(struct s3) == 8 ? 1 : -1];<br>
><br>
> +#pragma pack(push,2)<br>
> +#pragma options align=power<br>
> +struct s4 {<br>
> + char c;<br>
> + int x;<br>
> +};<br>
> +#pragma pack(pop)<br>
> +#pragma options align=reset<br>
> +extern int a[sizeof(struct s4) == 8 ? 1 : -1];<br>
> +<br>
> /* expected-warning {{#pragma options align=reset failed: stack empty}} */ #pragma options align=reset<br>
> /* expected-warning {{#pragma pack(pop, ...) failed: stack empty}} */ #pragma pack(pop)<br>
> +<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>