clang  3.7.0
SemaAttr.cpp
Go to the documentation of this file.
1 //===--- SemaAttr.cpp - Semantic Analysis for Attributes ------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements semantic analysis for non-trivial attributes and
11 // pragmas.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "clang/AST/ASTConsumer.h"
17 #include "clang/AST/Attr.h"
18 #include "clang/AST/Expr.h"
19 #include "clang/Basic/TargetInfo.h"
20 #include "clang/Lex/Preprocessor.h"
21 #include "clang/Sema/Lookup.h"
22 using namespace clang;
23 
24 //===----------------------------------------------------------------------===//
25 // Pragma 'pack' and 'options align'
26 //===----------------------------------------------------------------------===//
27 
28 namespace {
29  struct PackStackEntry {
30  // We just use a sentinel to represent when the stack is set to mac68k
31  // alignment.
32  static const unsigned kMac68kAlignmentSentinel = ~0U;
33 
34  unsigned Alignment;
35  IdentifierInfo *Name;
36  };
37 
38  /// PragmaPackStack - Simple class to wrap the stack used by #pragma
39  /// pack.
40  class PragmaPackStack {
41  typedef std::vector<PackStackEntry> stack_ty;
42 
43  /// Alignment - The current user specified alignment.
44  unsigned Alignment;
45 
46  /// Stack - Entries in the #pragma pack stack, consisting of saved
47  /// alignments and optional names.
48  stack_ty Stack;
49 
50  public:
51  PragmaPackStack() : Alignment(0) {}
52 
53  void setAlignment(unsigned A) { Alignment = A; }
54  unsigned getAlignment() { return Alignment; }
55 
56  /// push - Push the current alignment onto the stack, optionally
57  /// using the given \arg Name for the record, if non-zero.
58  void push(IdentifierInfo *Name) {
59  PackStackEntry PSE = { Alignment, Name };
60  Stack.push_back(PSE);
61  }
62 
63  /// pop - Pop a record from the stack and restore the current
64  /// alignment to the previous value. If \arg Name is non-zero then
65  /// the first such named record is popped, otherwise the top record
66  /// is popped. Returns true if the pop succeeded.
67  bool pop(IdentifierInfo *Name, bool IsReset);
68  };
69 } // end anonymous namespace.
70 
71 bool PragmaPackStack::pop(IdentifierInfo *Name, bool IsReset) {
72  // If name is empty just pop top.
73  if (!Name) {
74  // An empty stack is a special case...
75  if (Stack.empty()) {
76  // If this isn't a reset, it is always an error.
77  if (!IsReset)
78  return false;
79 
80  // Otherwise, it is an error only if some alignment has been set.
81  if (!Alignment)
82  return false;
83 
84  // Otherwise, reset to the default alignment.
85  Alignment = 0;
86  } else {
87  Alignment = Stack.back().Alignment;
88  Stack.pop_back();
89  }
90 
91  return true;
92  }
93 
94  // Otherwise, find the named record.
95  for (unsigned i = Stack.size(); i != 0; ) {
96  --i;
97  if (Stack[i].Name == Name) {
98  // Found it, pop up to and including this record.
99  Alignment = Stack[i].Alignment;
100  Stack.erase(Stack.begin() + i, Stack.end());
101  return true;
102  }
103  }
104 
105  return false;
106 }
107 
108 
109 /// FreePackedContext - Deallocate and null out PackContext.
111  delete static_cast<PragmaPackStack*>(PackContext);
112  PackContext = nullptr;
113 }
114 
116  // If there is no pack context, we don't need any attributes.
117  if (!PackContext)
118  return;
119 
120  PragmaPackStack *Stack = static_cast<PragmaPackStack*>(PackContext);
121 
122  // Otherwise, check to see if we need a max field alignment attribute.
123  if (unsigned Alignment = Stack->getAlignment()) {
124  if (Alignment == PackStackEntry::kMac68kAlignmentSentinel)
125  RD->addAttr(AlignMac68kAttr::CreateImplicit(Context));
126  else
127  RD->addAttr(MaxFieldAlignmentAttr::CreateImplicit(Context,
128  Alignment * 8));
129  }
130 }
131 
133  if (MSStructPragmaOn)
134  RD->addAttr(MSStructAttr::CreateImplicit(Context));
135 
136  // FIXME: We should merge AddAlignmentAttributesForRecord with
137  // AddMsStructLayoutForRecord into AddPragmaAttributesForRecord, which takes
138  // all active pragmas and applies them as attributes to class definitions.
139  if (VtorDispModeStack.back() != getLangOpts().VtorDispMode)
140  RD->addAttr(
141  MSVtorDispAttr::CreateImplicit(Context, VtorDispModeStack.back()));
142 }
143 
145  SourceLocation PragmaLoc) {
146  if (!PackContext)
147  PackContext = new PragmaPackStack();
148 
149  PragmaPackStack *Context = static_cast<PragmaPackStack*>(PackContext);
150 
151  switch (Kind) {
152  // For all targets we support native and natural are the same.
153  //
154  // FIXME: This is not true on Darwin/PPC.
155  case POAK_Native:
156  case POAK_Power:
157  case POAK_Natural:
158  Context->push(nullptr);
159  Context->setAlignment(0);
160  break;
161 
162  // Note that '#pragma options align=packed' is not equivalent to attribute
163  // packed, it has a different precedence relative to attribute aligned.
164  case POAK_Packed:
165  Context->push(nullptr);
166  Context->setAlignment(1);
167  break;
168 
169  case POAK_Mac68k:
170  // Check if the target supports this.
171  if (!this->Context.getTargetInfo().hasAlignMac68kSupport()) {
172  Diag(PragmaLoc, diag::err_pragma_options_align_mac68k_target_unsupported);
173  return;
174  }
175  Context->push(nullptr);
176  Context->setAlignment(PackStackEntry::kMac68kAlignmentSentinel);
177  break;
178 
179  case POAK_Reset:
180  // Reset just pops the top of the stack, or resets the current alignment to
181  // default.
182  if (!Context->pop(nullptr, /*IsReset=*/true)) {
183  Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
184  << "stack empty";
185  }
186  break;
187  }
188 }
189 
191  Expr *alignment, SourceLocation PragmaLoc,
192  SourceLocation LParenLoc, SourceLocation RParenLoc) {
193  Expr *Alignment = static_cast<Expr *>(alignment);
194 
195  // If specified then alignment must be a "small" power of two.
196  unsigned AlignmentVal = 0;
197  if (Alignment) {
198  llvm::APSInt Val;
199 
200  // pack(0) is like pack(), which just works out since that is what
201  // we use 0 for in PackAttr.
202  if (Alignment->isTypeDependent() ||
203  Alignment->isValueDependent() ||
204  !Alignment->isIntegerConstantExpr(Val, Context) ||
205  !(Val == 0 || Val.isPowerOf2()) ||
206  Val.getZExtValue() > 16) {
207  Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
208  return; // Ignore
209  }
210 
211  AlignmentVal = (unsigned) Val.getZExtValue();
212  }
213 
214  if (!PackContext)
215  PackContext = new PragmaPackStack();
216 
217  PragmaPackStack *Context = static_cast<PragmaPackStack*>(PackContext);
218 
219  switch (Kind) {
220  case Sema::PPK_Default: // pack([n])
221  Context->setAlignment(AlignmentVal);
222  break;
223 
224  case Sema::PPK_Show: // pack(show)
225  // Show the current alignment, making sure to show the right value
226  // for the default.
227  AlignmentVal = Context->getAlignment();
228  // FIXME: This should come from the target.
229  if (AlignmentVal == 0)
230  AlignmentVal = 8;
231  if (AlignmentVal == PackStackEntry::kMac68kAlignmentSentinel)
232  Diag(PragmaLoc, diag::warn_pragma_pack_show) << "mac68k";
233  else
234  Diag(PragmaLoc, diag::warn_pragma_pack_show) << AlignmentVal;
235  break;
236 
237  case Sema::PPK_Push: // pack(push [, id] [, [n])
238  Context->push(Name);
239  // Set the new alignment if specified.
240  if (Alignment)
241  Context->setAlignment(AlignmentVal);
242  break;
243 
244  case Sema::PPK_Pop: // pack(pop [, id] [, n])
245  // MSDN, C/C++ Preprocessor Reference > Pragma Directives > pack:
246  // "#pragma pack(pop, identifier, n) is undefined"
247  if (Alignment && Name)
248  Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifer_and_alignment);
249 
250  // Do the pop.
251  if (!Context->pop(Name, /*IsReset=*/false)) {
252  // If a name was specified then failure indicates the name
253  // wasn't found. Otherwise failure indicates the stack was
254  // empty.
255  Diag(PragmaLoc, diag::warn_pragma_pop_failed)
256  << "pack" << (Name ? "no record matching name" : "stack empty");
257 
258  // FIXME: Warn about popping named records as MSVC does.
259  } else {
260  // Pop succeeded, set the new alignment if specified.
261  if (Alignment)
262  Context->setAlignment(AlignmentVal);
263  }
264  break;
265  }
266 }
267 
269  MSStructPragmaOn = (Kind == PMSST_ON);
270 }
271 
273  // FIXME: Serialize this.
274  switch (Kind) {
275  case PCK_Unknown:
276  llvm_unreachable("unexpected pragma comment kind");
277  case PCK_Linker:
279  return;
280  case PCK_Lib:
282  return;
283  case PCK_Compiler:
284  case PCK_ExeStr:
285  case PCK_User:
286  return; // We ignore all of these.
287  }
288  llvm_unreachable("invalid pragma comment kind");
289 }
290 
291 void Sema::ActOnPragmaDetectMismatch(StringRef Name, StringRef Value) {
292  // FIXME: Serialize this.
293  Consumer.HandleDetectMismatch(Name, Value);
294 }
295 
297  LangOptions::PragmaMSPointersToMembersKind RepresentationMethod,
298  SourceLocation PragmaLoc) {
299  MSPointerToMemberRepresentationMethod = RepresentationMethod;
300  ImplicitMSInheritanceAttrLoc = PragmaLoc;
301 }
302 
304  SourceLocation PragmaLoc,
305  MSVtorDispAttr::Mode Mode) {
306  switch (Kind) {
307  case PVDK_Set:
308  VtorDispModeStack.back() = Mode;
309  break;
310  case PVDK_Push:
311  VtorDispModeStack.push_back(Mode);
312  break;
313  case PVDK_Reset:
314  VtorDispModeStack.clear();
315  VtorDispModeStack.push_back(MSVtorDispAttr::Mode(LangOpts.VtorDispMode));
316  break;
317  case PVDK_Pop:
318  VtorDispModeStack.pop_back();
319  if (VtorDispModeStack.empty()) {
320  Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "vtordisp"
321  << "stack empty";
322  VtorDispModeStack.push_back(MSVtorDispAttr::Mode(LangOpts.VtorDispMode));
323  }
324  break;
325  }
326 }
327 
328 template<typename ValueType>
331  llvm::StringRef StackSlotLabel,
332  ValueType Value) {
333  if (Action == PSK_Reset) {
334  CurrentValue = nullptr;
335  return;
336  }
337  if (Action & PSK_Push)
338  Stack.push_back(Slot(StackSlotLabel, CurrentValue, CurrentPragmaLocation));
339  else if (Action & PSK_Pop) {
340  if (!StackSlotLabel.empty()) {
341  // If we've got a label, try to find it and jump there.
342  auto I = std::find_if(Stack.rbegin(), Stack.rend(),
343  [&](const Slot &x) { return x.StackSlotLabel == StackSlotLabel; });
344  // If we found the label so pop from there.
345  if (I != Stack.rend()) {
346  CurrentValue = I->Value;
347  CurrentPragmaLocation = I->PragmaLocation;
348  Stack.erase(std::prev(I.base()), Stack.end());
349  }
350  } else if (!Stack.empty()) {
351  // We don't have a label, just pop the last entry.
352  CurrentValue = Stack.back().Value;
353  CurrentPragmaLocation = Stack.back().PragmaLocation;
354  Stack.pop_back();
355  }
356  }
357  if (Action & PSK_Set) {
358  CurrentValue = Value;
359  CurrentPragmaLocation = PragmaLocation;
360  }
361 }
362 
363 bool Sema::UnifySection(StringRef SectionName,
364  int SectionFlags,
365  DeclaratorDecl *Decl) {
366  auto Section = Context.SectionInfos.find(SectionName);
367  if (Section == Context.SectionInfos.end()) {
368  Context.SectionInfos[SectionName] =
369  ASTContext::SectionInfo(Decl, SourceLocation(), SectionFlags);
370  return false;
371  }
372  // A pre-declared section takes precedence w/o diagnostic.
373  if (Section->second.SectionFlags == SectionFlags ||
374  !(Section->second.SectionFlags & ASTContext::PSF_Implicit))
375  return false;
376  auto OtherDecl = Section->second.Decl;
377  Diag(Decl->getLocation(), diag::err_section_conflict)
378  << Decl << OtherDecl;
379  Diag(OtherDecl->getLocation(), diag::note_declared_at)
380  << OtherDecl->getName();
381  if (auto A = Decl->getAttr<SectionAttr>())
382  if (A->isImplicit())
383  Diag(A->getLocation(), diag::note_pragma_entered_here);
384  if (auto A = OtherDecl->getAttr<SectionAttr>())
385  if (A->isImplicit())
386  Diag(A->getLocation(), diag::note_pragma_entered_here);
387  return true;
388 }
389 
390 bool Sema::UnifySection(StringRef SectionName,
391  int SectionFlags,
392  SourceLocation PragmaSectionLocation) {
393  auto Section = Context.SectionInfos.find(SectionName);
394  if (Section != Context.SectionInfos.end()) {
395  if (Section->second.SectionFlags == SectionFlags)
396  return false;
397  if (!(Section->second.SectionFlags & ASTContext::PSF_Implicit)) {
398  Diag(PragmaSectionLocation, diag::err_section_conflict)
399  << "this" << "a prior #pragma section";
400  Diag(Section->second.PragmaSectionLocation,
401  diag::note_pragma_entered_here);
402  return true;
403  }
404  }
405  Context.SectionInfos[SectionName] =
406  ASTContext::SectionInfo(nullptr, PragmaSectionLocation, SectionFlags);
407  return false;
408 }
409 
410 /// \brief Called on well formed \#pragma bss_seg().
413  llvm::StringRef StackSlotLabel,
414  StringLiteral *SegmentName,
415  llvm::StringRef PragmaName) {
417  llvm::StringSwitch<PragmaStack<StringLiteral *> *>(PragmaName)
418  .Case("data_seg", &DataSegStack)
419  .Case("bss_seg", &BSSSegStack)
420  .Case("const_seg", &ConstSegStack)
421  .Case("code_seg", &CodeSegStack);
422  if (Action & PSK_Pop && Stack->Stack.empty())
423  Diag(PragmaLocation, diag::warn_pragma_pop_failed) << PragmaName
424  << "stack empty";
425  if (SegmentName &&
426  !checkSectionName(SegmentName->getLocStart(), SegmentName->getString()))
427  return;
428  Stack->Act(PragmaLocation, Action, StackSlotLabel, SegmentName);
429 }
430 
431 /// \brief Called on well formed \#pragma bss_seg().
433  int SectionFlags, StringLiteral *SegmentName) {
434  UnifySection(SegmentName->getString(), SectionFlags, PragmaLocation);
435 }
436 
438  StringLiteral *SegmentName) {
439  // There's no stack to maintain, so we just have a current section. When we
440  // see the default section, reset our current section back to null so we stop
441  // tacking on unnecessary attributes.
442  CurInitSeg = SegmentName->getString() == ".CRT$XCU" ? nullptr : SegmentName;
443  CurInitSegLoc = PragmaLocation;
444 }
445 
446 void Sema::ActOnPragmaUnused(const Token &IdTok, Scope *curScope,
447  SourceLocation PragmaLoc) {
448 
449  IdentifierInfo *Name = IdTok.getIdentifierInfo();
450  LookupResult Lookup(*this, Name, IdTok.getLocation(), LookupOrdinaryName);
451  LookupParsedName(Lookup, curScope, nullptr, true);
452 
453  if (Lookup.empty()) {
454  Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
455  << Name << SourceRange(IdTok.getLocation());
456  return;
457  }
458 
459  VarDecl *VD = Lookup.getAsSingle<VarDecl>();
460  if (!VD) {
461  Diag(PragmaLoc, diag::warn_pragma_unused_expected_var_arg)
462  << Name << SourceRange(IdTok.getLocation());
463  return;
464  }
465 
466  // Warn if this was used before being marked unused.
467  if (VD->isUsed())
468  Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name;
469 
470  VD->addAttr(UnusedAttr::CreateImplicit(Context, IdTok.getLocation()));
471 }
472 
475  if (!Loc.isValid()) return;
476 
477  // Don't add a redundant or conflicting attribute.
478  if (D->hasAttr<CFAuditedTransferAttr>() ||
479  D->hasAttr<CFUnknownTransferAttr>())
480  return;
481 
482  D->addAttr(CFAuditedTransferAttr::CreateImplicit(Context, Loc));
483 }
484 
485 void Sema::ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc) {
486  if(On)
488  else
489  OptimizeOffPragmaLocation = PragmaLoc;
490 }
491 
493  // In the future, check other pragmas if they're implemented (e.g. pragma
494  // optimize 0 will probably map to this functionality too).
497 }
498 
500  SourceLocation Loc) {
501  // Don't add a conflicting attribute. No diagnostic is needed.
502  if (FD->hasAttr<MinSizeAttr>() || FD->hasAttr<AlwaysInlineAttr>())
503  return;
504 
505  // Add attributes only if required. Optnone requires noinline as well, but if
506  // either is already present then don't bother adding them.
507  if (!FD->hasAttr<OptimizeNoneAttr>())
508  FD->addAttr(OptimizeNoneAttr::CreateImplicit(Context, Loc));
509  if (!FD->hasAttr<NoInlineAttr>())
510  FD->addAttr(NoInlineAttr::CreateImplicit(Context, Loc));
511 }
512 
513 typedef std::vector<std::pair<unsigned, SourceLocation> > VisStack;
514 enum : unsigned { NoVisibility = ~0U };
515 
517  if (!VisContext)
518  return;
519 
520  NamedDecl *ND = dyn_cast<NamedDecl>(D);
522  return;
523 
524  VisStack *Stack = static_cast<VisStack*>(VisContext);
525  unsigned rawType = Stack->back().first;
526  if (rawType == NoVisibility) return;
527 
528  VisibilityAttr::VisibilityType type
529  = (VisibilityAttr::VisibilityType) rawType;
530  SourceLocation loc = Stack->back().second;
531 
532  D->addAttr(VisibilityAttr::CreateImplicit(Context, type, loc));
533 }
534 
535 /// FreeVisContext - Deallocate and null out VisContext.
537  delete static_cast<VisStack*>(VisContext);
538  VisContext = nullptr;
539 }
540 
541 static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc) {
542  // Put visibility on stack.
543  if (!S.VisContext)
544  S.VisContext = new VisStack;
545 
546  VisStack *Stack = static_cast<VisStack*>(S.VisContext);
547  Stack->push_back(std::make_pair(type, loc));
548 }
549 
551  SourceLocation PragmaLoc) {
552  if (VisType) {
553  // Compute visibility to use.
554  VisibilityAttr::VisibilityType T;
555  if (!VisibilityAttr::ConvertStrToVisibilityType(VisType->getName(), T)) {
556  Diag(PragmaLoc, diag::warn_attribute_unknown_visibility) << VisType;
557  return;
558  }
559  PushPragmaVisibility(*this, T, PragmaLoc);
560  } else {
561  PopPragmaVisibility(false, PragmaLoc);
562  }
563 }
564 
566  switch (OOS) {
567  case tok::OOS_ON:
569  break;
570  case tok::OOS_OFF:
571  FPFeatures.fp_contract = 0;
572  break;
573  case tok::OOS_DEFAULT:
574  FPFeatures.fp_contract = getLangOpts().DefaultFPContract;
575  break;
576  }
577 }
578 
579 void Sema::PushNamespaceVisibilityAttr(const VisibilityAttr *Attr,
580  SourceLocation Loc) {
581  // Visibility calculations will consider the namespace's visibility.
582  // Here we just want to note that we're in a visibility context
583  // which overrides any enclosing #pragma context, but doesn't itself
584  // contribute visibility.
585  PushPragmaVisibility(*this, NoVisibility, Loc);
586 }
587 
588 void Sema::PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc) {
589  if (!VisContext) {
590  Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
591  return;
592  }
593 
594  // Pop visibility from stack
595  VisStack *Stack = static_cast<VisStack*>(VisContext);
596 
597  const std::pair<unsigned, SourceLocation> *Back = &Stack->back();
598  bool StartsWithPragma = Back->first != NoVisibility;
599  if (StartsWithPragma && IsNamespaceEnd) {
600  Diag(Back->second, diag::err_pragma_push_visibility_mismatch);
601  Diag(EndLoc, diag::note_surrounding_namespace_ends_here);
602 
603  // For better error recovery, eat all pushes inside the namespace.
604  do {
605  Stack->pop_back();
606  Back = &Stack->back();
607  StartsWithPragma = Back->first != NoVisibility;
608  } while (StartsWithPragma);
609  } else if (!StartsWithPragma && !IsNamespaceEnd) {
610  Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
611  Diag(Back->second, diag::note_surrounding_namespace_starts_here);
612  return;
613  }
614 
615  Stack->pop_back();
616  // To simplify the implementation, never keep around an empty stack.
617  if (Stack->empty())
618  FreeVisContext();
619 }
void FreePackedContext()
FreePackedContext - Deallocate and null out PackContext.
Definition: SemaAttr.cpp:110
PragmaStack< StringLiteral * > CodeSegStack
Definition: Sema.h:388
ASTConsumer & Consumer
Definition: Sema.h:296
void ActOnPragmaMSStruct(PragmaMSStructKind Kind)
ActOnPragmaMSStruct - Called on well formed #pragma ms_struct [on|off].
Definition: SemaAttr.cpp:268
PragmaMSCommentKind
Definition: Sema.h:7502
PragmaStack< StringLiteral * > DataSegStack
Definition: Sema.h:385
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:411
const LangOptions & getLangOpts() const
Definition: Sema.h:1019
PragmaVtorDispKind
Definition: Sema.h:327
SmallVector< MSVtorDispAttr::Mode, 2 > VtorDispModeStack
Whether to insert vtordisps prior to virtual bases in the Microsoft C++ ABI. Possible values are 0...
Definition: Sema.h:353
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1088
PragmaOptionsAlignKind
Definition: Sema.h:7477
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...
SourceLocation getLocStart() const LLVM_READONLY
Definition: Expr.h:1607
unsigned fp_contract
Definition: LangOptions.h:142
void ActOnPragmaFPContract(tok::OnOffSwitch OOS)
Definition: SemaAttr.cpp:565
#pragma vtordisp(mode)
Definition: Sema.h:329
void FreeVisContext()
FreeVisContext - Deallocate and null out VisContext.
Definition: SemaAttr.cpp:536
bool hasAttr() const
Definition: DeclBase.h:487
PragmaPackKind
Definition: Sema.h:7490
FrontendAction * Action
Definition: Tooling.cpp:168
virtual void HandleDetectMismatch(llvm::StringRef Name, llvm::StringRef Value)
Handle a pragma that emits a mismatch identifier and value to the object file for the linker to work ...
Definition: ASTConsumer.h:104
static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc)
Definition: SemaAttr.cpp:541
T * getAttr() const
Definition: DeclBase.h:484
void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags, StringLiteral *SegmentName)
Called on well formed #pragma section().
Definition: SemaAttr.cpp:432
Represents the results of name lookup.
Definition: Lookup.h:30
void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, SourceLocation PragmaLoc)
ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
Definition: SemaAttr.cpp:144
void ActOnPragmaPack(PragmaPackKind Kind, IdentifierInfo *Name, Expr *Alignment, SourceLocation PragmaLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
ActOnPragmaPack - Called on well formed #pragma pack(...).
Definition: SemaAttr.cpp:190
bool isValueDependent() const
Definition: Expr.h:146
bool UnifySection(StringRef SectionName, int SectionFlags, DeclaratorDecl *TheDecl)
Definition: SemaAttr.cpp:363
void AddPushedVisibilityAttribute(Decl *RD)
Definition: SemaAttr.cpp:516
PragmaMSStructKind
Definition: Sema.h:7497
Preprocessor & PP
Definition: Sema.h:294
const LangOptions & LangOpts
Definition: Sema.h:293
void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc)
Definition: SemaAttr.cpp:588
bool MSStructPragmaOn
Definition: Sema.h:321
llvm::StringMap< SectionInfo > SectionInfos
Definition: ASTContext.h:2473
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:258
Represents a ValueDecl that came out of a declarator. Contains type source information through TypeSo...
Definition: Decl.h:586
std::vector< bool > & Stack
std::vector< std::pair< unsigned, SourceLocation > > VisStack
Definition: SemaAttr.cpp:513
StringRef getName() const
Return the actual identifier string.
void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, StringLiteral *SegmentName)
Called on well-formed #pragma init_seg().
Definition: SemaAttr.cpp:437
Defines the clang::Preprocessor interface.
#pragma vtordisp()
Definition: Sema.h:331
PragmaStack< StringLiteral * > BSSSegStack
Definition: Sema.h:386
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Definition: Token.h:124
void ActOnPragmaUnused(const Token &Identifier, Scope *curScope, SourceLocation PragmaLoc)
ActOnPragmaUnused - Called on well-formed '#pragma unused'.
Definition: SemaAttr.cpp:446
void ActOnPragmaDetectMismatch(StringRef Name, StringRef Value)
ActOnPragmaDetectMismatch - Call on well-formed #pragma detect_mismatch.
Definition: SemaAttr.cpp:291
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:499
Optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
Definition: Decl.cpp:1111
void * PackContext
Definition: Sema.h:319
void addAttr(Attr *A)
Definition: DeclBase.h:437
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:492
StringLiteral * CurInitSeg
Last section used with #pragma init_seg.
Definition: Sema.h:394
virtual void HandleLinkerOptionPragma(llvm::StringRef Opts)
Handle a pragma that appends to Linker Options. Currently this only exists to support Microsoft's #pr...
Definition: ASTConsumer.h:99
Kind
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, llvm::StringRef StackSlotLabel, ValueType Value)
Definition: SemaAttr.cpp:329
void ActOnPragmaMSVtorDisp(PragmaVtorDispKind Kind, SourceLocation PragmaLoc, MSVtorDispAttr::Mode Value)
Called on well formed #pragma vtordisp().
Definition: SemaAttr.cpp:303
bool isValid() const
Return true if this is a valid SourceLocation object.
bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx, SourceLocation *Loc=nullptr, bool isEvaluated=true) const
SourceLocation OptimizeOffPragmaLocation
This represents the last location of a "#pragma clang optimize off" directive if such a directive has...
Definition: Sema.h:403
bool isTypeDependent() const
Definition: Expr.h:166
virtual void HandleDependentLibrary(llvm::StringRef Lib)
Handle a dependent library created by a pragma in the source. Currently this only exists to support M...
Definition: ASTConsumer.h:110
SourceLocation ImplicitMSInheritanceAttrLoc
Source location for newly created implicit MSInheritanceAttrs.
Definition: Sema.h:359
void AddAlignmentAttributesForRecord(RecordDecl *RD)
Definition: SemaAttr.cpp:115
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchers.h:1639
bool isUsed(bool CheckUsedAttr=true) const
Whether this declaration was used, meaning that a definition is required.
Definition: DeclBase.cpp:305
StringRef getString() const
Definition: Expr.h:1521
#pragma vtordisp(push, mode)
Definition: Sema.h:328
void ActOnPragmaMSComment(PragmaMSCommentKind Kind, StringRef Arg)
Definition: SemaAttr.cpp:272
PragmaMsStackAction
Definition: Sema.h:334
OnOffSwitch
Defines the possible values of an on-off-switch (C99 6.10.6p2).
Definition: TokenKinds.h:49
void ActOnPragmaMSPointersToMembers(LangOptions::PragmaMSPointersToMembersKind Kind, SourceLocation PragmaLoc)
Definition: SemaAttr.cpp:296
PragmaStack< StringLiteral * > ConstSegStack
Definition: Sema.h:387
void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, SourceLocation Loc)
Definition: SemaAttr.cpp:579
void * VisContext
VisContext - Manages the stack for #pragma GCC visibility.
Definition: Sema.h:398
LangOptions::PragmaMSPointersToMembersKind MSPointerToMemberRepresentationMethod
Controls member pointer representation format under the MS ABI.
Definition: Sema.h:325
Defines the clang::TargetInfo interface.
FPOptions FPFeatures
Definition: Sema.h:291
bool checkSectionName(SourceLocation LiteralLoc, StringRef Str)
void ActOnPragmaVisibility(const IdentifierInfo *VisType, SourceLocation PragmaLoc)
ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
Definition: SemaAttr.cpp:550
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
Definition: DeclBase.h:372
ASTContext & Context
Definition: Sema.h:295
void AddMsStructLayoutForRecord(RecordDecl *RD)
AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
Definition: SemaAttr.cpp:132
SmallVector< Slot, 2 > Stack
Definition: Sema.h:379
#pragma vtordisp(pop)
Definition: Sema.h:330
SourceLocation getPragmaARCCFCodeAuditedLoc() const
The location of the currently-active #pragma clang arc_cf_code_audited begin.
Attr - This represents one attribute.
Definition: Attr.h:44
void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc)
Called on well formed #pragma clang optimize.
Definition: SemaAttr.cpp:485
void AddCFAuditedAttribute(Decl *D)
Definition: SemaAttr.cpp:473
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:177
SourceLocation CurInitSegLoc
Definition: Sema.h:395