22 using namespace clang;
31 : S(S), SlotLabel(SlotLabel), ShouldAct(ShouldAct) {
81 unsigned Alignment = 0;
103 Diag(PragmaLoc, diag::err_pragma_options_align_mac68k_target_unsupported);
118 Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
126 PackStack.
Act(PragmaLoc, Action, StringRef(), Alignment);
133 case PragmaClangSectionKind::PCSK_BSS:
136 case PragmaClangSectionKind::PCSK_Data:
139 case PragmaClangSectionKind::PCSK_Rodata:
142 case PragmaClangSectionKind::PCSK_Text:
146 llvm_unreachable(
"invalid clang section kind");
149 if (Action == PragmaClangSectionAction::PCSA_Clear) {
160 StringRef SlotLabel,
Expr *alignment) {
161 Expr *Alignment =
static_cast<Expr *
>(alignment);
164 unsigned AlignmentVal = 0;
173 !(Val == 0 || Val.isPowerOf2()) ||
174 Val.getZExtValue() > 16) {
175 Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
179 AlignmentVal = (
unsigned) Val.getZExtValue();
186 if (AlignmentVal == 0)
189 Diag(PragmaLoc, diag::warn_pragma_pack_show) <<
"mac68k";
191 Diag(PragmaLoc, diag::warn_pragma_pack_show) << AlignmentVal;
196 if (Alignment && !SlotLabel.empty())
197 Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifer_and_alignment);
199 Diag(PragmaLoc, diag::warn_pragma_pop_failed) <<
"pack" <<
"stack empty";
202 PackStack.
Act(PragmaLoc, Action, SlotLabel, AlignmentVal);
234 MSVtorDispAttr::Mode Mode) {
236 Diag(PragmaLoc, diag::warn_pragma_pop_failed) <<
"vtordisp"
241 template<
typename ValueType>
244 llvm::StringRef StackSlotLabel,
247 CurrentValue = DefaultValue;
248 CurrentPragmaLocation = PragmaLocation;
252 Stack.push_back(
Slot(StackSlotLabel, CurrentValue, CurrentPragmaLocation));
254 if (!StackSlotLabel.empty()) {
256 auto I = llvm::find_if(llvm::reverse(
Stack), [&](
const Slot &x) {
261 CurrentValue =
I->Value;
262 CurrentPragmaLocation =
I->PragmaLocation;
265 }
else if (!
Stack.empty()) {
267 CurrentValue =
Stack.back().Value;
268 CurrentPragmaLocation =
Stack.back().PragmaLocation;
273 CurrentValue =
Value;
274 CurrentPragmaLocation = PragmaLocation;
288 if (Section->second.SectionFlags == SectionFlags ||
291 auto OtherDecl = Section->second.Decl;
293 << Decl << OtherDecl;
294 Diag(OtherDecl->getLocation(), diag::note_declared_at)
295 << OtherDecl->getName();
296 if (
auto A = Decl->
getAttr<SectionAttr>())
298 Diag(A->getLocation(), diag::note_pragma_entered_here);
299 if (
auto A = OtherDecl->getAttr<SectionAttr>())
301 Diag(A->getLocation(), diag::note_pragma_entered_here);
310 if (Section->second.SectionFlags == SectionFlags)
313 Diag(PragmaSectionLocation, diag::err_section_conflict)
314 <<
"this" <<
"a prior #pragma section";
315 Diag(Section->second.PragmaSectionLocation,
316 diag::note_pragma_entered_here);
328 llvm::StringRef StackSlotLabel,
330 llvm::StringRef PragmaName) {
332 llvm::StringSwitch<PragmaStack<StringLiteral *> *>(PragmaName)
338 Diag(PragmaLocation, diag::warn_pragma_pop_failed) << PragmaName
343 Stack->
Act(PragmaLocation, Action, StackSlotLabel, SegmentName);
368 if (Lookup.empty()) {
369 Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
376 Diag(PragmaLoc, diag::warn_pragma_unused_expected_var_arg)
383 Diag(PragmaLoc, diag::warn_used_but_marked_unused) <<
Name;
385 VD->
addAttr(UnusedAttr::CreateImplicit(
Context, UnusedAttr::GNU_unused,
394 if (D->
hasAttr<CFAuditedTransferAttr>() ||
395 D->
hasAttr<CFUnknownTransferAttr>())
405 using namespace attr;
409 #define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
410 #define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \
413 #include "clang/Basic/AttrSubMatchRulesList.inc"
418 using namespace attr;
422 #define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
423 #define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \
426 #include "clang/Basic/AttrSubMatchRulesList.inc"
445 llvm::raw_string_ostream OS(Result);
446 for (
const auto &
I : llvm::enumerate(Rules)) {
448 OS << (
I.index() == Rules.size() - 1 ?
", and " :
", ");
462 StrictSubjectMatchRuleSet;
466 if (StrictSubjectMatchRuleSet.empty()) {
473 llvm::SmallDenseMap<int, std::pair<int, SourceRange>, 2>
474 RulesToFirstSpecifiedNegatedSubRule;
475 for (
const auto &Rule : Rules) {
478 getParentAttrMatcherRule(MatchRule);
481 auto It = Rules.find(*ParentRule);
482 if (It != Rules.end()) {
484 Diag(Rule.second.getBegin(),
485 diag::err_pragma_attribute_matcher_subrule_contradicts_rule)
489 replacementRangeForListElement(*
this, Rule.second));
494 if (isNegatedAttrMatcherSubRule(MatchRule))
495 RulesToFirstSpecifiedNegatedSubRule.insert(
496 std::make_pair(*ParentRule, Rule));
498 bool IgnoreNegatedSubRules =
false;
499 for (
const auto &Rule : Rules) {
502 getParentAttrMatcherRule(MatchRule);
505 auto It = RulesToFirstSpecifiedNegatedSubRule.find(*ParentRule);
506 if (It != RulesToFirstSpecifiedNegatedSubRule.end() &&
507 It->second != Rule) {
510 It->second.second.getBegin(),
512 err_pragma_attribute_matcher_negated_subrule_contradicts_subrule)
517 replacementRangeForListElement(*
this, It->second.second));
519 IgnoreNegatedSubRules =
true;
520 RulesToFirstSpecifiedNegatedSubRule.erase(It);
524 if (!IgnoreNegatedSubRules) {
525 for (
const auto &Rule : Rules)
528 for (
const auto &Rule : Rules) {
535 for (
const auto &Rule : StrictSubjectMatchRuleSet) {
536 if (Rules.erase(Rule.first)) {
540 SubjectMatchRules.push_back(Rule.first);
545 if (!Rules.empty()) {
547 Diag(PragmaLoc, diag::err_pragma_attribute_invalid_matchers)
550 for (
const auto &Rule : Rules) {
553 replacementRangeForListElement(*
this, Rule.second));
555 Diagnostic << attrMatcherRuleListToString(ExtraRules);
559 {PragmaLoc, &Attribute, std::move(SubjectMatchRules),
false});
564 Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch);
569 assert(Entry.
Attribute &&
"Expected an attribute");
572 Diag(PragmaLoc, diag::note_pragma_attribute_region_ends_here);
582 assert(Attribute &&
"Expected an attribute");
585 bool Applies =
false;
586 for (
const auto &Rule : Entry.MatchRules) {
595 assert(!Attribute->
getNext() &&
"Expected just one attribute");
598 PragmaAttributeCurrentTargetDecl =
nullptr;
605 diag::note_pragma_attribute_applied_decl_here);
631 if (FD->
hasAttr<MinSizeAttr>() || FD->
hasAttr<AlwaysInlineAttr>())
636 if (!FD->
hasAttr<OptimizeNoneAttr>())
638 if (!FD->
hasAttr<NoInlineAttr>())
642 typedef std::vector<std::pair<unsigned, SourceLocation> >
VisStack;
654 unsigned rawType = Stack->back().first;
657 VisibilityAttr::VisibilityType
type
658 = (VisibilityAttr::VisibilityType) rawType;
676 Stack->push_back(std::make_pair(type, loc));
683 VisibilityAttr::VisibilityType T;
684 if (!VisibilityAttr::ConvertStrToVisibilityType(VisType->
getName(), T)) {
685 Diag(PragmaLoc, diag::warn_attribute_unknown_visibility) << VisType;
719 Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
726 const std::pair<unsigned, SourceLocation> *Back = &Stack->back();
728 if (StartsWithPragma && IsNamespaceEnd) {
729 Diag(Back->second, diag::err_pragma_push_visibility_mismatch);
730 Diag(EndLoc, diag::note_surrounding_namespace_ends_here);
735 Back = &Stack->back();
737 }
while (StartsWithPragma);
738 }
else if (!StartsWithPragma && !IsNamespaceEnd) {
739 Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
740 Diag(Back->second, diag::note_surrounding_namespace_starts_here);
SourceLocation getEnd() const
PragmaStack< StringLiteral * > CodeSegStack
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct)
void ActOnPragmaMSStruct(PragmaMSStructKind Kind)
ActOnPragmaMSStruct - Called on well formed #pragma ms_struct [on|off].
void SentinelAction(PragmaMsStackAction Action, StringRef Label)
PragmaStack< StringLiteral * > DataSegStack
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
void ActOnPragmaMSSeg(SourceLocation PragmaLocation, PragmaMsStackAction Action, llvm::StringRef StackSlotLabel, StringLiteral *SegmentName, llvm::StringRef PragmaName)
Called on well formed #pragma bss_seg/data_seg/const_seg/code_seg.
const LangOptions & getLangOpts() const
bool appliesToDecl(const Decl *D, attr::SubjectMatchRule MatchRule) const
static CharSourceRange getTokenRange(SourceRange R)
void getMatchRules(const LangOptions &LangOpts, SmallVectorImpl< std::pair< attr::SubjectMatchRule, bool >> &MatchRules) const
llvm::StringRef StackSlotLabel
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Decl - This represents one declaration (or definition), e.g.
void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, SourceLocation PragmaLoc, MSVtorDispAttr::Mode Value)
Called on well formed #pragma vtordisp().
bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, bool AllowBuiltinCreation=false, bool EnteringContext=false)
Performs name lookup for a name that was parsed in the source code, and may contain a C++ scope speci...
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
SourceLocation getLocStart() const LLVM_READONLY
VarDecl - An instance of this class is created to represent a variable declaration or definition...
DiagnosticsEngine & Diags
PragmaClangSection PragmaClangBSSSection
RecordDecl - Represents a struct/union/class.
void FreeVisContext()
FreeVisContext - Deallocate and null out VisContext.
One of these records is kept for each identifier that is lexed.
SubjectMatchRule
A list of all the recognized kinds of attributes.
bool hasAlignMac68kSupport() const
Check whether this target support '#pragma options align=mac68k'.
AttributeList * Attribute
Token - This structure provides full information about a lexed token.
static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc)
void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags, StringLiteral *SegmentName)
Called on well formed #pragma section().
Represents the results of name lookup.
const TargetInfo & getTargetInfo() const
void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, SourceLocation PragmaLoc)
ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
void ActOnPragmaAttributePop(SourceLocation PragmaLoc)
Called on well-formed '#pragma clang attribute pop'.
bool UnifySection(StringRef SectionName, int SectionFlags, DeclaratorDecl *TheDecl)
void AddPushedVisibilityAttribute(Decl *RD)
AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used, add an appropriate visibility at...
Scope - A scope is a transient data structure that is used while parsing the program.
void ActOnPragmaFPContract(LangOptions::FPContractModeKind FPC)
ActOnPragmaFPContract - Called on well formed #pragma {STDC,OPENCL} FP_CONTRACT and #pragma clang fp ...
void setAllowFPContractWithinStatement()
void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value)
ActOnPragmaDetectMismatch - Call on well-formed #pragma detect_mismatch.
detail::InMemoryDirectory::const_iterator I
const LangOptions & LangOpts
void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL, bool IncludeCXX11Attributes=true)
ProcessDeclAttributeList - Apply all the decl attributes in the specified attribute list to the speci...
void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc)
PopPragmaVisibility - Pop the top element of the visibility stack; used for '#pragma GCC visibility' ...
void PrintPragmaAttributeInstantiationPoint()
llvm::StringMap< SectionInfo > SectionInfos
Sema - This implements semantic analysis and AST building for C.
Represents a ValueDecl that came out of a declarator.
std::vector< bool > & Stack
std::vector< std::pair< unsigned, SourceLocation > > VisStack
const Decl * PragmaAttributeCurrentTargetDecl
The declaration that is currently receiving an attribute from the #pragma attribute stack...
SmallVector< PragmaAttributeEntry, 2 > PragmaAttributeStack
void setDisallowFPContract()
Expr - This represents one expression.
StringRef getName() const
Return the actual identifier string.
Represents a character-granular source range.
static SourceLocation findLocationAfterToken(SourceLocation loc, tok::TokenKind TKind, const SourceManager &SM, const LangOptions &LangOpts, bool SkipTrailingWhitespaceAndNewLine)
Checks that the given token is the first token that occurs after the given location (this excludes co...
void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, StringLiteral *SegmentName)
Called on well-formed #pragma init_seg().
TranslationUnitDecl * getTranslationUnitDecl() const
Defines the clang::Preprocessor interface.
PragmaStack< StringLiteral * > BSSSegStack
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
void ActOnPragmaUnused(const Token &Identifier, Scope *curScope, SourceLocation PragmaLoc)
ActOnPragmaUnused - Called on well-formed '#pragma unused'.
void ActOnPragmaMSComment(SourceLocation CommentLoc, PragmaMSCommentKind Kind, StringRef Arg)
ActOnPragmaMSComment - Called on well formed #pragma comment(kind, "arg").
~PragmaStackSentinelRAII()
void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc)
Adds the 'optnone' attribute to the function declaration if there are no conflicts; Loc represents th...
The result type of a method or function.
PragmaClangSectionKind
pragma clang section kind
Optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
static CharSourceRange getCharRange(SourceRange R)
SourceLocation getLocStart() const LLVM_READONLY
void AddRangeBasedOptnone(FunctionDecl *FD)
Only called on function definitions; if there is a pragma in scope with the effect of a range-based o...
StringLiteral * CurInitSeg
Last section used with #pragma init_seg.
Encodes a location in the source.
void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, llvm::StringRef StackSlotLabel, ValueType Value)
const char * getSubjectMatchRuleSpelling(SubjectMatchRule Rule)
void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, StringRef SlotLabel, Expr *Alignment)
ActOnPragmaPack - Called on well formed #pragma pack(...).
bool isValid() const
Return true if this is a valid SourceLocation object.
bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx, SourceLocation *Loc=nullptr, bool isEvaluated=true) const
isIntegerConstantExpr - Return true if this expression is a valid integer constant expression...
SourceLocation PragmaLocation
PragmaStack< MSVtorDispAttr::Mode > VtorDispStack
Whether to insert vtordisps prior to virtual bases in the Microsoft C++ ABI.
SourceLocation OptimizeOffPragmaLocation
This represents the last location of a "#pragma clang optimize off" directive if such a directive has...
void ActOnPragmaClangSection(SourceLocation PragmaLoc, PragmaClangSectionAction Action, PragmaClangSectionKind SecKind, StringRef SecName)
ActOnPragmaClangSection - Called on well formed #pragma clang section.
SourceLocation getBegin() const
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
PragmaMSPointersToMembersKind
SourceLocation ImplicitMSInheritanceAttrLoc
Source location for newly created implicit MSInheritanceAttrs.
void AddAlignmentAttributesForRecord(RecordDecl *RD)
AddAlignmentAttributesForRecord - Adds any needed alignment attributes to a the record decl...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
static PragmaDetectMismatchDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation Loc, StringRef Name, StringRef Value)
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
PragmaClangSection PragmaClangRodataSection
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required...
StringRef getString() const
void AddPragmaAttributes(Scope *S, Decl *D)
Adds the attributes that have been specified using the '#pragma clang attribute push' directives to t...
void DiagnoseUnterminatedPragmaAttribute()
PragmaClangSection PragmaClangDataSection
IdentifierInfo * getName() const
void ActOnPragmaMSPointersToMembers(LangOptions::PragmaMSPointersToMembersKind Kind, SourceLocation PragmaLoc)
ActOnPragmaMSPointersToMembers - called on well formed #pragma pointers_to_members(representation met...
SourceManager & getSourceManager() const
void setAllowFPContractAcrossStatement()
SourceLocation getLoc() const
void addDecl(Decl *D)
Add the declaration D into this context.
PragmaStack< StringLiteral * > ConstSegStack
PragmaClangSection PragmaClangTextSection
void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, SourceLocation Loc)
PushNamespaceVisibilityAttr - Note that we've entered a namespace with a visibility attribute...
void * VisContext
VisContext - Manages the stack for #pragma GCC visibility.
LangOptions::PragmaMSPointersToMembersKind MSPointerToMemberRepresentationMethod
Controls member pointer representation format under the MS ABI.
llvm::DenseMap< int, SourceRange > ParsedSubjectMatchRuleSet
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
StringLiteral - This represents a string literal expression, e.g.
Defines the clang::TargetInfo interface.
bool checkSectionName(SourceLocation LiteralLoc, StringRef Str)
void ActOnPragmaVisibility(const IdentifierInfo *VisType, SourceLocation PragmaLoc)
ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
void ActOnPragmaAttributePush(AttributeList &Attribute, SourceLocation PragmaLoc, attr::ParsedSubjectMatchRuleSet Rules)
Called on well-formed '#pragma clang attribute push'.
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
PragmaStack< unsigned > PackStack
AttributeList * getNext() const
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
NamedDecl - This represents a decl with a name.
void AddMsStructLayoutForRecord(RecordDecl *RD)
AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
SmallVector< Slot, 2 > Stack
SourceLocation getPragmaARCCFCodeAuditedLoc() const
The location of the currently-active #pragma clang arc_cf_code_audited begin.
Attr - This represents one attribute.
This represents the stack of attributes that were pushed by #pragma clang attribute.
void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc)
Called on well formed #pragma clang optimize.
static const unsigned kMac68kAlignmentSentinel
void AddCFAuditedAttribute(Decl *D)
AddCFAuditedAttribute - Check whether we're currently within '#pragma clang arc_cf_code_audited' and...
AttributeList - Represents a syntactic attribute.
IdentifierInfo * getIdentifierInfo() const
SourceLocation CurInitSegLoc