32 : S(S), SlotLabel(SlotLabel), ShouldAct(ShouldAct) {
34 S.VtorDispStack.SentinelAction(
PSK_Push, SlotLabel);
35 S.DataSegStack.SentinelAction(
PSK_Push, SlotLabel);
36 S.BSSSegStack.SentinelAction(
PSK_Push, SlotLabel);
37 S.ConstSegStack.SentinelAction(
PSK_Push, SlotLabel);
38 S.CodeSegStack.SentinelAction(
PSK_Push, SlotLabel);
39 S.StrictGuardStackCheckStack.SentinelAction(
PSK_Push, SlotLabel);
45 S.VtorDispStack.SentinelAction(
PSK_Pop, SlotLabel);
46 S.DataSegStack.SentinelAction(
PSK_Pop, SlotLabel);
47 S.BSSSegStack.SentinelAction(
PSK_Pop, SlotLabel);
48 S.ConstSegStack.SentinelAction(
PSK_Pop, SlotLabel);
49 S.CodeSegStack.SentinelAction(
PSK_Pop, SlotLabel);
50 S.StrictGuardStackCheckStack.SentinelAction(
PSK_Pop, SlotLabel);
67 }
else if (IsPackSet) {
69 RD->
addAttr(MaxFieldAlignmentAttr::CreateImplicit(
82 if (AlignPackedInclude.CurrentPragmaLocation !=
85 if (AlignPackedInclude.HasNonDefaultValue)
86 AlignPackedInclude.ShouldWarnOnInclude =
true;
98 RD->
addAttr(MSVtorDispAttr::CreateImplicit(
102template <
typename Attribute>
105 if (
Record->hasAttr<OwnerAttr>() ||
Record->hasAttr<PointerAttr>())
109 Redecl->addAttr(Attribute::CreateImplicit(Context,
nullptr));
114 if (!UnderlyingRecord)
117 const auto *Parent = dyn_cast<CXXRecordDecl>(ND->
getDeclContext());
121 static const llvm::StringSet<> Containers{
137 "unordered_multiset",
138 "unordered_multimap",
143 static const llvm::StringSet<> Iterators{
"iterator",
"const_iterator",
145 "const_reverse_iterator"};
147 if (Parent->isInStdNamespace() && Iterators.count(ND->
getName()) &&
148 Containers.count(Parent->getName()))
160 dyn_cast<TemplateSpecializationType>(Canonical.
getTypePtr())) {
162 if (
const auto *TD = TST->getTemplateName().getAsTemplateDecl())
163 RD = dyn_cast_or_null<CXXRecordDecl>(TD->getTemplatedDecl());
171 static const llvm::StringSet<> StdOwners{
191 "unordered_multiset",
192 "unordered_multimap",
197 static const llvm::StringSet<> StdPointers{
204 if (!
Record->getIdentifier())
208 if (
Record->isInStdNamespace()) {
209 if (
Record->hasAttr<OwnerAttr>() ||
Record->hasAttr<PointerAttr>())
212 if (StdOwners.count(
Record->getName()))
214 else if (StdPointers.count(
Record->getName()))
230 if (
const auto *E = dyn_cast<CXXNewExpr>(S))
249 case Builtin::BIaddressof:
250 case Builtin::BI__addressof:
251 case Builtin::BI__builtin_addressof:
252 case Builtin::BIas_const:
253 case Builtin::BIforward:
254 case Builtin::BIforward_like:
255 case Builtin::BImove:
256 case Builtin::BImove_if_noexcept:
258 !P->
hasAttr<LifetimeBoundAttr>())
277 for (
unsigned I = 0; I < Ctor->getNumParams(); ++I)
282 if (I < FD->getNumParams() &&
283 Ctor->getParamDecl(I)->hasAttr<LifetimeBoundAttr>() &&
284 Ctor->getParamDecl(I)->getType()->isReferenceType())
290 if (
auto *CMD = dyn_cast<CXXMethodDecl>(FD)) {
291 const auto *CRD = CMD->getParent();
292 if (!CRD->isInStdNamespace() || !CRD->getIdentifier())
296 auto *Param = CMD->getParamDecl(0);
297 if (Param->hasAttr<LifetimeBoundAttr>())
299 if (CRD->getName() ==
"basic_string_view" &&
300 Param->getType()->isPointerType()) {
306 }
else if (CRD->getName() ==
"span") {
310 if (LRT && LRT->getPointeeType().IgnoreParens()->isArrayType())
319 auto *MD = dyn_cast_if_present<CXXMethodDecl>(FD);
320 if (!MD || !MD->getParent()->isInStdNamespace())
325 if (PVD->hasAttr<LifetimeCaptureByAttr>())
332 if (PVD->getType()->isReferenceType() &&
334 int CaptureByThis[] = {LifetimeCaptureByAttr::This};
336 LifetimeCaptureByAttr::CreateImplicit(
Context, CaptureByThis, 1));
341 if (!MD->getIdentifier()) {
342 static const llvm::StringSet<> MapLikeContainer{
346 "unordered_multimap",
351 if (MD->getOverloadedOperator() == OO_Subscript &&
352 MapLikeContainer.contains(MD->getParent()->getName()))
356 static const llvm::StringSet<> CapturingMethods{
357 "insert",
"insert_or_assign",
"push",
"push_front",
"push_back"};
358 if (!CapturingMethods.contains(MD->getName()))
360 if (MD->getName() ==
"insert" && MD->getParent()->getName() ==
"basic_string")
366 static const llvm::StringSet<>
Nullable{
367 "auto_ptr",
"shared_ptr",
"unique_ptr",
"exception_ptr",
368 "coroutine_handle",
"function",
"move_only_function",
372 !CRD->
hasAttr<TypeNullableAttr>())
374 Redecl->addAttr(TypeNullableAttr::CreateImplicit(
Context));
403 if (!this->
Context.getTargetInfo().hasAlignMac68kSupport()) {
404 Diag(PragmaLoc, diag::err_pragma_options_align_mac68k_target_unsupported);
419 Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
458 llvm_unreachable(
"invalid clang section kind");
467 Diag(PragmaLoc, diag::err_pragma_section_invalid_for_target)
482 StringRef SlotLabel,
Expr *Alignment) {
485 if (IsXLPragma && !SlotLabel.empty()) {
486 Diag(PragmaLoc, diag::err_pragma_pack_identifer_not_supported);
493 unsigned AlignmentVal = 0;
497 std::optional<llvm::APSInt> Val;
503 !(*Val == 0 || Val->isPowerOf2()) || Val->getZExtValue() > 16) {
504 Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
508 if (IsXLPragma && *Val == 0) {
510 Diag(PragmaLoc, diag::err_pragma_pack_invalid_alignment);
514 AlignmentVal = (
unsigned)Val->getZExtValue();
524 Diag(PragmaLoc, diag::warn_pragma_pack_show) <<
"mac68k";
526 Diag(PragmaLoc, diag::warn_pragma_pack_show) << AlignmentVal;
532 if (Alignment && !SlotLabel.empty())
533 Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifier_and_alignment);
536 "Empty pack stack can only be at Native alignment mode.");
537 Diag(PragmaLoc, diag::warn_pragma_pop_failed) <<
"pack" <<
"stack empty";
549 for (
unsigned Idx = 0; Idx < Args.size(); Idx++) {
550 Expr *&E = Args.begin()[Idx];
551 assert(E &&
"error are handled before");
559 clang::CK_ArrayToPointerDecay)
564 clang::CK_FunctionToPointerDecay, E,
nullptr,
568 clang::CK_LValueToRValue, E,
nullptr,
580 if (!
Result || !Notes.empty()) {
583 for (
auto &
Note : Notes)
602 bool HasNonDefaultValue =
609 HasNonDefaultValue,
false});
622 Diag(IncludeLoc, diag::warn_pragma_pack_non_default_at_include);
627 Diag(IncludeLoc, diag::warn_pragma_pack_modified_after_include);
635 bool IsInnermost =
true;
640 for (
const auto &StackSlot : llvm::reverse(
AlignPackStack.Stack)) {
641 Diag(StackSlot.PragmaPushLocation, diag::warn_pragma_pack_no_pop_eof);
647 diag::note_pragma_pack_pop_instead_reset);
666 Context,
Context.getTranslationUnitDecl(), CommentLoc, Kind, Arg);
667 Context.getTranslationUnitDecl()->addDecl(PCD);
675 Context.getTranslationUnitDecl()->addDecl(PDMD);
684 llvm_unreachable(
"invalid pragma eval_method kind");
696 Diag(Loc, diag::err_setting_eval_method_used_in_unsafe_context) << 0 << 0;
698 Diag(Loc, diag::err_setting_eval_method_used_in_unsafe_context) << 0 << 1;
700 Diag(Loc, diag::err_setting_eval_method_used_in_unsafe_context) << 0 << 2;
703 PP.setCurrentFPEvalMethod(Loc,
Value);
711 !
CurContext->getRedeclContext()->isFileContext()) {
714 Diag(Loc, diag::err_pragma_fc_pp_scope);
719 llvm_unreachable(
"invalid pragma float_control kind");
726 Diag(Loc, diag::err_pragma_fc_noprecise_requires_noexcept);
728 Diag(Loc, diag::err_pragma_fc_noprecise_requires_nofenv);
735 Diag(Loc, diag::err_pragma_fc_except_requires_precise);
749 Diag(Loc, diag::warn_pragma_pop_failed) <<
"float_control"
771 Diag(PragmaLoc, diag::warn_pragma_pop_failed) <<
"vtordisp"
778 PragmaMsStackAction Action,
779 llvm::StringRef StackSlotLabel,
780 AlignPackInfo
Value) {
782 CurrentValue = DefaultValue;
783 CurrentPragmaLocation = PragmaLocation;
787 Stack.emplace_back(Slot(StackSlotLabel, CurrentValue, CurrentPragmaLocation,
790 if (!StackSlotLabel.empty()) {
792 auto I = llvm::find_if(llvm::reverse(Stack), [&](
const Slot &x) {
793 return x.StackSlotLabel == StackSlotLabel;
796 if (I != Stack.rend()) {
797 CurrentValue = I->Value;
798 CurrentPragmaLocation = I->PragmaLocation;
799 Stack.erase(std::prev(I.base()), Stack.end());
801 }
else if (
Value.IsXLStack() &&
Value.IsAlignAttr() &&
802 CurrentValue.IsPackAttr()) {
805 auto I = llvm::find_if(llvm::reverse(Stack), [&](
const Slot &x) {
806 return x.Value.IsAlignAttr();
809 if (I != Stack.rend()) {
810 Stack.erase(std::prev(I.base()), Stack.end());
812 CurrentValue = DefaultValue;
813 CurrentPragmaLocation = PragmaLocation;
815 CurrentValue = Stack.back().Value;
816 CurrentPragmaLocation = Stack.back().PragmaLocation;
820 }
else if (!Stack.empty()) {
823 if (
Value.IsXLStack() &&
Value.IsPackAttr() && CurrentValue.IsAlignAttr())
827 CurrentValue = Stack.back().Value;
828 CurrentPragmaLocation = Stack.back().PragmaLocation;
833 CurrentValue =
Value;
834 CurrentPragmaLocation = PragmaLocation;
843 PragmaLocation = A->getLocation();
844 auto [SectionIt, Inserted] =
Context.SectionInfos.try_emplace(
845 SectionName,
Decl, PragmaLocation, SectionFlags);
849 const auto &Section = SectionIt->second;
850 if (Section.SectionFlags == SectionFlags ||
856 Diag(Section.
Decl->getLocation(), diag::note_declared_at);
858 Diag(PragmaLocation, diag::note_pragma_entered_here);
859 if (Section.PragmaSectionLocation.isValid())
860 Diag(Section.PragmaSectionLocation, diag::note_pragma_entered_here);
867 auto SectionIt =
Context.SectionInfos.find(SectionName);
868 if (SectionIt !=
Context.SectionInfos.end()) {
869 const auto &Section = SectionIt->second;
870 if (Section.SectionFlags == SectionFlags)
873 Diag(PragmaSectionLocation, diag::err_section_conflict)
874 <<
"this" << Section;
876 Diag(Section.Decl->getLocation(), diag::note_declared_at);
877 if (Section.PragmaSectionLocation.isValid())
878 Diag(Section.PragmaSectionLocation, diag::note_pragma_entered_here);
882 Context.SectionInfos[SectionName] =
890 llvm::StringRef StackSlotLabel,
892 llvm::StringRef PragmaName) {
894 llvm::StringSwitch<PragmaStack<StringLiteral *> *>(PragmaName)
900 Diag(PragmaLocation, diag::warn_pragma_pop_failed) << PragmaName
906 if (SegmentName->
getString() ==
".drectve" &&
907 Context.getTargetInfo().getCXXABI().isMicrosoft())
908 Diag(PragmaLocation, diag::warn_attribute_section_drectve) << PragmaName;
911 Stack->
Act(PragmaLocation, Action, StackSlotLabel, SegmentName);
919 Diag(PragmaLocation, diag::warn_pragma_pop_failed) <<
"strict_gs_check"
942 const SmallVector<std::tuple<IdentifierInfo *, SourceLocation>>
944 if (!
CurContext->getRedeclContext()->isFileContext()) {
945 Diag(PragmaLocation, diag::err_pragma_expected_file_scope) <<
"alloc_text";
957 Diag(Loc, diag::err_undeclared_use) << II->
getName();
963 Diag(Loc, diag::err_pragma_alloc_text_not_function);
968 Diag(Loc, diag::err_pragma_alloc_text_c_linkage);
983 if (Lookup.
empty()) {
984 Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
991 Diag(PragmaLoc, diag::warn_pragma_unused_expected_var_arg)
998 Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name;
1001 UnusedAttr::GNU_unused));
1006std::optional<attr::SubjectMatchRule>
1008 using namespace attr;
1011 return std::nullopt;
1012#define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
1013#define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \
1016#include "clang/Basic/AttrSubMatchRulesList.inc"
1021 using namespace attr;
1025#define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
1026#define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \
1029#include "clang/Basic/AttrSubMatchRulesList.inc"
1033CharSourceRange replacementRangeForListElement(
const Sema &S,
1034 SourceRange Range) {
1046attrMatcherRuleListToString(ArrayRef<attr::SubjectMatchRule> Rules) {
1048 llvm::raw_string_ostream
OS(
Result);
1049 for (
const auto &I : llvm::enumerate(Rules)) {
1051 OS << (I.index() == Rules.size() - 1 ?
", and " :
", ");
1062 Attribute.setIsPragmaClangAttribute();
1066 StrictSubjectMatchRuleSet;
1067 Attribute.getMatchRules(
LangOpts, StrictSubjectMatchRuleSet);
1070 if (StrictSubjectMatchRuleSet.empty()) {
1077 llvm::SmallDenseMap<int, std::pair<int, SourceRange>, 2>
1078 RulesToFirstSpecifiedNegatedSubRule;
1079 for (
const auto &Rule : Rules) {
1081 std::optional<attr::SubjectMatchRule> ParentRule =
1082 getParentAttrMatcherRule(MatchRule);
1085 auto It = Rules.find(*ParentRule);
1086 if (It != Rules.end()) {
1088 Diag(Rule.second.getBegin(),
1089 diag::err_pragma_attribute_matcher_subrule_contradicts_rule)
1093 replacementRangeForListElement(*
this, Rule.second));
1098 if (isNegatedAttrMatcherSubRule(MatchRule))
1099 RulesToFirstSpecifiedNegatedSubRule.insert(
1100 std::make_pair(*ParentRule, Rule));
1102 bool IgnoreNegatedSubRules =
false;
1103 for (
const auto &Rule : Rules) {
1105 std::optional<attr::SubjectMatchRule> ParentRule =
1106 getParentAttrMatcherRule(MatchRule);
1109 auto It = RulesToFirstSpecifiedNegatedSubRule.find(*ParentRule);
1110 if (It != RulesToFirstSpecifiedNegatedSubRule.end() &&
1111 It->second != Rule) {
1114 It->second.second.getBegin(),
1116 err_pragma_attribute_matcher_negated_subrule_contradicts_subrule)
1121 replacementRangeForListElement(*
this, It->second.second));
1123 IgnoreNegatedSubRules =
true;
1124 RulesToFirstSpecifiedNegatedSubRule.erase(It);
1128 if (!IgnoreNegatedSubRules) {
1129 for (
const auto &Rule : Rules)
1132 for (
const auto &Rule : Rules) {
1144 for (
const auto &StrictRule : StrictSubjectMatchRuleSet) {
1146 if (Rules.erase(StrictRule.first)) {
1149 if (StrictRule.second)
1150 SubjectMatchRules.push_back(StrictRule.first);
1154 auto RulesToCheck = Rules;
1155 for (
const auto &Rule : RulesToCheck) {
1157 if (
auto ParentRule = getParentAttrMatcherRule(MatchRule)) {
1158 if (llvm::any_of(StrictSubjectMatchRuleSet,
1159 [ParentRule](
const auto &StrictRule) {
1160 return StrictRule.first == *ParentRule &&
1163 SubjectMatchRules.push_back(MatchRule);
1164 Rules.erase(MatchRule);
1170 if (!Rules.empty()) {
1172 Diag(PragmaLoc, diag::err_pragma_attribute_invalid_matchers)
1175 for (
const auto &Rule : Rules) {
1178 replacementRangeForListElement(*
this, Rule.second));
1180 Diagnostic << attrMatcherRuleListToString(ExtraRules);
1184 Diag(PragmaLoc, diag::err_pragma_attr_attr_no_push);
1189 {PragmaLoc, &Attribute, std::move(SubjectMatchRules),
false});
1202 Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
1215 if (!Entry.IsUsed) {
1216 assert(Entry.Attribute &&
"Expected an attribute");
1217 Diag(Entry.Attribute->getLoc(), diag::warn_pragma_attribute_unused)
1218 << *Entry.Attribute;
1219 Diag(PragmaLoc, diag::note_pragma_attribute_region_ends_here);
1228 Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch)
1229 << 0 << Namespace->getName();
1231 Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
1238 if (
const auto *P = dyn_cast<ParmVarDecl>(D))
1239 if (P->getType()->isVoidType())
1243 for (
auto &Entry : Group.Entries) {
1245 assert(Attribute &&
"Expected an attribute");
1246 assert(Attribute->isPragmaClangAttribute() &&
1247 "expected #pragma clang attribute");
1250 bool Applies =
false;
1251 for (
const auto &Rule : Entry.MatchRules) {
1252 if (Attribute->appliesToDecl(D, Rule)) {
1259 Entry.IsUsed =
true;
1273 PDiag(diag::note_pragma_attribute_applied_decl_here));
1279 "expected a valid source location");
1281 diag::warn_excess_precision_not_supported)
1282 <<
static_cast<bool>(
Num);
1300 if (!
CurContext->getRedeclContext()->isFileContext()) {
1301 Diag(Loc, diag::err_pragma_expected_file_scope) <<
"optimize";
1310 if (!
CurContext->getRedeclContext()->isFileContext()) {
1311 Diag(Loc, diag::err_pragma_expected_file_scope) <<
"function";
1329 StringRef Name = FD->
getName();
1334 std::tie(Section, Loc) = It->second;
1336 if (!FD->
hasAttr<SectionAttr>())
1351 if (FD->
hasAttr<MinSizeAttr>() || FD->
hasAttr<AlwaysInlineAttr>())
1356 if (!FD->
hasAttr<OptimizeNoneAttr>())
1358 if (!FD->
hasAttr<NoInlineAttr>())
1379 if (
auto *FD = dyn_cast<FunctionDecl>(D))
1380 if (FD->isExternC())
1390 if (!
CurContext->getRedeclContext()->isFileContext()) {
1391 Diag(NameLoc, diag::err_pragma_expected_file_scope) <<
"export";
1407 if (!FD->hasExternalFormalLinkage()) {
1408 Diag(NameLoc, diag::warn_pragma_not_applied) <<
"export" << PrevDecl;
1411 if (FD->hasBody()) {
1412 Diag(NameLoc, diag::warn_pragma_not_applied_to_defined_symbol)
1417 if (!VD->hasExternalFormalLinkage()) {
1418 Diag(NameLoc, diag::warn_pragma_not_applied) <<
"export" << PrevDecl;
1422 Diag(NameLoc, diag::warn_pragma_not_applied_to_defined_symbol)
1428 VisibilityAttr::Default);
1431typedef std::vector<std::pair<unsigned, SourceLocation> >
VisStack;
1443 unsigned rawType = Stack->back().first;
1446 VisibilityAttr::VisibilityType
type
1447 = (VisibilityAttr::VisibilityType) rawType;
1464 Stack->push_back(std::make_pair(
type, loc));
1471 VisibilityAttr::VisibilityType T;
1472 if (!VisibilityAttr::ConvertStrToVisibilityType(VisType->
getName(), T)) {
1473 Diag(PragmaLoc, diag::warn_attribute_unknown_visibility) << VisType;
1510 if (
PP.getLastFPEvalPragmaLocation().isValid())
1517 Diag(Loc, diag::err_setting_eval_method_used_in_unsafe_context)
1524 NewFPFeatures.setAllowFPReassociateOverride(IsEnabled);
1527 NewFPFeatures.setAllowReciprocalOverride(IsEnabled);
1530 llvm_unreachable(
"unhandled value changing pragma fp");
1539 NewFPFeatures.setConstRoundingModeOverride(FPR);
1547 NewFPFeatures.setSpecifiedExceptionModeOverride(FPE);
1560 Diag(Loc, diag::err_pragma_fenv_requires_precise);
1562 NewFPFeatures.setAllowFEnvAccessOverride(IsEnabled);
1563 NewFPFeatures.setRoundingMathOverride(IsEnabled);
1571 NewFPFeatures.setComplexRangeOverride(Range);
1592 Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
1599 const std::pair<unsigned, SourceLocation> *Back = &Stack->back();
1601 if (StartsWithPragma && IsNamespaceEnd) {
1602 Diag(Back->second, diag::err_pragma_push_visibility_mismatch);
1603 Diag(EndLoc, diag::note_surrounding_namespace_ends_here);
1608 Back = &Stack->back();
1610 }
while (StartsWithPragma);
1611 }
else if (!StartsWithPragma && !IsNamespaceEnd) {
1612 Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
1613 Diag(Back->second, diag::note_surrounding_namespace_starts_here);
1623template <
typename Ty>
1626 bool SkipArgCountCheck) {
1652 if (!SkipArgCountCheck) {
1672 bool SkipArgCountCheck) {
1673 return ::checkCommonAttributeFeatures(*
this, D, A, SkipArgCountCheck);
1676 bool SkipArgCountCheck) {
1677 return ::checkCommonAttributeFeatures(*
this, S, A, SkipArgCountCheck);
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
llvm::MachO::Record Record
Defines the clang::Preprocessor interface.
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
std::vector< std::pair< unsigned, SourceLocation > > VisStack
static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc)
static void addGslOwnerPointerAttributeIfNotExisting(ASTContext &Context, CXXRecordDecl *Record)
static const CXXNewExpr * findCXXNewExpr(const Stmt *S)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Attr - This represents one attribute.
Represents a call to a C++ constructor.
Represents a C++ constructor within a class.
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Represents a C++ struct/union/class.
static CharSourceRange getCharRange(SourceRange R)
static CharSourceRange getTokenRange(SourceRange R)
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Decl - This represents one declaration (or definition), e.g.
bool isInStdNamespace() const
SourceLocation getLocation() const
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
DeclContext * getDeclContext()
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
The name of a declaration.
bool isIdentifier() const
Predicate functions for querying what type of name this is.
SourceLocation getBeginLoc() const LLVM_READONLY
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine a...
This represents one expression.
bool isValueDependent() const
Determines whether the value of this expression depends on.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
bool EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx, ConstantExprKind Kind=ConstantExprKind::Normal) const
Evaluate an expression that is required to be a constant expression.
Represents difference between two FPOptions values.
void setAllowFPContractAcrossStatement()
void setFPPreciseEnabled(bool Value)
void setAllowFPContractWithinStatement()
FPOptions applyOverrides(FPOptions Base)
void setDisallowFPContract()
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
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.
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
QualType getReturnType() const
bool isDeleted() const
Whether this function has been deleted.
bool isDefaulted() const
Whether this function is defaulted.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
An lvalue reference type, per C++11 [dcl.ref].
FPEvalMethodKind
Possible float expression evaluation method choices.
@ FEM_Extended
Use extended type for fp arithmetic.
@ FEM_Double
Use the type double for fp arithmetic.
@ FEM_UnsetOnCommandLine
Used only for FE option processing; this is only used to indicate that the user did not specify an ex...
@ FEM_Source
Use the declared type for fp arithmetic.
ComplexRangeKind
Controls the various implementations for complex multiplication and.
PragmaMSPointersToMembersKind
FPExceptionModeKind
Possible floating point exception behavior.
@ FPE_Strict
Strictly preserve the floating-point exception semantics.
@ FPE_Ignore
Assume that floating-point exceptions are masked.
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...
Represents the results of name lookup.
DeclClass * getAsSingle() const
bool empty() const
Return true if no decls were found.
This represents a decl that may have a name.
@ VisibilityForValue
Do an LV computation for, ultimately, a non-type declaration.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
std::optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
Represents a parameter to a function.
ParsedAttr - Represents a syntactic attribute.
bool hasCustomParsing() const
unsigned getMinArgs() const
bool checkExactlyNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has exactly as many args as Num.
bool hasVariadicArg() const
bool diagnoseMutualExclusion(class Sema &S, const Decl *D) const
bool diagnoseAppertainsTo(class Sema &S, const Decl *D) const
bool checkAtLeastNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has at least as many args as Num.
unsigned getMaxArgs() const
AttributeCommonInfo::Kind getKind() const
bool diagnoseLangOpts(class Sema &S) const
bool checkAtMostNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has at most as many args as Num.
void addAtEnd(ParsedAttr *newAttr)
static PragmaDetectMismatchDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation Loc, StringRef Name, StringRef Value)
A (possibly-)qualified type.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getCanonicalType() const
Represents a struct/union/class.
Scope - A scope is a transient data structure that is used while parsing the program.
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
unsigned getPackNumber() const
Mode getAlignMode() const
~PragmaStackSentinelRAII()
PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct)
Sema - This implements semantic analysis and AST building for C.
void ActOnPragmaMSOptimize(SourceLocation Loc, bool IsOn)
pragma optimize("[optimization-list]", on | off).
bool ConstantFoldAttrArgs(const AttributeCommonInfo &CI, MutableArrayRef< Expr * > Args)
ConstantFoldAttrArgs - Folds attribute arguments into ConstantExprs (unless they are value dependent ...
void ActOnPragmaExport(IdentifierInfo *IdentId, SourceLocation ExportNameLoc, Scope *curScope)
ActonPragmaExport - called on well-formed '#pragma export'.
void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
void ActOnPragmaAttributePop(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
Called on well-formed '#pragma clang attribute pop'.
void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value)
ActOnPragmaDetectMismatch - Call on well-formed #pragma detect_mismatch.
const Decl * PragmaAttributeCurrentTargetDecl
The declaration that is currently receiving an attribute from the pragma attribute stack.
llvm::function_ref< void(SourceLocation, PartialDiagnostic)> InstantiationContextDiagFuncRef
void ActOnPragmaFEnvRound(SourceLocation Loc, llvm::RoundingMode)
Called to set constant rounding mode for floating point operations.
PragmaClangSection PragmaClangRodataSection
bool checkSectionName(SourceLocation LiteralLoc, StringRef Str)
void AddPragmaAttributes(Scope *S, Decl *D)
Adds the attributes that have been specified using the '#pragma clang attribute push' directives to t...
bool checkCommonAttributeFeatures(const Decl *D, const ParsedAttr &A, bool SkipArgCountCheck=false)
Handles semantic checking for features that are common to all attributes, such as checking whether a ...
void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc)
Adds the 'optnone' attribute to the function declaration if there are no conflicts; Loc represents th...
SourceLocation LocationOfExcessPrecisionNotSatisfied
void inferLifetimeCaptureByAttribute(FunctionDecl *FD)
Add [[clang:lifetime_capture_by(this)]] to STL container methods.
PragmaStack< FPOptionsOverride > FpPragmaStack
PragmaStack< StringLiteral * > CodeSegStack
void AddRangeBasedOptnone(FunctionDecl *FD)
Only called on function definitions; if there is a pragma in scope with the effect of a range-based o...
void ActOnPragmaMSComment(SourceLocation CommentLoc, PragmaMSCommentKind Kind, StringRef Arg)
ActOnPragmaMSComment - Called on well formed #pragma comment(kind, "arg").
SmallVector< AlignPackIncludeState, 8 > AlignPackIncludeStack
void AddAlignmentAttributesForRecord(RecordDecl *RD)
AddAlignmentAttributesForRecord - Adds any needed alignment attributes to a the record decl,...
FPOptionsOverride CurFPFeatureOverrides()
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.
NamedDecl * LookupSingleName(Scope *S, DeclarationName Name, SourceLocation Loc, LookupNameKind NameKind, RedeclarationKind Redecl=RedeclarationKind::NotForRedeclaration)
Look up a name, looking for a single declaration.
void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action, PragmaFloatControlKind Value)
ActOnPragmaFloatControl - Call on well-formed #pragma float_control.
void ActOnPragmaMSPointersToMembers(LangOptions::PragmaMSPointersToMembersKind Kind, SourceLocation PragmaLoc)
ActOnPragmaMSPointersToMembers - called on well formed #pragma pointers_to_members(representation met...
void DiagnosePrecisionLossInComplexDivision()
void ActOnPragmaUnused(const Token &Identifier, Scope *curScope, SourceLocation PragmaLoc)
ActOnPragmaUnused - Called on well-formed '#pragma unused'.
llvm::DenseMap< IdentifierInfo *, PendingPragmaInfo > PendingExportedNames
void ActOnPragmaMSAllocText(SourceLocation PragmaLocation, StringRef Section, const SmallVector< std::tuple< IdentifierInfo *, SourceLocation > > &Functions)
Called on well-formed #pragma alloc_text().
PragmaStack< bool > StrictGuardStackCheckStack
void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, SourceLocation PragmaLoc, attr::ParsedSubjectMatchRuleSet Rules)
PragmaStack< StringLiteral * > ConstSegStack
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_PRValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CheckedConversionKind::Implicit)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, SourceLocation PragmaLoc)
ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
void ActOnPragmaCXLimitedRange(SourceLocation Loc, LangOptions::ComplexRangeKind Range)
ActOnPragmaCXLimitedRange - Called on well formed #pragma STDC CX_LIMITED_RANGE.
void ActOnPragmaFPExceptions(SourceLocation Loc, LangOptions::FPExceptionModeKind)
Called on well formed '#pragma clang fp' that has option 'exceptions'.
void inferGslPointerAttribute(NamedDecl *ND, CXXRecordDecl *UnderlyingRecord)
Add gsl::Pointer attribute to std::container::iterator.
void mergeVisibilityType(Decl *D, SourceLocation Loc, VisibilityAttr::VisibilityType Type)
void ActOnPragmaFPEvalMethod(SourceLocation Loc, LangOptions::FPEvalMethodKind Value)
void ActOnPragmaClangSection(SourceLocation PragmaLoc, PragmaClangSectionAction Action, PragmaClangSectionKind SecKind, StringRef SecName)
ActOnPragmaClangSection - Called on well formed #pragma clang section.
bool UnifySection(StringRef SectionName, int SectionFlags, NamedDecl *TheDecl)
void setExceptionMode(SourceLocation Loc, LangOptions::FPExceptionModeKind)
Called to set exception behavior for floating point operations.
void inferGslOwnerPointerAttribute(CXXRecordDecl *Record)
Add [[gsl::Owner]] and [[gsl::Pointer]] attributes for std:: types.
Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, TranslationUnitKind TUKind=TU_Complete, CodeCompleteConsumer *CompletionConsumer=nullptr)
const LangOptions & getLangOpts() const
SourceLocation CurInitSegLoc
void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, SourceLocation PragmaLoc, MSVtorDispMode Value)
Called on well formed #pragma vtordisp().
void inferLifetimeBoundAttribute(FunctionDecl *FD)
Add [[clang:lifetimebound]] attr for std:: functions and methods.
bool MSPragmaOptimizeIsOn
The "on" or "off" argument passed by #pragma optimize, that denotes whether the optimizations in the ...
SmallVector< PragmaAttributeGroup, 2 > PragmaAttributeStack
const LangOptions & LangOpts
PragmaClangSection PragmaClangRelroSection
SourceLocation ImplicitMSInheritanceAttrLoc
Source location for newly created implicit MSInheritanceAttrs.
void ProcessDeclAttributeList(Scope *S, Decl *D, const ParsedAttributesView &AttrList, const ProcessDeclAttributeOptions &Options=ProcessDeclAttributeOptions())
ProcessDeclAttributeList - Apply all the decl attributes in the specified attribute list to the speci...
void AddImplicitMSFunctionNoBuiltinAttr(FunctionDecl *FD)
Only called on function definitions; if there is a pragma in scope with the effect of a range-based n...
PragmaStack< AlignPackInfo > AlignPackStack
PragmaStack< StringLiteral * > BSSSegStack
llvm::StringMap< std::tuple< StringRef, SourceLocation > > FunctionToSectionMap
Sections used with pragma alloc_text.
llvm::SmallSetVector< StringRef, 4 > MSFunctionNoBuiltins
Set of no-builtin functions listed by #pragma function.
NamedDecl * lookupExternCFunctionOrVariable(IdentifierInfo *IdentId, SourceLocation NameLoc, Scope *curScope)
void AddPushedVisibilityAttribute(Decl *RD)
AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used, add an appropriate visibility at...
StringLiteral * CurInitSeg
Last section used with pragma init_seg.
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
void ActOnPragmaMSFunction(SourceLocation Loc, const llvm::SmallVectorImpl< StringRef > &NoBuiltins)
Call on well formed #pragma function.
void ActOnPragmaMSStruct(PragmaMSStructKind Kind)
ActOnPragmaMSStruct - Called on well formed #pragma ms_struct [on|off].
bool isPreciseFPEnabled()
Are precise floating point semantics currently enabled?
void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, StringLiteral *SegmentName)
Called on well-formed #pragma init_seg().
SourceManager & getSourceManager() const
void PrintPragmaAttributeInstantiationPoint()
void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind, SourceLocation IncludeLoc)
PragmaClangSection PragmaClangTextSection
void ActOnPragmaFPValueChangingOption(SourceLocation Loc, PragmaFPKind Kind, bool IsEnabled)
Called on well formed #pragma clang fp reassociate or #pragma clang fp reciprocal.
std::vector< std::pair< QualType, unsigned > > ExcessPrecisionNotSatisfied
PragmaClangSection PragmaClangDataSection
llvm::Error isValidSectionSpecifier(StringRef Str)
Used to implement to perform semantic checking on attribute((section("foo"))) specifiers.
void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, SourceLocation Loc)
PushNamespaceVisibilityAttr - Note that we've entered a namespace with a visibility attribute.
PragmaStack< MSVtorDispMode > VtorDispStack
Whether to insert vtordisps prior to virtual bases in the Microsoft C++ ABI.
void AddMsStructLayoutForRecord(RecordDecl *RD)
AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
void * VisContext
VisContext - Manages the stack for #pragma GCC visibility.
bool CheckAttrTarget(const ParsedAttr &CurrAttr)
PragmaAlignPackDiagnoseKind
@ NonDefaultStateAtInclude
Scope * TUScope
Translation Unit Scope - useful to Objective-C actions that need to lookup file scope declarations in...
void DiagnoseUnterminatedPragmaAttribute()
void FreeVisContext()
FreeVisContext - Deallocate and null out VisContext.
void ModifyFnAttributesMSPragmaOptimize(FunctionDecl *FD)
Only called on function definitions; if there is a MSVC pragma optimize in scope, consider changing t...
void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc)
PopPragmaVisibility - Pop the top element of the visibility stack; used for '#pragma GCC visibility' ...
SourceManager & SourceMgr
void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, StringRef SlotLabel, Expr *Alignment)
ActOnPragmaPack - Called on well formed #pragma pack(...).
void DiagnoseUnterminatedPragmaAlignPack()
PragmaStack< StringLiteral * > DataSegStack
void ActOnPragmaVisibility(const IdentifierInfo *VisType, SourceLocation PragmaLoc)
ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
SourceLocation OptimizeOffPragmaLocation
This represents the last location of a "#pragma clang optimize off" directive if such a directive has...
LangOptions::PragmaMSPointersToMembersKind MSPointerToMemberRepresentationMethod
Controls member pointer representation format under the MS ABI.
void ActOnPragmaMSStrictGuardStackCheck(SourceLocation PragmaLocation, PragmaMsStackAction Action, bool Value)
ActOnPragmaMSStrictGuardStackCheck - Called on well formed #pragma strict_gs_check.
PragmaClangSection PragmaClangBSSSection
void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC)
ActOnPragmaFPContract - Called on well formed #pragma {STDC,OPENCL} FP_CONTRACT and #pragma clang fp ...
void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc)
Called on well formed #pragma clang optimize.
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false, bool ForceNoCPlusPlus=false)
Perform unqualified name lookup starting from a given scope.
void ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled)
ActOnPragmaFenvAccess - Called on well formed #pragma STDC FENV_ACCESS.
void AddSectionMSAllocText(FunctionDecl *FD)
Only called on function definitions; if there is a #pragma alloc_text that decides which code section...
void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags, StringLiteral *SegmentName)
Called on well formed #pragma section().
void inferNullableClassAttribute(CXXRecordDecl *CRD)
Add _Nullable attributes for std:: types.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
SourceLocation getBeginLoc() const LLVM_READONLY
StringLiteral - This represents a string literal expression, e.g.
SourceLocation getBeginLoc() const LLVM_READONLY
StringRef getString() const
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Token - This structure provides full information about a lexed token.
IdentifierInfo * getIdentifierInfo() const
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
The base class of the type hierarchy.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isFunctionType() const
Base class for declarations which introduce a typedef-name.
QualType getUnderlyingType() const
Represents a variable declaration or definition.
@ Definition
This declaration is definitely a definition.
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Attr > attr
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
SubjectMatchRule
A list of all the recognized kinds of attributes.
const char * getSubjectMatchRuleSpelling(SubjectMatchRule Rule)
llvm::DenseMap< int, SourceRange > ParsedSubjectMatchRuleSet
bool isGslPointerType(QualType QT)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
@ Nullable
Values of this type can be null.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ AANT_ArgumentConstantExpr
@ Result
The result type of a method or function.
MSVtorDispMode
In the Microsoft ABI, this controls the placement of virtual displacement members used to implement v...
PragmaClangSectionKind
pragma clang section kind
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
EvalResult is a struct with detailed info about an evaluated expression.
APValue Val
Val - This is the value the expression can be folded to.
SmallVectorImpl< PartialDiagnosticAt > * Diag
Diag - If this is non-null, it will be filled in with a stack of notes indicating why evaluation fail...
AlignPackInfo CurrentValue
SourceLocation CurrentPragmaLocation
Information from a C++ pragma export, for a symbol that we haven't seen the declaration for yet.
This an attribute introduced by #pragma clang attribute.
SourceLocation PragmaLocation
SmallVector< Slot, 2 > Stack
void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, llvm::StringRef StackSlotLabel, ValueType Value)