clang  12.0.0git
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().getVtorDispMode())
84  RD->addAttr(MSVtorDispAttr::CreateImplicit(
85  Context, unsigned(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  int SectionFlags = ASTContext::PSF_Read;
260  switch (SecKind) {
261  case PragmaClangSectionKind::PCSK_BSS:
262  CSec = &PragmaClangBSSSection;
264  break;
265  case PragmaClangSectionKind::PCSK_Data:
266  CSec = &PragmaClangDataSection;
267  SectionFlags |= ASTContext::PSF_Write;
268  break;
269  case PragmaClangSectionKind::PCSK_Rodata:
270  CSec = &PragmaClangRodataSection;
271  break;
272  case PragmaClangSectionKind::PCSK_Relro:
273  CSec = &PragmaClangRelroSection;
274  break;
275  case PragmaClangSectionKind::PCSK_Text:
276  CSec = &PragmaClangTextSection;
277  SectionFlags |= ASTContext::PSF_Execute;
278  break;
279  default:
280  llvm_unreachable("invalid clang section kind");
281  }
282 
283  if (Action == PragmaClangSectionAction::PCSA_Clear) {
284  CSec->Valid = false;
285  return;
286  }
287 
288  if (UnifySection(SecName, SectionFlags, PragmaLoc))
289  return;
290 
291  CSec->Valid = true;
292  CSec->SectionName = std::string(SecName);
293  CSec->PragmaLocation = PragmaLoc;
294 }
295 
297  StringRef SlotLabel, Expr *alignment) {
298  Expr *Alignment = static_cast<Expr *>(alignment);
299 
300  // If specified then alignment must be a "small" power of two.
301  unsigned AlignmentVal = 0;
302  if (Alignment) {
304 
305  // pack(0) is like pack(), which just works out since that is what
306  // we use 0 for in PackAttr.
307  if (Alignment->isTypeDependent() || Alignment->isValueDependent() ||
308  !(Val = Alignment->getIntegerConstantExpr(Context)) ||
309  !(*Val == 0 || Val->isPowerOf2()) || Val->getZExtValue() > 16) {
310  Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
311  return; // Ignore
312  }
313 
314  AlignmentVal = (unsigned)Val->getZExtValue();
315  }
316  if (Action == Sema::PSK_Show) {
317  // Show the current alignment, making sure to show the right value
318  // for the default.
319  // FIXME: This should come from the target.
320  AlignmentVal = PackStack.CurrentValue;
321  if (AlignmentVal == 0)
322  AlignmentVal = 8;
323  if (AlignmentVal == Sema::kMac68kAlignmentSentinel)
324  Diag(PragmaLoc, diag::warn_pragma_pack_show) << "mac68k";
325  else
326  Diag(PragmaLoc, diag::warn_pragma_pack_show) << AlignmentVal;
327  }
328  // MSDN, C/C++ Preprocessor Reference > Pragma Directives > pack:
329  // "#pragma pack(pop, identifier, n) is undefined"
330  if (Action & Sema::PSK_Pop) {
331  if (Alignment && !SlotLabel.empty())
332  Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifier_and_alignment);
333  if (PackStack.Stack.empty())
334  Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "pack" << "stack empty";
335  }
336 
337  PackStack.Act(PragmaLoc, Action, SlotLabel, AlignmentVal);
338 }
339 
341  SourceLocation IncludeLoc) {
344  // Warn about non-default alignment at #includes (without redundant
345  // warnings for the same directive in nested includes).
346  // The warning is delayed until the end of the file to avoid warnings
347  // for files that don't have any records that are affected by the modified
348  // alignment.
349  bool HasNonDefaultValue =
350  PackStack.hasValue() &&
351  (PackIncludeStack.empty() ||
352  PackIncludeStack.back().CurrentPragmaLocation != PrevLocation);
353  PackIncludeStack.push_back(
355  PackStack.hasValue() ? PrevLocation : SourceLocation(),
356  HasNonDefaultValue, /*ShouldWarnOnInclude*/ false});
357  return;
358  }
359 
360  assert(Kind == PragmaPackDiagnoseKind::ChangedStateAtExit && "invalid kind");
361  PackIncludeState PrevPackState = PackIncludeStack.pop_back_val();
362  if (PrevPackState.ShouldWarnOnInclude) {
363  // Emit the delayed non-default alignment at #include warning.
364  Diag(IncludeLoc, diag::warn_pragma_pack_non_default_at_include);
365  Diag(PrevPackState.CurrentPragmaLocation, diag::note_pragma_pack_here);
366  }
367  // Warn about modified alignment after #includes.
368  if (PrevPackState.CurrentValue != PackStack.CurrentValue) {
369  Diag(IncludeLoc, diag::warn_pragma_pack_modified_after_include);
370  Diag(PackStack.CurrentPragmaLocation, diag::note_pragma_pack_here);
371  }
372 }
373 
375  if (PackStack.Stack.empty())
376  return;
377  bool IsInnermost = true;
378  for (const auto &StackSlot : llvm::reverse(PackStack.Stack)) {
379  Diag(StackSlot.PragmaPushLocation, diag::warn_pragma_pack_no_pop_eof);
380  // The user might have already reset the alignment, so suggest replacing
381  // the reset with a pop.
382  if (IsInnermost && PackStack.CurrentValue == PackStack.DefaultValue) {
384  diag::note_pragma_pack_pop_instead_reset);
387  /*SkipTrailing=*/false);
388  if (FixItLoc.isValid())
389  DB << FixItHint::CreateInsertion(FixItLoc, "pop");
390  }
391  IsInnermost = false;
392  }
393 }
394 
396  MSStructPragmaOn = (Kind == PMSST_ON);
397 }
398 
400  PragmaMSCommentKind Kind, StringRef Arg) {
401  auto *PCD = PragmaCommentDecl::Create(
402  Context, Context.getTranslationUnitDecl(), CommentLoc, Kind, Arg);
405 }
406 
408  StringRef Value) {
413 }
414 
416  PragmaMsStackAction Action,
418  FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
419  if ((Action == PSK_Push_Set || Action == PSK_Push || Action == PSK_Pop) &&
421  // Push and pop can only occur at file or namespace scope.
422  Diag(Loc, diag::err_pragma_fc_pp_scope);
423  return;
424  }
425  switch (Value) {
426  default:
427  llvm_unreachable("invalid pragma float_control kind");
428  case PFC_Precise:
429  NewFPFeatures.setFPPreciseEnabled(true);
430  FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
431  break;
432  case PFC_NoPrecise:
433  if (CurFPFeatures.getFPExceptionMode() == LangOptions::FPE_Strict)
434  Diag(Loc, diag::err_pragma_fc_noprecise_requires_noexcept);
435  else if (CurFPFeatures.getAllowFEnvAccess())
436  Diag(Loc, diag::err_pragma_fc_noprecise_requires_nofenv);
437  else
438  NewFPFeatures.setFPPreciseEnabled(false);
439  FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
440  break;
441  case PFC_Except:
442  if (!isPreciseFPEnabled())
443  Diag(Loc, diag::err_pragma_fc_except_requires_precise);
444  else
445  NewFPFeatures.setFPExceptionModeOverride(LangOptions::FPE_Strict);
446  FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
447  break;
448  case PFC_NoExcept:
449  NewFPFeatures.setFPExceptionModeOverride(LangOptions::FPE_Ignore);
450  FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
451  break;
452  case PFC_Push:
453  FpPragmaStack.Act(Loc, Sema::PSK_Push_Set, StringRef(), NewFPFeatures);
454  break;
455  case PFC_Pop:
456  if (FpPragmaStack.Stack.empty()) {
457  Diag(Loc, diag::warn_pragma_pop_failed) << "float_control"
458  << "stack empty";
459  return;
460  }
461  FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
462  NewFPFeatures = FpPragmaStack.CurrentValue;
463  break;
464  }
465  CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
466 }
467 
469  LangOptions::PragmaMSPointersToMembersKind RepresentationMethod,
470  SourceLocation PragmaLoc) {
471  MSPointerToMemberRepresentationMethod = RepresentationMethod;
472  ImplicitMSInheritanceAttrLoc = PragmaLoc;
473 }
474 
476  SourceLocation PragmaLoc,
477  MSVtorDispMode Mode) {
478  if (Action & PSK_Pop && VtorDispStack.Stack.empty())
479  Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "vtordisp"
480  << "stack empty";
481  VtorDispStack.Act(PragmaLoc, Action, StringRef(), Mode);
482 }
483 
484 bool Sema::UnifySection(StringRef SectionName,
485  int SectionFlags,
486  DeclaratorDecl *Decl) {
487  SourceLocation PragmaLocation;
488  if (auto A = Decl->getAttr<SectionAttr>())
489  if (A->isImplicit())
490  PragmaLocation = A->getLocation();
491  auto SectionIt = Context.SectionInfos.find(SectionName);
492  if (SectionIt == Context.SectionInfos.end()) {
493  Context.SectionInfos[SectionName] =
494  ASTContext::SectionInfo(Decl, PragmaLocation, SectionFlags);
495  return false;
496  }
497  // A pre-declared section takes precedence w/o diagnostic.
498  const auto &Section = SectionIt->second;
499  if (Section.SectionFlags == SectionFlags ||
500  ((SectionFlags & ASTContext::PSF_Implicit) &&
501  !(Section.SectionFlags & ASTContext::PSF_Implicit)))
502  return false;
503  Diag(Decl->getLocation(), diag::err_section_conflict) << Decl << Section;
504  if (Section.Decl)
505  Diag(Section.Decl->getLocation(), diag::note_declared_at)
506  << Section.Decl->getName();
507  if (PragmaLocation.isValid())
508  Diag(PragmaLocation, diag::note_pragma_entered_here);
509  if (Section.PragmaSectionLocation.isValid())
510  Diag(Section.PragmaSectionLocation, diag::note_pragma_entered_here);
511  return true;
512 }
513 
514 bool Sema::UnifySection(StringRef SectionName,
515  int SectionFlags,
516  SourceLocation PragmaSectionLocation) {
517  auto SectionIt = Context.SectionInfos.find(SectionName);
518  if (SectionIt != Context.SectionInfos.end()) {
519  const auto &Section = SectionIt->second;
520  if (Section.SectionFlags == SectionFlags)
521  return false;
522  if (!(Section.SectionFlags & ASTContext::PSF_Implicit)) {
523  Diag(PragmaSectionLocation, diag::err_section_conflict)
524  << "this" << Section;
525  if (Section.Decl)
526  Diag(Section.Decl->getLocation(), diag::note_declared_at)
527  << Section.Decl->getName();
528  if (Section.PragmaSectionLocation.isValid())
529  Diag(Section.PragmaSectionLocation, diag::note_pragma_entered_here);
530  return true;
531  }
532  }
533  Context.SectionInfos[SectionName] =
534  ASTContext::SectionInfo(nullptr, PragmaSectionLocation, SectionFlags);
535  return false;
536 }
537 
538 /// Called on well formed \#pragma bss_seg().
540  PragmaMsStackAction Action,
541  llvm::StringRef StackSlotLabel,
542  StringLiteral *SegmentName,
543  llvm::StringRef PragmaName) {
545  llvm::StringSwitch<PragmaStack<StringLiteral *> *>(PragmaName)
546  .Case("data_seg", &DataSegStack)
547  .Case("bss_seg", &BSSSegStack)
548  .Case("const_seg", &ConstSegStack)
549  .Case("code_seg", &CodeSegStack);
550  if (Action & PSK_Pop && Stack->Stack.empty())
551  Diag(PragmaLocation, diag::warn_pragma_pop_failed) << PragmaName
552  << "stack empty";
553  if (SegmentName) {
554  if (!checkSectionName(SegmentName->getBeginLoc(), SegmentName->getString()))
555  return;
556 
557  if (SegmentName->getString() == ".drectve" &&
559  Diag(PragmaLocation, diag::warn_attribute_section_drectve) << PragmaName;
560  }
561 
562  Stack->Act(PragmaLocation, Action, StackSlotLabel, SegmentName);
563 }
564 
565 /// Called on well formed \#pragma bss_seg().
567  int SectionFlags, StringLiteral *SegmentName) {
568  UnifySection(SegmentName->getString(), SectionFlags, PragmaLocation);
569 }
570 
572  StringLiteral *SegmentName) {
573  // There's no stack to maintain, so we just have a current section. When we
574  // see the default section, reset our current section back to null so we stop
575  // tacking on unnecessary attributes.
576  CurInitSeg = SegmentName->getString() == ".CRT$XCU" ? nullptr : SegmentName;
577  CurInitSegLoc = PragmaLocation;
578 }
579 
580 void Sema::ActOnPragmaUnused(const Token &IdTok, Scope *curScope,
581  SourceLocation PragmaLoc) {
582 
583  IdentifierInfo *Name = IdTok.getIdentifierInfo();
584  LookupResult Lookup(*this, Name, IdTok.getLocation(), LookupOrdinaryName);
585  LookupParsedName(Lookup, curScope, nullptr, true);
586 
587  if (Lookup.empty()) {
588  Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
589  << Name << SourceRange(IdTok.getLocation());
590  return;
591  }
592 
593  VarDecl *VD = Lookup.getAsSingle<VarDecl>();
594  if (!VD) {
595  Diag(PragmaLoc, diag::warn_pragma_unused_expected_var_arg)
596  << Name << SourceRange(IdTok.getLocation());
597  return;
598  }
599 
600  // Warn if this was used before being marked unused.
601  if (VD->isUsed())
602  Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name;
603 
604  VD->addAttr(UnusedAttr::CreateImplicit(Context, IdTok.getLocation(),
606  UnusedAttr::GNU_unused));
607 }
608 
610  IdentifierInfo *Ident;
611  SourceLocation Loc;
612  std::tie(Ident, Loc) = PP.getPragmaARCCFCodeAuditedInfo();
613  if (!Loc.isValid()) return;
614 
615  // Don't add a redundant or conflicting attribute.
616  if (D->hasAttr<CFAuditedTransferAttr>() ||
617  D->hasAttr<CFUnknownTransferAttr>())
618  return;
619 
620  AttributeCommonInfo Info(Ident, SourceRange(Loc),
622  D->addAttr(CFAuditedTransferAttr::CreateImplicit(Context, Info));
623 }
624 
625 namespace {
626 
628 getParentAttrMatcherRule(attr::SubjectMatchRule Rule) {
629  using namespace attr;
630  switch (Rule) {
631  default:
632  return None;
633 #define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
634 #define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \
635  case Value: \
636  return Parent;
637 #include "clang/Basic/AttrSubMatchRulesList.inc"
638  }
639 }
640 
641 bool isNegatedAttrMatcherSubRule(attr::SubjectMatchRule Rule) {
642  using namespace attr;
643  switch (Rule) {
644  default:
645  return false;
646 #define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
647 #define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \
648  case Value: \
649  return IsNegated;
650 #include "clang/Basic/AttrSubMatchRulesList.inc"
651  }
652 }
653 
654 CharSourceRange replacementRangeForListElement(const Sema &S,
655  SourceRange Range) {
656  // Make sure that the ',' is removed as well.
658  Range.getEnd(), tok::comma, S.getSourceManager(), S.getLangOpts(),
659  /*SkipTrailingWhitespaceAndNewLine=*/false);
660  if (AfterCommaLoc.isValid())
661  return CharSourceRange::getCharRange(Range.getBegin(), AfterCommaLoc);
662  else
663  return CharSourceRange::getTokenRange(Range);
664 }
665 
666 std::string
667 attrMatcherRuleListToString(ArrayRef<attr::SubjectMatchRule> Rules) {
668  std::string Result;
669  llvm::raw_string_ostream OS(Result);
670  for (const auto &I : llvm::enumerate(Rules)) {
671  if (I.index())
672  OS << (I.index() == Rules.size() - 1 ? ", and " : ", ");
673  OS << "'" << attr::getSubjectMatchRuleSpelling(I.value()) << "'";
674  }
675  return OS.str();
676 }
677 
678 } // end anonymous namespace
679 
681  ParsedAttr &Attribute, SourceLocation PragmaLoc,
683  Attribute.setIsPragmaClangAttribute();
684  SmallVector<attr::SubjectMatchRule, 4> SubjectMatchRules;
685  // Gather the subject match rules that are supported by the attribute.
687  StrictSubjectMatchRuleSet;
688  Attribute.getMatchRules(LangOpts, StrictSubjectMatchRuleSet);
689 
690  // Figure out which subject matching rules are valid.
691  if (StrictSubjectMatchRuleSet.empty()) {
692  // Check for contradicting match rules. Contradicting match rules are
693  // either:
694  // - a top-level rule and one of its sub-rules. E.g. variable and
695  // variable(is_parameter).
696  // - a sub-rule and a sibling that's negated. E.g.
697  // variable(is_thread_local) and variable(unless(is_parameter))
698  llvm::SmallDenseMap<int, std::pair<int, SourceRange>, 2>
699  RulesToFirstSpecifiedNegatedSubRule;
700  for (const auto &Rule : Rules) {
701  attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
703  getParentAttrMatcherRule(MatchRule);
704  if (!ParentRule)
705  continue;
706  auto It = Rules.find(*ParentRule);
707  if (It != Rules.end()) {
708  // A sub-rule contradicts a parent rule.
709  Diag(Rule.second.getBegin(),
710  diag::err_pragma_attribute_matcher_subrule_contradicts_rule)
712  << attr::getSubjectMatchRuleSpelling(*ParentRule) << It->second
714  replacementRangeForListElement(*this, Rule.second));
715  // Keep going without removing this rule as it won't change the set of
716  // declarations that receive the attribute.
717  continue;
718  }
719  if (isNegatedAttrMatcherSubRule(MatchRule))
720  RulesToFirstSpecifiedNegatedSubRule.insert(
721  std::make_pair(*ParentRule, Rule));
722  }
723  bool IgnoreNegatedSubRules = false;
724  for (const auto &Rule : Rules) {
725  attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
727  getParentAttrMatcherRule(MatchRule);
728  if (!ParentRule)
729  continue;
730  auto It = RulesToFirstSpecifiedNegatedSubRule.find(*ParentRule);
731  if (It != RulesToFirstSpecifiedNegatedSubRule.end() &&
732  It->second != Rule) {
733  // Negated sub-rule contradicts another sub-rule.
734  Diag(
735  It->second.second.getBegin(),
736  diag::
737  err_pragma_attribute_matcher_negated_subrule_contradicts_subrule)
739  attr::SubjectMatchRule(It->second.first))
740  << attr::getSubjectMatchRuleSpelling(MatchRule) << Rule.second
742  replacementRangeForListElement(*this, It->second.second));
743  // Keep going but ignore all of the negated sub-rules.
744  IgnoreNegatedSubRules = true;
745  RulesToFirstSpecifiedNegatedSubRule.erase(It);
746  }
747  }
748 
749  if (!IgnoreNegatedSubRules) {
750  for (const auto &Rule : Rules)
751  SubjectMatchRules.push_back(attr::SubjectMatchRule(Rule.first));
752  } else {
753  for (const auto &Rule : Rules) {
754  if (!isNegatedAttrMatcherSubRule(attr::SubjectMatchRule(Rule.first)))
755  SubjectMatchRules.push_back(attr::SubjectMatchRule(Rule.first));
756  }
757  }
758  Rules.clear();
759  } else {
760  for (const auto &Rule : StrictSubjectMatchRuleSet) {
761  if (Rules.erase(Rule.first)) {
762  // Add the rule to the set of attribute receivers only if it's supported
763  // in the current language mode.
764  if (Rule.second)
765  SubjectMatchRules.push_back(Rule.first);
766  }
767  }
768  }
769 
770  if (!Rules.empty()) {
771  auto Diagnostic =
772  Diag(PragmaLoc, diag::err_pragma_attribute_invalid_matchers)
773  << Attribute;
775  for (const auto &Rule : Rules) {
776  ExtraRules.push_back(attr::SubjectMatchRule(Rule.first));
778  replacementRangeForListElement(*this, Rule.second));
779  }
780  Diagnostic << attrMatcherRuleListToString(ExtraRules);
781  }
782 
783  if (PragmaAttributeStack.empty()) {
784  Diag(PragmaLoc, diag::err_pragma_attr_attr_no_push);
785  return;
786  }
787 
788  PragmaAttributeStack.back().Entries.push_back(
789  {PragmaLoc, &Attribute, std::move(SubjectMatchRules), /*IsUsed=*/false});
790 }
791 
793  const IdentifierInfo *Namespace) {
794  PragmaAttributeStack.emplace_back();
795  PragmaAttributeStack.back().Loc = PragmaLoc;
796  PragmaAttributeStack.back().Namespace = Namespace;
797 }
798 
800  const IdentifierInfo *Namespace) {
801  if (PragmaAttributeStack.empty()) {
802  Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
803  return;
804  }
805 
806  // Dig back through the stack trying to find the most recently pushed group
807  // that in Namespace. Note that this works fine if no namespace is present,
808  // think of push/pops without namespaces as having an implicit "nullptr"
809  // namespace.
810  for (size_t Index = PragmaAttributeStack.size(); Index;) {
811  --Index;
812  if (PragmaAttributeStack[Index].Namespace == Namespace) {
813  for (const PragmaAttributeEntry &Entry :
814  PragmaAttributeStack[Index].Entries) {
815  if (!Entry.IsUsed) {
816  assert(Entry.Attribute && "Expected an attribute");
817  Diag(Entry.Attribute->getLoc(), diag::warn_pragma_attribute_unused)
818  << *Entry.Attribute;
819  Diag(PragmaLoc, diag::note_pragma_attribute_region_ends_here);
820  }
821  }
822  PragmaAttributeStack.erase(PragmaAttributeStack.begin() + Index);
823  return;
824  }
825  }
826 
827  if (Namespace)
828  Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch)
829  << 0 << Namespace->getName();
830  else
831  Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
832 }
833 
835  if (PragmaAttributeStack.empty())
836  return;
837  for (auto &Group : PragmaAttributeStack) {
838  for (auto &Entry : Group.Entries) {
839  ParsedAttr *Attribute = Entry.Attribute;
840  assert(Attribute && "Expected an attribute");
841  assert(Attribute->isPragmaClangAttribute() &&
842  "expected #pragma clang attribute");
843 
844  // Ensure that the attribute can be applied to the given declaration.
845  bool Applies = false;
846  for (const auto &Rule : Entry.MatchRules) {
847  if (Attribute->appliesToDecl(D, Rule)) {
848  Applies = true;
849  break;
850  }
851  }
852  if (!Applies)
853  continue;
854  Entry.IsUsed = true;
856  ParsedAttributesView Attrs;
857  Attrs.addAtEnd(Attribute);
858  ProcessDeclAttributeList(S, D, Attrs);
860  }
861  }
862 }
863 
865  assert(PragmaAttributeCurrentTargetDecl && "Expected an active declaration");
867  diag::note_pragma_attribute_applied_decl_here);
868 }
869 
871  if (PragmaAttributeStack.empty())
872  return;
873  Diag(PragmaAttributeStack.back().Loc, diag::err_pragma_attribute_no_pop_eof);
874 }
875 
876 void Sema::ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc) {
877  if(On)
879  else
880  OptimizeOffPragmaLocation = PragmaLoc;
881 }
882 
884  // In the future, check other pragmas if they're implemented (e.g. pragma
885  // optimize 0 will probably map to this functionality too).
888 }
889 
891  SourceLocation Loc) {
892  // Don't add a conflicting attribute. No diagnostic is needed.
893  if (FD->hasAttr<MinSizeAttr>() || FD->hasAttr<AlwaysInlineAttr>())
894  return;
895 
896  // Add attributes only if required. Optnone requires noinline as well, but if
897  // either is already present then don't bother adding them.
898  if (!FD->hasAttr<OptimizeNoneAttr>())
899  FD->addAttr(OptimizeNoneAttr::CreateImplicit(Context, Loc));
900  if (!FD->hasAttr<NoInlineAttr>())
901  FD->addAttr(NoInlineAttr::CreateImplicit(Context, Loc));
902 }
903 
904 typedef std::vector<std::pair<unsigned, SourceLocation> > VisStack;
905 enum : unsigned { NoVisibility = ~0U };
906 
908  if (!VisContext)
909  return;
910 
911  NamedDecl *ND = dyn_cast<NamedDecl>(D);
913  return;
914 
915  VisStack *Stack = static_cast<VisStack*>(VisContext);
916  unsigned rawType = Stack->back().first;
917  if (rawType == NoVisibility) return;
918 
919  VisibilityAttr::VisibilityType type
920  = (VisibilityAttr::VisibilityType) rawType;
921  SourceLocation loc = Stack->back().second;
922 
923  D->addAttr(VisibilityAttr::CreateImplicit(Context, type, loc));
924 }
925 
926 /// FreeVisContext - Deallocate and null out VisContext.
928  delete static_cast<VisStack*>(VisContext);
929  VisContext = nullptr;
930 }
931 
932 static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc) {
933  // Put visibility on stack.
934  if (!S.VisContext)
935  S.VisContext = new VisStack;
936 
937  VisStack *Stack = static_cast<VisStack*>(S.VisContext);
938  Stack->push_back(std::make_pair(type, loc));
939 }
940 
942  SourceLocation PragmaLoc) {
943  if (VisType) {
944  // Compute visibility to use.
945  VisibilityAttr::VisibilityType T;
946  if (!VisibilityAttr::ConvertStrToVisibilityType(VisType->getName(), T)) {
947  Diag(PragmaLoc, diag::warn_attribute_unknown_visibility) << VisType;
948  return;
949  }
950  PushPragmaVisibility(*this, T, PragmaLoc);
951  } else {
952  PopPragmaVisibility(false, PragmaLoc);
953  }
954 }
955 
958  FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
959  switch (FPC) {
960  case LangOptions::FPM_On:
961  NewFPFeatures.setAllowFPContractWithinStatement();
962  break;
964  NewFPFeatures.setAllowFPContractAcrossStatement();
965  break;
967  NewFPFeatures.setDisallowFPContract();
968  break;
969  }
970  FpPragmaStack.Act(Loc, Sema::PSK_Set, StringRef(), NewFPFeatures);
971  CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
972 }
973 
975  FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
976  NewFPFeatures.setAllowFPReassociateOverride(IsEnabled);
977  FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
978  CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
979 }
980 
981 void Sema::setRoundingMode(SourceLocation Loc, llvm::RoundingMode FPR) {
982  // C2x: 7.6.2p3 If the FE_DYNAMIC mode is specified and FENV_ACCESS is "off",
983  // the translator may assume that the default rounding mode is in effect.
984  if (FPR == llvm::RoundingMode::Dynamic &&
985  !CurFPFeatures.getAllowFEnvAccess() &&
986  CurFPFeatures.getFPExceptionMode() == LangOptions::FPE_Ignore)
987  FPR = llvm::RoundingMode::NearestTiesToEven;
988 
989  FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
990  NewFPFeatures.setRoundingModeOverride(FPR);
991  FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
992  CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
993 }
994 
997  FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
998  NewFPFeatures.setFPExceptionModeOverride(FPE);
999  FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
1000  CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
1001 }
1002 
1003 void Sema::ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled) {
1004  FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1005  auto LO = getLangOpts();
1006  if (IsEnabled) {
1007  // Verify Microsoft restriction:
1008  // You can't enable fenv_access unless precise semantics are enabled.
1009  // Precise semantics can be enabled either by the float_control
1010  // pragma, or by using the /fp:precise or /fp:strict compiler options
1011  if (!isPreciseFPEnabled())
1012  Diag(Loc, diag::err_pragma_fenv_requires_precise);
1013  NewFPFeatures.setAllowFEnvAccessOverride(true);
1014  // Enabling FENV access sets the RoundingMode to Dynamic.
1015  // and ExceptionBehavior to Strict
1016  NewFPFeatures.setRoundingModeOverride(llvm::RoundingMode::Dynamic);
1017  NewFPFeatures.setFPExceptionModeOverride(LangOptions::FPE_Strict);
1018  } else {
1019  NewFPFeatures.setAllowFEnvAccessOverride(false);
1020  }
1021  FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
1022  CurFPFeatures = NewFPFeatures.applyOverrides(LO);
1023 }
1024 
1027  setExceptionMode(Loc, FPE);
1028 }
1029 
1030 void Sema::PushNamespaceVisibilityAttr(const VisibilityAttr *Attr,
1031  SourceLocation Loc) {
1032  // Visibility calculations will consider the namespace's visibility.
1033  // Here we just want to note that we're in a visibility context
1034  // which overrides any enclosing #pragma context, but doesn't itself
1035  // contribute visibility.
1036  PushPragmaVisibility(*this, NoVisibility, Loc);
1037 }
1038 
1039 void Sema::PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc) {
1040  if (!VisContext) {
1041  Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
1042  return;
1043  }
1044 
1045  // Pop visibility from stack
1046  VisStack *Stack = static_cast<VisStack*>(VisContext);
1047 
1048  const std::pair<unsigned, SourceLocation> *Back = &Stack->back();
1049  bool StartsWithPragma = Back->first != NoVisibility;
1050  if (StartsWithPragma && IsNamespaceEnd) {
1051  Diag(Back->second, diag::err_pragma_push_visibility_mismatch);
1052  Diag(EndLoc, diag::note_surrounding_namespace_ends_here);
1053 
1054  // For better error recovery, eat all pushes inside the namespace.
1055  do {
1056  Stack->pop_back();
1057  Back = &Stack->back();
1058  StartsWithPragma = Back->first != NoVisibility;
1059  } while (StartsWithPragma);
1060  } else if (!StartsWithPragma && !IsNamespaceEnd) {
1061  Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
1062  Diag(Back->second, diag::note_surrounding_namespace_starts_here);
1063  return;
1064  }
1065 
1066  Stack->pop_back();
1067  // To simplify the implementation, never keep around an empty stack.
1068  if (Stack->empty())
1069  FreeVisContext();
1070 }
void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
Definition: SemaAttr.cpp:792
PragmaStack< StringLiteral * > CodeSegStack
Definition: Sema.h:587
MSVtorDispMode
In the Microsoft ABI, this controls the placement of virtual displacement members used to implement v...
Definition: LangOptions.h:50
Represents a function declaration or definition.
Definition: Decl.h:1805
void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, SourceLocation PragmaLoc, attr::ParsedSubjectMatchRuleSet Rules)
Definition: SemaAttr.cpp:680
PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct)
Definition: SemaAttr.cpp:27
A (possibly-)qualified type.
Definition: Type.h:661
ASTConsumer & Consumer
Definition: Sema.h:400
void ActOnPragmaMSStruct(PragmaMSStructKind Kind)
ActOnPragmaMSStruct - Called on well formed #pragma ms_struct [on|off].
Definition: SemaAttr.cpp:395
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:527
void SentinelAction(PragmaMsStackAction Action, StringRef Label)
Definition: Sema.h:543
SmallVector< PackIncludeState, 8 > PackIncludeStack
Definition: Sema.h:582
PragmaStack< StringLiteral * > DataSegStack
Definition: Sema.h:584
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
Definition: Sema.h:3799
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:539
bool hasValue() const
Definition: Sema.h:553
static CharSourceRange getTokenRange(SourceRange R)
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
void ProcessDeclAttributeList(Scope *S, Decl *D, const ParsedAttributesView &AL, bool IncludeCXX11Attributes=true)
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:422
PragmaOptionsAlignKind
Definition: Sema.h:9756
void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action, PragmaFloatControlKind Value)
ActOnPragmaFloatControl - Call on well-formed #pragma float_control.
Definition: SemaAttr.cpp:415
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...
FPOptions applyOverrides(FPOptions Base)
Definition: LangOptions.h:562
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1469
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:659
void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC)
ActOnPragmaFPContract - Called on well formed #pragma {STDC,OPENCL} FP_CONTRACT and #pragma clang fp ...
Definition: SemaAttr.cpp:956
Represents a variable declaration or definition.
Definition: Decl.h:834
DiagnosticsEngine & Diags
Definition: Sema.h:401
PragmaClangSection PragmaClangBSSSection
Definition: Sema.h:464
void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, SourceLocation PragmaLoc, MSVtorDispMode Value)
Called on well formed #pragma vtordisp().
Definition: SemaAttr.cpp:475
void ActOnPragmaFPExceptions(SourceLocation Loc, LangOptions::FPExceptionModeKind)
Called on well formed &#39;#pragma clang fp&#39; that has option &#39;exceptions&#39;.
Definition: SemaAttr.cpp:1025
PragmaFloatControlKind
Definition: PragmaKinds.h:28
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:244
Represents a struct/union/class.
Definition: Decl.h:3800
void FreeVisContext()
FreeVisContext - Deallocate and null out VisContext.
Definition: SemaAttr.cpp:927
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:1139
void ActOnPragmaFPReassociate(SourceLocation Loc, bool IsEnabled)
Called on well formed #pragma clang fp reassociate.
Definition: SemaAttr.cpp:974
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:186
void getMatchRules(const LangOptions &LangOpts, SmallVectorImpl< std::pair< attr::SubjectMatchRule, bool >> &MatchRules) const
Definition: ParsedAttr.cpp:167
bool isNamespace() const
Definition: DeclBase.h:1899
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:799
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:4708
static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc)
Definition: SemaAttr.cpp:932
void setIsPragmaClangAttribute()
Definition: ParsedAttr.h:448
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: Sema.cpp:1739
void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags, StringLiteral *SegmentName)
Called on well formed #pragma section().
Definition: SemaAttr.cpp:566
Represents the results of name lookup.
Definition: Lookup.h:46
void setExceptionMode(SourceLocation Loc, LangOptions::FPExceptionModeKind)
Called to set exception behavior for floating point operations.
Definition: SemaAttr.cpp:995
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:484
void AddPushedVisibilityAttribute(Decl *RD)
AddPushedVisibilityAttribute - If &#39;#pragma GCC visibility&#39; was used, add an appropriate visibility at...
Definition: SemaAttr.cpp:907
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:6392
PragmaPackDiagnoseKind
Definition: Sema.h:9778
void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value)
ActOnPragmaDetectMismatch - Call on well-formed #pragma detect_mismatch.
Definition: SemaAttr.cpp:407
Preprocessor & PP
Definition: Sema.h:398
const LangOptions & getLangOpts() const
Definition: Sema.h:1430
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:185
void addAtEnd(ParsedAttr *newAttr)
Definition: ParsedAttr.h:828
void DiagnoseNonDefaultPragmaPack(PragmaPackDiagnoseKind Kind, SourceLocation IncludeLoc)
Definition: SemaAttr.cpp:340
const LangOptions & LangOpts
Definition: Sema.h:397
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:1039
void PrintPragmaAttributeInstantiationPoint()
Definition: SemaAttr.cpp:864
bool MSStructPragmaOn
Definition: Sema.h:421
NodeId Parent
Definition: ASTDiff.cpp:192
bool hasAttr() const
Definition: DeclBase.h:547
llvm::StringMap< SectionInfo > SectionInfos
Definition: ASTContext.h:3101
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:340
StringRef getString() const
Definition: Expr.h:1838
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1753
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:686
Represents difference between two FPOptions values.
Definition: LangOptions.h:497
std::vector< std::pair< unsigned, SourceLocation > > VisStack
Definition: SemaAttr.cpp:904
const Decl * PragmaAttributeCurrentTargetDecl
The declaration that is currently receiving an attribute from the #pragma attribute stack...
Definition: Sema.h:645
PragmaStack< FPOptionsOverride > FpPragmaStack
Definition: Sema.h:590
This represents one expression.
Definition: Expr.h:109
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:1273
void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, StringLiteral *SegmentName)
Called on well-formed #pragma init_seg().
Definition: SemaAttr.cpp:571
bool isPreciseFPEnabled()
Are precise floating point semantics currently enabled?
Definition: Sema.h:9844
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.
FPExceptionModeKind
Possible floating point exception behavior.
Definition: LangOptions.h:199
DeclContext * getDeclContext()
Definition: DeclBase.h:439
PragmaStack< StringLiteral * > BSSSegStack
Definition: Sema.h:585
PragmaClangSectionAction
Definition: Sema.h:449
void ActOnPragmaUnused(const Token &Identifier, Scope *curScope, SourceLocation PragmaLoc)
ActOnPragmaUnused - Called on well-formed &#39;#pragma unused&#39;.
Definition: SemaAttr.cpp:580
void ActOnPragmaMSComment(SourceLocation CommentLoc, PragmaMSCommentKind Kind, StringRef Arg)
ActOnPragmaMSComment - Called on well formed #pragma comment(kind, "arg").
Definition: SemaAttr.cpp:399
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:781
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:890
The result type of a method or function.
void DiagnoseUnterminatedPragmaPack()
Definition: SemaAttr.cpp:374
PragmaClangSectionKind
pragma clang section kind
Definition: Sema.h:440
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:883
StringLiteral * CurInitSeg
Last section used with #pragma init_seg.
Definition: Sema.h:618
Kind
QualType getCanonicalType() const
Definition: Type.h:6431
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: Redeclarable.h:294
void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, llvm::StringRef StackSlotLabel, ValueType Value)
Definition: Sema.h:494
Encodes a location in the source.
SourceLocation CurrentPragmaLocation
Definition: Sema.h:558
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:296
PragmaStack< MSVtorDispMode > VtorDispStack
Whether to insert vtordisps prior to virtual bases in the Microsoft C++ ABI.
Definition: Sema.h:571
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:179
ParsedAttr - Represents a syntactic attribute.
Definition: ParsedAttr.h:196
SourceLocation PragmaLocation
Definition: Sema.h:457
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:168
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1930
SourceLocation OptimizeOffPragmaLocation
This represents the last location of a "#pragma clang optimize off" directive if such a directive has...
Definition: Sema.h:650
FPOptionsOverride CurFPFeatureOverrides()
Definition: Sema.h:591
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:443
StringRef getName() const
Return the actual identifier string.
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3121
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:431
Assume that floating-point exceptions are masked.
Definition: LangOptions.h:201
void AddAlignmentAttributesForRecord(RecordDecl *RD)
AddAlignmentAttributesForRecord - Adds any needed alignment attributes to a the record decl...
Definition: SemaAttr.cpp:50
void ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled)
ActOnPragmaFenvAccess - Called on well formed #pragma STDC FENV_ACCESS.
Definition: SemaAttr.cpp:1003
FPOptions CurFPFeatures
Definition: Sema.h:395
static PragmaDetectMismatchDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation Loc, StringRef Name, StringRef Value)
Definition: Decl.cpp:4731
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:3176
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
Definition: Diagnostic.h:122
Do an LV computation for, ultimately, a non-type declaration.
Definition: Decl.h:405
PragmaClangSection PragmaClangRodataSection
Definition: Sema.h:466
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:834
void DiagnoseUnterminatedPragmaAttribute()
Definition: SemaAttr.cpp:870
PragmaMsStackAction
Definition: Sema.h:470
PragmaClangSection PragmaClangDataSection
Definition: Sema.h:465
void ActOnPragmaMSPointersToMembers(LangOptions::PragmaMSPointersToMembersKind Kind, SourceLocation PragmaLoc)
ActOnPragmaMSPointersToMembers - called on well formed #pragma pointers_to_members(representation met...
Definition: SemaAttr.cpp:468
SmallVector< PragmaAttributeGroup, 2 > PragmaAttributeStack
Definition: Sema.h:641
ValueType CurrentValue
Definition: Sema.h:557
T * getAttr() const
Definition: DeclBase.h:543
void setFPPreciseEnabled(bool Value)
Definition: LangOptions.h:535
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:96
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1581
PragmaStack< StringLiteral * > ConstSegStack
Definition: Sema.h:586
PragmaClangSection PragmaClangTextSection
Definition: Sema.h:468
Optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
Definition: Decl.cpp:1186
void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, SourceLocation Loc)
PushNamespaceVisibilityAttr - Note that we&#39;ve entered a namespace with a visibility attribute...
Definition: SemaAttr.cpp:1030
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:955
void * VisContext
VisContext - Manages the stack for #pragma GCC visibility.
Definition: Sema.h:622
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:523
LangOptions::PragmaMSPointersToMembersKind MSPointerToMemberRepresentationMethod
Controls member pointer representation format under the MS ABI.
Definition: Sema.h:425
PragmaClangSection PragmaClangRelroSection
Definition: Sema.h:467
llvm::DenseMap< int, SourceRange > ParsedSubjectMatchRuleSet
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:411
bool appliesToDecl(const Decl *D, attr::SubjectMatchRule MatchRule) const
Definition: ParsedAttr.cpp:162
void addAttr(Attr *A)
Definition: DeclBase.cpp:882
SourceManager & getSourceManager() const
Definition: Sema.h:1435
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1493
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1755
Defines the clang::TargetInfo interface.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
Definition: TargetCXXABI.h:169
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:250
void ActOnPragmaVisibility(const IdentifierInfo *VisType, SourceLocation PragmaLoc)
ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
Definition: SemaAttr.cpp:941
SourceManager & SourceMgr
Definition: Sema.h:402
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:575
A trivial tuple used to represent a source range.
ASTContext & Context
Definition: Sema.h:399
This represents a decl that may have a name.
Definition: Decl.h:223
bool isTranslationUnit() const
Definition: DeclBase.h:1890
void setRoundingMode(SourceLocation Loc, llvm::RoundingMode)
Called to set constant rounding mode for floating point operations.
Definition: SemaAttr.cpp:981
Strictly preserve the floating-point exception semantics.
Definition: LangOptions.h:205
SourceLocation CurrentPragmaLocation
Definition: Sema.h:579
bool isInStdNamespace() const
Definition: DeclBase.cpp:394
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:446
SourceLocation getBegin() const
SmallVector< Slot, 2 > Stack
Definition: Sema.h:555
Attr - This represents one attribute.
Definition: Attr.h:46
Optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc=nullptr, bool isEvaluated=true) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression...
SourceLocation getLocation() const
Definition: DeclBase.h:430
This an attribute introduced by #pragma clang attribute.
Definition: Sema.h:625
void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc)
Called on well formed #pragma clang optimize.
Definition: SemaAttr.cpp:876
static const unsigned kMac68kAlignmentSentinel
Definition: Sema.h:574
void AddCFAuditedAttribute(Decl *D)
AddCFAuditedAttribute - Check whether we&#39;re currently within &#39;#pragma clang arc_cf_code_audited&#39; and...
Definition: SemaAttr.cpp:609
ValueType DefaultValue
Definition: Sema.h:556
SourceLocation CurInitSegLoc
Definition: Sema.h:619