diff options
author | Erik Pilkington <erik.pilkington@gmail.com> | 2018-10-29 03:24:16 +0000 |
---|---|---|
committer | Erik Pilkington <erik.pilkington@gmail.com> | 2018-10-29 03:24:16 +0000 |
commit | b287a015e3a8f19734762f89ff02d877037c80e9 (patch) | |
tree | f8d8c5c09d763e15a4f84f75dd7e0fe04473e06b /clang/lib | |
parent | a7cc6b360fe976c9105968d73f60e26172dc7b77 (diff) | |
download | bcm5719-llvm-b287a015e3a8f19734762f89ff02d877037c80e9.tar.gz bcm5719-llvm-b287a015e3a8f19734762f89ff02d877037c80e9.zip |
Revert "Support for groups of attributes in #pragma clang attribute"
This reverts commit r345486.
Looks like it causes some old versions of GCC to crash, I'll see if I can
work around it and recommit...
llvm-svn: 345487
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Parse/ParsePragma.cpp | 58 | ||||
-rw-r--r-- | clang/lib/Sema/SemaAttr.cpp | 72 |
2 files changed, 46 insertions, 84 deletions
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp index 35072a739b9..26b363f280c 100644 --- a/clang/lib/Parse/ParsePragma.cpp +++ b/clang/lib/Parse/ParsePragma.cpp @@ -1133,7 +1133,7 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) { namespace { struct PragmaAttributeInfo { - enum ActionType { Push, Pop, Attribute }; + enum ActionType { Push, Pop }; ParsedAttributes &Attributes; ActionType Action; ArrayRef<Token> Tokens; @@ -1394,16 +1394,8 @@ void Parser::HandlePragmaAttribute() { return; } // Parse the actual attribute with its arguments. - assert(Info->Action == PragmaAttributeInfo::Push || - Info->Action == PragmaAttributeInfo::Attribute && - "Unexpected #pragma attribute command"); - - if (Info->Action == PragmaAttributeInfo::Push && Info->Tokens.empty()) { - ConsumeAnnotationToken(); - Actions.ActOnPragmaAttributeEmptyPush(PragmaLoc); - return; - } - + assert(Info->Action == PragmaAttributeInfo::Push && + "Unexpected #pragma attribute command"); PP.EnterTokenStream(Info->Tokens, /*DisableMacroExpansion=*/false); ConsumeAnnotationToken(); @@ -1550,12 +1542,8 @@ void Parser::HandlePragmaAttribute() { // Consume the eof terminator token. ConsumeToken(); - // Handle a mixed push/attribute by desurging to a push, then an attribute. - if (Info->Action == PragmaAttributeInfo::Push) - Actions.ActOnPragmaAttributeEmptyPush(PragmaLoc); - - Actions.ActOnPragmaAttributeAttribute(Attribute, PragmaLoc, - std::move(SubjectMatchRules)); + Actions.ActOnPragmaAttributePush(Attribute, PragmaLoc, + std::move(SubjectMatchRules)); } // #pragma GCC visibility comes in two variants: @@ -3116,8 +3104,6 @@ void PragmaForceCUDAHostDeviceHandler::HandlePragma( /// The syntax is: /// \code /// #pragma clang attribute push(attribute, subject-set) -/// #pragma clang attribute push -/// #pragma clang attribute (attribute, subject-set) /// #pragma clang attribute pop /// \endcode /// @@ -3136,33 +3122,25 @@ void PragmaAttributeHandler::HandlePragma(Preprocessor &PP, auto *Info = new (PP.getPreprocessorAllocator()) PragmaAttributeInfo(AttributesForPragmaAttribute); - if (!Tok.isOneOf(tok::identifier, tok::l_paren)) { - PP.Diag(Tok.getLocation(), - diag::err_pragma_attribute_expected_push_pop_paren); + // Parse the 'push' or 'pop'. + if (Tok.isNot(tok::identifier)) { + PP.Diag(Tok.getLocation(), diag::err_pragma_attribute_expected_push_pop); return; } - - // Determine what action this pragma clang attribute represents. - if (Tok.is(tok::l_paren)) - Info->Action = PragmaAttributeInfo::Attribute; + const auto *II = Tok.getIdentifierInfo(); + if (II->isStr("push")) + Info->Action = PragmaAttributeInfo::Push; + else if (II->isStr("pop")) + Info->Action = PragmaAttributeInfo::Pop; else { - const IdentifierInfo *II = Tok.getIdentifierInfo(); - if (II->isStr("push")) - Info->Action = PragmaAttributeInfo::Push; - else if (II->isStr("pop")) - Info->Action = PragmaAttributeInfo::Pop; - else { - PP.Diag(Tok.getLocation(), diag::err_pragma_attribute_invalid_argument) - << PP.getSpelling(Tok); - return; - } - - PP.Lex(Tok); + PP.Diag(Tok.getLocation(), diag::err_pragma_attribute_invalid_argument) + << PP.getSpelling(Tok); + return; } + PP.Lex(Tok); // Parse the actual attribute. - if ((Info->Action == PragmaAttributeInfo::Push && Tok.isNot(tok::eod)) || - Info->Action == PragmaAttributeInfo::Attribute) { + if (Info->Action == PragmaAttributeInfo::Push) { if (Tok.isNot(tok::l_paren)) { PP.Diag(Tok.getLocation(), diag::err_expected) << tok::l_paren; return; diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp index f6ac9b44a83..8024e1a0515 100644 --- a/clang/lib/Sema/SemaAttr.cpp +++ b/clang/lib/Sema/SemaAttr.cpp @@ -520,9 +520,9 @@ attrMatcherRuleListToString(ArrayRef<attr::SubjectMatchRule> Rules) { } // end anonymous namespace -void Sema::ActOnPragmaAttributeAttribute( - ParsedAttr &Attribute, SourceLocation PragmaLoc, - attr::ParsedSubjectMatchRuleSet Rules) { +void Sema::ActOnPragmaAttributePush(ParsedAttr &Attribute, + SourceLocation PragmaLoc, + attr::ParsedSubjectMatchRuleSet Rules) { SmallVector<attr::SubjectMatchRule, 4> SubjectMatchRules; // Gather the subject match rules that are supported by the attribute. SmallVector<std::pair<attr::SubjectMatchRule, bool>, 4> @@ -622,64 +622,48 @@ void Sema::ActOnPragmaAttributeAttribute( Diagnostic << attrMatcherRuleListToString(ExtraRules); } - if (PragmaAttributeStack.empty()) { - Diag(PragmaLoc, diag::err_pragma_attr_attr_no_push); - return; - } - - PragmaAttributeStack.back().Entries.push_back( + PragmaAttributeStack.push_back( {PragmaLoc, &Attribute, std::move(SubjectMatchRules), /*IsUsed=*/false}); } -void Sema::ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc) { - PragmaAttributeStack.emplace_back(); - PragmaAttributeStack.back().Loc = PragmaLoc; -} - void Sema::ActOnPragmaAttributePop(SourceLocation PragmaLoc) { if (PragmaAttributeStack.empty()) { Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch); return; } - - for (const PragmaAttributeEntry &Entry : - PragmaAttributeStack.back().Entries) { - if (!Entry.IsUsed) { - assert(Entry.Attribute && "Expected an attribute"); - Diag(Entry.Attribute->getLoc(), diag::warn_pragma_attribute_unused) - << Entry.Attribute->getName(); - Diag(PragmaLoc, diag::note_pragma_attribute_region_ends_here); - } + const PragmaAttributeEntry &Entry = PragmaAttributeStack.back(); + if (!Entry.IsUsed) { + assert(Entry.Attribute && "Expected an attribute"); + Diag(Entry.Attribute->getLoc(), diag::warn_pragma_attribute_unused) + << Entry.Attribute->getName(); + Diag(PragmaLoc, diag::note_pragma_attribute_region_ends_here); } - PragmaAttributeStack.pop_back(); } void Sema::AddPragmaAttributes(Scope *S, Decl *D) { if (PragmaAttributeStack.empty()) return; - for (auto &Group : PragmaAttributeStack) { - for (auto &Entry : Group.Entries) { - ParsedAttr *Attribute = Entry.Attribute; - assert(Attribute && "Expected an attribute"); - - // Ensure that the attribute can be applied to the given declaration. - bool Applies = false; - for (const auto &Rule : Entry.MatchRules) { - if (Attribute->appliesToDecl(D, Rule)) { - Applies = true; - break; - } + for (auto &Entry : PragmaAttributeStack) { + ParsedAttr *Attribute = Entry.Attribute; + assert(Attribute && "Expected an attribute"); + + // Ensure that the attribute can be applied to the given declaration. + bool Applies = false; + for (const auto &Rule : Entry.MatchRules) { + if (Attribute->appliesToDecl(D, Rule)) { + Applies = true; + break; } - if (!Applies) - continue; - Entry.IsUsed = true; - PragmaAttributeCurrentTargetDecl = D; - ParsedAttributesView Attrs; - Attrs.addAtEnd(Attribute); - ProcessDeclAttributeList(S, D, Attrs); - PragmaAttributeCurrentTargetDecl = nullptr; } + if (!Applies) + continue; + Entry.IsUsed = true; + PragmaAttributeCurrentTargetDecl = D; + ParsedAttributesView Attrs; + Attrs.addAtEnd(Attribute); + ProcessDeclAttributeList(S, D, Attrs); + PragmaAttributeCurrentTargetDecl = nullptr; } } |