clang 17.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
15#include "clang/AST/Attr.h"
16#include "clang/AST/Expr.h"
19#include "clang/Sema/Lookup.h"
21#include <optional>
22using 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);
39 }
40}
41
43 if (ShouldAct) {
45 S.DataSegStack.SentinelAction(PSK_Pop, SlotLabel);
46 S.BSSSegStack.SentinelAction(PSK_Pop, SlotLabel);
47 S.ConstSegStack.SentinelAction(PSK_Pop, SlotLabel);
48 S.CodeSegStack.SentinelAction(PSK_Pop, SlotLabel);
50 }
51}
52
54 AlignPackInfo InfoVal = AlignPackStack.CurrentValue;
56 bool IsPackSet = InfoVal.IsPackSet();
57 bool IsXLPragma = getLangOpts().XLPragmaPack;
58
59 // If we are not under mac68k/natural alignment mode and also there is no pack
60 // value, we don't need any attributes.
61 if (!IsPackSet && M != AlignPackInfo::Mac68k && M != AlignPackInfo::Natural)
62 return;
63
64 if (M == AlignPackInfo::Mac68k && (IsXLPragma || InfoVal.IsAlignAttr())) {
65 RD->addAttr(AlignMac68kAttr::CreateImplicit(Context));
66 } else if (IsPackSet) {
67 // Check to see if we need a max field alignment attribute.
68 RD->addAttr(MaxFieldAlignmentAttr::CreateImplicit(
69 Context, InfoVal.getPackNumber() * 8));
70 }
71
72 if (IsXLPragma && M == AlignPackInfo::Natural)
73 RD->addAttr(AlignNaturalAttr::CreateImplicit(Context));
74
75 if (AlignPackIncludeStack.empty())
76 return;
77 // The #pragma align/pack affected a record in an included file, so Clang
78 // should warn when that pragma was written in a file that included the
79 // included file.
80 for (auto &AlignPackedInclude : llvm::reverse(AlignPackIncludeStack)) {
81 if (AlignPackedInclude.CurrentPragmaLocation !=
82 AlignPackStack.CurrentPragmaLocation)
83 break;
84 if (AlignPackedInclude.HasNonDefaultValue)
85 AlignPackedInclude.ShouldWarnOnInclude = true;
86 }
87}
88
91 RD->addAttr(MSStructAttr::CreateImplicit(Context));
92
93 // FIXME: We should merge AddAlignmentAttributesForRecord with
94 // AddMsStructLayoutForRecord into AddPragmaAttributesForRecord, which takes
95 // all active pragmas and applies them as attributes to class definitions.
96 if (VtorDispStack.CurrentValue != getLangOpts().getVtorDispMode())
97 RD->addAttr(MSVtorDispAttr::CreateImplicit(
99}
100
101template <typename Attribute>
103 CXXRecordDecl *Record) {
104 if (Record->hasAttr<OwnerAttr>() || Record->hasAttr<PointerAttr>())
105 return;
106
107 for (Decl *Redecl : Record->redecls())
108 Redecl->addAttr(Attribute::CreateImplicit(Context, /*DerefType=*/nullptr));
109}
110
112 CXXRecordDecl *UnderlyingRecord) {
113 if (!UnderlyingRecord)
114 return;
115
116 const auto *Parent = dyn_cast<CXXRecordDecl>(ND->getDeclContext());
117 if (!Parent)
118 return;
119
120 static llvm::StringSet<> Containers{
121 "array",
122 "basic_string",
123 "deque",
124 "forward_list",
125 "vector",
126 "list",
127 "map",
128 "multiset",
129 "multimap",
130 "priority_queue",
131 "queue",
132 "set",
133 "stack",
134 "unordered_set",
135 "unordered_map",
136 "unordered_multiset",
137 "unordered_multimap",
138 };
139
140 static llvm::StringSet<> Iterators{"iterator", "const_iterator",
141 "reverse_iterator",
142 "const_reverse_iterator"};
143
144 if (Parent->isInStdNamespace() && Iterators.count(ND->getName()) &&
145 Containers.count(Parent->getName()))
146 addGslOwnerPointerAttributeIfNotExisting<PointerAttr>(Context,
147 UnderlyingRecord);
148}
149
151
152 QualType Canonical = TD->getUnderlyingType().getCanonicalType();
153
154 CXXRecordDecl *RD = Canonical->getAsCXXRecordDecl();
155 if (!RD) {
156 if (auto *TST =
157 dyn_cast<TemplateSpecializationType>(Canonical.getTypePtr())) {
158
159 RD = dyn_cast_or_null<CXXRecordDecl>(
160 TST->getTemplateName().getAsTemplateDecl()->getTemplatedDecl());
161 }
162 }
163
165}
166
168 static llvm::StringSet<> StdOwners{
169 "any",
170 "array",
171 "basic_regex",
172 "basic_string",
173 "deque",
174 "forward_list",
175 "vector",
176 "list",
177 "map",
178 "multiset",
179 "multimap",
180 "optional",
181 "priority_queue",
182 "queue",
183 "set",
184 "stack",
185 "unique_ptr",
186 "unordered_set",
187 "unordered_map",
188 "unordered_multiset",
189 "unordered_multimap",
190 "variant",
191 };
192 static llvm::StringSet<> StdPointers{
193 "basic_string_view",
194 "reference_wrapper",
195 "regex_iterator",
196 };
197
198 if (!Record->getIdentifier())
199 return;
200
201 // Handle classes that directly appear in std namespace.
202 if (Record->isInStdNamespace()) {
203 if (Record->hasAttr<OwnerAttr>() || Record->hasAttr<PointerAttr>())
204 return;
205
206 if (StdOwners.count(Record->getName()))
207 addGslOwnerPointerAttributeIfNotExisting<OwnerAttr>(Context, Record);
208 else if (StdPointers.count(Record->getName()))
209 addGslOwnerPointerAttributeIfNotExisting<PointerAttr>(Context, Record);
210
211 return;
212 }
213
214 // Handle nested classes that could be a gsl::Pointer.
215 inferGslPointerAttribute(Record, Record);
216}
217
219 SourceLocation PragmaLoc) {
222
223 switch (Kind) {
224 // For most of the platforms we support, native and natural are the same.
225 // With XL, native is the same as power, natural means something else.
226 //
227 // FIXME: This is not true on Darwin/PPC.
228 case POAK_Native:
229 case POAK_Power:
230 Action = Sema::PSK_Push_Set;
231 break;
232 case POAK_Natural:
233 Action = Sema::PSK_Push_Set;
234 ModeVal = AlignPackInfo::Natural;
235 break;
236
237 // Note that '#pragma options align=packed' is not equivalent to attribute
238 // packed, it has a different precedence relative to attribute aligned.
239 case POAK_Packed:
240 Action = Sema::PSK_Push_Set;
241 ModeVal = AlignPackInfo::Packed;
242 break;
243
244 case POAK_Mac68k:
245 // Check if the target supports this.
247 Diag(PragmaLoc, diag::err_pragma_options_align_mac68k_target_unsupported);
248 return;
249 }
250 Action = Sema::PSK_Push_Set;
251 ModeVal = AlignPackInfo::Mac68k;
252 break;
253 case POAK_Reset:
254 // Reset just pops the top of the stack, or resets the current alignment to
255 // default.
256 Action = Sema::PSK_Pop;
257 if (AlignPackStack.Stack.empty()) {
258 if (AlignPackStack.CurrentValue.getAlignMode() != AlignPackInfo::Native ||
259 AlignPackStack.CurrentValue.IsPackAttr()) {
260 Action = Sema::PSK_Reset;
261 } else {
262 Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
263 << "stack empty";
264 return;
265 }
266 }
267 break;
268 }
269
270 AlignPackInfo Info(ModeVal, getLangOpts().XLPragmaPack);
271
272 AlignPackStack.Act(PragmaLoc, Action, StringRef(), Info);
273}
274
278 StringRef SecName) {
279 PragmaClangSection *CSec;
280 int SectionFlags = ASTContext::PSF_Read;
281 switch (SecKind) {
283 CSec = &PragmaClangBSSSection;
285 break;
288 SectionFlags |= ASTContext::PSF_Write;
289 break;
292 break;
295 break;
298 SectionFlags |= ASTContext::PSF_Execute;
299 break;
300 default:
301 llvm_unreachable("invalid clang section kind");
302 }
303
305 CSec->Valid = false;
306 return;
307 }
308
309 if (llvm::Error E = isValidSectionSpecifier(SecName)) {
310 Diag(PragmaLoc, diag::err_pragma_section_invalid_for_target)
311 << toString(std::move(E));
312 CSec->Valid = false;
313 return;
314 }
315
316 if (UnifySection(SecName, SectionFlags, PragmaLoc))
317 return;
318
319 CSec->Valid = true;
320 CSec->SectionName = std::string(SecName);
321 CSec->PragmaLocation = PragmaLoc;
322}
323
325 StringRef SlotLabel, Expr *alignment) {
326 bool IsXLPragma = getLangOpts().XLPragmaPack;
327 // XL pragma pack does not support identifier syntax.
328 if (IsXLPragma && !SlotLabel.empty()) {
329 Diag(PragmaLoc, diag::err_pragma_pack_identifer_not_supported);
330 return;
331 }
332
333 const AlignPackInfo CurVal = AlignPackStack.CurrentValue;
334 Expr *Alignment = static_cast<Expr *>(alignment);
335
336 // If specified then alignment must be a "small" power of two.
337 unsigned AlignmentVal = 0;
338 AlignPackInfo::Mode ModeVal = CurVal.getAlignMode();
339
340 if (Alignment) {
341 std::optional<llvm::APSInt> Val;
342 Val = Alignment->getIntegerConstantExpr(Context);
343
344 // pack(0) is like pack(), which just works out since that is what
345 // we use 0 for in PackAttr.
346 if (Alignment->isTypeDependent() || !Val ||
347 !(*Val == 0 || Val->isPowerOf2()) || Val->getZExtValue() > 16) {
348 Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
349 return; // Ignore
350 }
351
352 if (IsXLPragma && *Val == 0) {
353 // pack(0) does not work out with XL.
354 Diag(PragmaLoc, diag::err_pragma_pack_invalid_alignment);
355 return; // Ignore
356 }
357
358 AlignmentVal = (unsigned)Val->getZExtValue();
359 }
360
361 if (Action == Sema::PSK_Show) {
362 // Show the current alignment, making sure to show the right value
363 // for the default.
364 // FIXME: This should come from the target.
365 AlignmentVal = CurVal.IsPackSet() ? CurVal.getPackNumber() : 8;
366 if (ModeVal == AlignPackInfo::Mac68k &&
367 (IsXLPragma || CurVal.IsAlignAttr()))
368 Diag(PragmaLoc, diag::warn_pragma_pack_show) << "mac68k";
369 else
370 Diag(PragmaLoc, diag::warn_pragma_pack_show) << AlignmentVal;
371 }
372
373 // MSDN, C/C++ Preprocessor Reference > Pragma Directives > pack:
374 // "#pragma pack(pop, identifier, n) is undefined"
375 if (Action & Sema::PSK_Pop) {
376 if (Alignment && !SlotLabel.empty())
377 Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifier_and_alignment);
378 if (AlignPackStack.Stack.empty()) {
379 assert(CurVal.getAlignMode() == AlignPackInfo::Native &&
380 "Empty pack stack can only be at Native alignment mode.");
381 Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "pack" << "stack empty";
382 }
383 }
384
385 AlignPackInfo Info(ModeVal, AlignmentVal, IsXLPragma);
386
387 AlignPackStack.Act(PragmaLoc, Action, SlotLabel, Info);
388}
389
393 for (unsigned Idx = 0; Idx < Args.size(); Idx++) {
394 Expr *&E = Args.begin()[Idx];
395 assert(E && "error are handled before");
396 if (E->isValueDependent() || E->isTypeDependent())
397 continue;
398
399 // FIXME: Use DefaultFunctionArrayLValueConversion() in place of the logic
400 // that adds implicit casts here.
401 if (E->getType()->isArrayType())
403 clang::CK_ArrayToPointerDecay)
404 .get();
405 if (E->getType()->isFunctionType())
408 clang::CK_FunctionToPointerDecay, E, nullptr,
410 if (E->isLValue())
412 clang::CK_LValueToRValue, E, nullptr,
414
415 Expr::EvalResult Eval;
416 Notes.clear();
417 Eval.Diag = &Notes;
418
419 bool Result = E->EvaluateAsConstantExpr(Eval, Context);
420
421 /// Result means the expression can be folded to a constant.
422 /// Note.empty() means the expression is a valid constant expression in the
423 /// current language mode.
424 if (!Result || !Notes.empty()) {
425 Diag(E->getBeginLoc(), diag::err_attribute_argument_n_type)
426 << CI << (Idx + 1) << AANT_ArgumentConstantExpr;
427 for (auto &Note : Notes)
428 Diag(Note.first, Note.second);
429 return false;
430 }
431 assert(Eval.Val.hasValue());
432 E = ConstantExpr::Create(Context, E, Eval.Val);
433 }
434
435 return true;
436}
437
439 SourceLocation IncludeLoc) {
441 SourceLocation PrevLocation = AlignPackStack.CurrentPragmaLocation;
442 // Warn about non-default alignment at #includes (without redundant
443 // warnings for the same directive in nested includes).
444 // The warning is delayed until the end of the file to avoid warnings
445 // for files that don't have any records that are affected by the modified
446 // alignment.
447 bool HasNonDefaultValue =
448 AlignPackStack.hasValue() &&
449 (AlignPackIncludeStack.empty() ||
450 AlignPackIncludeStack.back().CurrentPragmaLocation != PrevLocation);
451 AlignPackIncludeStack.push_back(
452 {AlignPackStack.CurrentValue,
453 AlignPackStack.hasValue() ? PrevLocation : SourceLocation(),
454 HasNonDefaultValue, /*ShouldWarnOnInclude*/ false});
455 return;
456 }
457
459 "invalid kind");
460 AlignPackIncludeState PrevAlignPackState =
461 AlignPackIncludeStack.pop_back_val();
462 // FIXME: AlignPackStack may contain both #pragma align and #pragma pack
463 // information, diagnostics below might not be accurate if we have mixed
464 // pragmas.
465 if (PrevAlignPackState.ShouldWarnOnInclude) {
466 // Emit the delayed non-default alignment at #include warning.
467 Diag(IncludeLoc, diag::warn_pragma_pack_non_default_at_include);
468 Diag(PrevAlignPackState.CurrentPragmaLocation, diag::note_pragma_pack_here);
469 }
470 // Warn about modified alignment after #includes.
471 if (PrevAlignPackState.CurrentValue != AlignPackStack.CurrentValue) {
472 Diag(IncludeLoc, diag::warn_pragma_pack_modified_after_include);
473 Diag(AlignPackStack.CurrentPragmaLocation, diag::note_pragma_pack_here);
474 }
475}
476
478 if (AlignPackStack.Stack.empty())
479 return;
480 bool IsInnermost = true;
481
482 // FIXME: AlignPackStack may contain both #pragma align and #pragma pack
483 // information, diagnostics below might not be accurate if we have mixed
484 // pragmas.
485 for (const auto &StackSlot : llvm::reverse(AlignPackStack.Stack)) {
486 Diag(StackSlot.PragmaPushLocation, diag::warn_pragma_pack_no_pop_eof);
487 // The user might have already reset the alignment, so suggest replacing
488 // the reset with a pop.
489 if (IsInnermost &&
490 AlignPackStack.CurrentValue == AlignPackStack.DefaultValue) {
491 auto DB = Diag(AlignPackStack.CurrentPragmaLocation,
492 diag::note_pragma_pack_pop_instead_reset);
493 SourceLocation FixItLoc =
494 Lexer::findLocationAfterToken(AlignPackStack.CurrentPragmaLocation,
495 tok::l_paren, SourceMgr, LangOpts,
496 /*SkipTrailing=*/false);
497 if (FixItLoc.isValid())
498 DB << FixItHint::CreateInsertion(FixItLoc, "pop");
499 }
500 IsInnermost = false;
501 }
502}
503
505 MSStructPragmaOn = (Kind == PMSST_ON);
506}
507
509 PragmaMSCommentKind Kind, StringRef Arg) {
510 auto *PCD = PragmaCommentDecl::Create(
511 Context, Context.getTranslationUnitDecl(), CommentLoc, Kind, Arg);
514}
515
517 StringRef Value) {
522}
523
527 switch (Value) {
528 default:
529 llvm_unreachable("invalid pragma eval_method kind");
531 NewFPFeatures.setFPEvalMethodOverride(LangOptions::FEM_Source);
532 break;
534 NewFPFeatures.setFPEvalMethodOverride(LangOptions::FEM_Double);
535 break;
537 NewFPFeatures.setFPEvalMethodOverride(LangOptions::FEM_Extended);
538 break;
539 }
540 if (getLangOpts().ApproxFunc)
541 Diag(Loc, diag::err_setting_eval_method_used_in_unsafe_context) << 0 << 0;
542 if (getLangOpts().AllowFPReassoc)
543 Diag(Loc, diag::err_setting_eval_method_used_in_unsafe_context) << 0 << 1;
544 if (getLangOpts().AllowRecip)
545 Diag(Loc, diag::err_setting_eval_method_used_in_unsafe_context) << 0 << 2;
546 FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
547 CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
549}
550
552 PragmaMsStackAction Action,
555 if ((Action == PSK_Push_Set || Action == PSK_Push || Action == PSK_Pop) &&
557 // Push and pop can only occur at file or namespace scope, or within a
558 // language linkage declaration.
559 Diag(Loc, diag::err_pragma_fc_pp_scope);
560 return;
561 }
562 switch (Value) {
563 default:
564 llvm_unreachable("invalid pragma float_control kind");
565 case PFC_Precise:
566 NewFPFeatures.setFPPreciseEnabled(true);
567 FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
568 break;
569 case PFC_NoPrecise:
571 Diag(Loc, diag::err_pragma_fc_noprecise_requires_noexcept);
572 else if (CurFPFeatures.getAllowFEnvAccess())
573 Diag(Loc, diag::err_pragma_fc_noprecise_requires_nofenv);
574 else
575 NewFPFeatures.setFPPreciseEnabled(false);
576 FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
577 break;
578 case PFC_Except:
579 if (!isPreciseFPEnabled())
580 Diag(Loc, diag::err_pragma_fc_except_requires_precise);
581 else
582 NewFPFeatures.setSpecifiedExceptionModeOverride(LangOptions::FPE_Strict);
583 FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
584 break;
585 case PFC_NoExcept:
586 NewFPFeatures.setSpecifiedExceptionModeOverride(LangOptions::FPE_Ignore);
587 FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
588 break;
589 case PFC_Push:
590 FpPragmaStack.Act(Loc, Sema::PSK_Push_Set, StringRef(), NewFPFeatures);
591 break;
592 case PFC_Pop:
593 if (FpPragmaStack.Stack.empty()) {
594 Diag(Loc, diag::warn_pragma_pop_failed) << "float_control"
595 << "stack empty";
596 return;
597 }
598 FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
599 NewFPFeatures = FpPragmaStack.CurrentValue;
600 break;
601 }
602 CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
603}
604
607 SourceLocation PragmaLoc) {
608 MSPointerToMemberRepresentationMethod = RepresentationMethod;
610}
611
613 SourceLocation PragmaLoc,
614 MSVtorDispMode Mode) {
615 if (Action & PSK_Pop && VtorDispStack.Stack.empty())
616 Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "vtordisp"
617 << "stack empty";
618 VtorDispStack.Act(PragmaLoc, Action, StringRef(), Mode);
619}
620
621template <>
623 PragmaMsStackAction Action,
624 llvm::StringRef StackSlotLabel,
625 AlignPackInfo Value) {
626 if (Action == PSK_Reset) {
627 CurrentValue = DefaultValue;
628 CurrentPragmaLocation = PragmaLocation;
629 return;
630 }
631 if (Action & PSK_Push)
632 Stack.emplace_back(Slot(StackSlotLabel, CurrentValue, CurrentPragmaLocation,
633 PragmaLocation));
634 else if (Action & PSK_Pop) {
635 if (!StackSlotLabel.empty()) {
636 // If we've got a label, try to find it and jump there.
637 auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
638 return x.StackSlotLabel == StackSlotLabel;
639 });
640 // We found the label, so pop from there.
641 if (I != Stack.rend()) {
642 CurrentValue = I->Value;
643 CurrentPragmaLocation = I->PragmaLocation;
644 Stack.erase(std::prev(I.base()), Stack.end());
645 }
646 } else if (Value.IsXLStack() && Value.IsAlignAttr() &&
647 CurrentValue.IsPackAttr()) {
648 // XL '#pragma align(reset)' would pop the stack until
649 // a current in effect pragma align is popped.
650 auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
651 return x.Value.IsAlignAttr();
652 });
653 // If we found pragma align so pop from there.
654 if (I != Stack.rend()) {
655 Stack.erase(std::prev(I.base()), Stack.end());
656 if (Stack.empty()) {
657 CurrentValue = DefaultValue;
658 CurrentPragmaLocation = PragmaLocation;
659 } else {
660 CurrentValue = Stack.back().Value;
661 CurrentPragmaLocation = Stack.back().PragmaLocation;
662 Stack.pop_back();
663 }
664 }
665 } else if (!Stack.empty()) {
666 // xl '#pragma align' sets the baseline, and `#pragma pack` cannot pop
667 // over the baseline.
668 if (Value.IsXLStack() && Value.IsPackAttr() && CurrentValue.IsAlignAttr())
669 return;
670
671 // We don't have a label, just pop the last entry.
672 CurrentValue = Stack.back().Value;
673 CurrentPragmaLocation = Stack.back().PragmaLocation;
674 Stack.pop_back();
675 }
676 }
677 if (Action & PSK_Set) {
678 CurrentValue = Value;
679 CurrentPragmaLocation = PragmaLocation;
680 }
681}
682
683bool Sema::UnifySection(StringRef SectionName, int SectionFlags,
684 NamedDecl *Decl) {
685 SourceLocation PragmaLocation;
686 if (auto A = Decl->getAttr<SectionAttr>())
687 if (A->isImplicit())
688 PragmaLocation = A->getLocation();
689 auto SectionIt = Context.SectionInfos.find(SectionName);
690 if (SectionIt == Context.SectionInfos.end()) {
691 Context.SectionInfos[SectionName] =
692 ASTContext::SectionInfo(Decl, PragmaLocation, SectionFlags);
693 return false;
694 }
695 // A pre-declared section takes precedence w/o diagnostic.
696 const auto &Section = SectionIt->second;
697 if (Section.SectionFlags == SectionFlags ||
698 ((SectionFlags & ASTContext::PSF_Implicit) &&
699 !(Section.SectionFlags & ASTContext::PSF_Implicit)))
700 return false;
701 Diag(Decl->getLocation(), diag::err_section_conflict) << Decl << Section;
702 if (Section.Decl)
703 Diag(Section.Decl->getLocation(), diag::note_declared_at)
704 << Section.Decl->getName();
705 if (PragmaLocation.isValid())
706 Diag(PragmaLocation, diag::note_pragma_entered_here);
707 if (Section.PragmaSectionLocation.isValid())
708 Diag(Section.PragmaSectionLocation, diag::note_pragma_entered_here);
709 return true;
710}
711
712bool Sema::UnifySection(StringRef SectionName,
713 int SectionFlags,
714 SourceLocation PragmaSectionLocation) {
715 auto SectionIt = Context.SectionInfos.find(SectionName);
716 if (SectionIt != Context.SectionInfos.end()) {
717 const auto &Section = SectionIt->second;
718 if (Section.SectionFlags == SectionFlags)
719 return false;
720 if (!(Section.SectionFlags & ASTContext::PSF_Implicit)) {
721 Diag(PragmaSectionLocation, diag::err_section_conflict)
722 << "this" << Section;
723 if (Section.Decl)
724 Diag(Section.Decl->getLocation(), diag::note_declared_at)
725 << Section.Decl->getName();
726 if (Section.PragmaSectionLocation.isValid())
727 Diag(Section.PragmaSectionLocation, diag::note_pragma_entered_here);
728 return true;
729 }
730 }
731 Context.SectionInfos[SectionName] =
732 ASTContext::SectionInfo(nullptr, PragmaSectionLocation, SectionFlags);
733 return false;
734}
735
736/// Called on well formed \#pragma bss_seg().
738 PragmaMsStackAction Action,
739 llvm::StringRef StackSlotLabel,
740 StringLiteral *SegmentName,
741 llvm::StringRef PragmaName) {
743 llvm::StringSwitch<PragmaStack<StringLiteral *> *>(PragmaName)
744 .Case("data_seg", &DataSegStack)
745 .Case("bss_seg", &BSSSegStack)
746 .Case("const_seg", &ConstSegStack)
747 .Case("code_seg", &CodeSegStack);
748 if (Action & PSK_Pop && Stack->Stack.empty())
749 Diag(PragmaLocation, diag::warn_pragma_pop_failed) << PragmaName
750 << "stack empty";
751 if (SegmentName) {
752 if (!checkSectionName(SegmentName->getBeginLoc(), SegmentName->getString()))
753 return;
754
755 if (SegmentName->getString() == ".drectve" &&
757 Diag(PragmaLocation, diag::warn_attribute_section_drectve) << PragmaName;
758 }
759
760 Stack->Act(PragmaLocation, Action, StackSlotLabel, SegmentName);
761}
762
763/// Called on well formed \#pragma strict_gs_check().
765 PragmaMsStackAction Action,
766 bool Value) {
767 if (Action & PSK_Pop && StrictGuardStackCheckStack.Stack.empty())
768 Diag(PragmaLocation, diag::warn_pragma_pop_failed) << "strict_gs_check"
769 << "stack empty";
770
771 StrictGuardStackCheckStack.Act(PragmaLocation, Action, StringRef(), Value);
772}
773
774/// Called on well formed \#pragma bss_seg().
776 int SectionFlags, StringLiteral *SegmentName) {
777 UnifySection(SegmentName->getString(), SectionFlags, PragmaLocation);
778}
779
781 StringLiteral *SegmentName) {
782 // There's no stack to maintain, so we just have a current section. When we
783 // see the default section, reset our current section back to null so we stop
784 // tacking on unnecessary attributes.
785 CurInitSeg = SegmentName->getString() == ".CRT$XCU" ? nullptr : SegmentName;
786 CurInitSegLoc = PragmaLocation;
787}
788
790 SourceLocation PragmaLocation, StringRef Section,
791 const SmallVector<std::tuple<IdentifierInfo *, SourceLocation>>
792 &Functions) {
794 Diag(PragmaLocation, diag::err_pragma_expected_file_scope) << "alloc_text";
795 return;
796 }
797
798 for (auto &Function : Functions) {
799 IdentifierInfo *II;
800 SourceLocation Loc;
801 std::tie(II, Loc) = Function;
802
803 DeclarationName DN(II);
805 if (!ND) {
806 Diag(Loc, diag::err_undeclared_use) << II->getName();
807 return;
808 }
809
810 auto *FD = dyn_cast<FunctionDecl>(ND->getCanonicalDecl());
811 if (!FD) {
812 Diag(Loc, diag::err_pragma_alloc_text_not_function);
813 return;
814 }
815
816 if (getLangOpts().CPlusPlus && !FD->isInExternCContext()) {
817 Diag(Loc, diag::err_pragma_alloc_text_c_linkage);
818 return;
819 }
820
821 FunctionToSectionMap[II->getName()] = std::make_tuple(Section, Loc);
822 }
823}
824
825void Sema::ActOnPragmaUnused(const Token &IdTok, Scope *curScope,
826 SourceLocation PragmaLoc) {
827
828 IdentifierInfo *Name = IdTok.getIdentifierInfo();
829 LookupResult Lookup(*this, Name, IdTok.getLocation(), LookupOrdinaryName);
830 LookupParsedName(Lookup, curScope, nullptr, true);
831
832 if (Lookup.empty()) {
833 Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
834 << Name << SourceRange(IdTok.getLocation());
835 return;
836 }
837
838 VarDecl *VD = Lookup.getAsSingle<VarDecl>();
839 if (!VD) {
840 Diag(PragmaLoc, diag::warn_pragma_unused_expected_var_arg)
841 << Name << SourceRange(IdTok.getLocation());
842 return;
843 }
844
845 // Warn if this was used before being marked unused.
846 if (VD->isUsed())
847 Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name;
848
849 VD->addAttr(UnusedAttr::CreateImplicit(Context, IdTok.getLocation(),
851 UnusedAttr::GNU_unused));
852}
853
855 IdentifierInfo *Ident;
856 SourceLocation Loc;
857 std::tie(Ident, Loc) = PP.getPragmaARCCFCodeAuditedInfo();
858 if (!Loc.isValid()) return;
859
860 // Don't add a redundant or conflicting attribute.
861 if (D->hasAttr<CFAuditedTransferAttr>() ||
862 D->hasAttr<CFUnknownTransferAttr>())
863 return;
864
865 AttributeCommonInfo Info(Ident, SourceRange(Loc),
867 D->addAttr(CFAuditedTransferAttr::CreateImplicit(Context, Info));
868}
869
870namespace {
871
872std::optional<attr::SubjectMatchRule>
873getParentAttrMatcherRule(attr::SubjectMatchRule Rule) {
874 using namespace attr;
875 switch (Rule) {
876 default:
877 return std::nullopt;
878#define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
879#define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \
880 case Value: \
881 return Parent;
882#include "clang/Basic/AttrSubMatchRulesList.inc"
883 }
884}
885
886bool isNegatedAttrMatcherSubRule(attr::SubjectMatchRule Rule) {
887 using namespace attr;
888 switch (Rule) {
889 default:
890 return false;
891#define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
892#define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \
893 case Value: \
894 return IsNegated;
895#include "clang/Basic/AttrSubMatchRulesList.inc"
896 }
897}
898
899CharSourceRange replacementRangeForListElement(const Sema &S,
900 SourceRange Range) {
901 // Make sure that the ',' is removed as well.
903 Range.getEnd(), tok::comma, S.getSourceManager(), S.getLangOpts(),
904 /*SkipTrailingWhitespaceAndNewLine=*/false);
905 if (AfterCommaLoc.isValid())
906 return CharSourceRange::getCharRange(Range.getBegin(), AfterCommaLoc);
907 else
908 return CharSourceRange::getTokenRange(Range);
909}
910
911std::string
912attrMatcherRuleListToString(ArrayRef<attr::SubjectMatchRule> Rules) {
913 std::string Result;
914 llvm::raw_string_ostream OS(Result);
915 for (const auto &I : llvm::enumerate(Rules)) {
916 if (I.index())
917 OS << (I.index() == Rules.size() - 1 ? ", and " : ", ");
918 OS << "'" << attr::getSubjectMatchRuleSpelling(I.value()) << "'";
919 }
920 return Result;
921}
922
923} // end anonymous namespace
924
928 Attribute.setIsPragmaClangAttribute();
930 // Gather the subject match rules that are supported by the attribute.
932 StrictSubjectMatchRuleSet;
933 Attribute.getMatchRules(LangOpts, StrictSubjectMatchRuleSet);
934
935 // Figure out which subject matching rules are valid.
936 if (StrictSubjectMatchRuleSet.empty()) {
937 // Check for contradicting match rules. Contradicting match rules are
938 // either:
939 // - a top-level rule and one of its sub-rules. E.g. variable and
940 // variable(is_parameter).
941 // - a sub-rule and a sibling that's negated. E.g.
942 // variable(is_thread_local) and variable(unless(is_parameter))
943 llvm::SmallDenseMap<int, std::pair<int, SourceRange>, 2>
944 RulesToFirstSpecifiedNegatedSubRule;
945 for (const auto &Rule : Rules) {
946 attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
947 std::optional<attr::SubjectMatchRule> ParentRule =
948 getParentAttrMatcherRule(MatchRule);
949 if (!ParentRule)
950 continue;
951 auto It = Rules.find(*ParentRule);
952 if (It != Rules.end()) {
953 // A sub-rule contradicts a parent rule.
954 Diag(Rule.second.getBegin(),
955 diag::err_pragma_attribute_matcher_subrule_contradicts_rule)
957 << attr::getSubjectMatchRuleSpelling(*ParentRule) << It->second
959 replacementRangeForListElement(*this, Rule.second));
960 // Keep going without removing this rule as it won't change the set of
961 // declarations that receive the attribute.
962 continue;
963 }
964 if (isNegatedAttrMatcherSubRule(MatchRule))
965 RulesToFirstSpecifiedNegatedSubRule.insert(
966 std::make_pair(*ParentRule, Rule));
967 }
968 bool IgnoreNegatedSubRules = false;
969 for (const auto &Rule : Rules) {
970 attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
971 std::optional<attr::SubjectMatchRule> ParentRule =
972 getParentAttrMatcherRule(MatchRule);
973 if (!ParentRule)
974 continue;
975 auto It = RulesToFirstSpecifiedNegatedSubRule.find(*ParentRule);
976 if (It != RulesToFirstSpecifiedNegatedSubRule.end() &&
977 It->second != Rule) {
978 // Negated sub-rule contradicts another sub-rule.
979 Diag(
980 It->second.second.getBegin(),
981 diag::
982 err_pragma_attribute_matcher_negated_subrule_contradicts_subrule)
984 attr::SubjectMatchRule(It->second.first))
985 << attr::getSubjectMatchRuleSpelling(MatchRule) << Rule.second
987 replacementRangeForListElement(*this, It->second.second));
988 // Keep going but ignore all of the negated sub-rules.
989 IgnoreNegatedSubRules = true;
990 RulesToFirstSpecifiedNegatedSubRule.erase(It);
991 }
992 }
993
994 if (!IgnoreNegatedSubRules) {
995 for (const auto &Rule : Rules)
996 SubjectMatchRules.push_back(attr::SubjectMatchRule(Rule.first));
997 } else {
998 for (const auto &Rule : Rules) {
999 if (!isNegatedAttrMatcherSubRule(attr::SubjectMatchRule(Rule.first)))
1000 SubjectMatchRules.push_back(attr::SubjectMatchRule(Rule.first));
1001 }
1002 }
1003 Rules.clear();
1004 } else {
1005 // Each rule in Rules must be a strict subset of the attribute's
1006 // SubjectMatch rules. I.e. we're allowed to use
1007 // `apply_to=variables(is_global)` on an attrubute with SubjectList<[Var]>,
1008 // but should not allow `apply_to=variables` on an attribute which has
1009 // `SubjectList<[GlobalVar]>`.
1010 for (const auto &StrictRule : StrictSubjectMatchRuleSet) {
1011 // First, check for exact match.
1012 if (Rules.erase(StrictRule.first)) {
1013 // Add the rule to the set of attribute receivers only if it's supported
1014 // in the current language mode.
1015 if (StrictRule.second)
1016 SubjectMatchRules.push_back(StrictRule.first);
1017 }
1018 }
1019 // Check remaining rules for subset matches.
1020 auto RulesToCheck = Rules;
1021 for (const auto &Rule : RulesToCheck) {
1022 attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
1023 if (auto ParentRule = getParentAttrMatcherRule(MatchRule)) {
1024 if (llvm::any_of(StrictSubjectMatchRuleSet,
1025 [ParentRule](const auto &StrictRule) {
1026 return StrictRule.first == *ParentRule &&
1027 StrictRule.second; // IsEnabled
1028 })) {
1029 SubjectMatchRules.push_back(MatchRule);
1030 Rules.erase(MatchRule);
1031 }
1032 }
1033 }
1034 }
1035
1036 if (!Rules.empty()) {
1037 auto Diagnostic =
1038 Diag(PragmaLoc, diag::err_pragma_attribute_invalid_matchers)
1039 << Attribute;
1041 for (const auto &Rule : Rules) {
1042 ExtraRules.push_back(attr::SubjectMatchRule(Rule.first));
1044 replacementRangeForListElement(*this, Rule.second));
1045 }
1046 Diagnostic << attrMatcherRuleListToString(ExtraRules);
1047 }
1048
1049 if (PragmaAttributeStack.empty()) {
1050 Diag(PragmaLoc, diag::err_pragma_attr_attr_no_push);
1051 return;
1052 }
1053
1054 PragmaAttributeStack.back().Entries.push_back(
1055 {PragmaLoc, &Attribute, std::move(SubjectMatchRules), /*IsUsed=*/false});
1056}
1057
1059 const IdentifierInfo *Namespace) {
1060 PragmaAttributeStack.emplace_back();
1061 PragmaAttributeStack.back().Loc = PragmaLoc;
1062 PragmaAttributeStack.back().Namespace = Namespace;
1063}
1064
1066 const IdentifierInfo *Namespace) {
1067 if (PragmaAttributeStack.empty()) {
1068 Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
1069 return;
1070 }
1071
1072 // Dig back through the stack trying to find the most recently pushed group
1073 // that in Namespace. Note that this works fine if no namespace is present,
1074 // think of push/pops without namespaces as having an implicit "nullptr"
1075 // namespace.
1076 for (size_t Index = PragmaAttributeStack.size(); Index;) {
1077 --Index;
1078 if (PragmaAttributeStack[Index].Namespace == Namespace) {
1079 for (const PragmaAttributeEntry &Entry :
1080 PragmaAttributeStack[Index].Entries) {
1081 if (!Entry.IsUsed) {
1082 assert(Entry.Attribute && "Expected an attribute");
1083 Diag(Entry.Attribute->getLoc(), diag::warn_pragma_attribute_unused)
1084 << *Entry.Attribute;
1085 Diag(PragmaLoc, diag::note_pragma_attribute_region_ends_here);
1086 }
1087 }
1088 PragmaAttributeStack.erase(PragmaAttributeStack.begin() + Index);
1089 return;
1090 }
1091 }
1092
1093 if (Namespace)
1094 Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch)
1095 << 0 << Namespace->getName();
1096 else
1097 Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
1098}
1099
1101 if (PragmaAttributeStack.empty())
1102 return;
1103 for (auto &Group : PragmaAttributeStack) {
1104 for (auto &Entry : Group.Entries) {
1105 ParsedAttr *Attribute = Entry.Attribute;
1106 assert(Attribute && "Expected an attribute");
1107 assert(Attribute->isPragmaClangAttribute() &&
1108 "expected #pragma clang attribute");
1109
1110 // Ensure that the attribute can be applied to the given declaration.
1111 bool Applies = false;
1112 for (const auto &Rule : Entry.MatchRules) {
1113 if (Attribute->appliesToDecl(D, Rule)) {
1114 Applies = true;
1115 break;
1116 }
1117 }
1118 if (!Applies)
1119 continue;
1120 Entry.IsUsed = true;
1123 Attrs.addAtEnd(Attribute);
1124 ProcessDeclAttributeList(S, D, Attrs);
1126 }
1127 }
1128}
1129
1131 assert(PragmaAttributeCurrentTargetDecl && "Expected an active declaration");
1133 diag::note_pragma_attribute_applied_decl_here);
1134}
1135
1137 if (PragmaAttributeStack.empty())
1138 return;
1139 Diag(PragmaAttributeStack.back().Loc, diag::err_pragma_attribute_no_pop_eof);
1140}
1141
1143 if(On)
1145 else
1146 OptimizeOffPragmaLocation = PragmaLoc;
1147}
1148
1151 Diag(Loc, diag::err_pragma_expected_file_scope) << "optimize";
1152 return;
1153 }
1154
1155 MSPragmaOptimizeIsOn = IsOn;
1156}
1157
1159 SourceLocation Loc, const llvm::SmallVectorImpl<StringRef> &NoBuiltins) {
1161 Diag(Loc, diag::err_pragma_expected_file_scope) << "function";
1162 return;
1163 }
1164
1165 MSFunctionNoBuiltins.insert(NoBuiltins.begin(), NoBuiltins.end());
1166}
1167
1169 // In the future, check other pragmas if they're implemented (e.g. pragma
1170 // optimize 0 will probably map to this functionality too).
1173}
1174
1176 if (!FD->getIdentifier())
1177 return;
1178
1179 StringRef Name = FD->getName();
1180 auto It = FunctionToSectionMap.find(Name);
1181 if (It != FunctionToSectionMap.end()) {
1182 StringRef Section;
1183 SourceLocation Loc;
1184 std::tie(Section, Loc) = It->second;
1185
1186 if (!FD->hasAttr<SectionAttr>())
1187 FD->addAttr(SectionAttr::CreateImplicit(Context, Section));
1188 }
1189}
1190
1192 // Don't modify the function attributes if it's "on". "on" resets the
1193 // optimizations to the ones listed on the command line
1196}
1197
1199 SourceLocation Loc) {
1200 // Don't add a conflicting attribute. No diagnostic is needed.
1201 if (FD->hasAttr<MinSizeAttr>() || FD->hasAttr<AlwaysInlineAttr>())
1202 return;
1203
1204 // Add attributes only if required. Optnone requires noinline as well, but if
1205 // either is already present then don't bother adding them.
1206 if (!FD->hasAttr<OptimizeNoneAttr>())
1207 FD->addAttr(OptimizeNoneAttr::CreateImplicit(Context, Loc));
1208 if (!FD->hasAttr<NoInlineAttr>())
1209 FD->addAttr(NoInlineAttr::CreateImplicit(Context, Loc));
1210}
1211
1214 MSFunctionNoBuiltins.end());
1215 if (!MSFunctionNoBuiltins.empty())
1216 FD->addAttr(NoBuiltinAttr::CreateImplicit(Context, V.data(), V.size()));
1217}
1218
1219typedef std::vector<std::pair<unsigned, SourceLocation> > VisStack;
1220enum : unsigned { NoVisibility = ~0U };
1221
1223 if (!VisContext)
1224 return;
1225
1226 NamedDecl *ND = dyn_cast<NamedDecl>(D);
1228 return;
1229
1230 VisStack *Stack = static_cast<VisStack*>(VisContext);
1231 unsigned rawType = Stack->back().first;
1232 if (rawType == NoVisibility) return;
1233
1234 VisibilityAttr::VisibilityType type
1235 = (VisibilityAttr::VisibilityType) rawType;
1236 SourceLocation loc = Stack->back().second;
1237
1238 D->addAttr(VisibilityAttr::CreateImplicit(Context, type, loc));
1239}
1240
1241/// FreeVisContext - Deallocate and null out VisContext.
1243 delete static_cast<VisStack*>(VisContext);
1244 VisContext = nullptr;
1245}
1246
1247static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc) {
1248 // Put visibility on stack.
1249 if (!S.VisContext)
1250 S.VisContext = new VisStack;
1251
1252 VisStack *Stack = static_cast<VisStack*>(S.VisContext);
1253 Stack->push_back(std::make_pair(type, loc));
1254}
1255
1257 SourceLocation PragmaLoc) {
1258 if (VisType) {
1259 // Compute visibility to use.
1260 VisibilityAttr::VisibilityType T;
1261 if (!VisibilityAttr::ConvertStrToVisibilityType(VisType->getName(), T)) {
1262 Diag(PragmaLoc, diag::warn_attribute_unknown_visibility) << VisType;
1263 return;
1264 }
1265 PushPragmaVisibility(*this, T, PragmaLoc);
1266 } else {
1267 PopPragmaVisibility(false, PragmaLoc);
1268 }
1269}
1270
1273 FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1274 switch (FPC) {
1276 NewFPFeatures.setAllowFPContractWithinStatement();
1277 break;
1279 NewFPFeatures.setAllowFPContractAcrossStatement();
1280 break;
1282 NewFPFeatures.setDisallowFPContract();
1283 break;
1285 llvm_unreachable("Should not happen");
1286 }
1287 FpPragmaStack.Act(Loc, Sema::PSK_Set, StringRef(), NewFPFeatures);
1288 CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
1289}
1290
1292 if (IsEnabled) {
1293 // For value unsafe context, combining this pragma with eval method
1294 // setting is not recommended. See comment in function FixupInvocation#506.
1295 int Reason = -1;
1296 if (getLangOpts().getFPEvalMethod() != LangOptions::FEM_UnsetOnCommandLine)
1297 // Eval method set using the option 'ffp-eval-method'.
1298 Reason = 1;
1300 // Eval method set using the '#pragma clang fp eval_method'.
1301 // We could have both an option and a pragma used to the set the eval
1302 // method. The pragma overrides the option in the command line. The Reason
1303 // of the diagnostic is overriden too.
1304 Reason = 0;
1305 if (Reason != -1)
1306 Diag(Loc, diag::err_setting_eval_method_used_in_unsafe_context)
1307 << Reason << 4;
1308 }
1309 FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1310 NewFPFeatures.setAllowFPReassociateOverride(IsEnabled);
1311 FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
1312 CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
1313}
1314
1315void Sema::ActOnPragmaFEnvRound(SourceLocation Loc, llvm::RoundingMode FPR) {
1316 FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1317 NewFPFeatures.setConstRoundingModeOverride(FPR);
1318 FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
1319 CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
1320}
1321
1324 FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1325 NewFPFeatures.setSpecifiedExceptionModeOverride(FPE);
1326 FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
1327 CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
1328}
1329
1331 FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1332 if (IsEnabled) {
1333 // Verify Microsoft restriction:
1334 // You can't enable fenv_access unless precise semantics are enabled.
1335 // Precise semantics can be enabled either by the float_control
1336 // pragma, or by using the /fp:precise or /fp:strict compiler options
1337 if (!isPreciseFPEnabled())
1338 Diag(Loc, diag::err_pragma_fenv_requires_precise);
1339 }
1340 NewFPFeatures.setAllowFEnvAccessOverride(IsEnabled);
1341 FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
1342 CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
1343}
1344
1347 setExceptionMode(Loc, FPE);
1348}
1349
1350void Sema::PushNamespaceVisibilityAttr(const VisibilityAttr *Attr,
1351 SourceLocation Loc) {
1352 // Visibility calculations will consider the namespace's visibility.
1353 // Here we just want to note that we're in a visibility context
1354 // which overrides any enclosing #pragma context, but doesn't itself
1355 // contribute visibility.
1357}
1358
1359void Sema::PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc) {
1360 if (!VisContext) {
1361 Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
1362 return;
1363 }
1364
1365 // Pop visibility from stack
1366 VisStack *Stack = static_cast<VisStack*>(VisContext);
1367
1368 const std::pair<unsigned, SourceLocation> *Back = &Stack->back();
1369 bool StartsWithPragma = Back->first != NoVisibility;
1370 if (StartsWithPragma && IsNamespaceEnd) {
1371 Diag(Back->second, diag::err_pragma_push_visibility_mismatch);
1372 Diag(EndLoc, diag::note_surrounding_namespace_ends_here);
1373
1374 // For better error recovery, eat all pushes inside the namespace.
1375 do {
1376 Stack->pop_back();
1377 Back = &Stack->back();
1378 StartsWithPragma = Back->first != NoVisibility;
1379 } while (StartsWithPragma);
1380 } else if (!StartsWithPragma && !IsNamespaceEnd) {
1381 Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
1382 Diag(Back->second, diag::note_surrounding_namespace_starts_here);
1383 return;
1384 }
1385
1386 Stack->pop_back();
1387 // To simplify the implementation, never keep around an empty stack.
1388 if (Stack->empty())
1390}
1391
1392template <typename Ty>
1393static bool checkCommonAttributeFeatures(Sema &S, const Ty *Node,
1394 const ParsedAttr &A,
1395 bool SkipArgCountCheck) {
1396 // Several attributes carry different semantics than the parsing requires, so
1397 // those are opted out of the common argument checks.
1398 //
1399 // We also bail on unknown and ignored attributes because those are handled
1400 // as part of the target-specific handling logic.
1402 return false;
1403 // Check whether the attribute requires specific language extensions to be
1404 // enabled.
1405 if (!A.diagnoseLangOpts(S))
1406 return true;
1407 // Check whether the attribute appertains to the given subject.
1408 if (!A.diagnoseAppertainsTo(S, Node))
1409 return true;
1410 // Check whether the attribute is mutually exclusive with other attributes
1411 // that have already been applied to the declaration.
1412 if (!A.diagnoseMutualExclusion(S, Node))
1413 return true;
1414 // Check whether the attribute exists in the target architecture.
1415 if (S.CheckAttrTarget(A))
1416 return true;
1417
1418 if (A.hasCustomParsing())
1419 return false;
1420
1421 if (!SkipArgCountCheck) {
1422 if (A.getMinArgs() == A.getMaxArgs()) {
1423 // If there are no optional arguments, then checking for the argument
1424 // count is trivial.
1425 if (!A.checkExactlyNumArgs(S, A.getMinArgs()))
1426 return true;
1427 } else {
1428 // There are optional arguments, so checking is slightly more involved.
1429 if (A.getMinArgs() && !A.checkAtLeastNumArgs(S, A.getMinArgs()))
1430 return true;
1431 else if (!A.hasVariadicArg() && A.getMaxArgs() &&
1432 !A.checkAtMostNumArgs(S, A.getMaxArgs()))
1433 return true;
1434 }
1435 }
1436
1437 return false;
1438}
1439
1441 bool SkipArgCountCheck) {
1442 return ::checkCommonAttributeFeatures(*this, D, A, SkipArgCountCheck);
1443}
1445 bool SkipArgCountCheck) {
1446 return ::checkCommonAttributeFeatures(*this, S, A, SkipArgCountCheck);
1447}
#define V(N, I)
Definition: ASTContext.h:3217
NodeId Parent
Definition: ASTDiff.cpp:191
DynTypedNode Node
Defines the clang::Preprocessor interface.
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
std::vector< std::pair< unsigned, SourceLocation > > VisStack
Definition: SemaAttr.cpp:1219
static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc)
Definition: SemaAttr.cpp:1247
static void addGslOwnerPointerAttributeIfNotExisting(ASTContext &Context, CXXRecordDecl *Record)
Definition: SemaAttr.cpp:102
@ NoVisibility
Definition: SemaAttr.cpp:1220
bool hasValue() const
Definition: APValue.h:391
virtual bool HandleTopLevelDecl(DeclGroupRef D)
HandleTopLevelDecl - Handle the specified top-level declaration.
Definition: ASTConsumer.cpp:18
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1060
llvm::StringMap< SectionInfo > SectionInfos
Definition: ASTContext.h:3333
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:744
PtrTy get() const
Definition: Ownership.h:169
Attr - This represents one attribute.
Definition: Attr.h:40
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
Represents a character-granular source range.
static CharSourceRange getCharRange(SourceRange R)
static CharSourceRange getTokenRange(SourceRange R)
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition: Expr.cpp:403
bool isFileContext() const
Definition: DeclBase.h:2003
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1841
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1619
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
Decl()=delete
T * getAttr() const
Definition: DeclBase.h:556
void addAttr(Attr *A)
Definition: DeclBase.cpp:903
SourceLocation getLocation() const
Definition: DeclBase.h:432
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition: DeclBase.cpp:457
DeclContext * getDeclContext()
Definition: DeclBase.h:441
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:424
bool hasAttr() const
Definition: DeclBase.h:560
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:943
The name of a declaration.
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:817
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1566
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1542
This represents one expression.
Definition: Expr.h:110
std::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.
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:169
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:186
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
Definition: Expr.h:271
bool EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx, ConstantExprKind Kind=ConstantExprKind::Normal) const
Evaluate an expression that is required to be a constant expression.
QualType getType() const
Definition: Expr.h:142
Represents difference between two FPOptions values.
Definition: LangOptions.h:806
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:838
void setFPPreciseEnabled(bool Value)
Definition: LangOptions.h:846
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:834
FPOptions applyOverrides(FPOptions Base)
Definition: LangOptions.h:873
LangOptions::FPExceptionModeKind getExceptionMode() const
Definition: LangOptions.h:754
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
Definition: Diagnostic.h:123
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:97
Represents a function declaration or definition.
Definition: Decl.h:1917
One of these records is kept for each identifier that is lexed.
StringRef getName() const
Return the actual identifier string.
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition: Expr.cpp:2063
FPExceptionModeKind
Possible floating point exception behavior.
Definition: LangOptions.h:270
@ FPE_Ignore
Assume that floating-point exceptions are masked.
Definition: LangOptions.h:272
@ FPE_Strict
Strictly preserve the floating-point exception semantics.
Definition: LangOptions.h:276
FPEvalMethodKind
Possible float expression evaluation method choices.
Definition: LangOptions.h:282
@ FEM_UnsetOnCommandLine
Used only for FE option processing; this is only used to indicate that the user did not specify an ex...
Definition: LangOptions.h:296
@ FEM_Source
Use the declared type for fp arithmetic.
Definition: LangOptions.h:287
@ FEM_Double
Use the type double for fp arithmetic.
Definition: LangOptions.h:289
@ FEM_Extended
Use extended type for fp arithmetic.
Definition: LangOptions.h:291
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:1294
Represents the results of name lookup.
Definition: Lookup.h:46
DeclClass * getAsSingle() const
Definition: Lookup.h:533
bool empty() const
Return true if no decls were found.
Definition: Lookup.h:339
This represents a decl that may have a name.
Definition: Decl.h:247
@ VisibilityForValue
Do an LV computation for, ultimately, a non-type declaration.
Definition: Decl.h:433
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:268
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:274
std::optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
Definition: Decl.cpp:1267
ParsedAttr - Represents a syntactic attribute.
Definition: ParsedAttr.h:123
bool hasCustomParsing() const
Definition: ParsedAttr.cpp:152
unsigned getMinArgs() const
Definition: ParsedAttr.cpp:142
bool checkExactlyNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has exactly as many args as Num.
Definition: ParsedAttr.cpp:276
bool hasVariadicArg() const
Definition: ParsedAttr.cpp:244
bool diagnoseMutualExclusion(class Sema &S, const Decl *D) const
Definition: ParsedAttr.cpp:164
bool diagnoseAppertainsTo(class Sema &S, const Decl *D) const
Definition: ParsedAttr.cpp:156
bool checkAtLeastNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has at least as many args as Num.
Definition: ParsedAttr.cpp:281
unsigned getMaxArgs() const
Definition: ParsedAttr.cpp:144
AttributeCommonInfo::Kind getKind() const
Definition: ParsedAttr.h:612
bool diagnoseLangOpts(class Sema &S) const
Definition: ParsedAttr.cpp:180
bool checkAtMostNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has at most as many args as Num.
Definition: ParsedAttr.cpp:286
void addAtEnd(ParsedAttr *newAttr)
Definition: ParsedAttr.h:823
static PragmaCommentDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation CommentLoc, PragmaMSCommentKind CommentKind, StringRef Arg)
Definition: Decl.cpp:4980
static PragmaDetectMismatchDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation Loc, StringRef Name, StringRef Value)
Definition: Decl.cpp:5003
SourceLocation getLastFPEvalPragmaLocation() const
std::pair< IdentifierInfo *, SourceLocation > getPragmaARCCFCodeAuditedInfo() const
The location of the currently-active #pragma clang arc_cf_code_audited begin.
void setCurrentFPEvalMethod(SourceLocation PragmaLoc, LangOptions::FPEvalMethodKind Val)
A (possibly-)qualified type.
Definition: Type.h:736
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6649
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
Definition: Type.h:6858
QualType getCanonicalType() const
Definition: Type.h:6701
Represents a struct/union/class.
Definition: Decl.h:3998
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:41
unsigned getPackNumber() const
Definition: Sema.h:548
bool IsPackSet() const
Definition: Sema.h:550
bool IsAlignAttr() const
Definition: Sema.h:544
Mode getAlignMode() const
Definition: Sema.h:546
PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct)
Definition: SemaAttr.cpp:28
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:356
void ActOnPragmaMSOptimize(SourceLocation Loc, bool IsOn)
#pragma optimize("[optimization-list]", on | off).
Definition: SemaAttr.cpp:1149
bool ConstantFoldAttrArgs(const AttributeCommonInfo &CI, MutableArrayRef< Expr * > Args)
ConstantFoldAttrArgs - Folds attribute arguments into ConstantExprs (unless they are value dependent ...
Definition: SemaAttr.cpp:390
void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
Definition: SemaAttr.cpp:1058
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition: Sema.h:4289
void ActOnPragmaAttributePop(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
Called on well-formed '#pragma clang attribute pop'.
Definition: SemaAttr.cpp:1065
void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value)
ActOnPragmaDetectMismatch - Call on well-formed #pragma detect_mismatch.
Definition: SemaAttr.cpp:516
const Decl * PragmaAttributeCurrentTargetDecl
The declaration that is currently receiving an attribute from the #pragma attribute stack.
Definition: Sema.h:760
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: Sema.cpp:1884
void ActOnPragmaFEnvRound(SourceLocation Loc, llvm::RoundingMode)
Called to set constant rounding mode for floating point operations.
Definition: SemaAttr.cpp:1315
PragmaClangSection PragmaClangRodataSection
Definition: Sema.h:470
bool checkSectionName(SourceLocation LiteralLoc, StringRef Str)
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:1100
bool checkCommonAttributeFeatures(const Decl *D, const ParsedAttr &A, bool SkipArgCountCheck=false)
Handles semantic checking for features that are common to all attributes, such as checking whether a ...
Definition: SemaAttr.cpp:1440
PragmaClangSectionAction
Definition: Sema.h:457
@ PCSA_Clear
Definition: Sema.h:459
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:1198
PragmaStack< FPOptionsOverride > FpPragmaStack
Definition: Sema.h:702
PragmaStack< StringLiteral * > CodeSegStack
Definition: Sema.h:696
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:1168
void ActOnPragmaMSComment(SourceLocation CommentLoc, PragmaMSCommentKind Kind, StringRef Arg)
ActOnPragmaMSComment - Called on well formed #pragma comment(kind, "arg").
Definition: SemaAttr.cpp:508
SmallVector< AlignPackIncludeState, 8 > AlignPackIncludeStack
Definition: Sema.h:691
void AddAlignmentAttributesForRecord(RecordDecl *RD)
AddAlignmentAttributesForRecord - Adds any needed alignment attributes to a the record decl,...
Definition: SemaAttr.cpp:53
FPOptionsOverride CurFPFeatureOverrides()
Definition: Sema.h:703
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:737
void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action, PragmaFloatControlKind Value)
ActOnPragmaFloatControl - Call on well-formed #pragma float_control.
Definition: SemaAttr.cpp:551
void ActOnPragmaMSPointersToMembers(LangOptions::PragmaMSPointersToMembersKind Kind, SourceLocation PragmaLoc)
ActOnPragmaMSPointersToMembers - called on well formed #pragma pointers_to_members(representation met...
Definition: SemaAttr.cpp:605
ASTContext & Context
Definition: Sema.h:407
void ActOnPragmaUnused(const Token &Identifier, Scope *curScope, SourceLocation PragmaLoc)
ActOnPragmaUnused - Called on well-formed '#pragma unused'.
Definition: SemaAttr.cpp:825
void ActOnPragmaMSAllocText(SourceLocation PragmaLocation, StringRef Section, const SmallVector< std::tuple< IdentifierInfo *, SourceLocation > > &Functions)
Called on well-formed #pragma alloc_text().
Definition: SemaAttr.cpp:789
PragmaStack< bool > StrictGuardStackCheckStack
Definition: Sema.h:699
NamedDecl * LookupSingleName(Scope *S, DeclarationName Name, SourceLocation Loc, LookupNameKind NameKind, RedeclarationKind Redecl=NotForRedeclaration)
Look up a name, looking for a single declaration.
void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, SourceLocation PragmaLoc, attr::ParsedSubjectMatchRuleSet Rules)
Definition: SemaAttr.cpp:925
PragmaStack< StringLiteral * > ConstSegStack
Definition: Sema.h:695
void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, SourceLocation PragmaLoc)
ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
Definition: SemaAttr.cpp:218
void ActOnPragmaFPExceptions(SourceLocation Loc, LangOptions::FPExceptionModeKind)
Called on well formed '#pragma clang fp' that has option 'exceptions'.
Definition: SemaAttr.cpp:1345
void inferGslPointerAttribute(NamedDecl *ND, CXXRecordDecl *UnderlyingRecord)
Add gsl::Pointer attribute to std::container::iterator.
Definition: SemaAttr.cpp:111
void ActOnPragmaFPEvalMethod(SourceLocation Loc, LangOptions::FPEvalMethodKind Value)
Definition: SemaAttr.cpp:524
void ActOnPragmaClangSection(SourceLocation PragmaLoc, PragmaClangSectionAction Action, PragmaClangSectionKind SecKind, StringRef SecName)
ActOnPragmaClangSection - Called on well formed #pragma clang section.
Definition: SemaAttr.cpp:275
bool UnifySection(StringRef SectionName, int SectionFlags, NamedDecl *TheDecl)
Definition: SemaAttr.cpp:683
void setExceptionMode(SourceLocation Loc, LangOptions::FPExceptionModeKind)
Called to set exception behavior for floating point operations.
Definition: SemaAttr.cpp:1322
void PrintPragmaAttributeInstantiationPoint()
Definition: SemaAttr.cpp:1130
void inferGslOwnerPointerAttribute(CXXRecordDecl *Record)
Add [[gsl::Owner]] and [[gsl::Pointer]] attributes for std:: types.
Definition: SemaAttr.cpp:167
const LangOptions & getLangOpts() const
Definition: Sema.h:1645
SourceLocation CurInitSegLoc
Definition: Sema.h:731
void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, SourceLocation PragmaLoc, MSVtorDispMode Value)
Called on well formed #pragma vtordisp().
Definition: SemaAttr.cpp:612
Preprocessor & PP
Definition: Sema.h:406
bool MSPragmaOptimizeIsOn
The "on" or "off" argument passed by #pragma optimize, that denotes whether the optimizations in the ...
Definition: Sema.h:772
SmallVector< PragmaAttributeGroup, 2 > PragmaAttributeStack
Definition: Sema.h:756
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_PRValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CCK_ImplicitConversion)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
Definition: Sema.cpp:629
const LangOptions & LangOpts
Definition: Sema.h:405
PragmaClangSection PragmaClangRelroSection
Definition: Sema.h:471
SourceLocation ImplicitMSInheritanceAttrLoc
Source location for newly created implicit MSInheritanceAttrs.
Definition: Sema.h:439
void ProcessDeclAttributeList(Scope *S, Decl *D, const ParsedAttributesView &AttrList, const ProcessDeclAttributeOptions &Options=ProcessDeclAttributeOptions())
ProcessDeclAttributeList - Apply all the decl attributes in the specified attribute list to the speci...
void AddImplicitMSFunctionNoBuiltinAttr(FunctionDecl *FD)
Only called on function definitions; if there is a pragma in scope with the effect of a range-based n...
Definition: SemaAttr.cpp:1212
PragmaStack< AlignPackInfo > AlignPackStack
Definition: Sema.h:684
PragmaStack< StringLiteral * > BSSSegStack
Definition: Sema.h:694
llvm::StringMap< std::tuple< StringRef, SourceLocation > > FunctionToSectionMap
Sections used with #pragma alloc_text.
Definition: Sema.h:734
llvm::SmallSetVector< StringRef, 4 > MSFunctionNoBuiltins
Set of no-builtin functions listed by #pragma function.
Definition: Sema.h:775
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...
void AddCFAuditedAttribute(Decl *D)
AddCFAuditedAttribute - Check whether we're currently within '#pragma clang arc_cf_code_audited' and,...
Definition: SemaAttr.cpp:854
void AddPushedVisibilityAttribute(Decl *RD)
AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used, add an appropriate visibility at...
Definition: SemaAttr.cpp:1222
StringLiteral * CurInitSeg
Last section used with #pragma init_seg.
Definition: Sema.h:730
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:419
void ActOnPragmaMSFunction(SourceLocation Loc, const llvm::SmallVectorImpl< StringRef > &NoBuiltins)
Call on well formed #pragma function.
Definition: SemaAttr.cpp:1158
void ActOnPragmaMSStruct(PragmaMSStructKind Kind)
ActOnPragmaMSStruct - Called on well formed #pragma ms_struct [on|off].
Definition: SemaAttr.cpp:504
bool isPreciseFPEnabled()
Are precise floating point semantics currently enabled?
Definition: Sema.h:10702
void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, StringLiteral *SegmentName)
Called on well-formed #pragma init_seg().
Definition: SemaAttr.cpp:780
bool MSStructPragmaOn
Definition: Sema.h:429
SourceManager & getSourceManager() const
Definition: Sema.h:1650
void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind, SourceLocation IncludeLoc)
Definition: SemaAttr.cpp:438
PragmaClangSection PragmaClangTextSection
Definition: Sema.h:472
PragmaClangSection PragmaClangDataSection
Definition: Sema.h:469
llvm::Error isValidSectionSpecifier(StringRef Str)
Used to implement to perform semantic checking on attribute((section("foo"))) specifiers.
void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, SourceLocation Loc)
PushNamespaceVisibilityAttr - Note that we've entered a namespace with a visibility attribute.
Definition: SemaAttr.cpp:1350
PragmaStack< MSVtorDispMode > VtorDispStack
Whether to insert vtordisps prior to virtual bases in the Microsoft C++ ABI.
Definition: Sema.h:683
void AddMsStructLayoutForRecord(RecordDecl *RD)
AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record.
Definition: SemaAttr.cpp:89
void * VisContext
VisContext - Manages the stack for #pragma GCC visibility.
Definition: Sema.h:737
bool CheckAttrTarget(const ParsedAttr &CurrAttr)
ASTConsumer & Consumer
Definition: Sema.h:408
PragmaAlignPackDiagnoseKind
Definition: Sema.h:10625
Scope * TUScope
Translation Unit Scope - useful to Objective-C actions that need to lookup file scope declarations in...
Definition: Sema.h:1131
void DiagnoseUnterminatedPragmaAttribute()
Definition: SemaAttr.cpp:1136
void FreeVisContext()
FreeVisContext - Deallocate and null out VisContext.
Definition: SemaAttr.cpp:1242
void ModifyFnAttributesMSPragmaOptimize(FunctionDecl *FD)
Only called on function definitions; if there is a MSVC #pragma optimize in scope,...
Definition: SemaAttr.cpp:1191
void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc)
PopPragmaVisibility - Pop the top element of the visibility stack; used for '#pragma GCC visibility' ...
Definition: SemaAttr.cpp:1359
SourceManager & SourceMgr
Definition: Sema.h:410
void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, StringRef SlotLabel, Expr *Alignment)
ActOnPragmaPack - Called on well formed #pragma pack(...).
Definition: SemaAttr.cpp:324
DiagnosticsEngine & Diags
Definition: Sema.h:409
void DiagnoseUnterminatedPragmaAlignPack()
Definition: SemaAttr.cpp:477
FPOptions CurFPFeatures
Definition: Sema.h:403
PragmaStack< StringLiteral * > DataSegStack
Definition: Sema.h:693
void ActOnPragmaVisibility(const IdentifierInfo *VisType, SourceLocation PragmaLoc)
ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
Definition: SemaAttr.cpp:1256
SourceLocation OptimizeOffPragmaLocation
This represents the last location of a "#pragma clang optimize off" directive if such a directive has...
Definition: Sema.h:765
LangOptions::PragmaMSPointersToMembersKind MSPointerToMemberRepresentationMethod
Controls member pointer representation format under the MS ABI.
Definition: Sema.h:433
void ActOnPragmaMSStrictGuardStackCheck(SourceLocation PragmaLocation, PragmaMsStackAction Action, bool Value)
ActOnPragmaMSStrictGuardStackCheck - Called on well formed #pragma strict_gs_check.
Definition: SemaAttr.cpp:764
void ActOnPragmaFPReassociate(SourceLocation Loc, bool IsEnabled)
Called on well formed #pragma clang fp reassociate.
Definition: SemaAttr.cpp:1291
PragmaClangSection PragmaClangBSSSection
Definition: Sema.h:468
PragmaOptionsAlignKind
Definition: Sema.h:10603
@ POAK_Power
Definition: Sema.h:10607
@ POAK_Reset
Definition: Sema.h:10609
@ POAK_Packed
Definition: Sema.h:10606
@ POAK_Mac68k
Definition: Sema.h:10608
@ POAK_Natural
Definition: Sema.h:10605
@ POAK_Native
Definition: Sema.h:10604
void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC)
ActOnPragmaFPContract - Called on well formed #pragma {STDC,OPENCL} FP_CONTRACT and #pragma clang fp ...
Definition: SemaAttr.cpp:1271
void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc)
Called on well formed #pragma clang optimize.
Definition: SemaAttr.cpp:1142
void ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled)
ActOnPragmaFenvAccess - Called on well formed #pragma STDC FENV_ACCESS.
Definition: SemaAttr.cpp:1330
void AddSectionMSAllocText(FunctionDecl *FD)
Only called on function definitions; if there is a #pragma alloc_text that decides which code section...
Definition: SemaAttr.cpp:1175
void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags, StringLiteral *SegmentName)
Called on well formed #pragma section().
Definition: SemaAttr.cpp:775
PragmaClangSectionKind
pragma clang section kind
Definition: Sema.h:448
@ PCSK_BSS
Definition: Sema.h:450
@ PCSK_Data
Definition: Sema.h:451
@ PCSK_Text
Definition: Sema.h:453
@ PCSK_Relro
Definition: Sema.h:454
@ PCSK_Rodata
Definition: Sema.h:452
PragmaMsStackAction
Definition: Sema.h:474
@ PSK_Push_Set
Definition: Sema.h:480
@ PSK_Reset
Definition: Sema.h:475
@ PSK_Show
Definition: Sema.h:479
@ PSK_Pop
Definition: Sema.h:478
@ PSK_Set
Definition: Sema.h:476
@ PSK_Push
Definition: Sema.h:477
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Definition: Stmt.h:72
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:337
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1781
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1953
StringRef getString() const
Definition: Expr.h:1861
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
Definition: TargetCXXABI.h:136
bool hasAlignMac68kSupport() const
Check whether this target support '#pragma options align=mac68k'.
Definition: TargetInfo.h:890
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:1265
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:181
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:126
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1783
bool isArrayType() const
Definition: Type.h:6976
bool isFunctionType() const
Definition: Type.h:6906
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3290
QualType getUnderlyingType() const
Definition: Decl.h:3345
Represents a variable declaration or definition.
Definition: Decl.h:913
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
llvm::DenseMap< int, SourceRange > ParsedSubjectMatchRuleSet
SubjectMatchRule
A list of all the recognized kinds of attributes.
const char * getSubjectMatchRuleSpelling(SubjectMatchRule Rule)
Definition: Attributes.cpp:52
@ CPlusPlus
Definition: LangStandard.h:53
PragmaMSCommentKind
Definition: PragmaKinds.h:14
@ AANT_ArgumentConstantExpr
Definition: ParsedAttr.h:1032
@ Result
The result type of a method or function.
MSVtorDispMode
In the Microsoft ABI, this controls the placement of virtual displacement members used to implement v...
Definition: LangOptions.h:55
PragmaMSStructKind
Definition: PragmaKinds.h:23
@ PMSST_ON
Definition: PragmaKinds.h:25
PragmaFloatControlKind
Definition: PragmaKinds.h:28
@ PFC_NoExcept
Definition: PragmaKinds.h:33
@ PFC_NoPrecise
Definition: PragmaKinds.h:31
@ PFC_Pop
Definition: PragmaKinds.h:35
@ PFC_Precise
Definition: PragmaKinds.h:30
@ PFC_Except
Definition: PragmaKinds.h:32
@ PFC_Push
Definition: PragmaKinds.h:34
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:123
EvalResult is a struct with detailed info about an evaluated expression.
Definition: Expr.h:623
APValue Val
Val - This is the value the expression can be folded to.
Definition: Expr.h:625
SmallVectorImpl< PartialDiagnosticAt > * Diag
Diag - If this is non-null, it will be filled in with a stack of notes indicating why evaluation fail...
Definition: Expr.h:610
SourceLocation CurrentPragmaLocation
Definition: Sema.h:688
This an attribute introduced by #pragma clang attribute.
Definition: Sema.h:740
SourceLocation PragmaLocation
Definition: Sema.h:465
ValueType CurrentValue
Definition: Sema.h:669
void SentinelAction(PragmaMsStackAction Action, StringRef Label)
Definition: Sema.h:655
SmallVector< Slot, 2 > Stack
Definition: Sema.h:667
void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, llvm::StringRef StackSlotLabel, ValueType Value)
Definition: Sema.h:606