clang  3.9.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 
29  StringRef SlotLabel,
30  bool ShouldAct)
31  : S(S), SlotLabel(SlotLabel), ShouldAct(ShouldAct) {
32  if (ShouldAct) {
34  S.DataSegStack.SentinelAction(PSK_Push, SlotLabel);
35  S.BSSSegStack.SentinelAction(PSK_Push, SlotLabel);
36  S.ConstSegStack.SentinelAction(PSK_Push, SlotLabel);
37  S.CodeSegStack.SentinelAction(PSK_Push, SlotLabel);
38  }
39 }
40 
42  if (ShouldAct) {
44  S.DataSegStack.SentinelAction(PSK_Pop, SlotLabel);
45  S.BSSSegStack.SentinelAction(PSK_Pop, SlotLabel);
46  S.ConstSegStack.SentinelAction(PSK_Pop, SlotLabel);
47  S.CodeSegStack.SentinelAction(PSK_Pop, SlotLabel);
48  }
49 }
50 
52  // If there is no pack value, we don't need any attributes.
54  return;
55 
56  // Otherwise, check to see if we need a max field alignment attribute.
57  if (unsigned Alignment = PackStack.CurrentValue) {
58  if (Alignment == Sema::kMac68kAlignmentSentinel)
59  RD->addAttr(AlignMac68kAttr::CreateImplicit(Context));
60  else
61  RD->addAttr(MaxFieldAlignmentAttr::CreateImplicit(Context,
62  Alignment * 8));
63  }
64 }
65 
67  if (MSStructPragmaOn)
68  RD->addAttr(MSStructAttr::CreateImplicit(Context));
69 
70  // FIXME: We should merge AddAlignmentAttributesForRecord with
71  // AddMsStructLayoutForRecord into AddPragmaAttributesForRecord, which takes
72  // all active pragmas and applies them as attributes to class definitions.
73  if (VtorDispStack.CurrentValue != getLangOpts().VtorDispMode)
74  RD->addAttr(
75  MSVtorDispAttr::CreateImplicit(Context, VtorDispStack.CurrentValue));
76 }
77 
79  SourceLocation PragmaLoc) {
81  unsigned Alignment = 0;
82  switch (Kind) {
83  // For all targets we support native and natural are the same.
84  //
85  // FIXME: This is not true on Darwin/PPC.
86  case POAK_Native:
87  case POAK_Power:
88  case POAK_Natural:
89  Action = Sema::PSK_Push_Set;
90  Alignment = 0;
91  break;
92 
93  // Note that '#pragma options align=packed' is not equivalent to attribute
94  // packed, it has a different precedence relative to attribute aligned.
95  case POAK_Packed:
96  Action = Sema::PSK_Push_Set;
97  Alignment = 1;
98  break;
99 
100  case POAK_Mac68k:
101  // Check if the target supports this.
103  Diag(PragmaLoc, diag::err_pragma_options_align_mac68k_target_unsupported);
104  return;
105  }
106  Action = Sema::PSK_Push_Set;
107  Alignment = Sema::kMac68kAlignmentSentinel;
108  break;
109 
110  case POAK_Reset:
111  // Reset just pops the top of the stack, or resets the current alignment to
112  // default.
113  Action = Sema::PSK_Pop;
114  if (PackStack.Stack.empty()) {
115  if (PackStack.CurrentValue) {
116  Action = Sema::PSK_Reset;
117  } else {
118  Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
119  << "stack empty";
120  return;
121  }
122  }
123  break;
124  }
125 
126  PackStack.Act(PragmaLoc, Action, StringRef(), Alignment);
127 }
128 
130  StringRef SlotLabel, Expr *alignment) {
131  Expr *Alignment = static_cast<Expr *>(alignment);
132 
133  // If specified then alignment must be a "small" power of two.
134  unsigned AlignmentVal = 0;
135  if (Alignment) {
136  llvm::APSInt Val;
137 
138  // pack(0) is like pack(), which just works out since that is what
139  // we use 0 for in PackAttr.
140  if (Alignment->isTypeDependent() ||
141  Alignment->isValueDependent() ||
142  !Alignment->isIntegerConstantExpr(Val, Context) ||
143  !(Val == 0 || Val.isPowerOf2()) ||
144  Val.getZExtValue() > 16) {
145  Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
146  return; // Ignore
147  }
148 
149  AlignmentVal = (unsigned) Val.getZExtValue();
150  }
151  if (Action == Sema::PSK_Show) {
152  // Show the current alignment, making sure to show the right value
153  // for the default.
154  // FIXME: This should come from the target.
155  AlignmentVal = PackStack.CurrentValue;
156  if (AlignmentVal == 0)
157  AlignmentVal = 8;
158  if (AlignmentVal == Sema::kMac68kAlignmentSentinel)
159  Diag(PragmaLoc, diag::warn_pragma_pack_show) << "mac68k";
160  else
161  Diag(PragmaLoc, diag::warn_pragma_pack_show) << AlignmentVal;
162  }
163  // MSDN, C/C++ Preprocessor Reference > Pragma Directives > pack:
164  // "#pragma pack(pop, identifier, n) is undefined"
165  if (Action & Sema::PSK_Pop) {
166  if (Alignment && !SlotLabel.empty())
167  Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifer_and_alignment);
168  if (PackStack.Stack.empty())
169  Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "pack" << "stack empty";
170  }
171 
172  PackStack.Act(PragmaLoc, Action, SlotLabel, AlignmentVal);
173 }
174 
176  MSStructPragmaOn = (Kind == PMSST_ON);
177 }
178 
180  PragmaMSCommentKind Kind, StringRef Arg) {
181  auto *PCD = PragmaCommentDecl::Create(
182  Context, Context.getTranslationUnitDecl(), CommentLoc, Kind, Arg);
185 }
186 
188  StringRef Value) {
193 }
194 
196  LangOptions::PragmaMSPointersToMembersKind RepresentationMethod,
197  SourceLocation PragmaLoc) {
198  MSPointerToMemberRepresentationMethod = RepresentationMethod;
199  ImplicitMSInheritanceAttrLoc = PragmaLoc;
200 }
201 
203  SourceLocation PragmaLoc,
204  MSVtorDispAttr::Mode Mode) {
205  if (Action & PSK_Pop && VtorDispStack.Stack.empty())
206  Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "vtordisp"
207  << "stack empty";
208  VtorDispStack.Act(PragmaLoc, Action, StringRef(), Mode);
209 }
210 
211 template<typename ValueType>
214  llvm::StringRef StackSlotLabel,
215  ValueType Value) {
216  if (Action == PSK_Reset) {
217  CurrentValue = DefaultValue;
218  return;
219  }
220  if (Action & PSK_Push)
221  Stack.push_back(Slot(StackSlotLabel, CurrentValue, CurrentPragmaLocation));
222  else if (Action & PSK_Pop) {
223  if (!StackSlotLabel.empty()) {
224  // If we've got a label, try to find it and jump there.
225  auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
226  return x.StackSlotLabel == StackSlotLabel;
227  });
228  // If we found the label so pop from there.
229  if (I != Stack.rend()) {
230  CurrentValue = I->Value;
231  CurrentPragmaLocation = I->PragmaLocation;
232  Stack.erase(std::prev(I.base()), Stack.end());
233  }
234  } else if (!Stack.empty()) {
235  // We don't have a label, just pop the last entry.
236  CurrentValue = Stack.back().Value;
237  CurrentPragmaLocation = Stack.back().PragmaLocation;
238  Stack.pop_back();
239  }
240  }
241  if (Action & PSK_Set) {
242  CurrentValue = Value;
243  CurrentPragmaLocation = PragmaLocation;
244  }
245 }
246 
247 bool Sema::UnifySection(StringRef SectionName,
248  int SectionFlags,
249  DeclaratorDecl *Decl) {
250  auto Section = Context.SectionInfos.find(SectionName);
251  if (Section == Context.SectionInfos.end()) {
252  Context.SectionInfos[SectionName] =
253  ASTContext::SectionInfo(Decl, SourceLocation(), SectionFlags);
254  return false;
255  }
256  // A pre-declared section takes precedence w/o diagnostic.
257  if (Section->second.SectionFlags == SectionFlags ||
258  !(Section->second.SectionFlags & ASTContext::PSF_Implicit))
259  return false;
260  auto OtherDecl = Section->second.Decl;
261  Diag(Decl->getLocation(), diag::err_section_conflict)
262  << Decl << OtherDecl;
263  Diag(OtherDecl->getLocation(), diag::note_declared_at)
264  << OtherDecl->getName();
265  if (auto A = Decl->getAttr<SectionAttr>())
266  if (A->isImplicit())
267  Diag(A->getLocation(), diag::note_pragma_entered_here);
268  if (auto A = OtherDecl->getAttr<SectionAttr>())
269  if (A->isImplicit())
270  Diag(A->getLocation(), diag::note_pragma_entered_here);
271  return true;
272 }
273 
274 bool Sema::UnifySection(StringRef SectionName,
275  int SectionFlags,
276  SourceLocation PragmaSectionLocation) {
277  auto Section = Context.SectionInfos.find(SectionName);
278  if (Section != Context.SectionInfos.end()) {
279  if (Section->second.SectionFlags == SectionFlags)
280  return false;
281  if (!(Section->second.SectionFlags & ASTContext::PSF_Implicit)) {
282  Diag(PragmaSectionLocation, diag::err_section_conflict)
283  << "this" << "a prior #pragma section";
284  Diag(Section->second.PragmaSectionLocation,
285  diag::note_pragma_entered_here);
286  return true;
287  }
288  }
289  Context.SectionInfos[SectionName] =
290  ASTContext::SectionInfo(nullptr, PragmaSectionLocation, SectionFlags);
291  return false;
292 }
293 
294 /// \brief Called on well formed \#pragma bss_seg().
297  llvm::StringRef StackSlotLabel,
298  StringLiteral *SegmentName,
299  llvm::StringRef PragmaName) {
301  llvm::StringSwitch<PragmaStack<StringLiteral *> *>(PragmaName)
302  .Case("data_seg", &DataSegStack)
303  .Case("bss_seg", &BSSSegStack)
304  .Case("const_seg", &ConstSegStack)
305  .Case("code_seg", &CodeSegStack);
306  if (Action & PSK_Pop && Stack->Stack.empty())
307  Diag(PragmaLocation, diag::warn_pragma_pop_failed) << PragmaName
308  << "stack empty";
309  if (SegmentName &&
310  !checkSectionName(SegmentName->getLocStart(), SegmentName->getString()))
311  return;
312  Stack->Act(PragmaLocation, Action, StackSlotLabel, SegmentName);
313 }
314 
315 /// \brief Called on well formed \#pragma bss_seg().
317  int SectionFlags, StringLiteral *SegmentName) {
318  UnifySection(SegmentName->getString(), SectionFlags, PragmaLocation);
319 }
320 
322  StringLiteral *SegmentName) {
323  // There's no stack to maintain, so we just have a current section. When we
324  // see the default section, reset our current section back to null so we stop
325  // tacking on unnecessary attributes.
326  CurInitSeg = SegmentName->getString() == ".CRT$XCU" ? nullptr : SegmentName;
327  CurInitSegLoc = PragmaLocation;
328 }
329 
330 void Sema::ActOnPragmaUnused(const Token &IdTok, Scope *curScope,
331  SourceLocation PragmaLoc) {
332 
334  LookupResult Lookup(*this, Name, IdTok.getLocation(), LookupOrdinaryName);
335  LookupParsedName(Lookup, curScope, nullptr, true);
336 
337  if (Lookup.empty()) {
338  Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
339  << Name << SourceRange(IdTok.getLocation());
340  return;
341  }
342 
343  VarDecl *VD = Lookup.getAsSingle<VarDecl>();
344  if (!VD) {
345  Diag(PragmaLoc, diag::warn_pragma_unused_expected_var_arg)
346  << Name << SourceRange(IdTok.getLocation());
347  return;
348  }
349 
350  // Warn if this was used before being marked unused.
351  if (VD->isUsed())
352  Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name;
353 
354  VD->addAttr(UnusedAttr::CreateImplicit(Context, UnusedAttr::GNU_unused,
355  IdTok.getLocation()));
356 }
357 
360  if (!Loc.isValid()) return;
361 
362  // Don't add a redundant or conflicting attribute.
363  if (D->hasAttr<CFAuditedTransferAttr>() ||
364  D->hasAttr<CFUnknownTransferAttr>())
365  return;
366 
367  D->addAttr(CFAuditedTransferAttr::CreateImplicit(Context, Loc));
368 }
369 
370 void Sema::ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc) {
371  if(On)
373  else
374  OptimizeOffPragmaLocation = PragmaLoc;
375 }
376 
378  // In the future, check other pragmas if they're implemented (e.g. pragma
379  // optimize 0 will probably map to this functionality too).
382 }
383 
385  SourceLocation Loc) {
386  // Don't add a conflicting attribute. No diagnostic is needed.
387  if (FD->hasAttr<MinSizeAttr>() || FD->hasAttr<AlwaysInlineAttr>())
388  return;
389 
390  // Add attributes only if required. Optnone requires noinline as well, but if
391  // either is already present then don't bother adding them.
392  if (!FD->hasAttr<OptimizeNoneAttr>())
393  FD->addAttr(OptimizeNoneAttr::CreateImplicit(Context, Loc));
394  if (!FD->hasAttr<NoInlineAttr>())
395  FD->addAttr(NoInlineAttr::CreateImplicit(Context, Loc));
396 }
397 
398 typedef std::vector<std::pair<unsigned, SourceLocation> > VisStack;
399 enum : unsigned { NoVisibility = ~0U };
400 
402  if (!VisContext)
403  return;
404 
405  NamedDecl *ND = dyn_cast<NamedDecl>(D);
407  return;
408 
409  VisStack *Stack = static_cast<VisStack*>(VisContext);
410  unsigned rawType = Stack->back().first;
411  if (rawType == NoVisibility) return;
412 
413  VisibilityAttr::VisibilityType type
414  = (VisibilityAttr::VisibilityType) rawType;
415  SourceLocation loc = Stack->back().second;
416 
417  D->addAttr(VisibilityAttr::CreateImplicit(Context, type, loc));
418 }
419 
420 /// FreeVisContext - Deallocate and null out VisContext.
422  delete static_cast<VisStack*>(VisContext);
423  VisContext = nullptr;
424 }
425 
426 static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc) {
427  // Put visibility on stack.
428  if (!S.VisContext)
429  S.VisContext = new VisStack;
430 
431  VisStack *Stack = static_cast<VisStack*>(S.VisContext);
432  Stack->push_back(std::make_pair(type, loc));
433 }
434 
436  SourceLocation PragmaLoc) {
437  if (VisType) {
438  // Compute visibility to use.
439  VisibilityAttr::VisibilityType T;
440  if (!VisibilityAttr::ConvertStrToVisibilityType(VisType->getName(), T)) {
441  Diag(PragmaLoc, diag::warn_attribute_unknown_visibility) << VisType;
442  return;
443  }
444  PushPragmaVisibility(*this, T, PragmaLoc);
445  } else {
446  PopPragmaVisibility(false, PragmaLoc);
447  }
448 }
449 
451  switch (OOS) {
452  case tok::OOS_ON:
454  break;
455  case tok::OOS_OFF:
456  FPFeatures.fp_contract = 0;
457  break;
458  case tok::OOS_DEFAULT:
459  FPFeatures.fp_contract = getLangOpts().DefaultFPContract;
460  break;
461  }
462 }
463 
464 void Sema::PushNamespaceVisibilityAttr(const VisibilityAttr *Attr,
465  SourceLocation Loc) {
466  // Visibility calculations will consider the namespace's visibility.
467  // Here we just want to note that we're in a visibility context
468  // which overrides any enclosing #pragma context, but doesn't itself
469  // contribute visibility.
470  PushPragmaVisibility(*this, NoVisibility, Loc);
471 }
472 
473 void Sema::PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc) {
474  if (!VisContext) {
475  Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
476  return;
477  }
478 
479  // Pop visibility from stack
480  VisStack *Stack = static_cast<VisStack*>(VisContext);
481 
482  const std::pair<unsigned, SourceLocation> *Back = &Stack->back();
483  bool StartsWithPragma = Back->first != NoVisibility;
484  if (StartsWithPragma && IsNamespaceEnd) {
485  Diag(Back->second, diag::err_pragma_push_visibility_mismatch);
486  Diag(EndLoc, diag::note_surrounding_namespace_ends_here);
487 
488  // For better error recovery, eat all pushes inside the namespace.
489  do {
490  Stack->pop_back();
491  Back = &Stack->back();
492  StartsWithPragma = Back->first != NoVisibility;
493  } while (StartsWithPragma);
494  } else if (!StartsWithPragma && !IsNamespaceEnd) {
495  Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
496  Diag(Back->second, diag::note_surrounding_namespace_starts_here);
497  return;
498  }
499 
500  Stack->pop_back();
501  // To simplify the implementation, never keep around an empty stack.
502  if (Stack->empty())
503  FreeVisContext();
504 }
PragmaStack< StringLiteral * > CodeSegStack
Definition: Sema.h:409
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1561
PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct)
Definition: SemaAttr.cpp:28
ASTConsumer & Consumer
Definition: Sema.h:300
void ActOnPragmaMSStruct(PragmaMSStructKind Kind)
ActOnPragmaMSStruct - Called on well formed #pragma ms_struct [on|off].
Definition: SemaAttr.cpp:175
void SentinelAction(PragmaMsStackAction Action, StringRef Label)
Definition: Sema.h:374
PragmaStack< StringLiteral * > DataSegStack
Definition: Sema.h:406
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
Definition: Sema.h:2705
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:295
const LangOptions & getLangOpts() const
Definition: Sema.h:1062
llvm::StringRef StackSlotLabel
Definition: Sema.h:346
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1139
void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, SourceLocation PragmaLoc, MSVtorDispAttr::Mode Value)
Called on well formed #pragma vtordisp().
Definition: SemaAttr.cpp:202
PragmaOptionsAlignKind
Definition: Sema.h:7718
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:1602
unsigned fp_contract
Definition: LangOptions.h:163
void ActOnPragmaFPContract(tok::OnOffSwitch OOS)
ActOnPragmaFPContract - Called on well formed #pragma {STDC,OPENCL} FP_CONTRACT.
Definition: SemaAttr.cpp:450
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:768
RecordDecl - Represents a struct/union/class.
Definition: Decl.h:3253
void FreeVisContext()
FreeVisContext - Deallocate and null out VisContext.
Definition: SemaAttr.cpp:421
One of these records is kept for each identifier that is lexed.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4549
bool hasAlignMac68kSupport() const
Check whether this target support '#pragma options align=mac68k'.
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
FrontendAction * Action
Definition: Tooling.cpp:201
static PragmaCommentDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation CommentLoc, PragmaMSCommentKind CommentKind, StringRef Arg)
Definition: Decl.cpp:3926
static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc)
Definition: SemaAttr.cpp:426
void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags, StringLiteral *SegmentName)
Called on well formed #pragma section().
Definition: SemaAttr.cpp:316
Represents the results of name lookup.
Definition: Sema/Lookup.h:30
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:588
void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, SourceLocation PragmaLoc)
ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
Definition: SemaAttr.cpp:78
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
Definition: Expr.h:147
bool UnifySection(StringRef SectionName, int SectionFlags, DeclaratorDecl *TheDecl)
Definition: SemaAttr.cpp:247
void AddPushedVisibilityAttribute(Decl *RD)
AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used, add an appropriate visibility at...
Definition: SemaAttr.cpp:401
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:39
void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value)
ActOnPragmaDetectMismatch - Call on well-formed #pragma detect_mismatch.
Definition: SemaAttr.cpp:187
Preprocessor & PP
Definition: Sema.h:298
detail::InMemoryDirectory::const_iterator I
void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc)
PopPragmaVisibility - Pop the top element of the visibility stack; used for '#pragma GCC visibility' ...
Definition: SemaAttr.cpp:473
bool MSStructPragmaOn
Definition: Sema.h:321
llvm::StringMap< SectionInfo > SectionInfos
Definition: ASTContext.h:2601
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:263
Represents a ValueDecl that came out of a declarator.
Definition: Decl.h:646
std::vector< bool > & Stack
std::vector< std::pair< unsigned, SourceLocation > > VisStack
Definition: SemaAttr.cpp:398
Expr - This represents one expression.
Definition: Expr.h:105
StringRef getName() const
Return the actual identifier string.
void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, StringLiteral *SegmentName)
Called on well-formed #pragma init_seg().
Definition: SemaAttr.cpp:321
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:886
Defines the clang::Preprocessor interface.
PragmaStack< StringLiteral * > BSSSegStack
Definition: Sema.h:407
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Definition: Token.h:123
void ActOnPragmaUnused(const Token &Identifier, Scope *curScope, SourceLocation PragmaLoc)
ActOnPragmaUnused - Called on well-formed '#pragma unused'.
Definition: SemaAttr.cpp:330
void ActOnPragmaMSComment(SourceLocation CommentLoc, PragmaMSCommentKind Kind, StringRef Arg)
ActOnPragmaMSComment - Called on well formed #pragma comment(kind, "arg").
Definition: SemaAttr.cpp:179
PragmaMSCommentKind
Definition: PragmaKinds.h:15
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:384
Optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
Definition: Decl.cpp:1113
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:377
StringLiteral * CurInitSeg
Last section used with #pragma init_seg.
Definition: Sema.h:428
Kind
Encodes a location in the source.
void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, llvm::StringRef StackSlotLabel, ValueType Value)
Definition: SemaAttr.cpp:212
void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, StringRef SlotLabel, Expr *Alignment)
ActOnPragmaPack - Called on well formed #pragma pack(...).
Definition: SemaAttr.cpp:129
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
isIntegerConstantExpr - Return true if this expression is a valid integer constant expression...
PragmaStack< MSVtorDispAttr::Mode > VtorDispStack
Whether to insert vtordisps prior to virtual bases in the Microsoft C++ ABI.
Definition: Sema.h:400
SourceLocation OptimizeOffPragmaLocation
This represents the last location of a "#pragma clang optimize off" directive if such a directive has...
Definition: Sema.h:437
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
Definition: Expr.h:165
SourceLocation ImplicitMSInheritanceAttrLoc
Source location for newly created implicit MSInheritanceAttrs.
Definition: Sema.h:331
void AddAlignmentAttributesForRecord(RecordDecl *RD)
AddAlignmentAttributesForRecord - Adds any needed alignment attributes to a the record decl...
Definition: SemaAttr.cpp:51
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchers.h:1983
static PragmaDetectMismatchDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation Loc, StringRef Name, StringRef Value)
Definition: Decl.cpp:3949
StringRef getString() const
Definition: Expr.h:1514
PragmaMsStackAction
Definition: Sema.h:333
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)
ActOnPragmaMSPointersToMembers - called on well formed #pragma pointers_to_members(representation met...
Definition: SemaAttr.cpp:195
ValueType CurrentValue
Definition: Sema.h:386
PragmaMSStructKind
Definition: PragmaKinds.h:24
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1296
PragmaStack< StringLiteral * > ConstSegStack
Definition: Sema.h:408
void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, SourceLocation Loc)
PushNamespaceVisibilityAttr - Note that we've entered a namespace with a visibility attribute...
Definition: SemaAttr.cpp:464
void * VisContext
VisContext - Manages the stack for #pragma GCC visibility.
Definition: Sema.h:432
LangOptions::PragmaMSPointersToMembersKind MSPointerToMemberRepresentationMethod
Controls member pointer representation format under the MS ABI.
Definition: Sema.h:325
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1466
Defines the clang::TargetInfo interface.
FPOptions FPFeatures
Definition: Sema.h:295
bool checkSectionName(SourceLocation LiteralLoc, StringRef Str)
void ActOnPragmaVisibility(const IdentifierInfo *VisType, SourceLocation PragmaLoc)
ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
Definition: SemaAttr.cpp:435
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
Definition: ASTConsumer.cpp:19
PragmaStack< unsigned > PackStack
Definition: Sema.h:404
A trivial tuple used to represent a source range.
ASTContext & Context
Definition: Sema.h:299
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
void AddMsStructLayoutForRecord(RecordDecl *RD)
AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
Definition: SemaAttr.cpp:66
SmallVector< Slot, 2 > Stack
Definition: Sema.h:384
SourceLocation getPragmaARCCFCodeAuditedLoc() const
The location of the currently-active #pragma clang arc_cf_code_audited begin.
Attr - This represents one attribute.
Definition: Attr.h:45
void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc)
Called on well formed #pragma clang optimize.
Definition: SemaAttr.cpp:370
static const unsigned kMac68kAlignmentSentinel
Definition: Sema.h:403
void AddCFAuditedAttribute(Decl *D)
AddCFAuditedAttribute - Check whether we're currently within '#pragma clang arc_cf_code_audited' and...
Definition: SemaAttr.cpp:358
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:176
SourceLocation CurInitSegLoc
Definition: Sema.h:429