clang  10.0.0svn
SemaAttr.cpp
Go to the documentation of this file.
1 //===--- SemaAttr.cpp - Semantic Analysis for Attributes ------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements semantic analysis for non-trivial attributes and
10 // pragmas.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/ASTConsumer.h"
15 #include "clang/AST/Attr.h"
16 #include "clang/AST/Expr.h"
17 #include "clang/Basic/TargetInfo.h"
18 #include "clang/Lex/Preprocessor.h"
19 #include "clang/Sema/Lookup.h"
21 using namespace clang;
22 
23 //===----------------------------------------------------------------------===//
24 // Pragma 'pack' and 'options align'
25 //===----------------------------------------------------------------------===//
26 
28  StringRef SlotLabel,
29  bool ShouldAct)
30  : S(S), SlotLabel(SlotLabel), ShouldAct(ShouldAct) {
31  if (ShouldAct) {
33  S.DataSegStack.SentinelAction(PSK_Push, SlotLabel);
34  S.BSSSegStack.SentinelAction(PSK_Push, SlotLabel);
35  S.ConstSegStack.SentinelAction(PSK_Push, SlotLabel);
36  S.CodeSegStack.SentinelAction(PSK_Push, SlotLabel);
37  }
38 }
39 
41  if (ShouldAct) {
42  S.VtorDispStack.SentinelAction(PSK_Pop, SlotLabel);
43  S.DataSegStack.SentinelAction(PSK_Pop, SlotLabel);
44  S.BSSSegStack.SentinelAction(PSK_Pop, SlotLabel);
45  S.ConstSegStack.SentinelAction(PSK_Pop, SlotLabel);
46  S.CodeSegStack.SentinelAction(PSK_Pop, SlotLabel);
47  }
48 }
49 
51  // If there is no pack value, we don't need any attributes.
53  return;
54 
55  // Otherwise, check to see if we need a max field alignment attribute.
56  if (unsigned Alignment = PackStack.CurrentValue) {
57  if (Alignment == Sema::kMac68kAlignmentSentinel)
58  RD->addAttr(AlignMac68kAttr::CreateImplicit(Context));
59  else
60  RD->addAttr(MaxFieldAlignmentAttr::CreateImplicit(Context,
61  Alignment * 8));
62  }
63  if (PackIncludeStack.empty())
64  return;
65  // The #pragma pack affected a record in an included file, so Clang should
66  // warn when that pragma was written in a file that included the included
67  // file.
68  for (auto &PackedInclude : llvm::reverse(PackIncludeStack)) {
69  if (PackedInclude.CurrentPragmaLocation != PackStack.CurrentPragmaLocation)
70  break;
71  if (PackedInclude.HasNonDefaultValue)
72  PackedInclude.ShouldWarnOnInclude = true;
73  }
74 }
75 
77  if (MSStructPragmaOn)
78  RD->addAttr(MSStructAttr::CreateImplicit(Context));
79 
80  // FIXME: We should merge AddAlignmentAttributesForRecord with
81  // AddMsStructLayoutForRecord into AddPragmaAttributesForRecord, which takes
82  // all active pragmas and applies them as attributes to class definitions.
83  if (VtorDispStack.CurrentValue != getLangOpts().VtorDispMode)
84  RD->addAttr(
85  MSVtorDispAttr::CreateImplicit(Context, VtorDispStack.CurrentValue));
86 }
87 
88 template <typename Attribute>
90  CXXRecordDecl *Record) {
91  if (Record->hasAttr<OwnerAttr>() || Record->hasAttr<PointerAttr>())
92  return;
93 
94  for (Decl *Redecl : Record->redecls())
95  Redecl->addAttr(Attribute::CreateImplicit(Context, /*DerefType=*/nullptr));
96 }
97 
99  CXXRecordDecl *UnderlyingRecord) {
100  if (!UnderlyingRecord)
101  return;
102 
103  const auto *Parent = dyn_cast<CXXRecordDecl>(ND->getDeclContext());
104  if (!Parent)
105  return;
106 
107  static llvm::StringSet<> Containers{
108  "array",
109  "basic_string",
110  "deque",
111  "forward_list",
112  "vector",
113  "list",
114  "map",
115  "multiset",
116  "multimap",
117  "priority_queue",
118  "queue",
119  "set",
120  "stack",
121  "unordered_set",
122  "unordered_map",
123  "unordered_multiset",
124  "unordered_multimap",
125  };
126 
127  static llvm::StringSet<> Iterators{"iterator", "const_iterator",
128  "reverse_iterator",
129  "const_reverse_iterator"};
130 
131  if (Parent->isInStdNamespace() && Iterators.count(ND->getName()) &&
132  Containers.count(Parent->getName()))
133  addGslOwnerPointerAttributeIfNotExisting<PointerAttr>(Context,
134  UnderlyingRecord);
135 }
136 
138 
139  QualType Canonical = TD->getUnderlyingType().getCanonicalType();
140 
141  CXXRecordDecl *RD = Canonical->getAsCXXRecordDecl();
142  if (!RD) {
143  if (auto *TST =
144  dyn_cast<TemplateSpecializationType>(Canonical.getTypePtr())) {
145 
146  RD = dyn_cast_or_null<CXXRecordDecl>(
147  TST->getTemplateName().getAsTemplateDecl()->getTemplatedDecl());
148  }
149  }
150 
151  inferGslPointerAttribute(TD, RD);
152 }
153 
155  static llvm::StringSet<> StdOwners{
156  "any",
157  "array",
158  "basic_regex",
159  "basic_string",
160  "deque",
161  "forward_list",
162  "vector",
163  "list",
164  "map",
165  "multiset",
166  "multimap",
167  "optional",
168  "priority_queue",
169  "queue",
170  "set",
171  "stack",
172  "unique_ptr",
173  "unordered_set",
174  "unordered_map",
175  "unordered_multiset",
176  "unordered_multimap",
177  "variant",
178  };
179  static llvm::StringSet<> StdPointers{
180  "basic_string_view",
181  "reference_wrapper",
182  "regex_iterator",
183  };
184 
185  if (!Record->getIdentifier())
186  return;
187 
188  // Handle classes that directly appear in std namespace.
189  if (Record->isInStdNamespace()) {
190  if (Record->hasAttr<OwnerAttr>() || Record->hasAttr<PointerAttr>())
191  return;
192 
193  if (StdOwners.count(Record->getName()))
194  addGslOwnerPointerAttributeIfNotExisting<OwnerAttr>(Context, Record);
195  else if (StdPointers.count(Record->getName()))
196  addGslOwnerPointerAttributeIfNotExisting<PointerAttr>(Context, Record);
197 
198  return;
199  }
200 
201  // Handle nested classes that could be a gsl::Pointer.
202  inferGslPointerAttribute(Record, Record);
203 }
204 
206  SourceLocation PragmaLoc) {
208  unsigned Alignment = 0;
209  switch (Kind) {
210  // For all targets we support native and natural are the same.
211  //
212  // FIXME: This is not true on Darwin/PPC.
213  case POAK_Native:
214  case POAK_Power:
215  case POAK_Natural:
216  Action = Sema::PSK_Push_Set;
217  Alignment = 0;
218  break;
219 
220  // Note that '#pragma options align=packed' is not equivalent to attribute
221  // packed, it has a different precedence relative to attribute aligned.
222  case POAK_Packed:
223  Action = Sema::PSK_Push_Set;
224  Alignment = 1;
225  break;
226 
227  case POAK_Mac68k:
228  // Check if the target supports this.
230  Diag(PragmaLoc, diag::err_pragma_options_align_mac68k_target_unsupported);
231  return;
232  }
233  Action = Sema::PSK_Push_Set;
234  Alignment = Sema::kMac68kAlignmentSentinel;
235  break;
236 
237  case POAK_Reset:
238  // Reset just pops the top of the stack, or resets the current alignment to
239  // default.
240  Action = Sema::PSK_Pop;
241  if (PackStack.Stack.empty()) {
242  if (PackStack.CurrentValue) {
243  Action = Sema::PSK_Reset;
244  } else {
245  Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
246  << "stack empty";
247  return;
248  }
249  }
250  break;
251  }
252 
253  PackStack.Act(PragmaLoc, Action, StringRef(), Alignment);
254 }
255 
257  PragmaClangSectionKind SecKind, StringRef SecName) {
258  PragmaClangSection *CSec;
259  switch (SecKind) {
260  case PragmaClangSectionKind::PCSK_BSS:
261  CSec = &PragmaClangBSSSection;
262  break;
263  case PragmaClangSectionKind::PCSK_Data:
264  CSec = &PragmaClangDataSection;
265  break;
266  case PragmaClangSectionKind::PCSK_Rodata:
267  CSec = &PragmaClangRodataSection;
268  break;
269  case PragmaClangSectionKind::PCSK_Relro:
270  CSec = &PragmaClangRelroSection;
271  break;
272  case PragmaClangSectionKind::PCSK_Text:
273  CSec = &PragmaClangTextSection;
274  break;
275  default:
276  llvm_unreachable("invalid clang section kind");
277  }
278 
279  if (Action == PragmaClangSectionAction::PCSA_Clear) {
280  CSec->Valid = false;
281  return;
282  }
283 
284  CSec->Valid = true;
285  CSec->SectionName = SecName;
286  CSec->PragmaLocation = PragmaLoc;
287 }
288 
290  StringRef SlotLabel, Expr *alignment) {
291  Expr *Alignment = static_cast<Expr *>(alignment);
292 
293  // If specified then alignment must be a "small" power of two.
294  unsigned AlignmentVal = 0;
295  if (Alignment) {
296  llvm::APSInt Val;
297 
298  // pack(0) is like pack(), which just works out since that is what
299  // we use 0 for in PackAttr.
300  if (Alignment->isTypeDependent() ||
301  Alignment->isValueDependent() ||
302  !Alignment->isIntegerConstantExpr(Val, Context) ||
303  !(Val == 0 || Val.isPowerOf2()) ||
304  Val.getZExtValue() > 16) {
305  Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
306  return; // Ignore
307  }
308 
309  AlignmentVal = (unsigned) Val.getZExtValue();
310  }
311  if (Action == Sema::PSK_Show) {
312  // Show the current alignment, making sure to show the right value
313  // for the default.
314  // FIXME: This should come from the target.
315  AlignmentVal = PackStack.CurrentValue;
316  if (AlignmentVal == 0)
317  AlignmentVal = 8;
318  if (AlignmentVal == Sema::kMac68kAlignmentSentinel)
319  Diag(PragmaLoc, diag::warn_pragma_pack_show) << "mac68k";
320  else
321  Diag(PragmaLoc, diag::warn_pragma_pack_show) << AlignmentVal;
322  }
323  // MSDN, C/C++ Preprocessor Reference > Pragma Directives > pack:
324  // "#pragma pack(pop, identifier, n) is undefined"
325  if (Action & Sema::PSK_Pop) {
326  if (Alignment && !SlotLabel.empty())
327  Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifier_and_alignment);
328  if (PackStack.Stack.empty())
329  Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "pack" << "stack empty";
330  }
331 
332  PackStack.Act(PragmaLoc, Action, SlotLabel, AlignmentVal);
333 }
334 
336  SourceLocation IncludeLoc) {
339  // Warn about non-default alignment at #includes (without redundant
340  // warnings for the same directive in nested includes).
341  // The warning is delayed until the end of the file to avoid warnings
342  // for files that don't have any records that are affected by the modified
343  // alignment.
344  bool HasNonDefaultValue =
345  PackStack.hasValue() &&
346  (PackIncludeStack.empty() ||
347  PackIncludeStack.back().CurrentPragmaLocation != PrevLocation);
348  PackIncludeStack.push_back(
350  PackStack.hasValue() ? PrevLocation : SourceLocation(),
351  HasNonDefaultValue, /*ShouldWarnOnInclude*/ false});
352  return;
353  }
354 
355  assert(Kind == PragmaPackDiagnoseKind::ChangedStateAtExit && "invalid kind");
356  PackIncludeState PrevPackState = PackIncludeStack.pop_back_val();
357  if (PrevPackState.ShouldWarnOnInclude) {
358  // Emit the delayed non-default alignment at #include warning.
359  Diag(IncludeLoc, diag::warn_pragma_pack_non_default_at_include);
360  Diag(PrevPackState.CurrentPragmaLocation, diag::note_pragma_pack_here);
361  }
362  // Warn about modified alignment after #includes.
363  if (PrevPackState.CurrentValue != PackStack.CurrentValue) {
364  Diag(IncludeLoc, diag::warn_pragma_pack_modified_after_include);
365  Diag(PackStack.CurrentPragmaLocation, diag::note_pragma_pack_here);
366  }
367 }
368 
370  if (PackStack.Stack.empty())
371  return;
372  bool IsInnermost = true;
373  for (const auto &StackSlot : llvm::reverse(PackStack.Stack)) {
374  Diag(StackSlot.PragmaPushLocation, diag::warn_pragma_pack_no_pop_eof);
375  // The user might have already reset the alignment, so suggest replacing
376  // the reset with a pop.
377  if (IsInnermost && PackStack.CurrentValue == PackStack.DefaultValue) {
379  diag::note_pragma_pack_pop_instead_reset);
382  /*SkipTrailing=*/false);
383  if (FixItLoc.isValid())
384  DB << FixItHint::CreateInsertion(FixItLoc, "pop");
385  }
386  IsInnermost = false;
387  }
388 }
389 
391  MSStructPragmaOn = (Kind == PMSST_ON);
392 }
393 
395  PragmaMSCommentKind Kind, StringRef Arg) {
396  auto *PCD = PragmaCommentDecl::Create(
397  Context, Context.getTranslationUnitDecl(), CommentLoc, Kind, Arg);
400 }
401 
403  StringRef Value) {
408 }
409 
411  LangOptions::PragmaMSPointersToMembersKind RepresentationMethod,
412  SourceLocation PragmaLoc) {
413  MSPointerToMemberRepresentationMethod = RepresentationMethod;
414  ImplicitMSInheritanceAttrLoc = PragmaLoc;
415 }
416 
418  SourceLocation PragmaLoc,
419  MSVtorDispAttr::Mode Mode) {
420  if (Action & PSK_Pop && VtorDispStack.Stack.empty())
421  Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "vtordisp"
422  << "stack empty";
423  VtorDispStack.Act(PragmaLoc, Action, StringRef(), Mode);
424 }
425 
426 template<typename ValueType>
428  PragmaMsStackAction Action,
429  llvm::StringRef StackSlotLabel,
430  ValueType Value) {
431  if (Action == PSK_Reset) {
432  CurrentValue = DefaultValue;
433  CurrentPragmaLocation = PragmaLocation;
434  return;
435  }
436  if (Action & PSK_Push)
437  Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation,
438  PragmaLocation);
439  else if (Action & PSK_Pop) {
440  if (!StackSlotLabel.empty()) {
441  // If we've got a label, try to find it and jump there.
442  auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
443  return x.StackSlotLabel == StackSlotLabel;
444  });
445  // If we found the label so pop from there.
446  if (I != Stack.rend()) {
447  CurrentValue = I->Value;
448  CurrentPragmaLocation = I->PragmaLocation;
449  Stack.erase(std::prev(I.base()), Stack.end());
450  }
451  } else if (!Stack.empty()) {
452  // We do not have a label, just pop the last entry.
453  CurrentValue = Stack.back().Value;
454  CurrentPragmaLocation = Stack.back().PragmaLocation;
455  Stack.pop_back();
456  }
457  }
458  if (Action & PSK_Set) {
459  CurrentValue = Value;
460  CurrentPragmaLocation = PragmaLocation;
461  }
462 }
463 
464 bool Sema::UnifySection(StringRef SectionName,
465  int SectionFlags,
466  DeclaratorDecl *Decl) {
467  auto Section = Context.SectionInfos.find(SectionName);
468  if (Section == Context.SectionInfos.end()) {
469  Context.SectionInfos[SectionName] =
470  ASTContext::SectionInfo(Decl, SourceLocation(), SectionFlags);
471  return false;
472  }
473  // A pre-declared section takes precedence w/o diagnostic.
474  if (Section->second.SectionFlags == SectionFlags ||
475  !(Section->second.SectionFlags & ASTContext::PSF_Implicit))
476  return false;
477  auto OtherDecl = Section->second.Decl;
478  Diag(Decl->getLocation(), diag::err_section_conflict)
479  << Decl << OtherDecl;
480  Diag(OtherDecl->getLocation(), diag::note_declared_at)
481  << OtherDecl->getName();
482  if (auto A = Decl->getAttr<SectionAttr>())
483  if (A->isImplicit())
484  Diag(A->getLocation(), diag::note_pragma_entered_here);
485  if (auto A = OtherDecl->getAttr<SectionAttr>())
486  if (A->isImplicit())
487  Diag(A->getLocation(), diag::note_pragma_entered_here);
488  return true;
489 }
490 
491 bool Sema::UnifySection(StringRef SectionName,
492  int SectionFlags,
493  SourceLocation PragmaSectionLocation) {
494  auto Section = Context.SectionInfos.find(SectionName);
495  if (Section != Context.SectionInfos.end()) {
496  if (Section->second.SectionFlags == SectionFlags)
497  return false;
498  if (!(Section->second.SectionFlags & ASTContext::PSF_Implicit)) {
499  Diag(PragmaSectionLocation, diag::err_section_conflict)
500  << "this" << "a prior #pragma section";
501  Diag(Section->second.PragmaSectionLocation,
502  diag::note_pragma_entered_here);
503  return true;
504  }
505  }
506  Context.SectionInfos[SectionName] =
507  ASTContext::SectionInfo(nullptr, PragmaSectionLocation, SectionFlags);
508  return false;
509 }
510 
511 /// Called on well formed \#pragma bss_seg().
513  PragmaMsStackAction Action,
514  llvm::StringRef StackSlotLabel,
515  StringLiteral *SegmentName,
516  llvm::StringRef PragmaName) {
518  llvm::StringSwitch<PragmaStack<StringLiteral *> *>(PragmaName)
519  .Case("data_seg", &DataSegStack)
520  .Case("bss_seg", &BSSSegStack)
521  .Case("const_seg", &ConstSegStack)
522  .Case("code_seg", &CodeSegStack);
523  if (Action & PSK_Pop && Stack->Stack.empty())
524  Diag(PragmaLocation, diag::warn_pragma_pop_failed) << PragmaName
525  << "stack empty";
526  if (SegmentName) {
527  if (!checkSectionName(SegmentName->getBeginLoc(), SegmentName->getString()))
528  return;
529 
530  if (SegmentName->getString() == ".drectve" &&
532  Diag(PragmaLocation, diag::warn_attribute_section_drectve) << PragmaName;
533  }
534 
535  Stack->Act(PragmaLocation, Action, StackSlotLabel, SegmentName);
536 }
537 
538 /// Called on well formed \#pragma bss_seg().
540  int SectionFlags, StringLiteral *SegmentName) {
541  UnifySection(SegmentName->getString(), SectionFlags, PragmaLocation);
542 }
543 
545  StringLiteral *SegmentName) {
546  // There's no stack to maintain, so we just have a current section. When we
547  // see the default section, reset our current section back to null so we stop
548  // tacking on unnecessary attributes.
549  CurInitSeg = SegmentName->getString() == ".CRT$XCU" ? nullptr : SegmentName;
550  CurInitSegLoc = PragmaLocation;
551 }
552 
553 void Sema::ActOnPragmaUnused(const Token &IdTok, Scope *curScope,
554  SourceLocation PragmaLoc) {
555 
556  IdentifierInfo *Name = IdTok.getIdentifierInfo();
557  LookupResult Lookup(*this, Name, IdTok.getLocation(), LookupOrdinaryName);
558  LookupParsedName(Lookup, curScope, nullptr, true);
559 
560  if (Lookup.empty()) {
561  Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
562  << Name << SourceRange(IdTok.getLocation());
563  return;
564  }
565 
566  VarDecl *VD = Lookup.getAsSingle<VarDecl>();
567  if (!VD) {
568  Diag(PragmaLoc, diag::warn_pragma_unused_expected_var_arg)
569  << Name << SourceRange(IdTok.getLocation());
570  return;
571  }
572 
573  // Warn if this was used before being marked unused.
574  if (VD->isUsed())
575  Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name;
576 
577  VD->addAttr(UnusedAttr::CreateImplicit(Context, IdTok.getLocation(),
579  UnusedAttr::GNU_unused));
580 }
581 
583  IdentifierInfo *Ident;
584  SourceLocation Loc;
585  std::tie(Ident, Loc) = PP.getPragmaARCCFCodeAuditedInfo();
586  if (!Loc.isValid()) return;
587 
588  // Don't add a redundant or conflicting attribute.
589  if (D->hasAttr<CFAuditedTransferAttr>() ||
590  D->hasAttr<CFUnknownTransferAttr>())
591  return;
592 
593  AttributeCommonInfo Info(Ident, SourceRange(Loc),
595  D->addAttr(CFAuditedTransferAttr::CreateImplicit(Context, Info));
596 }
597 
598 namespace {
599 
601 getParentAttrMatcherRule(attr::SubjectMatchRule Rule) {
602  using namespace attr;
603  switch (Rule) {
604  default:
605  return None;
606 #define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
607 #define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \
608  case Value: \
609  return Parent;
610 #include "clang/Basic/AttrSubMatchRulesList.inc"
611  }
612 }
613 
614 bool isNegatedAttrMatcherSubRule(attr::SubjectMatchRule Rule) {
615  using namespace attr;
616  switch (Rule) {
617  default:
618  return false;
619 #define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
620 #define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \
621  case Value: \
622  return IsNegated;
623 #include "clang/Basic/AttrSubMatchRulesList.inc"
624  }
625 }
626 
627 CharSourceRange replacementRangeForListElement(const Sema &S,
628  SourceRange Range) {
629  // Make sure that the ',' is removed as well.
631  Range.getEnd(), tok::comma, S.getSourceManager(), S.getLangOpts(),
632  /*SkipTrailingWhitespaceAndNewLine=*/false);
633  if (AfterCommaLoc.isValid())
634  return CharSourceRange::getCharRange(Range.getBegin(), AfterCommaLoc);
635  else
636  return CharSourceRange::getTokenRange(Range);
637 }
638 
639 std::string
640 attrMatcherRuleListToString(ArrayRef<attr::SubjectMatchRule> Rules) {
641  std::string Result;
642  llvm::raw_string_ostream OS(Result);
643  for (const auto &I : llvm::enumerate(Rules)) {
644  if (I.index())
645  OS << (I.index() == Rules.size() - 1 ? ", and " : ", ");
646  OS << "'" << attr::getSubjectMatchRuleSpelling(I.value()) << "'";
647  }
648  return OS.str();
649 }
650 
651 } // end anonymous namespace
652 
654  ParsedAttr &Attribute, SourceLocation PragmaLoc,
656  Attribute.setIsPragmaClangAttribute();
657  SmallVector<attr::SubjectMatchRule, 4> SubjectMatchRules;
658  // Gather the subject match rules that are supported by the attribute.
660  StrictSubjectMatchRuleSet;
661  Attribute.getMatchRules(LangOpts, StrictSubjectMatchRuleSet);
662 
663  // Figure out which subject matching rules are valid.
664  if (StrictSubjectMatchRuleSet.empty()) {
665  // Check for contradicting match rules. Contradicting match rules are
666  // either:
667  // - a top-level rule and one of its sub-rules. E.g. variable and
668  // variable(is_parameter).
669  // - a sub-rule and a sibling that's negated. E.g.
670  // variable(is_thread_local) and variable(unless(is_parameter))
671  llvm::SmallDenseMap<int, std::pair<int, SourceRange>, 2>
672  RulesToFirstSpecifiedNegatedSubRule;
673  for (const auto &Rule : Rules) {
674  attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
676  getParentAttrMatcherRule(MatchRule);
677  if (!ParentRule)
678  continue;
679  auto It = Rules.find(*ParentRule);
680  if (It != Rules.end()) {
681  // A sub-rule contradicts a parent rule.
682  Diag(Rule.second.getBegin(),
683  diag::err_pragma_attribute_matcher_subrule_contradicts_rule)
685  << attr::getSubjectMatchRuleSpelling(*ParentRule) << It->second
687  replacementRangeForListElement(*this, Rule.second));
688  // Keep going without removing this rule as it won't change the set of
689  // declarations that receive the attribute.
690  continue;
691  }
692  if (isNegatedAttrMatcherSubRule(MatchRule))
693  RulesToFirstSpecifiedNegatedSubRule.insert(
694  std::make_pair(*ParentRule, Rule));
695  }
696  bool IgnoreNegatedSubRules = false;
697  for (const auto &Rule : Rules) {
698  attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
700  getParentAttrMatcherRule(MatchRule);
701  if (!ParentRule)
702  continue;
703  auto It = RulesToFirstSpecifiedNegatedSubRule.find(*ParentRule);
704  if (It != RulesToFirstSpecifiedNegatedSubRule.end() &&
705  It->second != Rule) {
706  // Negated sub-rule contradicts another sub-rule.
707  Diag(
708  It->second.second.getBegin(),
709  diag::
710  err_pragma_attribute_matcher_negated_subrule_contradicts_subrule)
712  attr::SubjectMatchRule(It->second.first))
713  << attr::getSubjectMatchRuleSpelling(MatchRule) << Rule.second
715  replacementRangeForListElement(*this, It->second.second));
716  // Keep going but ignore all of the negated sub-rules.
717  IgnoreNegatedSubRules = true;
718  RulesToFirstSpecifiedNegatedSubRule.erase(It);
719  }
720  }
721 
722  if (!IgnoreNegatedSubRules) {
723  for (const auto &Rule : Rules)
724  SubjectMatchRules.push_back(attr::SubjectMatchRule(Rule.first));
725  } else {
726  for (const auto &Rule : Rules) {
727  if (!isNegatedAttrMatcherSubRule(attr::SubjectMatchRule(Rule.first)))
728  SubjectMatchRules.push_back(attr::SubjectMatchRule(Rule.first));
729  }
730  }
731  Rules.clear();
732  } else {
733  for (const auto &Rule : StrictSubjectMatchRuleSet) {
734  if (Rules.erase(Rule.first)) {
735  // Add the rule to the set of attribute receivers only if it's supported
736  // in the current language mode.
737  if (Rule.second)
738  SubjectMatchRules.push_back(Rule.first);
739  }
740  }
741  }
742 
743  if (!Rules.empty()) {
744  auto Diagnostic =
745  Diag(PragmaLoc, diag::err_pragma_attribute_invalid_matchers)
746  << Attribute;
748  for (const auto &Rule : Rules) {
749  ExtraRules.push_back(attr::SubjectMatchRule(Rule.first));
751  replacementRangeForListElement(*this, Rule.second));
752  }
753  Diagnostic << attrMatcherRuleListToString(ExtraRules);
754  }
755 
756  if (PragmaAttributeStack.empty()) {
757  Diag(PragmaLoc, diag::err_pragma_attr_attr_no_push);
758  return;
759  }
760 
761  PragmaAttributeStack.back().Entries.push_back(
762  {PragmaLoc, &Attribute, std::move(SubjectMatchRules), /*IsUsed=*/false});
763 }
764 
766  const IdentifierInfo *Namespace) {
767  PragmaAttributeStack.emplace_back();
768  PragmaAttributeStack.back().Loc = PragmaLoc;
769  PragmaAttributeStack.back().Namespace = Namespace;
770 }
771 
773  const IdentifierInfo *Namespace) {
774  if (PragmaAttributeStack.empty()) {
775  Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
776  return;
777  }
778 
779  // Dig back through the stack trying to find the most recently pushed group
780  // that in Namespace. Note that this works fine if no namespace is present,
781  // think of push/pops without namespaces as having an implicit "nullptr"
782  // namespace.
783  for (size_t Index = PragmaAttributeStack.size(); Index;) {
784  --Index;
785  if (PragmaAttributeStack[Index].Namespace == Namespace) {
786  for (const PragmaAttributeEntry &Entry :
787  PragmaAttributeStack[Index].Entries) {
788  if (!Entry.IsUsed) {
789  assert(Entry.Attribute && "Expected an attribute");
790  Diag(Entry.Attribute->getLoc(), diag::warn_pragma_attribute_unused)
791  << *Entry.Attribute;
792  Diag(PragmaLoc, diag::note_pragma_attribute_region_ends_here);
793  }
794  }
795  PragmaAttributeStack.erase(PragmaAttributeStack.begin() + Index);
796  return;
797  }
798  }
799 
800  if (Namespace)
801  Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch)
802  << 0 << Namespace->getName();
803  else
804  Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
805 }
806 
808  if (PragmaAttributeStack.empty())
809  return;
810  for (auto &Group : PragmaAttributeStack) {
811  for (auto &Entry : Group.Entries) {
812  ParsedAttr *Attribute = Entry.Attribute;
813  assert(Attribute && "Expected an attribute");
814  assert(Attribute->isPragmaClangAttribute() &&
815  "expected #pragma clang attribute");
816 
817  // Ensure that the attribute can be applied to the given declaration.
818  bool Applies = false;
819  for (const auto &Rule : Entry.MatchRules) {
820  if (Attribute->appliesToDecl(D, Rule)) {
821  Applies = true;
822  break;
823  }
824  }
825  if (!Applies)
826  continue;
827  Entry.IsUsed = true;
829  ParsedAttributesView Attrs;
830  Attrs.addAtEnd(Attribute);
831  ProcessDeclAttributeList(S, D, Attrs);
833  }
834  }
835 }
836 
838  assert(PragmaAttributeCurrentTargetDecl && "Expected an active declaration");
840  diag::note_pragma_attribute_applied_decl_here);
841 }
842 
844  if (PragmaAttributeStack.empty())
845  return;
846  Diag(PragmaAttributeStack.back().Loc, diag::err_pragma_attribute_no_pop_eof);
847 }
848 
849 void Sema::ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc) {
850  if(On)
852  else
853  OptimizeOffPragmaLocation = PragmaLoc;
854 }
855 
857  // In the future, check other pragmas if they're implemented (e.g. pragma
858  // optimize 0 will probably map to this functionality too).
861 }
862 
864  SourceLocation Loc) {
865  // Don't add a conflicting attribute. No diagnostic is needed.
866  if (FD->hasAttr<MinSizeAttr>() || FD->hasAttr<AlwaysInlineAttr>())
867  return;
868 
869  // Add attributes only if required. Optnone requires noinline as well, but if
870  // either is already present then don't bother adding them.
871  if (!FD->hasAttr<OptimizeNoneAttr>())
872  FD->addAttr(OptimizeNoneAttr::CreateImplicit(Context, Loc));
873  if (!FD->hasAttr<NoInlineAttr>())
874  FD->addAttr(NoInlineAttr::CreateImplicit(Context, Loc));
875 }
876 
877 typedef std::vector<std::pair<unsigned, SourceLocation> > VisStack;
878 enum : unsigned { NoVisibility = ~0U };
879 
881  if (!VisContext)
882  return;
883 
884  NamedDecl *ND = dyn_cast<NamedDecl>(D);
886  return;
887 
888  VisStack *Stack = static_cast<VisStack*>(VisContext);
889  unsigned rawType = Stack->back().first;
890  if (rawType == NoVisibility) return;
891 
892  VisibilityAttr::VisibilityType type
893  = (VisibilityAttr::VisibilityType) rawType;
894  SourceLocation loc = Stack->back().second;
895 
896  D->addAttr(VisibilityAttr::CreateImplicit(Context, type, loc));
897 }
898 
899 /// FreeVisContext - Deallocate and null out VisContext.
901  delete static_cast<VisStack*>(VisContext);
902  VisContext = nullptr;
903 }
904 
905 static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc) {
906  // Put visibility on stack.
907  if (!S.VisContext)
908  S.VisContext = new VisStack;
909 
910  VisStack *Stack = static_cast<VisStack*>(S.VisContext);
911  Stack->push_back(std::make_pair(type, loc));
912 }
913 
915  SourceLocation PragmaLoc) {
916  if (VisType) {
917  // Compute visibility to use.
918  VisibilityAttr::VisibilityType T;
919  if (!VisibilityAttr::ConvertStrToVisibilityType(VisType->getName(), T)) {
920  Diag(PragmaLoc, diag::warn_attribute_unknown_visibility) << VisType;
921  return;
922  }
923  PushPragmaVisibility(*this, T, PragmaLoc);
924  } else {
925  PopPragmaVisibility(false, PragmaLoc);
926  }
927 }
928 
930  switch (FPC) {
931  case LangOptions::FPC_On:
933  break;
936  break;
939  break;
940  }
941 }
942 
944  switch (FPC) {
945  case LangOptions::FEA_On:
947  break;
950  break;
951  }
952 }
953 
954 
955 void Sema::PushNamespaceVisibilityAttr(const VisibilityAttr *Attr,
956  SourceLocation Loc) {
957  // Visibility calculations will consider the namespace's visibility.
958  // Here we just want to note that we're in a visibility context
959  // which overrides any enclosing #pragma context, but doesn't itself
960  // contribute visibility.
961  PushPragmaVisibility(*this, NoVisibility, Loc);
962 }
963 
964 void Sema::PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc) {
965  if (!VisContext) {
966  Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
967  return;
968  }
969 
970  // Pop visibility from stack
971  VisStack *Stack = static_cast<VisStack*>(VisContext);
972 
973  const std::pair<unsigned, SourceLocation> *Back = &Stack->back();
974  bool StartsWithPragma = Back->first != NoVisibility;
975  if (StartsWithPragma && IsNamespaceEnd) {
976  Diag(Back->second, diag::err_pragma_push_visibility_mismatch);
977  Diag(EndLoc, diag::note_surrounding_namespace_ends_here);
978 
979  // For better error recovery, eat all pushes inside the namespace.
980  do {
981  Stack->pop_back();
982  Back = &Stack->back();
983  StartsWithPragma = Back->first != NoVisibility;
984  } while (StartsWithPragma);
985  } else if (!StartsWithPragma && !IsNamespaceEnd) {
986  Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
987  Diag(Back->second, diag::note_surrounding_namespace_starts_here);
988  return;
989  }
990 
991  Stack->pop_back();
992  // To simplify the implementation, never keep around an empty stack.
993  if (Stack->empty())
994  FreeVisContext();
995 }
void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
Definition: SemaAttr.cpp:765
PragmaStack< StringLiteral * > CodeSegStack
Definition: Sema.h:534
Represents a function declaration or definition.
Definition: Decl.h:1784
void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, SourceLocation PragmaLoc, attr::ParsedSubjectMatchRuleSet Rules)
Definition: SemaAttr.cpp:653
PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct)
Definition: SemaAttr.cpp:27
A (possibly-)qualified type.
Definition: Type.h:643
ASTConsumer & Consumer
Definition: Sema.h:378
void ActOnPragmaMSStruct(PragmaMSStructKind Kind)
ActOnPragmaMSStruct - Called on well formed #pragma ms_struct [on|off].
Definition: SemaAttr.cpp:390
void SentinelAction(PragmaMsStackAction Action, StringRef Label)
Definition: Sema.h:490
SmallVector< PackIncludeState, 8 > PackIncludeStack
Definition: Sema.h:529
PragmaStack< StringLiteral * > DataSegStack
Definition: Sema.h:531
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
Definition: Sema.h:3315
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.
Definition: SemaAttr.cpp:512
bool hasValue() const
Definition: Sema.h:500
static CharSourceRange getTokenRange(SourceRange R)
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1375
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:88
void ProcessDeclAttributeList(Scope *S, Decl *D, const ParsedAttributesView &AL, bool IncludeCXX11Attributes=true)
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:421
void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, SourceLocation PragmaLoc, MSVtorDispAttr::Mode Value)
Called on well formed #pragma vtordisp().
Definition: SemaAttr.cpp:417
PragmaOptionsAlignKind
Definition: Sema.h:8839
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.
Definition: Diagnostic.h:1290
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:706
Represents a variable declaration or definition.
Definition: Decl.h:827
DiagnosticsEngine & Diags
Definition: Sema.h:379
PragmaClangSection PragmaClangBSSSection
Definition: Sema.h:442
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:269
Represents a struct/union/class.
Definition: Decl.h:3662
void FreeVisContext()
FreeVisContext - Deallocate and null out VisContext.
Definition: SemaAttr.cpp:900
One of these records is kept for each identifier that is lexed.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:1060
SubjectMatchRule
A list of all the recognized kinds of attributes.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:160
void getMatchRules(const LangOptions &LangOpts, SmallVectorImpl< std::pair< attr::SubjectMatchRule, bool >> &MatchRules) const
Definition: ParsedAttr.cpp:151
bool checkSectionName(SourceLocation LiteralLoc, StringRef Str)
void ActOnPragmaAttributePop(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
Called on well-formed &#39;#pragma clang attribute pop&#39;.
Definition: SemaAttr.cpp:772
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
static void addGslOwnerPointerAttributeIfNotExisting(ASTContext &Context, CXXRecordDecl *Record)
Definition: SemaAttr.cpp:89
static PragmaCommentDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation CommentLoc, PragmaMSCommentKind CommentKind, StringRef Arg)
Definition: Decl.cpp:4513
static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc)
Definition: SemaAttr.cpp:905
void setIsPragmaClangAttribute()
Definition: ParsedAttr.h:365
void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags, StringLiteral *SegmentName)
Called on well formed #pragma section().
Definition: SemaAttr.cpp:539
Represents the results of name lookup.
Definition: Lookup.h:46
void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, SourceLocation PragmaLoc)
ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
Definition: SemaAttr.cpp:205
bool UnifySection(StringRef SectionName, int SectionFlags, DeclaratorDecl *TheDecl)
Definition: SemaAttr.cpp:464
void AddPushedVisibilityAttribute(Decl *RD)
AddPushedVisibilityAttribute - If &#39;#pragma GCC visibility&#39; was used, add an appropriate visibility at...
Definition: SemaAttr.cpp:880
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6148
void ActOnPragmaFPContract(LangOptions::FPContractModeKind FPC)
ActOnPragmaFPContract - Called on well formed #pragma {STDC,OPENCL} FP_CONTRACT and #pragma clang fp ...
Definition: SemaAttr.cpp:929
PragmaPackDiagnoseKind
Definition: Sema.h:8861
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:347
void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value)
ActOnPragmaDetectMismatch - Call on well-formed #pragma detect_mismatch.
Definition: SemaAttr.cpp:402
Preprocessor & PP
Definition: Sema.h:376
const LangOptions & getLangOpts() const
Definition: Sema.h:1288
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.
Definition: Expr.h:176
void addAtEnd(ParsedAttr *newAttr)
Definition: ParsedAttr.h:738
void DiagnoseNonDefaultPragmaPack(PragmaPackDiagnoseKind Kind, SourceLocation IncludeLoc)
Definition: SemaAttr.cpp:335
const LangOptions & LangOpts
Definition: Sema.h:375
void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc)
PopPragmaVisibility - Pop the top element of the visibility stack; used for &#39;#pragma GCC visibility&#39; ...
Definition: SemaAttr.cpp:964
void PrintPragmaAttributeInstantiationPoint()
Definition: SemaAttr.cpp:837
bool MSStructPragmaOn
Definition: Sema.h:399
NodeId Parent
Definition: ASTDiff.cpp:191
bool hasAttr() const
Definition: DeclBase.h:542
llvm::StringMap< SectionInfo > SectionInfos
Definition: ASTContext.h:3039
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:331
StringRef getString() const
Definition: Expr.h:1769
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1043
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1692
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:696
std::vector< std::pair< unsigned, SourceLocation > > VisStack
Definition: SemaAttr.cpp:877
const Decl * PragmaAttributeCurrentTargetDecl
The declaration that is currently receiving an attribute from the #pragma attribute stack...
Definition: Sema.h:580
void setDisallowFPContract()
Definition: LangOptions.h:355
This represents one expression.
Definition: Expr.h:108
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...
Definition: Lexer.cpp:1270
void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, StringLiteral *SegmentName)
Called on well-formed #pragma init_seg().
Definition: SemaAttr.cpp:544
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Definition: Token.h:126
Defines the clang::Preprocessor interface.
DeclContext * getDeclContext()
Definition: DeclBase.h:438
PragmaStack< StringLiteral * > BSSSegStack
Definition: Sema.h:532
PragmaClangSectionAction
Definition: Sema.h:427
void ActOnPragmaUnused(const Token &Identifier, Scope *curScope, SourceLocation PragmaLoc)
ActOnPragmaUnused - Called on well-formed &#39;#pragma unused&#39;.
Definition: SemaAttr.cpp:553
void ActOnPragmaMSComment(SourceLocation CommentLoc, PragmaMSCommentKind Kind, StringRef Arg)
ActOnPragmaMSComment - Called on well formed #pragma comment(kind, "arg").
Definition: SemaAttr.cpp:394
PragmaMSCommentKind
Definition: PragmaKinds.h:14
SourceLocation getEnd() const
bool hasAlignMac68kSupport() const
Check whether this target support &#39;#pragma options align=mac68k&#39;.
Definition: TargetInfo.h:717
void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc)
Adds the &#39;optnone&#39; attribute to the function declaration if there are no conflicts; Loc represents th...
Definition: SemaAttr.cpp:863
The result type of a method or function.
void DiagnoseUnterminatedPragmaPack()
Definition: SemaAttr.cpp:369
PragmaClangSectionKind
pragma clang section kind
Definition: Sema.h:418
static CharSourceRange getCharRange(SourceRange R)
void AddRangeBasedOptnone(FunctionDecl *FD)
Only called on function definitions; if there is a pragma in scope with the effect of a range-based o...
Definition: SemaAttr.cpp:856
StringLiteral * CurInitSeg
Last section used with #pragma init_seg.
Definition: Sema.h:553
Kind
QualType getCanonicalType() const
Definition: Type.h:6187
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: Redeclarable.h:294
Encodes a location in the source.
void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, llvm::StringRef StackSlotLabel, ValueType Value)
Definition: SemaAttr.cpp:427
SourceLocation CurrentPragmaLocation
Definition: Sema.h:505
llvm::APSInt APSInt
const char * getSubjectMatchRuleSpelling(SubjectMatchRule Rule)
Definition: Attributes.cpp:28
void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, StringRef SlotLabel, Expr *Alignment)
ActOnPragmaPack - Called on well formed #pragma pack(...).
Definition: SemaAttr.cpp:289
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:179
ParsedAttr - Represents a syntactic attribute.
Definition: ParsedAttr.h:117
SourceLocation PragmaLocation
Definition: Sema.h:435
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
Definition: Expr.h:158
PragmaStack< MSVtorDispAttr::Mode > VtorDispStack
Whether to insert vtordisps prior to virtual bases in the Microsoft C++ ABI.
Definition: Sema.h:518
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1861
SourceLocation OptimizeOffPragmaLocation
This represents the last location of a "#pragma clang optimize off" directive if such a directive has...
Definition: Sema.h:585
void ActOnPragmaClangSection(SourceLocation PragmaLoc, PragmaClangSectionAction Action, PragmaClangSectionKind SecKind, StringRef SecName)
ActOnPragmaClangSection - Called on well formed #pragma clang section.
Definition: SemaAttr.cpp:256
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required...
Definition: DeclBase.cpp:398
StringRef getName() const
Return the actual identifier string.
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2985
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.
Definition: Sema.h:409
void AddAlignmentAttributesForRecord(RecordDecl *RD)
AddAlignmentAttributesForRecord - Adds any needed alignment attributes to a the record decl...
Definition: SemaAttr.cpp:50
static PragmaDetectMismatchDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation Loc, StringRef Name, StringRef Value)
Definition: Decl.cpp:4536
std::pair< IdentifierInfo *, SourceLocation > getPragmaARCCFCodeAuditedInfo() const
The location of the currently-active #pragma clang arc_cf_code_audited begin.
QualType getUnderlyingType() const
Definition: Decl.h:3040
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
Definition: Diagnostic.h:118
void setDisallowFEnvAccess()
Definition: LangOptions.h:365
Do an LV computation for, ultimately, a non-type declaration.
Definition: Decl.h:415
PragmaClangSection PragmaClangRodataSection
Definition: Sema.h:444
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...
void AddPragmaAttributes(Scope *S, Decl *D)
Adds the attributes that have been specified using the &#39;#pragma clang attribute push&#39; directives to t...
Definition: SemaAttr.cpp:807
void DiagnoseUnterminatedPragmaAttribute()
Definition: SemaAttr.cpp:843
PragmaMsStackAction
Definition: Sema.h:448
PragmaClangSection PragmaClangDataSection
Definition: Sema.h:443
void ActOnPragmaMSPointersToMembers(LangOptions::PragmaMSPointersToMembersKind Kind, SourceLocation PragmaLoc)
ActOnPragmaMSPointersToMembers - called on well formed #pragma pointers_to_members(representation met...
Definition: SemaAttr.cpp:410
SmallVector< PragmaAttributeGroup, 2 > PragmaAttributeStack
Definition: Sema.h:576
ValueType CurrentValue
Definition: Sema.h:504
T * getAttr() const
Definition: DeclBase.h:538
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:351
PragmaMSStructKind
Definition: PragmaKinds.h:23
void inferGslOwnerPointerAttribute(CXXRecordDecl *Record)
Add [[gsl::Owner]] and [[gsl::Pointer]] attributes for std:: types.
Definition: SemaAttr.cpp:154
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.
Definition: Diagnostic.h:92
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1521
PragmaStack< StringLiteral * > ConstSegStack
Definition: Sema.h:533
PragmaClangSection PragmaClangTextSection
Definition: Sema.h:446
Optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
Definition: Decl.cpp:1177
void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, SourceLocation Loc)
PushNamespaceVisibilityAttr - Note that we&#39;ve entered a namespace with a visibility attribute...
Definition: SemaAttr.cpp:955
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1008
void * VisContext
VisContext - Manages the stack for #pragma GCC visibility.
Definition: Sema.h:557
Represents a C++ struct/union/class.
Definition: DeclCXX.h:255
LangOptions::PragmaMSPointersToMembersKind MSPointerToMemberRepresentationMethod
Controls member pointer representation format under the MS ABI.
Definition: Sema.h:403
PragmaClangSection PragmaClangRelroSection
Definition: Sema.h:445
llvm::DenseMap< int, SourceRange > ParsedSubjectMatchRuleSet
bool appliesToDecl(const Decl *D, attr::SubjectMatchRule MatchRule) const
Definition: ParsedAttr.cpp:146
void addAttr(Attr *A)
Definition: DeclBase.cpp:830
SourceManager & getSourceManager() const
Definition: Sema.h:1293
void setAllowFEnvAccess()
Definition: LangOptions.h:361
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1317
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1686
Defines the clang::TargetInfo interface.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
Definition: TargetCXXABI.h:153
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:275
FPOptions FPFeatures
Definition: Sema.h:373
void ActOnPragmaVisibility(const IdentifierInfo *VisType, SourceLocation PragmaLoc)
ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
Definition: SemaAttr.cpp:914
SourceManager & SourceMgr
Definition: Sema.h:380
void inferGslPointerAttribute(NamedDecl *ND, CXXRecordDecl *UnderlyingRecord)
Add gsl::Pointer attribute to std::container::iterator.
Definition: SemaAttr.cpp:98
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
Definition: ASTConsumer.cpp:18
PragmaStack< unsigned > PackStack
Definition: Sema.h:522
A trivial tuple used to represent a source range.
ASTContext & Context
Definition: Sema.h:377
This represents a decl that may have a name.
Definition: Decl.h:248
void ActOnPragmaFEnvAccess(LangOptions::FEnvAccessModeKind FPC)
ActOnPragmaFenvAccess - Called on well formed #pragma STDC FENV_ACCESS.
Definition: SemaAttr.cpp:943
SourceLocation CurrentPragmaLocation
Definition: Sema.h:526
bool isInStdNamespace() const
Definition: DeclBase.cpp:357
void AddMsStructLayoutForRecord(RecordDecl *RD)
AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
Definition: SemaAttr.cpp:76
bool isPragmaClangAttribute() const
True if the attribute is specified using &#39;#pragma clang attribute&#39;.
Definition: ParsedAttr.h:363
SourceLocation getBegin() const
SmallVector< Slot, 2 > Stack
Definition: Sema.h:502
Attr - This represents one attribute.
Definition: Attr.h:45
SourceLocation getLocation() const
Definition: DeclBase.h:429
This an attribute introduced by #pragma clang attribute.
Definition: Sema.h:560
void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc)
Called on well formed #pragma clang optimize.
Definition: SemaAttr.cpp:849
static const unsigned kMac68kAlignmentSentinel
Definition: Sema.h:521
void AddCFAuditedAttribute(Decl *D)
AddCFAuditedAttribute - Check whether we&#39;re currently within &#39;#pragma clang arc_cf_code_audited&#39; and...
Definition: SemaAttr.cpp:582
ValueType DefaultValue
Definition: Sema.h:503
SourceLocation CurInitSegLoc
Definition: Sema.h:554