clang  13.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  AlignPackInfo InfoVal = AlignPackStack.CurrentValue;
52  AlignPackInfo::Mode M = InfoVal.getAlignMode();
53  bool IsPackSet = InfoVal.IsPackSet();
54  bool IsXLPragma = getLangOpts().XLPragmaPack;
55 
56  // If we are not under mac68k/natural alignment mode and also there is no pack
57  // value, we don't need any attributes.
58  if (!IsPackSet && M != AlignPackInfo::Mac68k && M != AlignPackInfo::Natural)
59  return;
60 
61  if (M == AlignPackInfo::Mac68k && (IsXLPragma || InfoVal.IsAlignAttr())) {
62  RD->addAttr(AlignMac68kAttr::CreateImplicit(Context));
63  } else if (IsPackSet) {
64  // Check to see if we need a max field alignment attribute.
65  RD->addAttr(MaxFieldAlignmentAttr::CreateImplicit(
66  Context, InfoVal.getPackNumber() * 8));
67  }
68 
69  if (IsXLPragma && M == AlignPackInfo::Natural)
70  RD->addAttr(AlignNaturalAttr::CreateImplicit(Context));
71 
72  if (AlignPackIncludeStack.empty())
73  return;
74  // The #pragma align/pack affected a record in an included file, so Clang
75  // should warn when that pragma was written in a file that included the
76  // included file.
77  for (auto &AlignPackedInclude : llvm::reverse(AlignPackIncludeStack)) {
78  if (AlignPackedInclude.CurrentPragmaLocation !=
79  AlignPackStack.CurrentPragmaLocation)
80  break;
81  if (AlignPackedInclude.HasNonDefaultValue)
82  AlignPackedInclude.ShouldWarnOnInclude = true;
83  }
84 }
85 
87  if (MSStructPragmaOn)
88  RD->addAttr(MSStructAttr::CreateImplicit(Context));
89 
90  // FIXME: We should merge AddAlignmentAttributesForRecord with
91  // AddMsStructLayoutForRecord into AddPragmaAttributesForRecord, which takes
92  // all active pragmas and applies them as attributes to class definitions.
93  if (VtorDispStack.CurrentValue != getLangOpts().getVtorDispMode())
94  RD->addAttr(MSVtorDispAttr::CreateImplicit(
95  Context, unsigned(VtorDispStack.CurrentValue)));
96 }
97 
98 template <typename Attribute>
100  CXXRecordDecl *Record) {
101  if (Record->hasAttr<OwnerAttr>() || Record->hasAttr<PointerAttr>())
102  return;
103 
104  for (Decl *Redecl : Record->redecls())
105  Redecl->addAttr(Attribute::CreateImplicit(Context, /*DerefType=*/nullptr));
106 }
107 
109  CXXRecordDecl *UnderlyingRecord) {
110  if (!UnderlyingRecord)
111  return;
112 
113  const auto *Parent = dyn_cast<CXXRecordDecl>(ND->getDeclContext());
114  if (!Parent)
115  return;
116 
117  static llvm::StringSet<> Containers{
118  "array",
119  "basic_string",
120  "deque",
121  "forward_list",
122  "vector",
123  "list",
124  "map",
125  "multiset",
126  "multimap",
127  "priority_queue",
128  "queue",
129  "set",
130  "stack",
131  "unordered_set",
132  "unordered_map",
133  "unordered_multiset",
134  "unordered_multimap",
135  };
136 
137  static llvm::StringSet<> Iterators{"iterator", "const_iterator",
138  "reverse_iterator",
139  "const_reverse_iterator"};
140 
141  if (Parent->isInStdNamespace() && Iterators.count(ND->getName()) &&
142  Containers.count(Parent->getName()))
143  addGslOwnerPointerAttributeIfNotExisting<PointerAttr>(Context,
144  UnderlyingRecord);
145 }
146 
148 
149  QualType Canonical = TD->getUnderlyingType().getCanonicalType();
150 
151  CXXRecordDecl *RD = Canonical->getAsCXXRecordDecl();
152  if (!RD) {
153  if (auto *TST =
154  dyn_cast<TemplateSpecializationType>(Canonical.getTypePtr())) {
155 
156  RD = dyn_cast_or_null<CXXRecordDecl>(
157  TST->getTemplateName().getAsTemplateDecl()->getTemplatedDecl());
158  }
159  }
160 
161  inferGslPointerAttribute(TD, RD);
162 }
163 
165  static llvm::StringSet<> StdOwners{
166  "any",
167  "array",
168  "basic_regex",
169  "basic_string",
170  "deque",
171  "forward_list",
172  "vector",
173  "list",
174  "map",
175  "multiset",
176  "multimap",
177  "optional",
178  "priority_queue",
179  "queue",
180  "set",
181  "stack",
182  "unique_ptr",
183  "unordered_set",
184  "unordered_map",
185  "unordered_multiset",
186  "unordered_multimap",
187  "variant",
188  };
189  static llvm::StringSet<> StdPointers{
190  "basic_string_view",
191  "reference_wrapper",
192  "regex_iterator",
193  };
194 
195  if (!Record->getIdentifier())
196  return;
197 
198  // Handle classes that directly appear in std namespace.
199  if (Record->isInStdNamespace()) {
200  if (Record->hasAttr<OwnerAttr>() || Record->hasAttr<PointerAttr>())
201  return;
202 
203  if (StdOwners.count(Record->getName()))
204  addGslOwnerPointerAttributeIfNotExisting<OwnerAttr>(Context, Record);
205  else if (StdPointers.count(Record->getName()))
206  addGslOwnerPointerAttributeIfNotExisting<PointerAttr>(Context, Record);
207 
208  return;
209  }
210 
211  // Handle nested classes that could be a gsl::Pointer.
212  inferGslPointerAttribute(Record, Record);
213 }
214 
216  SourceLocation PragmaLoc) {
219 
220  switch (Kind) {
221  // For most of the platforms we support, native and natural are the same.
222  // With XL, native is the same as power, natural means something else.
223  //
224  // FIXME: This is not true on Darwin/PPC.
225  case POAK_Native:
226  case POAK_Power:
227  Action = Sema::PSK_Push_Set;
228  break;
229  case POAK_Natural:
230  Action = Sema::PSK_Push_Set;
231  ModeVal = AlignPackInfo::Natural;
232  break;
233 
234  // Note that '#pragma options align=packed' is not equivalent to attribute
235  // packed, it has a different precedence relative to attribute aligned.
236  case POAK_Packed:
237  Action = Sema::PSK_Push_Set;
238  ModeVal = AlignPackInfo::Packed;
239  break;
240 
241  case POAK_Mac68k:
242  // Check if the target supports this.
244  Diag(PragmaLoc, diag::err_pragma_options_align_mac68k_target_unsupported);
245  return;
246  }
247  Action = Sema::PSK_Push_Set;
248  ModeVal = AlignPackInfo::Mac68k;
249  break;
250  case POAK_Reset:
251  // Reset just pops the top of the stack, or resets the current alignment to
252  // default.
253  Action = Sema::PSK_Pop;
254  if (AlignPackStack.Stack.empty()) {
255  if (AlignPackStack.CurrentValue.getAlignMode() != AlignPackInfo::Native ||
256  AlignPackStack.CurrentValue.IsPackAttr()) {
257  Action = Sema::PSK_Reset;
258  } else {
259  Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
260  << "stack empty";
261  return;
262  }
263  }
264  break;
265  }
266 
267  AlignPackInfo Info(ModeVal, getLangOpts().XLPragmaPack);
268 
269  AlignPackStack.Act(PragmaLoc, Action, StringRef(), Info);
270 }
271 
274  PragmaClangSectionKind SecKind,
275  StringRef SecName) {
276  PragmaClangSection *CSec;
277  int SectionFlags = ASTContext::PSF_Read;
278  switch (SecKind) {
279  case PragmaClangSectionKind::PCSK_BSS:
280  CSec = &PragmaClangBSSSection;
282  break;
283  case PragmaClangSectionKind::PCSK_Data:
284  CSec = &PragmaClangDataSection;
285  SectionFlags |= ASTContext::PSF_Write;
286  break;
287  case PragmaClangSectionKind::PCSK_Rodata:
288  CSec = &PragmaClangRodataSection;
289  break;
290  case PragmaClangSectionKind::PCSK_Relro:
291  CSec = &PragmaClangRelroSection;
292  break;
293  case PragmaClangSectionKind::PCSK_Text:
294  CSec = &PragmaClangTextSection;
295  SectionFlags |= ASTContext::PSF_Execute;
296  break;
297  default:
298  llvm_unreachable("invalid clang section kind");
299  }
300 
301  if (Action == PragmaClangSectionAction::PCSA_Clear) {
302  CSec->Valid = false;
303  return;
304  }
305 
306  if (llvm::Error E = isValidSectionSpecifier(SecName)) {
307  Diag(PragmaLoc, diag::err_pragma_section_invalid_for_target)
308  << toString(std::move(E));
309  CSec->Valid = false;
310  return;
311  }
312 
313  if (UnifySection(SecName, SectionFlags, PragmaLoc))
314  return;
315 
316  CSec->Valid = true;
317  CSec->SectionName = std::string(SecName);
318  CSec->PragmaLocation = PragmaLoc;
319 }
320 
322  StringRef SlotLabel, Expr *alignment) {
323  bool IsXLPragma = getLangOpts().XLPragmaPack;
324  // XL pragma pack does not support identifier syntax.
325  if (IsXLPragma && !SlotLabel.empty()) {
326  Diag(PragmaLoc, diag::err_pragma_pack_identifer_not_supported);
327  return;
328  }
329 
330  const AlignPackInfo CurVal = AlignPackStack.CurrentValue;
331  Expr *Alignment = static_cast<Expr *>(alignment);
332 
333  // If specified then alignment must be a "small" power of two.
334  unsigned AlignmentVal = 0;
335  AlignPackInfo::Mode ModeVal = CurVal.getAlignMode();
336 
337  if (Alignment) {
339  Val = Alignment->getIntegerConstantExpr(Context);
340 
341  // pack(0) is like pack(), which just works out since that is what
342  // we use 0 for in PackAttr.
343  if (Alignment->isTypeDependent() || Alignment->isValueDependent() || !Val ||
344  !(*Val == 0 || Val->isPowerOf2()) || Val->getZExtValue() > 16) {
345  Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
346  return; // Ignore
347  }
348 
349  if (IsXLPragma && *Val == 0) {
350  // pack(0) does not work out with XL.
351  Diag(PragmaLoc, diag::err_pragma_pack_invalid_alignment);
352  return; // Ignore
353  }
354 
355  AlignmentVal = (unsigned)Val->getZExtValue();
356  }
357 
358  if (Action == Sema::PSK_Show) {
359  // Show the current alignment, making sure to show the right value
360  // for the default.
361  // FIXME: This should come from the target.
362  AlignmentVal = CurVal.IsPackSet() ? CurVal.getPackNumber() : 8;
363  if (ModeVal == AlignPackInfo::Mac68k &&
364  (IsXLPragma || CurVal.IsAlignAttr()))
365  Diag(PragmaLoc, diag::warn_pragma_pack_show) << "mac68k";
366  else
367  Diag(PragmaLoc, diag::warn_pragma_pack_show) << AlignmentVal;
368  }
369 
370  // MSDN, C/C++ Preprocessor Reference > Pragma Directives > pack:
371  // "#pragma pack(pop, identifier, n) is undefined"
372  if (Action & Sema::PSK_Pop) {
373  if (Alignment && !SlotLabel.empty())
374  Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifier_and_alignment);
375  if (AlignPackStack.Stack.empty()) {
376  assert(CurVal.getAlignMode() == AlignPackInfo::Native &&
377  "Empty pack stack can only be at Native alignment mode.");
378  Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "pack" << "stack empty";
379  }
380  }
381 
382  AlignPackInfo Info(ModeVal, AlignmentVal, IsXLPragma);
383 
384  AlignPackStack.Act(PragmaLoc, Action, SlotLabel, Info);
385 }
386 
388  SourceLocation IncludeLoc) {
390  SourceLocation PrevLocation = AlignPackStack.CurrentPragmaLocation;
391  // Warn about non-default alignment at #includes (without redundant
392  // warnings for the same directive in nested includes).
393  // The warning is delayed until the end of the file to avoid warnings
394  // for files that don't have any records that are affected by the modified
395  // alignment.
396  bool HasNonDefaultValue =
397  AlignPackStack.hasValue() &&
398  (AlignPackIncludeStack.empty() ||
399  AlignPackIncludeStack.back().CurrentPragmaLocation != PrevLocation);
400  AlignPackIncludeStack.push_back(
401  {AlignPackStack.CurrentValue,
402  AlignPackStack.hasValue() ? PrevLocation : SourceLocation(),
403  HasNonDefaultValue, /*ShouldWarnOnInclude*/ false});
404  return;
405  }
406 
408  "invalid kind");
409  AlignPackIncludeState PrevAlignPackState =
410  AlignPackIncludeStack.pop_back_val();
411  // FIXME: AlignPackStack may contain both #pragma align and #pragma pack
412  // information, diagnostics below might not be accurate if we have mixed
413  // pragmas.
414  if (PrevAlignPackState.ShouldWarnOnInclude) {
415  // Emit the delayed non-default alignment at #include warning.
416  Diag(IncludeLoc, diag::warn_pragma_pack_non_default_at_include);
417  Diag(PrevAlignPackState.CurrentPragmaLocation, diag::note_pragma_pack_here);
418  }
419  // Warn about modified alignment after #includes.
420  if (PrevAlignPackState.CurrentValue != AlignPackStack.CurrentValue) {
421  Diag(IncludeLoc, diag::warn_pragma_pack_modified_after_include);
422  Diag(AlignPackStack.CurrentPragmaLocation, diag::note_pragma_pack_here);
423  }
424 }
425 
427  if (AlignPackStack.Stack.empty())
428  return;
429  bool IsInnermost = true;
430 
431  // FIXME: AlignPackStack may contain both #pragma align and #pragma pack
432  // information, diagnostics below might not be accurate if we have mixed
433  // pragmas.
434  for (const auto &StackSlot : llvm::reverse(AlignPackStack.Stack)) {
435  Diag(StackSlot.PragmaPushLocation, diag::warn_pragma_pack_no_pop_eof);
436  // The user might have already reset the alignment, so suggest replacing
437  // the reset with a pop.
438  if (IsInnermost &&
439  AlignPackStack.CurrentValue == AlignPackStack.DefaultValue) {
440  auto DB = Diag(AlignPackStack.CurrentPragmaLocation,
441  diag::note_pragma_pack_pop_instead_reset);
442  SourceLocation FixItLoc =
443  Lexer::findLocationAfterToken(AlignPackStack.CurrentPragmaLocation,
444  tok::l_paren, SourceMgr, LangOpts,
445  /*SkipTrailing=*/false);
446  if (FixItLoc.isValid())
447  DB << FixItHint::CreateInsertion(FixItLoc, "pop");
448  }
449  IsInnermost = false;
450  }
451 }
452 
455 }
456 
458  PragmaMSCommentKind Kind, StringRef Arg) {
459  auto *PCD = PragmaCommentDecl::Create(
460  Context, Context.getTranslationUnitDecl(), CommentLoc, Kind, Arg);
463 }
464 
466  StringRef Value) {
471 }
472 
474  PragmaMsStackAction Action,
476  FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
477  if ((Action == PSK_Push_Set || Action == PSK_Push || Action == PSK_Pop) &&
479  // Push and pop can only occur at file or namespace scope.
480  Diag(Loc, diag::err_pragma_fc_pp_scope);
481  return;
482  }
483  switch (Value) {
484  default:
485  llvm_unreachable("invalid pragma float_control kind");
486  case PFC_Precise:
487  NewFPFeatures.setFPPreciseEnabled(true);
488  FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
489  break;
490  case PFC_NoPrecise:
491  if (CurFPFeatures.getFPExceptionMode() == LangOptions::FPE_Strict)
492  Diag(Loc, diag::err_pragma_fc_noprecise_requires_noexcept);
493  else if (CurFPFeatures.getAllowFEnvAccess())
494  Diag(Loc, diag::err_pragma_fc_noprecise_requires_nofenv);
495  else
496  NewFPFeatures.setFPPreciseEnabled(false);
497  FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
498  break;
499  case PFC_Except:
500  if (!isPreciseFPEnabled())
501  Diag(Loc, diag::err_pragma_fc_except_requires_precise);
502  else
503  NewFPFeatures.setFPExceptionModeOverride(LangOptions::FPE_Strict);
504  FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
505  break;
506  case PFC_NoExcept:
507  NewFPFeatures.setFPExceptionModeOverride(LangOptions::FPE_Ignore);
508  FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
509  break;
510  case PFC_Push:
511  FpPragmaStack.Act(Loc, Sema::PSK_Push_Set, StringRef(), NewFPFeatures);
512  break;
513  case PFC_Pop:
514  if (FpPragmaStack.Stack.empty()) {
515  Diag(Loc, diag::warn_pragma_pop_failed) << "float_control"
516  << "stack empty";
517  return;
518  }
519  FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
520  NewFPFeatures = FpPragmaStack.CurrentValue;
521  break;
522  }
523  CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
524 }
525 
527  LangOptions::PragmaMSPointersToMembersKind RepresentationMethod,
528  SourceLocation PragmaLoc) {
529  MSPointerToMemberRepresentationMethod = RepresentationMethod;
530  ImplicitMSInheritanceAttrLoc = PragmaLoc;
531 }
532 
534  SourceLocation PragmaLoc,
535  MSVtorDispMode Mode) {
536  if (Action & PSK_Pop && VtorDispStack.Stack.empty())
537  Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "vtordisp"
538  << "stack empty";
539  VtorDispStack.Act(PragmaLoc, Action, StringRef(), Mode);
540 }
541 
542 template <>
544  PragmaMsStackAction Action,
545  llvm::StringRef StackSlotLabel,
546  AlignPackInfo Value) {
547  if (Action == PSK_Reset) {
548  CurrentValue = DefaultValue;
549  CurrentPragmaLocation = PragmaLocation;
550  return;
551  }
552  if (Action & PSK_Push)
553  Stack.emplace_back(Slot(StackSlotLabel, CurrentValue, CurrentPragmaLocation,
554  PragmaLocation));
555  else if (Action & PSK_Pop) {
556  if (!StackSlotLabel.empty()) {
557  // If we've got a label, try to find it and jump there.
558  auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
559  return x.StackSlotLabel == StackSlotLabel;
560  });
561  // We found the label, so pop from there.
562  if (I != Stack.rend()) {
563  CurrentValue = I->Value;
564  CurrentPragmaLocation = I->PragmaLocation;
565  Stack.erase(std::prev(I.base()), Stack.end());
566  }
567  } else if (Value.IsXLStack() && Value.IsAlignAttr() &&
568  CurrentValue.IsPackAttr()) {
569  // XL '#pragma align(reset)' would pop the stack until
570  // a current in effect pragma align is popped.
571  auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
572  return x.Value.IsAlignAttr();
573  });
574  // If we found pragma align so pop from there.
575  if (I != Stack.rend()) {
576  Stack.erase(std::prev(I.base()), Stack.end());
577  if (Stack.empty()) {
578  CurrentValue = DefaultValue;
579  CurrentPragmaLocation = PragmaLocation;
580  } else {
581  CurrentValue = Stack.back().Value;
582  CurrentPragmaLocation = Stack.back().PragmaLocation;
583  Stack.pop_back();
584  }
585  }
586  } else if (!Stack.empty()) {
587  // xl '#pragma align' sets the baseline, and `#pragma pack` cannot pop
588  // over the baseline.
589  if (Value.IsXLStack() && Value.IsPackAttr() && CurrentValue.IsAlignAttr())
590  return;
591 
592  // We don't have a label, just pop the last entry.
593  CurrentValue = Stack.back().Value;
594  CurrentPragmaLocation = Stack.back().PragmaLocation;
595  Stack.pop_back();
596  }
597  }
598  if (Action & PSK_Set) {
599  CurrentValue = Value;
600  CurrentPragmaLocation = PragmaLocation;
601  }
602 }
603 
604 bool Sema::UnifySection(StringRef SectionName, int SectionFlags,
605  NamedDecl *Decl) {
606  SourceLocation PragmaLocation;
607  if (auto A = Decl->getAttr<SectionAttr>())
608  if (A->isImplicit())
609  PragmaLocation = A->getLocation();
610  auto SectionIt = Context.SectionInfos.find(SectionName);
611  if (SectionIt == Context.SectionInfos.end()) {
612  Context.SectionInfos[SectionName] =
613  ASTContext::SectionInfo(Decl, PragmaLocation, SectionFlags);
614  return false;
615  }
616  // A pre-declared section takes precedence w/o diagnostic.
617  const auto &Section = SectionIt->second;
618  if (Section.SectionFlags == SectionFlags ||
619  ((SectionFlags & ASTContext::PSF_Implicit) &&
620  !(Section.SectionFlags & ASTContext::PSF_Implicit)))
621  return false;
622  Diag(Decl->getLocation(), diag::err_section_conflict) << Decl << Section;
623  if (Section.Decl)
624  Diag(Section.Decl->getLocation(), diag::note_declared_at)
625  << Section.Decl->getName();
626  if (PragmaLocation.isValid())
627  Diag(PragmaLocation, diag::note_pragma_entered_here);
628  if (Section.PragmaSectionLocation.isValid())
629  Diag(Section.PragmaSectionLocation, diag::note_pragma_entered_here);
630  return true;
631 }
632 
633 bool Sema::UnifySection(StringRef SectionName,
634  int SectionFlags,
635  SourceLocation PragmaSectionLocation) {
636  auto SectionIt = Context.SectionInfos.find(SectionName);
637  if (SectionIt != Context.SectionInfos.end()) {
638  const auto &Section = SectionIt->second;
639  if (Section.SectionFlags == SectionFlags)
640  return false;
641  if (!(Section.SectionFlags & ASTContext::PSF_Implicit)) {
642  Diag(PragmaSectionLocation, diag::err_section_conflict)
643  << "this" << Section;
644  if (Section.Decl)
645  Diag(Section.Decl->getLocation(), diag::note_declared_at)
646  << Section.Decl->getName();
647  if (Section.PragmaSectionLocation.isValid())
648  Diag(Section.PragmaSectionLocation, diag::note_pragma_entered_here);
649  return true;
650  }
651  }
652  Context.SectionInfos[SectionName] =
653  ASTContext::SectionInfo(nullptr, PragmaSectionLocation, SectionFlags);
654  return false;
655 }
656 
657 /// Called on well formed \#pragma bss_seg().
659  PragmaMsStackAction Action,
660  llvm::StringRef StackSlotLabel,
661  StringLiteral *SegmentName,
662  llvm::StringRef PragmaName) {
664  llvm::StringSwitch<PragmaStack<StringLiteral *> *>(PragmaName)
665  .Case("data_seg", &DataSegStack)
666  .Case("bss_seg", &BSSSegStack)
667  .Case("const_seg", &ConstSegStack)
668  .Case("code_seg", &CodeSegStack);
669  if (Action & PSK_Pop && Stack->Stack.empty())
670  Diag(PragmaLocation, diag::warn_pragma_pop_failed) << PragmaName
671  << "stack empty";
672  if (SegmentName) {
673  if (!checkSectionName(SegmentName->getBeginLoc(), SegmentName->getString()))
674  return;
675 
676  if (SegmentName->getString() == ".drectve" &&
678  Diag(PragmaLocation, diag::warn_attribute_section_drectve) << PragmaName;
679  }
680 
681  Stack->Act(PragmaLocation, Action, StackSlotLabel, SegmentName);
682 }
683 
684 /// Called on well formed \#pragma bss_seg().
686  int SectionFlags, StringLiteral *SegmentName) {
687  UnifySection(SegmentName->getString(), SectionFlags, PragmaLocation);
688 }
689 
691  StringLiteral *SegmentName) {
692  // There's no stack to maintain, so we just have a current section. When we
693  // see the default section, reset our current section back to null so we stop
694  // tacking on unnecessary attributes.
695  CurInitSeg = SegmentName->getString() == ".CRT$XCU" ? nullptr : SegmentName;
696  CurInitSegLoc = PragmaLocation;
697 }
698 
699 void Sema::ActOnPragmaUnused(const Token &IdTok, Scope *curScope,
700  SourceLocation PragmaLoc) {
701 
702  IdentifierInfo *Name = IdTok.getIdentifierInfo();
703  LookupResult Lookup(*this, Name, IdTok.getLocation(), LookupOrdinaryName);
704  LookupParsedName(Lookup, curScope, nullptr, true);
705 
706  if (Lookup.empty()) {
707  Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
708  << Name << SourceRange(IdTok.getLocation());
709  return;
710  }
711 
712  VarDecl *VD = Lookup.getAsSingle<VarDecl>();
713  if (!VD) {
714  Diag(PragmaLoc, diag::warn_pragma_unused_expected_var_arg)
715  << Name << SourceRange(IdTok.getLocation());
716  return;
717  }
718 
719  // Warn if this was used before being marked unused.
720  if (VD->isUsed())
721  Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name;
722 
723  VD->addAttr(UnusedAttr::CreateImplicit(Context, IdTok.getLocation(),
725  UnusedAttr::GNU_unused));
726 }
727 
729  IdentifierInfo *Ident;
730  SourceLocation Loc;
731  std::tie(Ident, Loc) = PP.getPragmaARCCFCodeAuditedInfo();
732  if (!Loc.isValid()) return;
733 
734  // Don't add a redundant or conflicting attribute.
735  if (D->hasAttr<CFAuditedTransferAttr>() ||
736  D->hasAttr<CFUnknownTransferAttr>())
737  return;
738 
739  AttributeCommonInfo Info(Ident, SourceRange(Loc),
741  D->addAttr(CFAuditedTransferAttr::CreateImplicit(Context, Info));
742 }
743 
744 namespace {
745 
747 getParentAttrMatcherRule(attr::SubjectMatchRule Rule) {
748  using namespace attr;
749  switch (Rule) {
750  default:
751  return None;
752 #define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
753 #define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \
754  case Value: \
755  return Parent;
756 #include "clang/Basic/AttrSubMatchRulesList.inc"
757  }
758 }
759 
760 bool isNegatedAttrMatcherSubRule(attr::SubjectMatchRule Rule) {
761  using namespace attr;
762  switch (Rule) {
763  default:
764  return false;
765 #define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
766 #define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \
767  case Value: \
768  return IsNegated;
769 #include "clang/Basic/AttrSubMatchRulesList.inc"
770  }
771 }
772 
773 CharSourceRange replacementRangeForListElement(const Sema &S,
774  SourceRange Range) {
775  // Make sure that the ',' is removed as well.
777  Range.getEnd(), tok::comma, S.getSourceManager(), S.getLangOpts(),
778  /*SkipTrailingWhitespaceAndNewLine=*/false);
779  if (AfterCommaLoc.isValid())
780  return CharSourceRange::getCharRange(Range.getBegin(), AfterCommaLoc);
781  else
782  return CharSourceRange::getTokenRange(Range);
783 }
784 
786 attrMatcherRuleListToString(ArrayRef<attr::SubjectMatchRule> Rules) {
787  std::string Result;
788  llvm::raw_string_ostream OS(Result);
789  for (const auto &I : llvm::enumerate(Rules)) {
790  if (I.index())
791  OS << (I.index() == Rules.size() - 1 ? ", and " : ", ");
792  OS << "'" << attr::getSubjectMatchRuleSpelling(I.value()) << "'";
793  }
794  return OS.str();
795 }
796 
797 } // end anonymous namespace
798 
800  ParsedAttr &Attribute, SourceLocation PragmaLoc,
802  Attribute.setIsPragmaClangAttribute();
803  SmallVector<attr::SubjectMatchRule, 4> SubjectMatchRules;
804  // Gather the subject match rules that are supported by the attribute.
806  StrictSubjectMatchRuleSet;
807  Attribute.getMatchRules(LangOpts, StrictSubjectMatchRuleSet);
808 
809  // Figure out which subject matching rules are valid.
810  if (StrictSubjectMatchRuleSet.empty()) {
811  // Check for contradicting match rules. Contradicting match rules are
812  // either:
813  // - a top-level rule and one of its sub-rules. E.g. variable and
814  // variable(is_parameter).
815  // - a sub-rule and a sibling that's negated. E.g.
816  // variable(is_thread_local) and variable(unless(is_parameter))
817  llvm::SmallDenseMap<int, std::pair<int, SourceRange>, 2>
818  RulesToFirstSpecifiedNegatedSubRule;
819  for (const auto &Rule : Rules) {
820  attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
822  getParentAttrMatcherRule(MatchRule);
823  if (!ParentRule)
824  continue;
825  auto It = Rules.find(*ParentRule);
826  if (It != Rules.end()) {
827  // A sub-rule contradicts a parent rule.
828  Diag(Rule.second.getBegin(),
829  diag::err_pragma_attribute_matcher_subrule_contradicts_rule)
831  << attr::getSubjectMatchRuleSpelling(*ParentRule) << It->second
833  replacementRangeForListElement(*this, Rule.second));
834  // Keep going without removing this rule as it won't change the set of
835  // declarations that receive the attribute.
836  continue;
837  }
838  if (isNegatedAttrMatcherSubRule(MatchRule))
839  RulesToFirstSpecifiedNegatedSubRule.insert(
840  std::make_pair(*ParentRule, Rule));
841  }
842  bool IgnoreNegatedSubRules = false;
843  for (const auto &Rule : Rules) {
844  attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
846  getParentAttrMatcherRule(MatchRule);
847  if (!ParentRule)
848  continue;
849  auto It = RulesToFirstSpecifiedNegatedSubRule.find(*ParentRule);
850  if (It != RulesToFirstSpecifiedNegatedSubRule.end() &&
851  It->second != Rule) {
852  // Negated sub-rule contradicts another sub-rule.
853  Diag(
854  It->second.second.getBegin(),
855  diag::
856  err_pragma_attribute_matcher_negated_subrule_contradicts_subrule)
858  attr::SubjectMatchRule(It->second.first))
859  << attr::getSubjectMatchRuleSpelling(MatchRule) << Rule.second
861  replacementRangeForListElement(*this, It->second.second));
862  // Keep going but ignore all of the negated sub-rules.
863  IgnoreNegatedSubRules = true;
864  RulesToFirstSpecifiedNegatedSubRule.erase(It);
865  }
866  }
867 
868  if (!IgnoreNegatedSubRules) {
869  for (const auto &Rule : Rules)
870  SubjectMatchRules.push_back(attr::SubjectMatchRule(Rule.first));
871  } else {
872  for (const auto &Rule : Rules) {
873  if (!isNegatedAttrMatcherSubRule(attr::SubjectMatchRule(Rule.first)))
874  SubjectMatchRules.push_back(attr::SubjectMatchRule(Rule.first));
875  }
876  }
877  Rules.clear();
878  } else {
879  // Each rule in Rules must be a strict subset of the attribute's
880  // SubjectMatch rules. I.e. we're allowed to use
881  // `apply_to=variables(is_global)` on an attrubute with SubjectList<[Var]>,
882  // but should not allow `apply_to=variables` on an attribute which has
883  // `SubjectList<[GlobalVar]>`.
884  for (const auto &StrictRule : StrictSubjectMatchRuleSet) {
885  // First, check for exact match.
886  if (Rules.erase(StrictRule.first)) {
887  // Add the rule to the set of attribute receivers only if it's supported
888  // in the current language mode.
889  if (StrictRule.second)
890  SubjectMatchRules.push_back(StrictRule.first);
891  }
892  }
893  // Check remaining rules for subset matches.
894  auto RulesToCheck = Rules;
895  for (const auto &Rule : RulesToCheck) {
896  attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
897  if (auto ParentRule = getParentAttrMatcherRule(MatchRule)) {
898  if (llvm::any_of(StrictSubjectMatchRuleSet,
899  [ParentRule](const auto &StrictRule) {
900  return StrictRule.first == *ParentRule &&
901  StrictRule.second; // IsEnabled
902  })) {
903  SubjectMatchRules.push_back(MatchRule);
904  Rules.erase(MatchRule);
905  }
906  }
907  }
908  }
909 
910  if (!Rules.empty()) {
911  auto Diagnostic =
912  Diag(PragmaLoc, diag::err_pragma_attribute_invalid_matchers)
913  << Attribute;
915  for (const auto &Rule : Rules) {
916  ExtraRules.push_back(attr::SubjectMatchRule(Rule.first));
918  replacementRangeForListElement(*this, Rule.second));
919  }
920  Diagnostic << attrMatcherRuleListToString(ExtraRules);
921  }
922 
923  if (PragmaAttributeStack.empty()) {
924  Diag(PragmaLoc, diag::err_pragma_attr_attr_no_push);
925  return;
926  }
927 
928  PragmaAttributeStack.back().Entries.push_back(
929  {PragmaLoc, &Attribute, std::move(SubjectMatchRules), /*IsUsed=*/false});
930 }
931 
933  const IdentifierInfo *Namespace) {
934  PragmaAttributeStack.emplace_back();
935  PragmaAttributeStack.back().Loc = PragmaLoc;
936  PragmaAttributeStack.back().Namespace = Namespace;
937 }
938 
940  const IdentifierInfo *Namespace) {
941  if (PragmaAttributeStack.empty()) {
942  Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
943  return;
944  }
945 
946  // Dig back through the stack trying to find the most recently pushed group
947  // that in Namespace. Note that this works fine if no namespace is present,
948  // think of push/pops without namespaces as having an implicit "nullptr"
949  // namespace.
950  for (size_t Index = PragmaAttributeStack.size(); Index;) {
951  --Index;
952  if (PragmaAttributeStack[Index].Namespace == Namespace) {
953  for (const PragmaAttributeEntry &Entry :
954  PragmaAttributeStack[Index].Entries) {
955  if (!Entry.IsUsed) {
956  assert(Entry.Attribute && "Expected an attribute");
957  Diag(Entry.Attribute->getLoc(), diag::warn_pragma_attribute_unused)
958  << *Entry.Attribute;
959  Diag(PragmaLoc, diag::note_pragma_attribute_region_ends_here);
960  }
961  }
962  PragmaAttributeStack.erase(PragmaAttributeStack.begin() + Index);
963  return;
964  }
965  }
966 
967  if (Namespace)
968  Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch)
969  << 0 << Namespace->getName();
970  else
971  Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
972 }
973 
975  if (PragmaAttributeStack.empty())
976  return;
977  for (auto &Group : PragmaAttributeStack) {
978  for (auto &Entry : Group.Entries) {
979  ParsedAttr *Attribute = Entry.Attribute;
980  assert(Attribute && "Expected an attribute");
981  assert(Attribute->isPragmaClangAttribute() &&
982  "expected #pragma clang attribute");
983 
984  // Ensure that the attribute can be applied to the given declaration.
985  bool Applies = false;
986  for (const auto &Rule : Entry.MatchRules) {
987  if (Attribute->appliesToDecl(D, Rule)) {
988  Applies = true;
989  break;
990  }
991  }
992  if (!Applies)
993  continue;
994  Entry.IsUsed = true;
996  ParsedAttributesView Attrs;
997  Attrs.addAtEnd(Attribute);
998  ProcessDeclAttributeList(S, D, Attrs);
1000  }
1001  }
1002 }
1003 
1005  assert(PragmaAttributeCurrentTargetDecl && "Expected an active declaration");
1007  diag::note_pragma_attribute_applied_decl_here);
1008 }
1009 
1011  if (PragmaAttributeStack.empty())
1012  return;
1013  Diag(PragmaAttributeStack.back().Loc, diag::err_pragma_attribute_no_pop_eof);
1014 }
1015 
1016 void Sema::ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc) {
1017  if(On)
1019  else
1020  OptimizeOffPragmaLocation = PragmaLoc;
1021 }
1022 
1024  // In the future, check other pragmas if they're implemented (e.g. pragma
1025  // optimize 0 will probably map to this functionality too).
1028 }
1029 
1031  SourceLocation Loc) {
1032  // Don't add a conflicting attribute. No diagnostic is needed.
1033  if (FD->hasAttr<MinSizeAttr>() || FD->hasAttr<AlwaysInlineAttr>())
1034  return;
1035 
1036  // Add attributes only if required. Optnone requires noinline as well, but if
1037  // either is already present then don't bother adding them.
1038  if (!FD->hasAttr<OptimizeNoneAttr>())
1039  FD->addAttr(OptimizeNoneAttr::CreateImplicit(Context, Loc));
1040  if (!FD->hasAttr<NoInlineAttr>())
1041  FD->addAttr(NoInlineAttr::CreateImplicit(Context, Loc));
1042 }
1043 
1044 typedef std::vector<std::pair<unsigned, SourceLocation> > VisStack;
1045 enum : unsigned { NoVisibility = ~0U };
1046 
1048  if (!VisContext)
1049  return;
1050 
1051  NamedDecl *ND = dyn_cast<NamedDecl>(D);
1053  return;
1054 
1055  VisStack *Stack = static_cast<VisStack*>(VisContext);
1056  unsigned rawType = Stack->back().first;
1057  if (rawType == NoVisibility) return;
1058 
1059  VisibilityAttr::VisibilityType type
1060  = (VisibilityAttr::VisibilityType) rawType;
1061  SourceLocation loc = Stack->back().second;
1062 
1063  D->addAttr(VisibilityAttr::CreateImplicit(Context, type, loc));
1064 }
1065 
1066 /// FreeVisContext - Deallocate and null out VisContext.
1068  delete static_cast<VisStack*>(VisContext);
1069  VisContext = nullptr;
1070 }
1071 
1072 static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc) {
1073  // Put visibility on stack.
1074  if (!S.VisContext)
1075  S.VisContext = new VisStack;
1076 
1077  VisStack *Stack = static_cast<VisStack*>(S.VisContext);
1078  Stack->push_back(std::make_pair(type, loc));
1079 }
1080 
1082  SourceLocation PragmaLoc) {
1083  if (VisType) {
1084  // Compute visibility to use.
1085  VisibilityAttr::VisibilityType T;
1086  if (!VisibilityAttr::ConvertStrToVisibilityType(VisType->getName(), T)) {
1087  Diag(PragmaLoc, diag::warn_attribute_unknown_visibility) << VisType;
1088  return;
1089  }
1090  PushPragmaVisibility(*this, T, PragmaLoc);
1091  } else {
1092  PopPragmaVisibility(false, PragmaLoc);
1093  }
1094 }
1095 
1098  FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1099  switch (FPC) {
1100  case LangOptions::FPM_On:
1101  NewFPFeatures.setAllowFPContractWithinStatement();
1102  break;
1103  case LangOptions::FPM_Fast:
1104  NewFPFeatures.setAllowFPContractAcrossStatement();
1105  break;
1106  case LangOptions::FPM_Off:
1107  NewFPFeatures.setDisallowFPContract();
1108  break;
1110  llvm_unreachable("Should not happen");
1111  }
1112  FpPragmaStack.Act(Loc, Sema::PSK_Set, StringRef(), NewFPFeatures);
1113  CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
1114 }
1115 
1117  FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1118  NewFPFeatures.setAllowFPReassociateOverride(IsEnabled);
1119  FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
1120  CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
1121 }
1122 
1123 void Sema::setRoundingMode(SourceLocation Loc, llvm::RoundingMode FPR) {
1124  // C2x: 7.6.2p3 If the FE_DYNAMIC mode is specified and FENV_ACCESS is "off",
1125  // the translator may assume that the default rounding mode is in effect.
1126  if (FPR == llvm::RoundingMode::Dynamic &&
1127  !CurFPFeatures.getAllowFEnvAccess() &&
1128  CurFPFeatures.getFPExceptionMode() == LangOptions::FPE_Ignore)
1129  FPR = llvm::RoundingMode::NearestTiesToEven;
1130 
1131  FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1132  NewFPFeatures.setRoundingModeOverride(FPR);
1133  FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
1134  CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
1135 }
1136 
1139  FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1140  NewFPFeatures.setFPExceptionModeOverride(FPE);
1141  FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
1142  CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
1143 }
1144 
1145 void Sema::ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled) {
1146  FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1147  auto LO = getLangOpts();
1148  if (IsEnabled) {
1149  // Verify Microsoft restriction:
1150  // You can't enable fenv_access unless precise semantics are enabled.
1151  // Precise semantics can be enabled either by the float_control
1152  // pragma, or by using the /fp:precise or /fp:strict compiler options
1153  if (!isPreciseFPEnabled())
1154  Diag(Loc, diag::err_pragma_fenv_requires_precise);
1155  NewFPFeatures.setAllowFEnvAccessOverride(true);
1156  // Enabling FENV access sets the RoundingMode to Dynamic.
1157  // and ExceptionBehavior to Strict
1158  NewFPFeatures.setRoundingModeOverride(llvm::RoundingMode::Dynamic);
1159  NewFPFeatures.setFPExceptionModeOverride(LangOptions::FPE_Strict);
1160  } else {
1161  NewFPFeatures.setAllowFEnvAccessOverride(false);
1162  }
1163  FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
1164  CurFPFeatures = NewFPFeatures.applyOverrides(LO);
1165 }
1166 
1169  setExceptionMode(Loc, FPE);
1170 }
1171 
1172 void Sema::PushNamespaceVisibilityAttr(const VisibilityAttr *Attr,
1173  SourceLocation Loc) {
1174  // Visibility calculations will consider the namespace's visibility.
1175  // Here we just want to note that we're in a visibility context
1176  // which overrides any enclosing #pragma context, but doesn't itself
1177  // contribute visibility.
1178  PushPragmaVisibility(*this, NoVisibility, Loc);
1179 }
1180 
1181 void Sema::PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc) {
1182  if (!VisContext) {
1183  Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
1184  return;
1185  }
1186 
1187  // Pop visibility from stack
1188  VisStack *Stack = static_cast<VisStack*>(VisContext);
1189 
1190  const std::pair<unsigned, SourceLocation> *Back = &Stack->back();
1191  bool StartsWithPragma = Back->first != NoVisibility;
1192  if (StartsWithPragma && IsNamespaceEnd) {
1193  Diag(Back->second, diag::err_pragma_push_visibility_mismatch);
1194  Diag(EndLoc, diag::note_surrounding_namespace_ends_here);
1195 
1196  // For better error recovery, eat all pushes inside the namespace.
1197  do {
1198  Stack->pop_back();
1199  Back = &Stack->back();
1200  StartsWithPragma = Back->first != NoVisibility;
1201  } while (StartsWithPragma);
1202  } else if (!StartsWithPragma && !IsNamespaceEnd) {
1203  Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
1204  Diag(Back->second, diag::note_surrounding_namespace_starts_here);
1205  return;
1206  }
1207 
1208  Stack->pop_back();
1209  // To simplify the implementation, never keep around an empty stack.
1210  if (Stack->empty())
1211  FreeVisContext();
1212 }
1213 
1214 template <typename Ty>
1215 static bool checkCommonAttributeFeatures(Sema& S, const Ty *Node,
1216  const ParsedAttr& A) {
1217  // Several attributes carry different semantics than the parsing requires, so
1218  // those are opted out of the common argument checks.
1219  //
1220  // We also bail on unknown and ignored attributes because those are handled
1221  // as part of the target-specific handling logic.
1223  return false;
1224  // Check whether the attribute requires specific language extensions to be
1225  // enabled.
1226  if (!A.diagnoseLangOpts(S))
1227  return true;
1228  // Check whether the attribute appertains to the given subject.
1229  if (!A.diagnoseAppertainsTo(S, Node))
1230  return true;
1231  // Check whether the attribute is mutually exclusive with other attributes
1232  // that have already been applied to the declaration.
1233  if (!A.diagnoseMutualExclusion(S, Node))
1234  return true;
1235  // Check whether the attribute exists in the target architecture.
1236  if (S.CheckAttrTarget(A))
1237  return true;
1238 
1239  if (A.hasCustomParsing())
1240  return false;
1241 
1242  if (A.getMinArgs() == A.getMaxArgs()) {
1243  // If there are no optional arguments, then checking for the argument count
1244  // is trivial.
1245  if (!A.checkExactlyNumArgs(S, A.getMinArgs()))
1246  return true;
1247  } else {
1248  // There are optional arguments, so checking is slightly more involved.
1249  if (A.getMinArgs() && !A.checkAtLeastNumArgs(S, A.getMinArgs()))
1250  return true;
1251  else if (!A.hasVariadicArg() && A.getMaxArgs() &&
1252  !A.checkAtMostNumArgs(S, A.getMaxArgs()))
1253  return true;
1254  }
1255 
1256  return false;
1257 }
1258 
1261 }
1264 }
clang::Sema::UnifySection
bool UnifySection(StringRef SectionName, int SectionFlags, NamedDecl *TheDecl)
Definition: SemaAttr.cpp:604
clang::Sema::CurContext
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:420
clang::ParsedAttr::getMinArgs
unsigned getMinArgs() const
Definition: ParsedAttr.cpp:148
clang::FPOptionsOverride::setAllowFPContractAcrossStatement
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:590
clang::Sema::PragmaOptionsAlignKind
PragmaOptionsAlignKind
Definition: Sema.h:9850
clang::Sema::PragmaClangRelroSection
PragmaClangSection PragmaClangRelroSection
Definition: Sema.h:472
clang::Decl::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:422
type
clang::ParsedAttr::getKind
AttributeCommonInfo::Kind getKind() const
Definition: ParsedAttr.h:674
clang::Sema::ActOnPragmaUnused
void ActOnPragmaUnused(const Token &Identifier, Scope *curScope, SourceLocation PragmaLoc)
ActOnPragmaUnused - Called on well-formed '#pragma unused'.
Definition: SemaAttr.cpp:699
clang::Sema::inferGslOwnerPointerAttribute
void inferGslOwnerPointerAttribute(CXXRecordDecl *Record)
Add [[gsl::Owner]] and [[gsl::Pointer]] attributes for std:: types.
Definition: SemaAttr.cpp:164
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:212
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::Decl::hasAttr
bool hasAttr() const
Definition: DeclBase.h:547
clang::Sema::ActOnPragmaMSInitSeg
void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, StringLiteral *SegmentName)
Called on well-formed #pragma init_seg().
Definition: SemaAttr.cpp:690
clang::FixItHint::CreateInsertion
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
clang::Sema::CurInitSeg
StringLiteral * CurInitSeg
Last section used with #pragma init_seg.
Definition: Sema.h:722
clang::Sema::FreeVisContext
void FreeVisContext()
FreeVisContext - Deallocate and null out VisContext.
Definition: SemaAttr.cpp:1067
clang::Decl::Decl
Decl()=delete
clang::Sema::SourceMgr
SourceManager & SourceMgr
Definition: Sema.h:411
clang::Sema::DataSegStack
PragmaStack< StringLiteral * > DataSegStack
Definition: Sema.h:688
clang::PFC_Pop
@ PFC_Pop
Definition: PragmaKinds.h:35
clang::Sema::AlignPackInfo::IsPackSet
bool IsPackSet() const
Definition: Sema.h:545
clang::Sema::ActOnPragmaMSSeg
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:658
SemaInternal.h
clang::Sema::ActOnPragmaFloatControl
void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action, PragmaFloatControlKind Value)
ActOnPragmaFloatControl - Call on well-formed #pragma float_control.
Definition: SemaAttr.cpp:473
clang::StringLiteral::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1932
llvm::SmallVector< attr::SubjectMatchRule, 4 >
Lookup.h
clang::ParsedAttr::appliesToDecl
bool appliesToDecl(const Decl *D, attr::SubjectMatchRule MatchRule) const
Definition: ParsedAttr.cpp:170
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:89
clang::Sema::ActOnPragmaDetectMismatch
void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value)
ActOnPragmaDetectMismatch - Call on well-formed #pragma detect_mismatch.
Definition: SemaAttr.cpp:465
clang::Sema::CodeSegStack
PragmaStack< StringLiteral * > CodeSegStack
Definition: Sema.h:691
clang::TargetCXXABI::isMicrosoft
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
Definition: TargetCXXABI.h:132
clang::Sema::AddPushedVisibilityAttribute
void AddPushedVisibilityAttribute(Decl *RD)
AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used, add an appropriate visibility at...
Definition: SemaAttr.cpp:1047
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:223
TargetInfo.h
clang::Sema::DiagnoseUnterminatedPragmaAttribute
void DiagnoseUnterminatedPragmaAttribute()
Definition: SemaAttr.cpp:1010
clang::Sema::PragmaStack::Stack
SmallVector< Slot, 2 > Stack
Definition: Sema.h:662
clang::Sema::FpPragmaStack
PragmaStack< FPOptionsOverride > FpPragmaStack
Definition: Sema.h:694
clang::Sema::checkSectionName
bool checkSectionName(SourceLocation LiteralLoc, StringRef Str)
Definition: SemaDeclAttr.cpp:3016
clang::Sema::ProcessDeclAttributeList
void ProcessDeclAttributeList(Scope *S, Decl *D, const ParsedAttributesView &AL, bool IncludeCXX11Attributes=true)
ProcessDeclAttributeList - Apply all the decl attributes in the specified attribute list to the speci...
Definition: SemaDeclAttr.cpp:8300
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:668
Attr.h
clang::Sema::AlignPackInfo::Packed
@ Packed
Definition: Sema.h:490
clang::Sema::PragmaStack
Definition: Sema.h:588
clang::Token::getIdentifierInfo
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:179
clang::QualType::getCanonicalType
QualType getCanonicalType() const
Definition: Type.h:6466
clang::LookupResult
Represents the results of name lookup.
Definition: Lookup.h:46
clang::TargetInfo::getCXXABI
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:1177
clang::Sema::Diag
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: Sema.cpp:1774
clang::Decl::isUsed
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
clang::LangOptions::FPM_On
@ FPM_On
Definition: LangOptions.h:206
clang::ASTContext::PSF_Execute
@ PSF_Execute
Definition: ASTContext.h:3130
clang::ASTContext::PSF_Write
@ PSF_Write
Definition: ASTContext.h:3129
clang::Sema::getSourceManager
SourceManager & getSourceManager() const
Definition: Sema.h:1539
clang::Sema::ActOnPragmaAttributePop
void ActOnPragmaAttributePop(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
Called on well-formed '#pragma clang attribute pop'.
Definition: SemaAttr.cpp:939
clang::Sema::PSK_Push_Set
@ PSK_Push_Set
Definition: Sema.h:481
llvm::Optional
Definition: LLVM.h:40
clang::Sema::setRoundingMode
void setRoundingMode(SourceLocation Loc, llvm::RoundingMode)
Called to set constant rounding mode for floating point operations.
Definition: SemaAttr.cpp:1123
clang::Sema::AddMsStructLayoutForRecord
void AddMsStructLayoutForRecord(RecordDecl *RD)
AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
Definition: SemaAttr.cpp:86
clang::Sema::AlignPackIncludeState::CurrentValue
AlignPackInfo CurrentValue
Definition: Sema.h:682
clang::Decl::getAttr
T * getAttr() const
Definition: DeclBase.h:543
clang::Sema::AlignPackInfo::Mode
Mode
Definition: Sema.h:490
clang::Sema::ActOnPragmaMSSection
void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags, StringLiteral *SegmentName)
Called on well formed #pragma section().
Definition: SemaAttr.cpp:685
clang::FPOptionsOverride::setFPPreciseEnabled
void setFPPreciseEnabled(bool Value)
Definition: LangOptions.h:598
VisStack
std::vector< std::pair< unsigned, SourceLocation > > VisStack
Definition: SemaAttr.cpp:1044
clang::MSVtorDispMode
MSVtorDispMode
In the Microsoft ABI, this controls the placement of virtual displacement members used to implement v...
Definition: LangOptions.h:54
clang::Sema::ActOnPragmaAttributeEmptyPush
void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
Definition: SemaAttr.cpp:932
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
clang::ParsedAttr::checkAtLeastNumArgs
bool checkAtLeastNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has at least as many args as Num.
Definition: ParsedAttr.cpp:237
clang::ParsedAttr::setIsPragmaClangAttribute
void setIsPragmaClangAttribute()
Definition: ParsedAttr.h:460
clang::Sema::POAK_Natural
@ POAK_Natural
Definition: Sema.h:9852
clang::ASTContext::getTranslationUnitDecl
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:994
clang::Sema::setExceptionMode
void setExceptionMode(SourceLocation Loc, LangOptions::FPExceptionModeKind)
Called to set exception behavior for floating point operations.
Definition: SemaAttr.cpp:1137
clang::PFC_Except
@ PFC_Except
Definition: PragmaKinds.h:32
clang::Sema::ActOnPragmaFEnvAccess
void ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled)
ActOnPragmaFenvAccess - Called on well formed #pragma STDC FENV_ACCESS.
Definition: SemaAttr.cpp:1145
clang::attr::SubjectMatchRule
SubjectMatchRule
A list of all the recognized kinds of attributes.
Definition: AttrSubjectMatchRules.h:19
clang::ParsedAttr::checkExactlyNumArgs
bool checkExactlyNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has exactly as many args as Num.
Definition: ParsedAttr.cpp:232
clang::Sema::Context
ASTContext & Context
Definition: Sema.h:408
Preprocessor.h
clang::Sema::ActOnPragmaOptimize
void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc)
Called on well formed #pragma clang optimize.
Definition: SemaAttr.cpp:1016
clang::Sema::PSK_Set
@ PSK_Set
Definition: Sema.h:477
clang::Sema::PushNamespaceVisibilityAttr
void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, SourceLocation Loc)
PushNamespaceVisibilityAttr - Note that we've entered a namespace with a visibility attribute.
Definition: SemaAttr.cpp:1172
clang::Sema::AddPragmaAttributes
void AddPragmaAttributes(Scope *S, Decl *D)
Adds the attributes that have been specified using the '#pragma clang attribute push' directives to t...
Definition: SemaAttr.cpp:974
clang::Diagnostic
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1532
clang::Sema::getLangOpts
const LangOptions & getLangOpts() const
Definition: Sema.h:1534
clang::ASTContext::PSF_ZeroInit
@ PSF_ZeroInit
Definition: ASTContext.h:3132
U
clang::CharSourceRange::getCharRange
static CharSourceRange getCharRange(SourceRange R)
Definition: SourceLocation.h:267
clang::Expr::getIntegerConstantExpr
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.
Definition: ExprConstant.cpp:15498
clang::AttributeCommonInfo::UnknownAttribute
@ UnknownAttribute
Definition: AttributeCommonInfo.h:58
clang::NamedDecl::getExplicitVisibility
Optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
Definition: Decl.cpp:1209
clang::Sema::isPreciseFPEnabled
bool isPreciseFPEnabled()
Are precise floating point semantics currently enabled?
Definition: Sema.h:9937
clang::Expr::isTypeDependent
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:185
clang::PragmaFloatControlKind
PragmaFloatControlKind
Definition: PragmaKinds.h:28
clang::Sema::CurFPFeatures
FPOptions CurFPFeatures
Definition: Sema.h:404
clang::Sema::PSK_Reset
@ PSK_Reset
Definition: Sema.h:476
clang::Sema::CurFPFeatureOverrides
FPOptionsOverride CurFPFeatureOverrides()
Definition: Sema.h:695
Node
DynTypedNode Node
Definition: ASTMatchFinder.cpp:67
clang::ParsedAttr::getMaxArgs
unsigned getMaxArgs() const
Definition: ParsedAttr.cpp:150
clang::Sema::ActOnPragmaOptionsAlign
void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, SourceLocation PragmaLoc)
ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
Definition: SemaAttr.cpp:215
clang::Scope
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
clang::Decl::isInStdNamespace
bool isInStdNamespace() const
Definition: DeclBase.cpp:394
clang::Sema::VisContext
void * VisContext
VisContext - Manages the stack for #pragma GCC visibility.
Definition: Sema.h:726
clang::threadSafety::sx::toString
std::string toString(const til::SExpr *E)
Definition: ThreadSafetyCommon.h:89
clang::ASTContext::PSF_Read
@ PSF_Read
Definition: ASTContext.h:3128
clang::FPOptionsOverride
Represents difference between two FPOptions values.
Definition: LangOptions.h:560
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
clang::LangOptions::FPExceptionModeKind
FPExceptionModeKind
Possible floating point exception behavior.
Definition: LangOptions.h:220
clang::Sema::AlignPackInfo::Native
@ Native
Definition: Sema.h:490
clang::Sema::PragmaStackSentinelRAII::PragmaStackSentinelRAII
PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct)
Definition: SemaAttr.cpp:27
clang::Sema::isValidSectionSpecifier
llvm::Error isValidSectionSpecifier(StringRef Str)
Used to implement to perform semantic checking on attribute((section("foo"))) specifiers.
Definition: SemaDeclAttr.cpp:3004
clang::Sema::ActOnPragmaPack
void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, StringRef SlotLabel, Expr *Alignment)
ActOnPragmaPack - Called on well formed #pragma pack(...).
Definition: SemaAttr.cpp:321
clang::FPOptionsOverride::applyOverrides
FPOptions applyOverrides(FPOptions Base)
Definition: LangOptions.h:625
clang::Sema::AlignPackInfo
Definition: Sema.h:486
clang::Sema::MSStructPragmaOn
bool MSStructPragmaOn
Definition: Sema.h:430
clang::Sema::PragmaClangSection::SectionName
std::string SectionName
Definition: Sema.h:464
clang::Sema::Diags
DiagnosticsEngine & Diags
Definition: Sema.h:410
clang::Sema::ActOnPragmaFPContract
void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC)
ActOnPragmaFPContract - Called on well formed #pragma {STDC,OPENCL} FP_CONTRACT and #pragma clang fp ...
Definition: SemaAttr.cpp:1096
clang::TypedefNameDecl::getUnderlyingType
QualType getUnderlyingType() const
Definition: Decl.h:3196
clang::DeclContext::isTranslationUnit
bool isTranslationUnit() const
Definition: DeclBase.h:1935
clang::Sema::PSK_Push
@ PSK_Push
Definition: Sema.h:478
clang::ParsedAttr
ParsedAttr - Represents a syntactic attribute.
Definition: ParsedAttr.h:208
clang::attr::getSubjectMatchRuleSpelling
const char * getSubjectMatchRuleSpelling(SubjectMatchRule Rule)
Definition: Attributes.cpp:28
clang::ParsedAttributesView::addAtEnd
void addAtEnd(ParsedAttr *newAttr)
Definition: ParsedAttr.h:878
Expr.h
clang::Redeclarable::redecls
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: Redeclarable.h:294
clang::PragmaDetectMismatchDecl::Create
static PragmaDetectMismatchDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation Loc, StringRef Name, StringRef Value)
Definition: Decl.cpp:4763
clang::Sema::PragmaClangTextSection
PragmaClangSection PragmaClangTextSection
Definition: Sema.h:473
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:848
clang::PFC_Precise
@ PFC_Precise
Definition: PragmaKinds.h:30
clang::StringLiteral
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1757
clang::Sema::AlignPackIncludeStack
SmallVector< AlignPackIncludeState, 8 > AlignPackIncludeStack
Definition: Sema.h:686
clang::Type::getAsCXXRecordDecl
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1753
clang::Sema::LookupParsedName
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...
Definition: SemaLookup.cpp:2448
clang::DeclContext::isNamespace
bool isNamespace() const
Definition: DeclBase.h:1944
clang::Sema::PragmaStackSentinelRAII::~PragmaStackSentinelRAII
~PragmaStackSentinelRAII()
Definition: SemaAttr.cpp:40
clang::PFC_Push
@ PFC_Push
Definition: PragmaKinds.h:34
x
IRgen optimization opportunities The common pattern of short x
Definition: README.txt:7
clang::Sema::PragmaClangSectionAction
PragmaClangSectionAction
Definition: Sema.h:458
clang::Sema::AlignPackInfo::Natural
@ Natural
Definition: Sema.h:490
clang::Sema::CurInitSegLoc
SourceLocation CurInitSegLoc
Definition: Sema.h:723
clang::Sema::ActOnPragmaVisibility
void ActOnPragmaVisibility(const IdentifierInfo *VisType, SourceLocation PragmaLoc)
ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
Definition: SemaAttr.cpp:1081
clang::ASTConsumer::HandleTopLevelDecl
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
Definition: ASTConsumer.cpp:18
clang::Sema::LangOpts
const LangOptions & LangOpts
Definition: Sema.h:406
clang::PragmaCommentDecl::Create
static PragmaCommentDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation CommentLoc, PragmaMSCommentKind CommentKind, StringRef Arg)
Definition: Decl.cpp:4740
clang::PFC_NoExcept
@ PFC_NoExcept
Definition: PragmaKinds.h:33
clang::Sema::PragmaStack::Act
void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, llvm::StringRef StackSlotLabel, ValueType Value)
Definition: Sema.h:601
clang::Sema::PSK_Show
@ PSK_Show
Definition: Sema.h:480
clang::transformer::EditKind::Range
@ Range
clang::LangOptions::FPModeKind
FPModeKind
Definition: LangOptions.h:201
clang::Sema::PragmaClangSection
Definition: Sema.h:463
clang::Sema::ActOnPragmaFPExceptions
void ActOnPragmaFPExceptions(SourceLocation Loc, LangOptions::FPExceptionModeKind)
Called on well formed '#pragma clang fp' that has option 'exceptions'.
Definition: SemaAttr.cpp:1167
clang::Sema::PragmaClangBSSSection
PragmaClangSection PragmaClangBSSSection
Definition: Sema.h:469
clang::ParsedAttr::hasVariadicArg
bool hasVariadicArg() const
Definition: ParsedAttr.cpp:208
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
clang::ParsedAttr::checkAtMostNumArgs
bool checkAtMostNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has at most as many args as Num.
Definition: ParsedAttr.cpp:242
clang::Sema::BSSSegStack
PragmaStack< StringLiteral * > BSSSegStack
Definition: Sema.h:689
clang::TargetInfo::hasAlignMac68kSupport
bool hasAlignMac68kSupport() const
Check whether this target support '#pragma options align=mac68k'.
Definition: TargetInfo.h:814
clang::ParsedAttr::diagnoseMutualExclusion
bool diagnoseMutualExclusion(class Sema &S, const Decl *D) const
Definition: ParsedAttr.cpp:166
clang::Sema::POAK_Reset
@ POAK_Reset
Definition: Sema.h:9856
clang::LookupResult::empty
bool empty() const
Return true if no decls were found.
Definition: Lookup.h:339
clang::Sema::AlignPackIncludeState::CurrentPragmaLocation
SourceLocation CurrentPragmaLocation
Definition: Sema.h:683
clang::Sema::PrintPragmaAttributeInstantiationPoint
void PrintPragmaAttributeInstantiationPoint()
Definition: SemaAttr.cpp:1004
clang::Sema::ActOnPragmaMSVtorDisp
void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, SourceLocation PragmaLoc, MSVtorDispMode Value)
Called on well formed #pragma vtordisp().
Definition: SemaAttr.cpp:533
clang::Sema::checkCommonAttributeFeatures
bool checkCommonAttributeFeatures(const Decl *D, const ParsedAttr &A)
Handles semantic checking for features that are common to all attributes, such as checking whether a ...
Definition: SemaAttr.cpp:1259
clang::Sema::ActOnPragmaMSStruct
void ActOnPragmaMSStruct(PragmaMSStructKind Kind)
ActOnPragmaMSStruct - Called on well formed #pragma ms_struct [on|off].
Definition: SemaAttr.cpp:453
clang::Sema::PragmaAttributeEntry
This an attribute introduced by #pragma clang attribute.
Definition: Sema.h:729
clang::NamedDecl::getIdentifier
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:244
clang::ASTContext::PSF_Implicit
@ PSF_Implicit
Definition: ASTContext.h:3131
clang::Sema::MSPointerToMemberRepresentationMethod
LangOptions::PragmaMSPointersToMembersKind MSPointerToMemberRepresentationMethod
Controls member pointer representation format under the MS ABI.
Definition: Sema.h:434
clang::DeclContext::addDecl
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1541
clang::Sema::AlignPackInfo::IsAlignAttr
bool IsAlignAttr() const
Definition: Sema.h:539
clang::CharSourceRange::getTokenRange
static CharSourceRange getTokenRange(SourceRange R)
Definition: SourceLocation.h:263
clang::Preprocessor::getPragmaARCCFCodeAuditedInfo
std::pair< IdentifierInfo *, SourceLocation > getPragmaARCCFCodeAuditedInfo() const
The location of the currently-active #pragma clang arc_cf_code_audited begin.
Definition: Preprocessor.h:1661
clang::Sema::DiagnoseNonDefaultPragmaAlignPack
void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind, SourceLocation IncludeLoc)
Definition: SemaAttr.cpp:387
llvm::ArrayRef
Definition: LLVM.h:34
Value
Value
Definition: UninitializedValues.cpp:102
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
clang::AttributeCommonInfo
Definition: AttributeCommonInfo.h:22
clang::Sema::PragmaAttributeStack
SmallVector< PragmaAttributeGroup, 2 > PragmaAttributeStack
Definition: Sema.h:745
clang::Sema::ActOnPragmaMSComment
void ActOnPragmaMSComment(SourceLocation CommentLoc, PragmaMSCommentKind Kind, StringRef Arg)
ActOnPragmaMSComment - Called on well formed #pragma comment(kind, "arg").
Definition: SemaAttr.cpp:457
clang::DeclGroupRef
Definition: DeclGroup.h:51
clang::Sema::Consumer
ASTConsumer & Consumer
Definition: Sema.h:409
clang::PFC_NoPrecise
@ PFC_NoPrecise
Definition: PragmaKinds.h:31
clang::CharSourceRange
Represents a character-granular source range.
Definition: SourceLocation.h:255
clang::Sema
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:352
clang::LangOptions::FPM_FastHonorPragmas
@ FPM_FastHonorPragmas
Definition: LangOptions.h:212
ASTConsumer.h
clang::ParsedAttr::diagnoseAppertainsTo
bool diagnoseAppertainsTo(class Sema &S, const Decl *D) const
Definition: ParsedAttr.cpp:158
clang::Expr::isValueDependent
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:168
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:67
clang::Sema::ImplicitMSInheritanceAttrLoc
SourceLocation ImplicitMSInheritanceAttrLoc
Source location for newly created implicit MSInheritanceAttrs.
Definition: Sema.h:440
clang::Token::getLocation
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:126
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:693
clang::Sema::DiagnoseUnterminatedPragmaAlignPack
void DiagnoseUnterminatedPragmaAlignPack()
Definition: SemaAttr.cpp:426
clang::Sema::PragmaStack::CurrentValue
ValueType CurrentValue
Definition: Sema.h:664
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::ParsedAttr::isPragmaClangAttribute
bool isPragmaClangAttribute() const
True if the attribute is specified using '#pragma clang attribute'.
Definition: ParsedAttr.h:458
clang::Sema::POAK_Power
@ POAK_Power
Definition: Sema.h:9854
clang::attr::ParsedSubjectMatchRuleSet
llvm::DenseMap< int, SourceRange > ParsedSubjectMatchRuleSet
Definition: AttrSubjectMatchRules.h:26
clang::Sema::ActOnPragmaClangSection
void ActOnPragmaClangSection(SourceLocation PragmaLoc, PragmaClangSectionAction Action, PragmaClangSectionKind SecKind, StringRef SecName)
ActOnPragmaClangSection - Called on well formed #pragma clang section.
Definition: SemaAttr.cpp:272
clang::ASTContext::SectionInfos
llvm::StringMap< SectionInfo > SectionInfos
Definition: ASTContext.h:3148
clang::Sema::PragmaMsStackAction
PragmaMsStackAction
Definition: Sema.h:475
clang::Sema::PopPragmaVisibility
void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc)
PopPragmaVisibility - Pop the top element of the visibility stack; used for '#pragma GCC visibility' ...
Definition: SemaAttr.cpp:1181
addGslOwnerPointerAttributeIfNotExisting
static void addGslOwnerPointerAttributeIfNotExisting(ASTContext &Context, CXXRecordDecl *Record)
Definition: SemaAttr.cpp:99
clang::Sema::ConstSegStack
PragmaStack< StringLiteral * > ConstSegStack
Definition: Sema.h:690
clang::IdentifierInfo::getName
StringRef getName() const
Return the actual identifier string.
Definition: IdentifierTable.h:168
clang::LangOptions::PragmaMSPointersToMembersKind
PragmaMSPointersToMembersKind
Definition: LangOptions.h:97
clang
Definition: CalledOnceCheck.h:17
clang::ParsedAttr::hasCustomParsing
bool hasCustomParsing() const
Definition: ParsedAttr.cpp:154
clang::Sema::inferGslPointerAttribute
void inferGslPointerAttribute(NamedDecl *ND, CXXRecordDecl *UnderlyingRecord)
Add gsl::Pointer attribute to std::container::iterator.
Definition: SemaAttr.cpp:108
clang::Sema::PragmaClangSection::Valid
bool Valid
Definition: Sema.h:465
clang::Sema::AlignPackInfo::Mac68k
@ Mac68k
Definition: Sema.h:490
clang::Sema::POAK_Packed
@ POAK_Packed
Definition: Sema.h:9853
PushPragmaVisibility
static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc)
Definition: SemaAttr.cpp:1072
clang::Sema::PSK_Pop
@ PSK_Pop
Definition: Sema.h:479
clang::Sema::AlignPackInfo::getPackNumber
unsigned getPackNumber() const
Definition: Sema.h:543
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:68
clang::Sema::PragmaAlignPackDiagnoseKind::NonDefaultStateAtInclude
@ NonDefaultStateAtInclude
clang::Sema::PragmaClangSection::PragmaLocation
SourceLocation PragmaLocation
Definition: Sema.h:466
clang::Sema::AddOptnoneAttributeIfNoConflicts
void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc)
Adds the 'optnone' attribute to the function declaration if there are no conflicts; Loc represents th...
Definition: SemaAttr.cpp:1030
clang::Sema::PragmaClangSectionKind
PragmaClangSectionKind
pragma clang section kind
Definition: Sema.h:449
clang::ParsedAttr::diagnoseLangOpts
bool diagnoseLangOpts(class Sema &S) const
Definition: ParsedAttr.cpp:182
clang::FPOptionsOverride::setDisallowFPContract
void setDisallowFPContract()
Definition: LangOptions.h:594
clang::ParsedAttr::getMatchRules
void getMatchRules(const LangOptions &LangOpts, SmallVectorImpl< std::pair< attr::SubjectMatchRule, bool >> &MatchRules) const
Definition: ParsedAttr.cpp:175
clang::Sema::AddCFAuditedAttribute
void AddCFAuditedAttribute(Decl *D)
AddCFAuditedAttribute - Check whether we're currently within '#pragma clang arc_cf_code_audited' and,...
Definition: SemaAttr.cpp:728
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:110
clang::LangOptions::FPE_Ignore
@ FPE_Ignore
Assume that floating-point exceptions are masked.
Definition: LangOptions.h:222
clang::Attr
Attr - This represents one attribute.
Definition: Attr.h:46
clang::FixItHint::CreateRemoval
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
Definition: Diagnostic.h:122
clang::LangOptions::FPE_Strict
@ FPE_Strict
Strictly preserve the floating-point exception semantics.
Definition: LangOptions.h:226
NoVisibility
@ NoVisibility
Definition: SemaAttr.cpp:1045
unsigned
clang::Sema::OptimizeOffPragmaLocation
SourceLocation OptimizeOffPragmaLocation
This represents the last location of a "#pragma clang optimize off" directive if such a directive has...
Definition: Sema.h:754
clang::AttributeCommonInfo::AS_Pragma
@ AS_Pragma
#pragma ...
Definition: AttributeCommonInfo.h:45
clang::TypedefNameDecl
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3141
clang::PragmaMSStructKind
PragmaMSStructKind
Definition: PragmaKinds.h:23
clang::Sema::AlignPackStack
PragmaStack< AlignPackInfo > AlignPackStack
Definition: Sema.h:679
clang::LookupResult::getAsSingle
DeclClass * getAsSingle() const
Definition: Lookup.h:507
clang::Sema::AlignPackInfo::getAlignMode
Mode getAlignMode() const
Definition: Sema.h:541
clang::Sema::POAK_Mac68k
@ POAK_Mac68k
Definition: Sema.h:9855
clang::QualType::getTypePtr
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6427
clang::Sema::PragmaAlignPackDiagnoseKind
PragmaAlignPackDiagnoseKind
Definition: Sema.h:9872
clang::Sema::ActOnPragmaMSPointersToMembers
void ActOnPragmaMSPointersToMembers(LangOptions::PragmaMSPointersToMembersKind Kind, SourceLocation PragmaLoc)
ActOnPragmaMSPointersToMembers - called on well formed #pragma pointers_to_members(representation met...
Definition: SemaAttr.cpp:526
Parent
NodeId Parent
Definition: ASTDiff.cpp:192
clang::NamedDecl::VisibilityForValue
@ VisibilityForValue
Do an LV computation for, ultimately, a non-type declaration.
Definition: Decl.h:409
clang::Sema::CheckAttrTarget
bool CheckAttrTarget(const ParsedAttr &CurrAttr)
Definition: SemaDeclAttr.cpp:2076
clang::LangOptions::FPM_Off
@ FPM_Off
Definition: LangOptions.h:203
clang::Sema::PragmaClangDataSection
PragmaClangSection PragmaClangDataSection
Definition: Sema.h:470
clang::PragmaMSCommentKind
PragmaMSCommentKind
Definition: PragmaKinds.h:14
clang::Sema::LookupOrdinaryName
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition: Sema.h:3913
clang::Sema::AlignPackIncludeState
Definition: Sema.h:681
clang::Sema::AddRangeBasedOptnone
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:1023
clang::Lexer::findLocationAfterToken
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
clang::Sema::PragmaAttributeCurrentTargetDecl
const Decl * PragmaAttributeCurrentTargetDecl
The declaration that is currently receiving an attribute from the #pragma attribute stack.
Definition: Sema.h:749
clang::ParsedAttributesView
Definition: ParsedAttr.h:868
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::Sema::AddAlignmentAttributesForRecord
void AddAlignmentAttributesForRecord(RecordDecl *RD)
AddAlignmentAttributesForRecord - Adds any needed alignment attributes to a the record decl,...
Definition: SemaAttr.cpp:50
clang::FPOptionsOverride::setAllowFPContractWithinStatement
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:586
clang::PMSST_ON
@ PMSST_ON
Definition: PragmaKinds.h:25
clang::Sema::PragmaClangRodataSection
PragmaClangSection PragmaClangRodataSection
Definition: Sema.h:471
clang::Sema::PP
Preprocessor & PP
Definition: Sema.h:407
clang::Sema::AlignPackIncludeState::ShouldWarnOnInclude
bool ShouldWarnOnInclude
Definition: Sema.h:684
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:430
clang::ASTContext::SectionInfo
Definition: ASTContext.h:3136
clang::Decl::addAttr
void addAttr(Attr *A)
Definition: DeclBase.cpp:881
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1825
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3820
clang::LangOptions::FPM_Fast
@ FPM_Fast
Definition: LangOptions.h:209
clang::Sema::VtorDispStack
PragmaStack< MSVtorDispMode > VtorDispStack
Whether to insert vtordisps prior to virtual bases in the Microsoft C++ ABI.
Definition: Sema.h:678
clang::Sema::PragmaAlignPackDiagnoseKind::ChangedStateAtExit
@ ChangedStateAtExit
checkCommonAttributeFeatures
static bool checkCommonAttributeFeatures(Sema &S, const Ty *Node, const ParsedAttr &A)
Definition: SemaAttr.cpp:1215
clang::StringLiteral::getString
StringRef getString() const
Definition: Expr.h:1840
clang::Sema::POAK_Native
@ POAK_Native
Definition: Sema.h:9851
clang::Sema::PragmaStack::SentinelAction
void SentinelAction(PragmaMsStackAction Action, StringRef Label)
Definition: Sema.h:650
clang::ento::ObjKind::OS
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1508
clang::Sema::ActOnPragmaFPReassociate
void ActOnPragmaFPReassociate(SourceLocation Loc, bool IsEnabled)
Called on well formed #pragma clang fp reassociate.
Definition: SemaAttr.cpp:1116
clang::Sema::ActOnPragmaAttributeAttribute
void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, SourceLocation PragmaLoc, attr::ParsedSubjectMatchRuleSet Rules)
Definition: SemaAttr.cpp:799
clang::Decl::getDeclContext
DeclContext * getDeclContext()
Definition: DeclBase.h:439
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:250