22 using namespace clang;
31 : S(S), SlotLabel(SlotLabel), ShouldAct(ShouldAct) {
72 if (PackedInclude.HasNonDefaultValue)
73 PackedInclude.ShouldWarnOnInclude =
true;
92 unsigned Alignment = 0;
114 Diag(PragmaLoc, diag::err_pragma_options_align_mac68k_target_unsupported);
129 Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
137 PackStack.
Act(PragmaLoc, Action, StringRef(), Alignment);
144 case PragmaClangSectionKind::PCSK_BSS:
147 case PragmaClangSectionKind::PCSK_Data:
150 case PragmaClangSectionKind::PCSK_Rodata:
153 case PragmaClangSectionKind::PCSK_Text:
157 llvm_unreachable(
"invalid clang section kind");
160 if (Action == PragmaClangSectionAction::PCSA_Clear) {
171 StringRef SlotLabel,
Expr *alignment) {
172 Expr *Alignment =
static_cast<Expr *
>(alignment);
175 unsigned AlignmentVal = 0;
184 !(Val == 0 || Val.isPowerOf2()) ||
185 Val.getZExtValue() > 16) {
186 Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
190 AlignmentVal = (unsigned) Val.getZExtValue();
197 if (AlignmentVal == 0)
200 Diag(PragmaLoc, diag::warn_pragma_pack_show) <<
"mac68k";
202 Diag(PragmaLoc, diag::warn_pragma_pack_show) << AlignmentVal;
207 if (Alignment && !SlotLabel.empty())
208 Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifier_and_alignment);
210 Diag(PragmaLoc, diag::warn_pragma_pop_failed) <<
"pack" <<
"stack empty";
213 PackStack.
Act(PragmaLoc, Action, SlotLabel, AlignmentVal);
225 bool HasNonDefaultValue =
232 HasNonDefaultValue,
false});
240 Diag(IncludeLoc, diag::warn_pragma_pack_non_default_at_include);
245 Diag(IncludeLoc, diag::warn_pragma_pack_modified_after_include);
253 bool IsInnermost =
true;
255 Diag(StackSlot.PragmaPushLocation, diag::warn_pragma_pack_no_pop_eof);
260 diag::note_pragma_pack_pop_instead_reset);
300 MSVtorDispAttr::Mode Mode) {
302 Diag(PragmaLoc, diag::warn_pragma_pop_failed) <<
"vtordisp" 307 template<
typename ValueType>
310 llvm::StringRef StackSlotLabel,
313 CurrentValue = DefaultValue;
314 CurrentPragmaLocation = PragmaLocation;
318 Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation,
321 if (!StackSlotLabel.empty()) {
323 auto I = llvm::find_if(llvm::reverse(Stack), [&](
const Slot &x) {
324 return x.StackSlotLabel == StackSlotLabel;
327 if (I != Stack.rend()) {
328 CurrentValue = I->Value;
329 CurrentPragmaLocation = I->PragmaLocation;
330 Stack.erase(std::prev(I.base()), Stack.end());
332 }
else if (!Stack.empty()) {
334 CurrentValue = Stack.back().Value;
335 CurrentPragmaLocation = Stack.back().PragmaLocation;
340 CurrentValue =
Value;
341 CurrentPragmaLocation = PragmaLocation;
355 if (Section->second.SectionFlags == SectionFlags ||
358 auto OtherDecl = Section->second.Decl;
360 << Decl << OtherDecl;
361 Diag(OtherDecl->getLocation(), diag::note_declared_at)
362 << OtherDecl->getName();
363 if (
auto A = Decl->
getAttr<SectionAttr>())
365 Diag(A->getLocation(), diag::note_pragma_entered_here);
366 if (
auto A = OtherDecl->getAttr<SectionAttr>())
368 Diag(A->getLocation(), diag::note_pragma_entered_here);
377 if (Section->second.SectionFlags == SectionFlags)
380 Diag(PragmaSectionLocation, diag::err_section_conflict)
381 <<
"this" <<
"a prior #pragma section";
382 Diag(Section->second.PragmaSectionLocation,
383 diag::note_pragma_entered_here);
395 llvm::StringRef StackSlotLabel,
397 llvm::StringRef PragmaName) {
399 llvm::StringSwitch<PragmaStack<StringLiteral *> *>(PragmaName)
405 Diag(PragmaLocation, diag::warn_pragma_pop_failed) << PragmaName
410 Stack->
Act(PragmaLocation, Action, StackSlotLabel, SegmentName);
435 if (Lookup.empty()) {
436 Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
443 Diag(PragmaLoc, diag::warn_pragma_unused_expected_var_arg)
450 Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name;
452 VD->
addAttr(UnusedAttr::CreateImplicit(
Context, UnusedAttr::GNU_unused,
461 if (D->
hasAttr<CFAuditedTransferAttr>() ||
462 D->
hasAttr<CFUnknownTransferAttr>())
472 using namespace attr;
476 #define ATTR_MATCH_RULE(Value, Spelling, IsAbstract) 477 #define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \ 480 #include "clang/Basic/AttrSubMatchRulesList.inc" 485 using namespace attr;
489 #define ATTR_MATCH_RULE(Value, Spelling, IsAbstract) 490 #define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \ 493 #include "clang/Basic/AttrSubMatchRulesList.inc" 512 llvm::raw_string_ostream OS(Result);
513 for (
const auto &I : llvm::enumerate(Rules)) {
515 OS << (I.index() == Rules.size() - 1 ?
", and " :
", ");
529 StrictSubjectMatchRuleSet;
533 if (StrictSubjectMatchRuleSet.empty()) {
540 llvm::SmallDenseMap<int, std::pair<int, SourceRange>, 2>
541 RulesToFirstSpecifiedNegatedSubRule;
542 for (
const auto &Rule : Rules) {
545 getParentAttrMatcherRule(MatchRule);
548 auto It = Rules.find(*ParentRule);
549 if (It != Rules.end()) {
551 Diag(Rule.second.getBegin(),
552 diag::err_pragma_attribute_matcher_subrule_contradicts_rule)
556 replacementRangeForListElement(*
this, Rule.second));
561 if (isNegatedAttrMatcherSubRule(MatchRule))
562 RulesToFirstSpecifiedNegatedSubRule.insert(
563 std::make_pair(*ParentRule, Rule));
565 bool IgnoreNegatedSubRules =
false;
566 for (
const auto &Rule : Rules) {
569 getParentAttrMatcherRule(MatchRule);
572 auto It = RulesToFirstSpecifiedNegatedSubRule.find(*ParentRule);
573 if (It != RulesToFirstSpecifiedNegatedSubRule.end() &&
574 It->second != Rule) {
577 It->second.second.getBegin(),
579 err_pragma_attribute_matcher_negated_subrule_contradicts_subrule)
584 replacementRangeForListElement(*
this, It->second.second));
586 IgnoreNegatedSubRules =
true;
587 RulesToFirstSpecifiedNegatedSubRule.erase(It);
591 if (!IgnoreNegatedSubRules) {
592 for (
const auto &Rule : Rules)
595 for (
const auto &Rule : Rules) {
602 for (
const auto &Rule : StrictSubjectMatchRuleSet) {
603 if (Rules.erase(Rule.first)) {
607 SubjectMatchRules.push_back(Rule.first);
612 if (!Rules.empty()) {
614 Diag(PragmaLoc, diag::err_pragma_attribute_invalid_matchers)
617 for (
const auto &Rule : Rules) {
620 replacementRangeForListElement(*
this, Rule.second));
622 Diagnostic << attrMatcherRuleListToString(ExtraRules);
626 {PragmaLoc, &Attribute, std::move(SubjectMatchRules),
false});
631 Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch);
636 assert(Entry.
Attribute &&
"Expected an attribute");
639 Diag(PragmaLoc, diag::note_pragma_attribute_region_ends_here);
649 assert(Attribute &&
"Expected an attribute");
652 bool Applies =
false;
653 for (
const auto &Rule : Entry.MatchRules) {
673 diag::note_pragma_attribute_applied_decl_here);
699 if (FD->
hasAttr<MinSizeAttr>() || FD->
hasAttr<AlwaysInlineAttr>())
704 if (!FD->
hasAttr<OptimizeNoneAttr>())
706 if (!FD->
hasAttr<NoInlineAttr>())
710 typedef std::vector<std::pair<unsigned, SourceLocation> >
VisStack;
722 unsigned rawType = Stack->back().first;
725 VisibilityAttr::VisibilityType
type 726 = (VisibilityAttr::VisibilityType) rawType;
744 Stack->push_back(std::make_pair(type, loc));
751 VisibilityAttr::VisibilityType T;
752 if (!VisibilityAttr::ConvertStrToVisibilityType(VisType->
getName(), T)) {
753 Diag(PragmaLoc, diag::warn_attribute_unknown_visibility) << VisType;
787 Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
794 const std::pair<unsigned, SourceLocation> *Back = &Stack->back();
796 if (StartsWithPragma && IsNamespaceEnd) {
797 Diag(Back->second, diag::err_pragma_push_visibility_mismatch);
798 Diag(EndLoc, diag::note_surrounding_namespace_ends_here);
803 Back = &Stack->back();
805 }
while (StartsWithPragma);
806 }
else if (!StartsWithPragma && !IsNamespaceEnd) {
807 Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
808 Diag(Back->second, diag::note_surrounding_namespace_starts_here);
PragmaStack< StringLiteral * > CodeSegStack
Represents 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)
SmallVector< PackIncludeState, 8 > PackIncludeStack
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.
static CharSourceRange getTokenRange(SourceRange R)
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Decl - This represents one declaration (or definition), e.g.
SourceLocation getPragmaARCCFCodeAuditedLoc() const
The location of the currently-active #pragma clang arc_cf_code_audited begin.
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.
const TargetInfo & getTargetInfo() const
SourceLocation getLocStart() const LLVM_READONLY
Represents a variable declaration or definition.
DiagnosticsEngine & Diags
PragmaClangSection PragmaClangBSSSection
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.
void getMatchRules(const LangOptions &LangOpts, SmallVectorImpl< std::pair< attr::SubjectMatchRule, bool >> &MatchRules) const
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.
void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, SourceLocation PragmaLoc)
ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
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.
const LangOptions & getLangOpts() 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.
void DiagnoseNonDefaultPragmaPack(PragmaPackDiagnoseKind Kind, SourceLocation IncludeLoc)
const LangOptions & LangOpts
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.
StringRef getString() const
A little helper class used to produce diagnostics.
Represents a ValueDecl that came out of a declarator.
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.
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().
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Defines the clang::Preprocessor interface.
PragmaStack< StringLiteral * > BSSSegStack
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").
void ActOnPragmaAttributePush(ParsedAttr &Attribute, SourceLocation PragmaLoc, attr::ParsedSubjectMatchRuleSet Rules)
Called on well-formed '#pragma clang attribute push'.
SourceLocation getEnd() const
~PragmaStackSentinelRAII()
bool hasAlignMac68kSupport() const
Check whether this target support '#pragma options align=mac68k'.
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.
void DiagnoseUnterminatedPragmaPack()
PragmaClangSectionKind
pragma clang section kind
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.
void addAtStart(ParsedAttr *newAttr)
Encodes a location in the source.
void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, llvm::StringRef StackSlotLabel, ValueType Value)
SourceLocation CurrentPragmaLocation
const char * getSubjectMatchRuleSpelling(SubjectMatchRule Rule)
void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, StringRef SlotLabel, Expr *Alignment)
ActOnPragmaPack - Called on well formed #pragma pack(...).
void ProcessDeclAttributeList(Scope *S, Decl *D, const ParsedAttributesView &AL, bool IncludeCXX11Attributes=true)
ProcessDeclAttributeList - Apply all the decl attributes in the specified attribute list to the speci...
IdentifierInfo * getIdentifierInfo() const
ParsedAttr - Represents a syntactic attribute.
SourceLocation PragmaLocation
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
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.
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required...
PragmaMSPointersToMembersKind
StringRef getName() const
Return the actual identifier string.
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
SourceLocation ImplicitMSInheritanceAttrLoc
Source location for newly created implicit MSInheritanceAttrs.
void AddAlignmentAttributesForRecord(RecordDecl *RD)
AddAlignmentAttributesForRecord - Adds any needed alignment attributes to a the record decl...
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.
Do an LV computation for, ultimately, a non-type declaration.
SourceLocation getLoc() const
PragmaClangSection PragmaClangRodataSection
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...
IdentifierInfo * getName() 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
void ActOnPragmaMSPointersToMembers(LangOptions::PragmaMSPointersToMembersKind Kind, SourceLocation PragmaLoc)
ActOnPragmaMSPointersToMembers - called on well formed #pragma pointers_to_members(representation met...
void setAllowFPContractAcrossStatement()
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
void addDecl(Decl *D)
Add the declaration D into this context.
PragmaStack< StringLiteral * > ConstSegStack
PragmaClangSection PragmaClangTextSection
Optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, SourceLocation Loc)
PushNamespaceVisibilityAttr - Note that we've entered a namespace with a visibility attribute...
TranslationUnitDecl * getTranslationUnitDecl() const
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
bool appliesToDecl(const Decl *D, attr::SubjectMatchRule MatchRule) const
SourceManager & getSourceManager() const
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... .
SourceManager & SourceMgr
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
PragmaStack< unsigned > PackStack
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
SourceLocation CurrentPragmaLocation
void AddMsStructLayoutForRecord(RecordDecl *RD)
AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
SourceLocation getBegin() const
SmallVector< Slot, 2 > Stack
Attr - This represents one attribute.
SourceLocation getLocation() const
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...
SourceLocation CurInitSegLoc