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) {
303  llvm::APSInt Val;
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() ||
308  Alignment->isValueDependent() ||
309  !Alignment->isIntegerConstantExpr(Val, Context) ||
310  !(Val == 0 || Val.isPowerOf2()) ||
311  Val.getZExtValue() > 16) {
312  Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
313  return; // Ignore
314  }
315 
316  AlignmentVal = (unsigned) Val.getZExtValue();
317  }
318  if (Action == Sema::PSK_Show) {
319  // Show the current alignment, making sure to show the right value
320  // for the default.
321  // FIXME: This should come from the target.
322  AlignmentVal = PackStack.CurrentValue;
323  if (AlignmentVal == 0)
324  AlignmentVal = 8;
325  if (AlignmentVal == Sema::kMac68kAlignmentSentinel)
326  Diag(PragmaLoc, diag::warn_pragma_pack_show) << "mac68k";
327  else
328  Diag(PragmaLoc, diag::warn_pragma_pack_show) << AlignmentVal;
329  }
330  // MSDN, C/C++ Preprocessor Reference > Pragma Directives > pack:
331  // "#pragma pack(pop, identifier, n) is undefined"
332  if (Action & Sema::PSK_Pop) {
333  if (Alignment && !SlotLabel.empty())
334  Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifier_and_alignment);
335  if (PackStack.Stack.empty())
336  Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "pack" << "stack empty";
337  }
338 
339  PackStack.Act(PragmaLoc, Action, SlotLabel, AlignmentVal);
340 }
341 
343  SourceLocation IncludeLoc) {
346  // Warn about non-default alignment at #includes (without redundant
347  // warnings for the same directive in nested includes).
348  // The warning is delayed until the end of the file to avoid warnings
349  // for files that don't have any records that are affected by the modified
350  // alignment.
351  bool HasNonDefaultValue =
352  PackStack.hasValue() &&
353  (PackIncludeStack.empty() ||
354  PackIncludeStack.back().CurrentPragmaLocation != PrevLocation);
355  PackIncludeStack.push_back(
357  PackStack.hasValue() ? PrevLocation : SourceLocation(),
358  HasNonDefaultValue, /*ShouldWarnOnInclude*/ false});
359  return;
360  }
361 
362  assert(Kind == PragmaPackDiagnoseKind::ChangedStateAtExit && "invalid kind");
363  PackIncludeState PrevPackState = PackIncludeStack.pop_back_val();
364  if (PrevPackState.ShouldWarnOnInclude) {
365  // Emit the delayed non-default alignment at #include warning.
366  Diag(IncludeLoc, diag::warn_pragma_pack_non_default_at_include);
367  Diag(PrevPackState.CurrentPragmaLocation, diag::note_pragma_pack_here);
368  }
369  // Warn about modified alignment after #includes.
370  if (PrevPackState.CurrentValue != PackStack.CurrentValue) {
371  Diag(IncludeLoc, diag::warn_pragma_pack_modified_after_include);
372  Diag(PackStack.CurrentPragmaLocation, diag::note_pragma_pack_here);
373  }
374 }
375 
377  if (PackStack.Stack.empty())
378  return;
379  bool IsInnermost = true;
380  for (const auto &StackSlot : llvm::reverse(PackStack.Stack)) {
381  Diag(StackSlot.PragmaPushLocation, diag::warn_pragma_pack_no_pop_eof);
382  // The user might have already reset the alignment, so suggest replacing
383  // the reset with a pop.
384  if (IsInnermost && PackStack.CurrentValue == PackStack.DefaultValue) {
386  diag::note_pragma_pack_pop_instead_reset);
389  /*SkipTrailing=*/false);
390  if (FixItLoc.isValid())
391  DB << FixItHint::CreateInsertion(FixItLoc, "pop");
392  }
393  IsInnermost = false;
394  }
395 }
396 
398  MSStructPragmaOn = (Kind == PMSST_ON);
399 }
400 
402  PragmaMSCommentKind Kind, StringRef Arg) {
403  auto *PCD = PragmaCommentDecl::Create(
404  Context, Context.getTranslationUnitDecl(), CommentLoc, Kind, Arg);
407 }
408 
410  StringRef Value) {
415 }
416 
418  PragmaMsStackAction Action,
420  unsigned NewValue = FpPragmaStack.hasValue()
423  FPOptionsOverride NewFPFeatures(NewValue);
424  if ((Action == PSK_Push_Set || Action == PSK_Push || Action == PSK_Pop) &&
426  // Push and pop can only occur at file or namespace scope.
427  Diag(Loc, diag::err_pragma_fc_pp_scope);
428  return;
429  }
430  switch (Value) {
431  default:
432  llvm_unreachable("invalid pragma float_control kind");
433  case PFC_Precise:
434  NewFPFeatures.setFPPreciseEnabled(true);
435  NewValue = NewFPFeatures.getAsOpaqueInt();
436  FpPragmaStack.Act(Loc, Action, StringRef(), NewValue);
437  break;
438  case PFC_NoPrecise:
439  if (CurFPFeatures.getFPExceptionMode() == LangOptions::FPE_Strict)
440  Diag(Loc, diag::err_pragma_fc_noprecise_requires_noexcept);
441  else if (CurFPFeatures.getAllowFEnvAccess())
442  Diag(Loc, diag::err_pragma_fc_noprecise_requires_nofenv);
443  else
444  NewFPFeatures.setFPPreciseEnabled(false);
445  NewValue = NewFPFeatures.getAsOpaqueInt();
446  FpPragmaStack.Act(Loc, Action, StringRef(), NewValue);
447  break;
448  case PFC_Except:
449  if (!isPreciseFPEnabled())
450  Diag(Loc, diag::err_pragma_fc_except_requires_precise);
451  else
452  NewFPFeatures.setFPExceptionModeOverride(LangOptions::FPE_Strict);
453  NewValue = NewFPFeatures.getAsOpaqueInt();
454  FpPragmaStack.Act(Loc, Action, StringRef(), NewValue);
455  break;
456  case PFC_NoExcept:
457  NewFPFeatures.setFPExceptionModeOverride(LangOptions::FPE_Ignore);
458  NewValue = NewFPFeatures.getAsOpaqueInt();
459  FpPragmaStack.Act(Loc, Action, StringRef(), NewValue);
460  break;
461  case PFC_Push:
462  FpPragmaStack.Act(Loc, Sema::PSK_Push_Set, StringRef(),
463  NewFPFeatures.getAsOpaqueInt());
464  break;
465  case PFC_Pop:
466  if (FpPragmaStack.Stack.empty()) {
467  Diag(Loc, diag::warn_pragma_pop_failed) << "float_control"
468  << "stack empty";
469  return;
470  }
471  FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures.getAsOpaqueInt());
472  NewValue = FpPragmaStack.CurrentValue;
473  break;
474  }
475  FPOptionsOverride NewOverrides;
476  if (NewValue != FpPragmaStack.DefaultValue)
477  NewOverrides.getFromOpaqueInt(NewValue);
478  CurFPFeatures = NewOverrides.applyOverrides(getLangOpts());
479 }
480 
482  LangOptions::PragmaMSPointersToMembersKind RepresentationMethod,
483  SourceLocation PragmaLoc) {
484  MSPointerToMemberRepresentationMethod = RepresentationMethod;
485  ImplicitMSInheritanceAttrLoc = PragmaLoc;
486 }
487 
489  SourceLocation PragmaLoc,
490  MSVtorDispMode Mode) {
491  if (Action & PSK_Pop && VtorDispStack.Stack.empty())
492  Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "vtordisp"
493  << "stack empty";
494  VtorDispStack.Act(PragmaLoc, Action, StringRef(), Mode);
495 }
496 
497 bool Sema::UnifySection(StringRef SectionName,
498  int SectionFlags,
499  DeclaratorDecl *Decl) {
500  SourceLocation PragmaLocation;
501  if (auto A = Decl->getAttr<SectionAttr>())
502  if (A->isImplicit())
503  PragmaLocation = A->getLocation();
504  auto SectionIt = Context.SectionInfos.find(SectionName);
505  if (SectionIt == Context.SectionInfos.end()) {
506  Context.SectionInfos[SectionName] =
507  ASTContext::SectionInfo(Decl, PragmaLocation, SectionFlags);
508  return false;
509  }
510  // A pre-declared section takes precedence w/o diagnostic.
511  const auto &Section = SectionIt->second;
512  if (Section.SectionFlags == SectionFlags ||
513  ((SectionFlags & ASTContext::PSF_Implicit) &&
514  !(Section.SectionFlags & ASTContext::PSF_Implicit)))
515  return false;
516  Diag(Decl->getLocation(), diag::err_section_conflict) << Decl << Section;
517  if (Section.Decl)
518  Diag(Section.Decl->getLocation(), diag::note_declared_at)
519  << Section.Decl->getName();
520  if (PragmaLocation.isValid())
521  Diag(PragmaLocation, diag::note_pragma_entered_here);
522  if (Section.PragmaSectionLocation.isValid())
523  Diag(Section.PragmaSectionLocation, diag::note_pragma_entered_here);
524  return true;
525 }
526 
527 bool Sema::UnifySection(StringRef SectionName,
528  int SectionFlags,
529  SourceLocation PragmaSectionLocation) {
530  auto SectionIt = Context.SectionInfos.find(SectionName);
531  if (SectionIt != Context.SectionInfos.end()) {
532  const auto &Section = SectionIt->second;
533  if (Section.SectionFlags == SectionFlags)
534  return false;
535  if (!(Section.SectionFlags & ASTContext::PSF_Implicit)) {
536  Diag(PragmaSectionLocation, diag::err_section_conflict)
537  << "this" << Section;
538  if (Section.Decl)
539  Diag(Section.Decl->getLocation(), diag::note_declared_at)
540  << Section.Decl->getName();
541  if (Section.PragmaSectionLocation.isValid())
542  Diag(Section.PragmaSectionLocation, diag::note_pragma_entered_here);
543  return true;
544  }
545  }
546  Context.SectionInfos[SectionName] =
547  ASTContext::SectionInfo(nullptr, PragmaSectionLocation, SectionFlags);
548  return false;
549 }
550 
551 /// Called on well formed \#pragma bss_seg().
553  PragmaMsStackAction Action,
554  llvm::StringRef StackSlotLabel,
555  StringLiteral *SegmentName,
556  llvm::StringRef PragmaName) {
558  llvm::StringSwitch<PragmaStack<StringLiteral *> *>(PragmaName)
559  .Case("data_seg", &DataSegStack)
560  .Case("bss_seg", &BSSSegStack)
561  .Case("const_seg", &ConstSegStack)
562  .Case("code_seg", &CodeSegStack);
563  if (Action & PSK_Pop && Stack->Stack.empty())
564  Diag(PragmaLocation, diag::warn_pragma_pop_failed) << PragmaName
565  << "stack empty";
566  if (SegmentName) {
567  if (!checkSectionName(SegmentName->getBeginLoc(), SegmentName->getString()))
568  return;
569 
570  if (SegmentName->getString() == ".drectve" &&
572  Diag(PragmaLocation, diag::warn_attribute_section_drectve) << PragmaName;
573  }
574 
575  Stack->Act(PragmaLocation, Action, StackSlotLabel, SegmentName);
576 }
577 
578 /// Called on well formed \#pragma bss_seg().
580  int SectionFlags, StringLiteral *SegmentName) {
581  UnifySection(SegmentName->getString(), SectionFlags, PragmaLocation);
582 }
583 
585  StringLiteral *SegmentName) {
586  // There's no stack to maintain, so we just have a current section. When we
587  // see the default section, reset our current section back to null so we stop
588  // tacking on unnecessary attributes.
589  CurInitSeg = SegmentName->getString() == ".CRT$XCU" ? nullptr : SegmentName;
590  CurInitSegLoc = PragmaLocation;
591 }
592 
593 void Sema::ActOnPragmaUnused(const Token &IdTok, Scope *curScope,
594  SourceLocation PragmaLoc) {
595 
596  IdentifierInfo *Name = IdTok.getIdentifierInfo();
597  LookupResult Lookup(*this, Name, IdTok.getLocation(), LookupOrdinaryName);
598  LookupParsedName(Lookup, curScope, nullptr, true);
599 
600  if (Lookup.empty()) {
601  Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
602  << Name << SourceRange(IdTok.getLocation());
603  return;
604  }
605 
606  VarDecl *VD = Lookup.getAsSingle<VarDecl>();
607  if (!VD) {
608  Diag(PragmaLoc, diag::warn_pragma_unused_expected_var_arg)
609  << Name << SourceRange(IdTok.getLocation());
610  return;
611  }
612 
613  // Warn if this was used before being marked unused.
614  if (VD->isUsed())
615  Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name;
616 
617  VD->addAttr(UnusedAttr::CreateImplicit(Context, IdTok.getLocation(),
619  UnusedAttr::GNU_unused));
620 }
621 
623  IdentifierInfo *Ident;
624  SourceLocation Loc;
625  std::tie(Ident, Loc) = PP.getPragmaARCCFCodeAuditedInfo();
626  if (!Loc.isValid()) return;
627 
628  // Don't add a redundant or conflicting attribute.
629  if (D->hasAttr<CFAuditedTransferAttr>() ||
630  D->hasAttr<CFUnknownTransferAttr>())
631  return;
632 
633  AttributeCommonInfo Info(Ident, SourceRange(Loc),
635  D->addAttr(CFAuditedTransferAttr::CreateImplicit(Context, Info));
636 }
637 
638 namespace {
639 
641 getParentAttrMatcherRule(attr::SubjectMatchRule Rule) {
642  using namespace attr;
643  switch (Rule) {
644  default:
645  return None;
646 #define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
647 #define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \
648  case Value: \
649  return Parent;
650 #include "clang/Basic/AttrSubMatchRulesList.inc"
651  }
652 }
653 
654 bool isNegatedAttrMatcherSubRule(attr::SubjectMatchRule Rule) {
655  using namespace attr;
656  switch (Rule) {
657  default:
658  return false;
659 #define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
660 #define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \
661  case Value: \
662  return IsNegated;
663 #include "clang/Basic/AttrSubMatchRulesList.inc"
664  }
665 }
666 
667 CharSourceRange replacementRangeForListElement(const Sema &S,
668  SourceRange Range) {
669  // Make sure that the ',' is removed as well.
671  Range.getEnd(), tok::comma, S.getSourceManager(), S.getLangOpts(),
672  /*SkipTrailingWhitespaceAndNewLine=*/false);
673  if (AfterCommaLoc.isValid())
674  return CharSourceRange::getCharRange(Range.getBegin(), AfterCommaLoc);
675  else
676  return CharSourceRange::getTokenRange(Range);
677 }
678 
679 std::string
680 attrMatcherRuleListToString(ArrayRef<attr::SubjectMatchRule> Rules) {
681  std::string Result;
682  llvm::raw_string_ostream OS(Result);
683  for (const auto &I : llvm::enumerate(Rules)) {
684  if (I.index())
685  OS << (I.index() == Rules.size() - 1 ? ", and " : ", ");
686  OS << "'" << attr::getSubjectMatchRuleSpelling(I.value()) << "'";
687  }
688  return OS.str();
689 }
690 
691 } // end anonymous namespace
692 
694  ParsedAttr &Attribute, SourceLocation PragmaLoc,
696  Attribute.setIsPragmaClangAttribute();
697  SmallVector<attr::SubjectMatchRule, 4> SubjectMatchRules;
698  // Gather the subject match rules that are supported by the attribute.
700  StrictSubjectMatchRuleSet;
701  Attribute.getMatchRules(LangOpts, StrictSubjectMatchRuleSet);
702 
703  // Figure out which subject matching rules are valid.
704  if (StrictSubjectMatchRuleSet.empty()) {
705  // Check for contradicting match rules. Contradicting match rules are
706  // either:
707  // - a top-level rule and one of its sub-rules. E.g. variable and
708  // variable(is_parameter).
709  // - a sub-rule and a sibling that's negated. E.g.
710  // variable(is_thread_local) and variable(unless(is_parameter))
711  llvm::SmallDenseMap<int, std::pair<int, SourceRange>, 2>
712  RulesToFirstSpecifiedNegatedSubRule;
713  for (const auto &Rule : Rules) {
714  attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
716  getParentAttrMatcherRule(MatchRule);
717  if (!ParentRule)
718  continue;
719  auto It = Rules.find(*ParentRule);
720  if (It != Rules.end()) {
721  // A sub-rule contradicts a parent rule.
722  Diag(Rule.second.getBegin(),
723  diag::err_pragma_attribute_matcher_subrule_contradicts_rule)
725  << attr::getSubjectMatchRuleSpelling(*ParentRule) << It->second
727  replacementRangeForListElement(*this, Rule.second));
728  // Keep going without removing this rule as it won't change the set of
729  // declarations that receive the attribute.
730  continue;
731  }
732  if (isNegatedAttrMatcherSubRule(MatchRule))
733  RulesToFirstSpecifiedNegatedSubRule.insert(
734  std::make_pair(*ParentRule, Rule));
735  }
736  bool IgnoreNegatedSubRules = false;
737  for (const auto &Rule : Rules) {
738  attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
740  getParentAttrMatcherRule(MatchRule);
741  if (!ParentRule)
742  continue;
743  auto It = RulesToFirstSpecifiedNegatedSubRule.find(*ParentRule);
744  if (It != RulesToFirstSpecifiedNegatedSubRule.end() &&
745  It->second != Rule) {
746  // Negated sub-rule contradicts another sub-rule.
747  Diag(
748  It->second.second.getBegin(),
749  diag::
750  err_pragma_attribute_matcher_negated_subrule_contradicts_subrule)
752  attr::SubjectMatchRule(It->second.first))
753  << attr::getSubjectMatchRuleSpelling(MatchRule) << Rule.second
755  replacementRangeForListElement(*this, It->second.second));
756  // Keep going but ignore all of the negated sub-rules.
757  IgnoreNegatedSubRules = true;
758  RulesToFirstSpecifiedNegatedSubRule.erase(It);
759  }
760  }
761 
762  if (!IgnoreNegatedSubRules) {
763  for (const auto &Rule : Rules)
764  SubjectMatchRules.push_back(attr::SubjectMatchRule(Rule.first));
765  } else {
766  for (const auto &Rule : Rules) {
767  if (!isNegatedAttrMatcherSubRule(attr::SubjectMatchRule(Rule.first)))
768  SubjectMatchRules.push_back(attr::SubjectMatchRule(Rule.first));
769  }
770  }
771  Rules.clear();
772  } else {
773  for (const auto &Rule : StrictSubjectMatchRuleSet) {
774  if (Rules.erase(Rule.first)) {
775  // Add the rule to the set of attribute receivers only if it's supported
776  // in the current language mode.
777  if (Rule.second)
778  SubjectMatchRules.push_back(Rule.first);
779  }
780  }
781  }
782 
783  if (!Rules.empty()) {
784  auto Diagnostic =
785  Diag(PragmaLoc, diag::err_pragma_attribute_invalid_matchers)
786  << Attribute;
788  for (const auto &Rule : Rules) {
789  ExtraRules.push_back(attr::SubjectMatchRule(Rule.first));
791  replacementRangeForListElement(*this, Rule.second));
792  }
793  Diagnostic << attrMatcherRuleListToString(ExtraRules);
794  }
795 
796  if (PragmaAttributeStack.empty()) {
797  Diag(PragmaLoc, diag::err_pragma_attr_attr_no_push);
798  return;
799  }
800 
801  PragmaAttributeStack.back().Entries.push_back(
802  {PragmaLoc, &Attribute, std::move(SubjectMatchRules), /*IsUsed=*/false});
803 }
804 
806  const IdentifierInfo *Namespace) {
807  PragmaAttributeStack.emplace_back();
808  PragmaAttributeStack.back().Loc = PragmaLoc;
809  PragmaAttributeStack.back().Namespace = Namespace;
810 }
811 
813  const IdentifierInfo *Namespace) {
814  if (PragmaAttributeStack.empty()) {
815  Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
816  return;
817  }
818 
819  // Dig back through the stack trying to find the most recently pushed group
820  // that in Namespace. Note that this works fine if no namespace is present,
821  // think of push/pops without namespaces as having an implicit "nullptr"
822  // namespace.
823  for (size_t Index = PragmaAttributeStack.size(); Index;) {
824  --Index;
825  if (PragmaAttributeStack[Index].Namespace == Namespace) {
826  for (const PragmaAttributeEntry &Entry :
827  PragmaAttributeStack[Index].Entries) {
828  if (!Entry.IsUsed) {
829  assert(Entry.Attribute && "Expected an attribute");
830  Diag(Entry.Attribute->getLoc(), diag::warn_pragma_attribute_unused)
831  << *Entry.Attribute;
832  Diag(PragmaLoc, diag::note_pragma_attribute_region_ends_here);
833  }
834  }
835  PragmaAttributeStack.erase(PragmaAttributeStack.begin() + Index);
836  return;
837  }
838  }
839 
840  if (Namespace)
841  Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch)
842  << 0 << Namespace->getName();
843  else
844  Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
845 }
846 
848  if (PragmaAttributeStack.empty())
849  return;
850  for (auto &Group : PragmaAttributeStack) {
851  for (auto &Entry : Group.Entries) {
852  ParsedAttr *Attribute = Entry.Attribute;
853  assert(Attribute && "Expected an attribute");
854  assert(Attribute->isPragmaClangAttribute() &&
855  "expected #pragma clang attribute");
856 
857  // Ensure that the attribute can be applied to the given declaration.
858  bool Applies = false;
859  for (const auto &Rule : Entry.MatchRules) {
860  if (Attribute->appliesToDecl(D, Rule)) {
861  Applies = true;
862  break;
863  }
864  }
865  if (!Applies)
866  continue;
867  Entry.IsUsed = true;
869  ParsedAttributesView Attrs;
870  Attrs.addAtEnd(Attribute);
871  ProcessDeclAttributeList(S, D, Attrs);
873  }
874  }
875 }
876 
878  assert(PragmaAttributeCurrentTargetDecl && "Expected an active declaration");
880  diag::note_pragma_attribute_applied_decl_here);
881 }
882 
884  if (PragmaAttributeStack.empty())
885  return;
886  Diag(PragmaAttributeStack.back().Loc, diag::err_pragma_attribute_no_pop_eof);
887 }
888 
889 void Sema::ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc) {
890  if(On)
892  else
893  OptimizeOffPragmaLocation = PragmaLoc;
894 }
895 
897  // In the future, check other pragmas if they're implemented (e.g. pragma
898  // optimize 0 will probably map to this functionality too).
901 }
902 
904  SourceLocation Loc) {
905  // Don't add a conflicting attribute. No diagnostic is needed.
906  if (FD->hasAttr<MinSizeAttr>() || FD->hasAttr<AlwaysInlineAttr>())
907  return;
908 
909  // Add attributes only if required. Optnone requires noinline as well, but if
910  // either is already present then don't bother adding them.
911  if (!FD->hasAttr<OptimizeNoneAttr>())
912  FD->addAttr(OptimizeNoneAttr::CreateImplicit(Context, Loc));
913  if (!FD->hasAttr<NoInlineAttr>())
914  FD->addAttr(NoInlineAttr::CreateImplicit(Context, Loc));
915 }
916 
917 typedef std::vector<std::pair<unsigned, SourceLocation> > VisStack;
918 enum : unsigned { NoVisibility = ~0U };
919 
921  if (!VisContext)
922  return;
923 
924  NamedDecl *ND = dyn_cast<NamedDecl>(D);
926  return;
927 
928  VisStack *Stack = static_cast<VisStack*>(VisContext);
929  unsigned rawType = Stack->back().first;
930  if (rawType == NoVisibility) return;
931 
932  VisibilityAttr::VisibilityType type
933  = (VisibilityAttr::VisibilityType) rawType;
934  SourceLocation loc = Stack->back().second;
935 
936  D->addAttr(VisibilityAttr::CreateImplicit(Context, type, loc));
937 }
938 
939 /// FreeVisContext - Deallocate and null out VisContext.
941  delete static_cast<VisStack*>(VisContext);
942  VisContext = nullptr;
943 }
944 
945 static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc) {
946  // Put visibility on stack.
947  if (!S.VisContext)
948  S.VisContext = new VisStack;
949 
950  VisStack *Stack = static_cast<VisStack*>(S.VisContext);
951  Stack->push_back(std::make_pair(type, loc));
952 }
953 
955  SourceLocation PragmaLoc) {
956  if (VisType) {
957  // Compute visibility to use.
958  VisibilityAttr::VisibilityType T;
959  if (!VisibilityAttr::ConvertStrToVisibilityType(VisType->getName(), T)) {
960  Diag(PragmaLoc, diag::warn_attribute_unknown_visibility) << VisType;
961  return;
962  }
963  PushPragmaVisibility(*this, T, PragmaLoc);
964  } else {
965  PopPragmaVisibility(false, PragmaLoc);
966  }
967 }
968 
971  unsigned NewValue = FpPragmaStack.hasValue()
974  FPOptionsOverride NewFPFeatures(NewValue);
975  switch (FPC) {
976  case LangOptions::FPM_On:
977  NewFPFeatures.setAllowFPContractWithinStatement();
978  break;
980  NewFPFeatures.setAllowFPContractAcrossStatement();
981  break;
983  NewFPFeatures.setDisallowFPContract();
984  break;
985  }
986  CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
987  FpPragmaStack.Act(Loc, Sema::PSK_Set, StringRef(),
988  NewFPFeatures.getAsOpaqueInt());
989 }
990 
992  unsigned NewValue = FpPragmaStack.hasValue()
995  FPOptionsOverride NewFPFeatures(NewValue);
996  NewFPFeatures.setAllowFPReassociateOverride(IsEnabled);
997  NewValue = NewFPFeatures.getAsOpaqueInt();
998  FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewValue);
999  FPOptionsOverride NewOverrides(NewValue);
1000  CurFPFeatures = NewOverrides.applyOverrides(getLangOpts());
1001 }
1002 
1003 void Sema::setRoundingMode(SourceLocation Loc, llvm::RoundingMode FPR) {
1004  unsigned NewValue = FpPragmaStack.hasValue()
1007  FPOptionsOverride NewFPFeatures(NewValue);
1008  NewFPFeatures.setRoundingModeOverride(FPR);
1009  NewValue = NewFPFeatures.getAsOpaqueInt();
1010  FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewValue);
1011  FPOptionsOverride NewOverrides(NewValue);
1012  CurFPFeatures = NewOverrides.applyOverrides(getLangOpts());
1013 }
1014 
1017  unsigned NewValue = FpPragmaStack.hasValue()
1020  FPOptionsOverride NewFPFeatures(NewValue);
1021  NewFPFeatures.setFPExceptionModeOverride(FPE);
1022  NewValue = NewFPFeatures.getAsOpaqueInt();
1023  FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewValue);
1024  FPOptionsOverride NewOverrides(NewValue);
1025  CurFPFeatures = NewOverrides.applyOverrides(getLangOpts());
1026 }
1027 
1028 void Sema::ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled) {
1029  unsigned NewValue = FpPragmaStack.hasValue()
1032  FPOptionsOverride NewFPFeatures(NewValue);
1033  if (IsEnabled) {
1034  // Verify Microsoft restriction:
1035  // You can't enable fenv_access unless precise semantics are enabled.
1036  // Precise semantics can be enabled either by the float_control
1037  // pragma, or by using the /fp:precise or /fp:strict compiler options
1038  if (!isPreciseFPEnabled())
1039  Diag(Loc, diag::err_pragma_fenv_requires_precise);
1040  NewFPFeatures.setAllowFEnvAccessOverride(true);
1041  } else
1042  NewFPFeatures.setAllowFEnvAccessOverride(false);
1043  NewValue = NewFPFeatures.getAsOpaqueInt();
1044  FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewValue);
1045  FPOptionsOverride NewOverrides(NewValue);
1046  CurFPFeatures = NewOverrides.applyOverrides(getLangOpts());
1047 }
1048 
1049 void Sema::PushNamespaceVisibilityAttr(const VisibilityAttr *Attr,
1050  SourceLocation Loc) {
1051  // Visibility calculations will consider the namespace's visibility.
1052  // Here we just want to note that we're in a visibility context
1053  // which overrides any enclosing #pragma context, but doesn't itself
1054  // contribute visibility.
1055  PushPragmaVisibility(*this, NoVisibility, Loc);
1056 }
1057 
1058 void Sema::PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc) {
1059  if (!VisContext) {
1060  Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
1061  return;
1062  }
1063 
1064  // Pop visibility from stack
1065  VisStack *Stack = static_cast<VisStack*>(VisContext);
1066 
1067  const std::pair<unsigned, SourceLocation> *Back = &Stack->back();
1068  bool StartsWithPragma = Back->first != NoVisibility;
1069  if (StartsWithPragma && IsNamespaceEnd) {
1070  Diag(Back->second, diag::err_pragma_push_visibility_mismatch);
1071  Diag(EndLoc, diag::note_surrounding_namespace_ends_here);
1072 
1073  // For better error recovery, eat all pushes inside the namespace.
1074  do {
1075  Stack->pop_back();
1076  Back = &Stack->back();
1077  StartsWithPragma = Back->first != NoVisibility;
1078  } while (StartsWithPragma);
1079  } else if (!StartsWithPragma && !IsNamespaceEnd) {
1080  Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
1081  Diag(Back->second, diag::note_surrounding_namespace_starts_here);
1082  return;
1083  }
1084 
1085  Stack->pop_back();
1086  // To simplify the implementation, never keep around an empty stack.
1087  if (Stack->empty())
1088  FreeVisContext();
1089 }
void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
Definition: SemaAttr.cpp:805
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:1783
void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, SourceLocation PragmaLoc, attr::ParsedSubjectMatchRuleSet Rules)
Definition: SemaAttr.cpp:693
PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct)
Definition: SemaAttr.cpp:27
A (possibly-)qualified type.
Definition: Type.h:655
ASTConsumer & Consumer
Definition: Sema.h:400
void ActOnPragmaMSStruct(PragmaMSStructKind Kind)
ActOnPragmaMSStruct - Called on well formed #pragma ms_struct [on|off].
Definition: SemaAttr.cpp:397
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:475
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:3633
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:552
bool hasValue() const
Definition: Sema.h:553
static CharSourceRange getTokenRange(SourceRange R)
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1517
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:9573
void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action, PragmaFloatControlKind Value)
ActOnPragmaFloatControl - Call on well-formed #pragma float_control.
Definition: SemaAttr.cpp:417
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:1330
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:647
void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC)
ActOnPragmaFPContract - Called on well formed #pragma {STDC,OPENCL} FP_CONTRACT and #pragma clang fp ...
Definition: SemaAttr.cpp:969
Represents a variable declaration or definition.
Definition: Decl.h:820
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:488
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:3770
void FreeVisContext()
FreeVisContext - Deallocate and null out VisContext.
Definition: SemaAttr.cpp:940
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:1129
void ActOnPragmaFPReassociate(SourceLocation Loc, bool IsEnabled)
Called on well formed #pragma clang fp reassociate.
Definition: SemaAttr.cpp:991
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:174
void getMatchRules(const LangOptions &LangOpts, SmallVectorImpl< std::pair< attr::SubjectMatchRule, bool >> &MatchRules) const
Definition: ParsedAttr.cpp:167
bool isNamespace() const
Definition: DeclBase.h:1900
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:812
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:4627
static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc)
Definition: SemaAttr.cpp:945
void setIsPragmaClangAttribute()
Definition: ParsedAttr.h:448
void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags, StringLiteral *SegmentName)
Called on well formed #pragma section().
Definition: SemaAttr.cpp:579
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:1015
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:497
void AddPushedVisibilityAttribute(Decl *RD)
AddPushedVisibilityAttribute - If &#39;#pragma GCC visibility&#39; was used, add an appropriate visibility at...
Definition: SemaAttr.cpp:920
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:6402
PragmaPackDiagnoseKind
Definition: Sema.h:9595
void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value)
ActOnPragmaDetectMismatch - Call on well-formed #pragma detect_mismatch.
Definition: SemaAttr.cpp:409
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:186
void addAtEnd(ParsedAttr *newAttr)
Definition: ParsedAttr.h:824
void DiagnoseNonDefaultPragmaPack(PragmaPackDiagnoseKind Kind, SourceLocation IncludeLoc)
Definition: SemaAttr.cpp:342
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:1058
void PrintPragmaAttributeInstantiationPoint()
Definition: SemaAttr.cpp:877
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:3016
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:340
StringRef getString() const
Definition: Expr.h:1815
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1062
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1758
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:671
The FPOptions override type is value of the new FPOptions plus a mask showing which fields are actual...
Definition: LangOptions.h:458
std::vector< std::pair< unsigned, SourceLocation > > VisStack
Definition: SemaAttr.cpp:917
const Decl * PragmaAttributeCurrentTargetDecl
The declaration that is currently receiving an attribute from the #pragma attribute stack...
Definition: Sema.h:645
This represents one expression.
Definition: Expr.h:110
FPOptions applyOverrides(const LangOptions &LO)
Definition: LangOptions.h:506
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:1271
void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, StringLiteral *SegmentName)
Called on well-formed #pragma init_seg().
Definition: SemaAttr.cpp:584
bool isPreciseFPEnabled()
Are precise floating point semantics currently enabled?
Definition: Sema.h:9661
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:193
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:593
void ActOnPragmaMSComment(SourceLocation CommentLoc, PragmaMSCommentKind Kind, StringRef Arg)
ActOnPragmaMSComment - Called on well formed #pragma comment(kind, "arg").
Definition: SemaAttr.cpp:401
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:778
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:903
The result type of a method or function.
void DiagnoseUnterminatedPragmaPack()
Definition: SemaAttr.cpp:376
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:896
StringLiteral * CurInitSeg
Last section used with #pragma init_seg.
Definition: Sema.h:618
Kind
QualType getCanonicalType() const
Definition: Type.h:6441
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
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: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:169
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1907
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:3091
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:195
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:1028
void getFromOpaqueInt(unsigned I)
Definition: LangOptions.h:501
unsigned getAsOpaqueInt() const
Definition: LangOptions.h:498
FPOptions CurFPFeatures
Definition: Sema.h:395
static PragmaDetectMismatchDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation Loc, StringRef Name, StringRef Value)
Definition: Decl.cpp:4650
std::pair< IdentifierInfo *, SourceLocation > getPragmaARCCFCodeAuditedInfo() const
The location of the currently-active #pragma clang arc_cf_code_audited begin.
PragmaStack< unsigned > FpPragmaStack
Definition: Sema.h:590
QualType getUnderlyingType() const
Definition: Decl.h:3146
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:390
PragmaClangSection PragmaClangRodataSection
Definition: Sema.h:466
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:847
void DiagnoseUnterminatedPragmaAttribute()
Definition: SemaAttr.cpp:883
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:481
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:483
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:1573
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:1049
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:935
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:471
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:881
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:1354
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1732
Defines the clang::TargetInfo interface.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
Definition: TargetCXXABI.h:168
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:954
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:1891
void setRoundingMode(SourceLocation Loc, llvm::RoundingMode)
Called to set rounding mode for floating point operations.
Definition: SemaAttr.cpp:1003
Strictly preserve the floating-point exception semantics.
Definition: LangOptions.h:199
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
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:889
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:622
ValueType DefaultValue
Definition: Sema.h:556
SourceLocation CurInitSegLoc
Definition: Sema.h:619