22 using namespace clang;
29 struct PackStackEntry {
32 static const unsigned kMac68kAlignmentSentinel = ~0U;
40 class PragmaPackStack {
41 typedef std::vector<PackStackEntry> stack_ty;
51 PragmaPackStack() : Alignment(0) {}
53 void setAlignment(
unsigned A) { Alignment = A; }
54 unsigned getAlignment() {
return Alignment; }
59 PackStackEntry PSE = { Alignment, Name };
87 Alignment =
Stack.back().Alignment;
95 for (
unsigned i =
Stack.size(); i != 0; ) {
97 if (
Stack[i].Name == Name) {
99 Alignment =
Stack[i].Alignment;
123 if (
unsigned Alignment = Stack->getAlignment()) {
124 if (Alignment == PackStackEntry::kMac68kAlignmentSentinel)
158 Context->push(
nullptr);
159 Context->setAlignment(0);
165 Context->push(
nullptr);
166 Context->setAlignment(1);
171 if (!this->Context.getTargetInfo().hasAlignMac68kSupport()) {
172 Diag(PragmaLoc, diag::err_pragma_options_align_mac68k_target_unsupported);
175 Context->push(
nullptr);
176 Context->setAlignment(PackStackEntry::kMac68kAlignmentSentinel);
182 if (!Context->pop(
nullptr,
true)) {
183 Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
193 Expr *Alignment =
static_cast<Expr *
>(alignment);
196 unsigned AlignmentVal = 0;
205 !(Val == 0 || Val.isPowerOf2()) ||
206 Val.getZExtValue() > 16) {
207 Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
211 AlignmentVal = (
unsigned) Val.getZExtValue();
221 Context->setAlignment(AlignmentVal);
227 AlignmentVal = Context->getAlignment();
229 if (AlignmentVal == 0)
231 if (AlignmentVal == PackStackEntry::kMac68kAlignmentSentinel)
232 Diag(PragmaLoc, diag::warn_pragma_pack_show) <<
"mac68k";
234 Diag(PragmaLoc, diag::warn_pragma_pack_show) << AlignmentVal;
241 Context->setAlignment(AlignmentVal);
247 if (Alignment && Name)
248 Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifer_and_alignment);
251 if (!Context->pop(Name,
false)) {
255 Diag(PragmaLoc, diag::warn_pragma_pop_failed)
256 <<
"pack" << (Name ?
"no record matching name" :
"stack empty");
262 Context->setAlignment(AlignmentVal);
276 llvm_unreachable(
"unexpected pragma comment kind");
288 llvm_unreachable(
"invalid pragma comment kind");
305 MSVtorDispAttr::Mode Mode) {
320 Diag(PragmaLoc, diag::warn_pragma_pop_failed) <<
"vtordisp"
328 template<
typename ValueType>
331 llvm::StringRef StackSlotLabel,
333 if (Action == PSK_Reset) {
334 CurrentValue =
nullptr;
337 if (Action & PSK_Push)
338 Stack.push_back(
Slot(StackSlotLabel, CurrentValue, CurrentPragmaLocation));
339 else if (Action & PSK_Pop) {
340 if (!StackSlotLabel.empty()) {
342 auto I = std::find_if(
Stack.rbegin(),
Stack.rend(),
343 [&](
const Slot &x) {
return x.StackSlotLabel == StackSlotLabel; });
345 if (I !=
Stack.rend()) {
346 CurrentValue = I->Value;
347 CurrentPragmaLocation = I->PragmaLocation;
348 Stack.erase(std::prev(I.base()),
Stack.end());
350 }
else if (!
Stack.empty()) {
352 CurrentValue =
Stack.back().Value;
353 CurrentPragmaLocation =
Stack.back().PragmaLocation;
357 if (Action & PSK_Set) {
358 CurrentValue =
Value;
359 CurrentPragmaLocation = PragmaLocation;
373 if (Section->second.SectionFlags == SectionFlags ||
376 auto OtherDecl = Section->second.Decl;
378 << Decl << OtherDecl;
379 Diag(OtherDecl->getLocation(), diag::note_declared_at)
380 << OtherDecl->getName();
381 if (
auto A = Decl->
getAttr<SectionAttr>())
383 Diag(A->getLocation(), diag::note_pragma_entered_here);
384 if (
auto A = OtherDecl->getAttr<SectionAttr>())
386 Diag(A->getLocation(), diag::note_pragma_entered_here);
395 if (Section->second.SectionFlags == SectionFlags)
398 Diag(PragmaSectionLocation, diag::err_section_conflict)
399 <<
"this" <<
"a prior #pragma section";
400 Diag(Section->second.PragmaSectionLocation,
401 diag::note_pragma_entered_here);
413 llvm::StringRef StackSlotLabel,
415 llvm::StringRef PragmaName) {
417 llvm::StringSwitch<PragmaStack<StringLiteral *> *>(PragmaName)
423 Diag(PragmaLocation, diag::warn_pragma_pop_failed) << PragmaName
428 Stack->
Act(PragmaLocation, Action, StackSlotLabel, SegmentName);
453 if (Lookup.empty()) {
454 Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
461 Diag(PragmaLoc, diag::warn_pragma_unused_expected_var_arg)
468 Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name;
478 if (D->
hasAttr<CFAuditedTransferAttr>() ||
479 D->
hasAttr<CFUnknownTransferAttr>())
502 if (FD->
hasAttr<MinSizeAttr>() || FD->
hasAttr<AlwaysInlineAttr>())
507 if (!FD->
hasAttr<OptimizeNoneAttr>())
509 if (!FD->
hasAttr<NoInlineAttr>())
513 typedef std::vector<std::pair<unsigned, SourceLocation> >
VisStack;
525 unsigned rawType = Stack->back().first;
528 VisibilityAttr::VisibilityType
type
529 = (VisibilityAttr::VisibilityType) rawType;
547 Stack->push_back(std::make_pair(type, loc));
554 VisibilityAttr::VisibilityType T;
555 if (!VisibilityAttr::ConvertStrToVisibilityType(VisType->
getName(), T)) {
556 Diag(PragmaLoc, diag::warn_attribute_unknown_visibility) << VisType;
590 Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
597 const std::pair<unsigned, SourceLocation> *Back = &Stack->back();
599 if (StartsWithPragma && IsNamespaceEnd) {
600 Diag(Back->second, diag::err_pragma_push_visibility_mismatch);
601 Diag(EndLoc, diag::note_surrounding_namespace_ends_here);
606 Back = &Stack->back();
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);
void FreePackedContext()
FreePackedContext - Deallocate and null out PackContext.
PragmaStack< StringLiteral * > CodeSegStack
void ActOnPragmaMSStruct(PragmaMSStructKind Kind)
ActOnPragmaMSStruct - Called on well formed #pragma ms_struct [on|off].
PragmaStack< StringLiteral * > DataSegStack
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
SmallVector< MSVtorDispAttr::Mode, 2 > VtorDispModeStack
Whether to insert vtordisps prior to virtual bases in the Microsoft C++ ABI. Possible values are 0...
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
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)
void FreeVisContext()
FreeVisContext - Deallocate and null out VisContext.
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 ...
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.
void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, SourceLocation PragmaLoc)
ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
void ActOnPragmaPack(PragmaPackKind Kind, IdentifierInfo *Name, Expr *Alignment, SourceLocation PragmaLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
ActOnPragmaPack - Called on well formed #pragma pack(...).
bool isValueDependent() const
bool UnifySection(StringRef SectionName, int SectionFlags, DeclaratorDecl *TheDecl)
void AddPushedVisibilityAttribute(Decl *RD)
const LangOptions & LangOpts
void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc)
llvm::StringMap< SectionInfo > SectionInfos
Sema - This implements semantic analysis and AST building for C.
Represents a ValueDecl that came out of a declarator. Contains type source information through TypeSo...
std::vector< bool > & Stack
std::vector< std::pair< unsigned, SourceLocation > > VisStack
StringRef getName() const
Return the actual identifier string.
void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, StringLiteral *SegmentName)
Called on well-formed #pragma init_seg().
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 ActOnPragmaDetectMismatch(StringRef Name, StringRef Value)
ActOnPragmaDetectMismatch - Call on well-formed #pragma detect_mismatch.
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.
virtual void HandleLinkerOptionPragma(llvm::StringRef Opts)
Handle a pragma that appends to Linker Options. Currently this only exists to support Microsoft's #pr...
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)
void ActOnPragmaMSVtorDisp(PragmaVtorDispKind Kind, SourceLocation PragmaLoc, MSVtorDispAttr::Mode Value)
Called on well formed #pragma vtordisp().
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...
bool isTypeDependent() const
PragmaMSPointersToMembersKind
virtual void HandleDependentLibrary(llvm::StringRef Lib)
Handle a dependent library created by a pragma in the source. Currently this only exists to support M...
SourceLocation ImplicitMSInheritanceAttrLoc
Source location for newly created implicit MSInheritanceAttrs.
void AddAlignmentAttributesForRecord(RecordDecl *RD)
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
bool isUsed(bool CheckUsedAttr=true) const
Whether this declaration was used, meaning that a definition is required.
StringRef getString() const
#pragma vtordisp(push, mode)
void ActOnPragmaMSComment(PragmaMSCommentKind Kind, StringRef Arg)
OnOffSwitch
Defines the possible values of an on-off-switch (C99 6.10.6p2).
void ActOnPragmaMSPointersToMembers(LangOptions::PragmaMSPointersToMembersKind Kind, SourceLocation PragmaLoc)
PragmaStack< StringLiteral * > ConstSegStack
void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, SourceLocation Loc)
void * VisContext
VisContext - Manages the stack for #pragma GCC visibility.
LangOptions::PragmaMSPointersToMembersKind MSPointerToMemberRepresentationMethod
Controls member pointer representation format under the MS ABI.
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... .
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
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.
void AddCFAuditedAttribute(Decl *D)
IdentifierInfo * getIdentifierInfo() const
SourceLocation CurInitSegLoc