22 using namespace clang;
31 : S(S), SlotLabel(SlotLabel), ShouldAct(ShouldAct) {
59 RD->addAttr(AlignMac68kAttr::CreateImplicit(
Context));
61 RD->addAttr(MaxFieldAlignmentAttr::CreateImplicit(
Context,
68 RD->addAttr(MSStructAttr::CreateImplicit(
Context));
81 unsigned Alignment = 0;
103 Diag(PragmaLoc, diag::err_pragma_options_align_mac68k_target_unsupported);
118 Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
126 PackStack.
Act(PragmaLoc, Action, StringRef(), Alignment);
130 StringRef SlotLabel,
Expr *alignment) {
131 Expr *Alignment =
static_cast<Expr *
>(alignment);
134 unsigned AlignmentVal = 0;
143 !(Val == 0 || Val.isPowerOf2()) ||
144 Val.getZExtValue() > 16) {
145 Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
149 AlignmentVal = (
unsigned) Val.getZExtValue();
156 if (AlignmentVal == 0)
159 Diag(PragmaLoc, diag::warn_pragma_pack_show) <<
"mac68k";
161 Diag(PragmaLoc, diag::warn_pragma_pack_show) << AlignmentVal;
166 if (Alignment && !SlotLabel.empty())
167 Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifer_and_alignment);
169 Diag(PragmaLoc, diag::warn_pragma_pop_failed) <<
"pack" <<
"stack empty";
172 PackStack.
Act(PragmaLoc, Action, SlotLabel, AlignmentVal);
204 MSVtorDispAttr::Mode Mode) {
206 Diag(PragmaLoc, diag::warn_pragma_pop_failed) <<
"vtordisp"
211 template<
typename ValueType>
214 llvm::StringRef StackSlotLabel,
217 CurrentValue = DefaultValue;
221 Stack.push_back(
Slot(StackSlotLabel, CurrentValue, CurrentPragmaLocation));
223 if (!StackSlotLabel.empty()) {
225 auto I = llvm::find_if(llvm::reverse(
Stack), [&](
const Slot &x) {
230 CurrentValue =
I->Value;
231 CurrentPragmaLocation =
I->PragmaLocation;
234 }
else if (!
Stack.empty()) {
236 CurrentValue =
Stack.back().Value;
237 CurrentPragmaLocation =
Stack.back().PragmaLocation;
242 CurrentValue =
Value;
243 CurrentPragmaLocation = PragmaLocation;
257 if (Section->second.SectionFlags == SectionFlags ||
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>())
267 Diag(A->getLocation(), diag::note_pragma_entered_here);
268 if (
auto A = OtherDecl->getAttr<SectionAttr>())
270 Diag(A->getLocation(), diag::note_pragma_entered_here);
279 if (Section->second.SectionFlags == SectionFlags)
282 Diag(PragmaSectionLocation, diag::err_section_conflict)
283 <<
"this" <<
"a prior #pragma section";
284 Diag(Section->second.PragmaSectionLocation,
285 diag::note_pragma_entered_here);
297 llvm::StringRef StackSlotLabel,
299 llvm::StringRef PragmaName) {
301 llvm::StringSwitch<PragmaStack<StringLiteral *> *>(PragmaName)
307 Diag(PragmaLocation, diag::warn_pragma_pop_failed) << PragmaName
312 Stack->
Act(PragmaLocation, Action, StackSlotLabel, SegmentName);
337 if (Lookup.empty()) {
338 Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
345 Diag(PragmaLoc, diag::warn_pragma_unused_expected_var_arg)
352 Diag(PragmaLoc, diag::warn_used_but_marked_unused) <<
Name;
354 VD->addAttr(UnusedAttr::CreateImplicit(
Context, UnusedAttr::GNU_unused,
363 if (D->hasAttr<CFAuditedTransferAttr>() ||
364 D->hasAttr<CFUnknownTransferAttr>())
367 D->addAttr(CFAuditedTransferAttr::CreateImplicit(
Context, Loc));
387 if (FD->hasAttr<MinSizeAttr>() || FD->hasAttr<AlwaysInlineAttr>())
392 if (!FD->hasAttr<OptimizeNoneAttr>())
393 FD->addAttr(OptimizeNoneAttr::CreateImplicit(
Context, Loc));
394 if (!FD->hasAttr<NoInlineAttr>())
395 FD->addAttr(NoInlineAttr::CreateImplicit(
Context, Loc));
398 typedef std::vector<std::pair<unsigned, SourceLocation> >
VisStack;
410 unsigned rawType = Stack->back().first;
413 VisibilityAttr::VisibilityType
type
414 = (VisibilityAttr::VisibilityType) rawType;
417 D->addAttr(VisibilityAttr::CreateImplicit(
Context, type, loc));
432 Stack->push_back(std::make_pair(type, loc));
439 VisibilityAttr::VisibilityType T;
440 if (!VisibilityAttr::ConvertStrToVisibilityType(VisType->
getName(), T)) {
441 Diag(PragmaLoc, diag::warn_attribute_unknown_visibility) << VisType;
475 Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
482 const std::pair<unsigned, SourceLocation> *Back = &Stack->back();
484 if (StartsWithPragma && IsNamespaceEnd) {
485 Diag(Back->second, diag::err_pragma_push_visibility_mismatch);
486 Diag(EndLoc, diag::note_surrounding_namespace_ends_here);
491 Back = &Stack->back();
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);
PragmaStack< StringLiteral * > CodeSegStack
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct)
void ActOnPragmaMSStruct(PragmaMSStructKind Kind)
ActOnPragmaMSStruct - Called on well formed #pragma ms_struct [on|off].
void SentinelAction(PragmaMsStackAction Action, StringRef Label)
PragmaStack< StringLiteral * > DataSegStack
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
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.
const LangOptions & getLangOpts() const
llvm::StringRef StackSlotLabel
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, SourceLocation PragmaLoc, MSVtorDispAttr::Mode Value)
Called on well formed #pragma vtordisp().
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
void ActOnPragmaFPContract(tok::OnOffSwitch OOS)
ActOnPragmaFPContract - Called on well formed #pragma {STDC,OPENCL} FP_CONTRACT.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
RecordDecl - Represents a struct/union/class.
void FreeVisContext()
FreeVisContext - Deallocate and null out VisContext.
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. ...
bool hasAlignMac68kSupport() const
Check whether this target support '#pragma options align=mac68k'.
Token - This structure provides full information about a lexed token.
static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc)
void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags, StringLiteral *SegmentName)
Called on well formed #pragma section().
Represents the results of name lookup.
const TargetInfo & getTargetInfo() const
void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, SourceLocation PragmaLoc)
ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
bool UnifySection(StringRef SectionName, int SectionFlags, DeclaratorDecl *TheDecl)
void AddPushedVisibilityAttribute(Decl *RD)
AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used, add an appropriate visibility at...
Scope - A scope is a transient data structure that is used while parsing the program.
void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value)
ActOnPragmaDetectMismatch - Call on well-formed #pragma detect_mismatch.
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' ...
llvm::StringMap< SectionInfo > SectionInfos
Sema - This implements semantic analysis and AST building for C.
Represents a ValueDecl that came out of a declarator.
std::vector< bool > & Stack
std::vector< std::pair< unsigned, SourceLocation > > VisStack
Expr - This represents one expression.
StringRef getName() const
Return the actual identifier string.
void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, StringLiteral *SegmentName)
Called on well-formed #pragma init_seg().
TranslationUnitDecl * getTranslationUnitDecl() const
Defines the clang::Preprocessor interface.
PragmaStack< StringLiteral * > BSSSegStack
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
void ActOnPragmaUnused(const Token &Identifier, Scope *curScope, SourceLocation PragmaLoc)
ActOnPragmaUnused - Called on well-formed '#pragma unused'.
void ActOnPragmaMSComment(SourceLocation CommentLoc, PragmaMSCommentKind Kind, StringRef Arg)
ActOnPragmaMSComment - Called on well formed #pragma comment(kind, "arg").
~PragmaStackSentinelRAII()
void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc)
Adds the 'optnone' attribute to the function declaration if there are no conflicts; Loc represents th...
Optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
void AddRangeBasedOptnone(FunctionDecl *FD)
Only called on function definitions; if there is a pragma in scope with the effect of a range-based o...
StringLiteral * CurInitSeg
Last section used with #pragma init_seg.
Encodes a location in the source.
void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, llvm::StringRef StackSlotLabel, ValueType Value)
void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, StringRef SlotLabel, Expr *Alignment)
ActOnPragmaPack - Called on well formed #pragma pack(...).
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.
SourceLocation OptimizeOffPragmaLocation
This represents the last location of a "#pragma clang optimize off" directive if such a directive has...
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.
PragmaMSPointersToMembersKind
SourceLocation ImplicitMSInheritanceAttrLoc
Source location for newly created implicit MSInheritanceAttrs.
void AddAlignmentAttributesForRecord(RecordDecl *RD)
AddAlignmentAttributesForRecord - Adds any needed alignment attributes to a the record decl...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
static PragmaDetectMismatchDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation Loc, StringRef Name, StringRef Value)
StringRef getString() const
OnOffSwitch
Defines the possible values of an on-off-switch (C99 6.10.6p2).
void ActOnPragmaMSPointersToMembers(LangOptions::PragmaMSPointersToMembersKind Kind, SourceLocation PragmaLoc)
ActOnPragmaMSPointersToMembers - called on well formed #pragma pointers_to_members(representation met...
void addDecl(Decl *D)
Add the declaration D into this context.
PragmaStack< StringLiteral * > ConstSegStack
void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, SourceLocation Loc)
PushNamespaceVisibilityAttr - Note that we've entered a namespace with a visibility attribute...
void * VisContext
VisContext - Manages the stack for #pragma GCC visibility.
LangOptions::PragmaMSPointersToMembersKind MSPointerToMemberRepresentationMethod
Controls member pointer representation format under the MS ABI.
StringLiteral - This represents a string literal expression, e.g.
Defines the clang::TargetInfo interface.
bool checkSectionName(SourceLocation LiteralLoc, StringRef Str)
void ActOnPragmaVisibility(const IdentifierInfo *VisType, SourceLocation PragmaLoc)
ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
PragmaStack< unsigned > PackStack
A trivial tuple used to represent a source range.
NamedDecl - This represents a decl with a name.
void AddMsStructLayoutForRecord(RecordDecl *RD)
AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
SmallVector< Slot, 2 > Stack
SourceLocation getPragmaARCCFCodeAuditedLoc() const
The location of the currently-active #pragma clang arc_cf_code_audited begin.
Attr - This represents one attribute.
void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc)
Called on well formed #pragma clang optimize.
static const unsigned kMac68kAlignmentSentinel
void AddCFAuditedAttribute(Decl *D)
AddCFAuditedAttribute - Check whether we're currently within '#pragma clang arc_cf_code_audited' and...
IdentifierInfo * getIdentifierInfo() const
SourceLocation CurInitSegLoc