clang 19.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>
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.
216}
217
219 static llvm::StringSet<> Nullable{
220 "auto_ptr", "shared_ptr", "unique_ptr", "exception_ptr",
221 "coroutine_handle", "function", "move_only_function",
222 };
223
224 if (CRD->isInStdNamespace() && Nullable.count(CRD->getName()) &&
225 !CRD->hasAttr<TypeNullableAttr>())
226 for (Decl *Redecl : CRD->redecls())
227 Redecl->addAttr(TypeNullableAttr::CreateImplicit(Context));
228}
229
231 SourceLocation PragmaLoc) {
234
235 switch (Kind) {
236 // For most of the platforms we support, native and natural are the same.
237 // With XL, native is the same as power, natural means something else.
238 case POAK_Native:
239 case POAK_Power:
240 Action = Sema::PSK_Push_Set;
241 break;
242 case POAK_Natural:
243 Action = Sema::PSK_Push_Set;
244 ModeVal = AlignPackInfo::Natural;
245 break;
246
247 // Note that '#pragma options align=packed' is not equivalent to attribute
248 // packed, it has a different precedence relative to attribute aligned.
249 case POAK_Packed:
250 Action = Sema::PSK_Push_Set;
251 ModeVal = AlignPackInfo::Packed;
252 break;
253
254 case POAK_Mac68k:
255 // Check if the target supports this.
257 Diag(PragmaLoc, diag::err_pragma_options_align_mac68k_target_unsupported);
258 return;
259 }
260 Action = Sema::PSK_Push_Set;
261 ModeVal = AlignPackInfo::Mac68k;
262 break;
263 case POAK_Reset:
264 // Reset just pops the top of the stack, or resets the current alignment to
265 // default.
266 Action = Sema::PSK_Pop;
267 if (AlignPackStack.Stack.empty()) {
268 if (AlignPackStack.CurrentValue.getAlignMode() != AlignPackInfo::Native ||
269 AlignPackStack.CurrentValue.IsPackAttr()) {
270 Action = Sema::PSK_Reset;
271 } else {
272 Diag(PragmaLoc, diag::warn_pragma_options_align_reset_failed)
273 << "stack empty";
274 return;
275 }
276 }
277 break;
278 }
279
280 AlignPackInfo Info(ModeVal, getLangOpts().XLPragmaPack);
281
282 AlignPackStack.Act(PragmaLoc, Action, StringRef(), Info);
283}
284
288 StringRef SecName) {
289 PragmaClangSection *CSec;
290 int SectionFlags = ASTContext::PSF_Read;
291 switch (SecKind) {
293 CSec = &PragmaClangBSSSection;
295 break;
298 SectionFlags |= ASTContext::PSF_Write;
299 break;
302 break;
305 break;
308 SectionFlags |= ASTContext::PSF_Execute;
309 break;
310 default:
311 llvm_unreachable("invalid clang section kind");
312 }
313
315 CSec->Valid = false;
316 return;
317 }
318
319 if (llvm::Error E = isValidSectionSpecifier(SecName)) {
320 Diag(PragmaLoc, diag::err_pragma_section_invalid_for_target)
321 << toString(std::move(E));
322 CSec->Valid = false;
323 return;
324 }
325
326 if (UnifySection(SecName, SectionFlags, PragmaLoc))
327 return;
328
329 CSec->Valid = true;
330 CSec->SectionName = std::string(SecName);
331 CSec->PragmaLocation = PragmaLoc;
332}
333
335 StringRef SlotLabel, Expr *alignment) {
336 bool IsXLPragma = getLangOpts().XLPragmaPack;
337 // XL pragma pack does not support identifier syntax.
338 if (IsXLPragma && !SlotLabel.empty()) {
339 Diag(PragmaLoc, diag::err_pragma_pack_identifer_not_supported);
340 return;
341 }
342
343 const AlignPackInfo CurVal = AlignPackStack.CurrentValue;
344 Expr *Alignment = static_cast<Expr *>(alignment);
345
346 // If specified then alignment must be a "small" power of two.
347 unsigned AlignmentVal = 0;
348 AlignPackInfo::Mode ModeVal = CurVal.getAlignMode();
349
350 if (Alignment) {
351 std::optional<llvm::APSInt> Val;
352 Val = Alignment->getIntegerConstantExpr(Context);
353
354 // pack(0) is like pack(), which just works out since that is what
355 // we use 0 for in PackAttr.
356 if (Alignment->isTypeDependent() || !Val ||
357 !(*Val == 0 || Val->isPowerOf2()) || Val->getZExtValue() > 16) {
358 Diag(PragmaLoc, diag::warn_pragma_pack_invalid_alignment);
359 return; // Ignore
360 }
361
362 if (IsXLPragma && *Val == 0) {
363 // pack(0) does not work out with XL.
364 Diag(PragmaLoc, diag::err_pragma_pack_invalid_alignment);
365 return; // Ignore
366 }
367
368 AlignmentVal = (unsigned)Val->getZExtValue();
369 }
370
371 if (Action == Sema::PSK_Show) {
372 // Show the current alignment, making sure to show the right value
373 // for the default.
374 // FIXME: This should come from the target.
375 AlignmentVal = CurVal.IsPackSet() ? CurVal.getPackNumber() : 8;
376 if (ModeVal == AlignPackInfo::Mac68k &&
377 (IsXLPragma || CurVal.IsAlignAttr()))
378 Diag(PragmaLoc, diag::warn_pragma_pack_show) << "mac68k";
379 else
380 Diag(PragmaLoc, diag::warn_pragma_pack_show) << AlignmentVal;
381 }
382
383 // MSDN, C/C++ Preprocessor Reference > Pragma Directives > pack:
384 // "#pragma pack(pop, identifier, n) is undefined"
385 if (Action & Sema::PSK_Pop) {
386 if (Alignment && !SlotLabel.empty())
387 Diag(PragmaLoc, diag::warn_pragma_pack_pop_identifier_and_alignment);
388 if (AlignPackStack.Stack.empty()) {
389 assert(CurVal.getAlignMode() == AlignPackInfo::Native &&
390 "Empty pack stack can only be at Native alignment mode.");
391 Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "pack" << "stack empty";
392 }
393 }
394
395 AlignPackInfo Info(ModeVal, AlignmentVal, IsXLPragma);
396
397 AlignPackStack.Act(PragmaLoc, Action, SlotLabel, Info);
398}
399
403 for (unsigned Idx = 0; Idx < Args.size(); Idx++) {
404 Expr *&E = Args.begin()[Idx];
405 assert(E && "error are handled before");
406 if (E->isValueDependent() || E->isTypeDependent())
407 continue;
408
409 // FIXME: Use DefaultFunctionArrayLValueConversion() in place of the logic
410 // that adds implicit casts here.
411 if (E->getType()->isArrayType())
413 clang::CK_ArrayToPointerDecay)
414 .get();
415 if (E->getType()->isFunctionType())
418 clang::CK_FunctionToPointerDecay, E, nullptr,
420 if (E->isLValue())
422 clang::CK_LValueToRValue, E, nullptr,
424
425 Expr::EvalResult Eval;
426 Notes.clear();
427 Eval.Diag = &Notes;
428
429 bool Result = E->EvaluateAsConstantExpr(Eval, Context);
430
431 /// Result means the expression can be folded to a constant.
432 /// Note.empty() means the expression is a valid constant expression in the
433 /// current language mode.
434 if (!Result || !Notes.empty()) {
435 Diag(E->getBeginLoc(), diag::err_attribute_argument_n_type)
436 << CI << (Idx + 1) << AANT_ArgumentConstantExpr;
437 for (auto &Note : Notes)
438 Diag(Note.first, Note.second);
439 return false;
440 }
441 assert(Eval.Val.hasValue());
442 E = ConstantExpr::Create(Context, E, Eval.Val);
443 }
444
445 return true;
446}
447
449 SourceLocation IncludeLoc) {
451 SourceLocation PrevLocation = AlignPackStack.CurrentPragmaLocation;
452 // Warn about non-default alignment at #includes (without redundant
453 // warnings for the same directive in nested includes).
454 // The warning is delayed until the end of the file to avoid warnings
455 // for files that don't have any records that are affected by the modified
456 // alignment.
457 bool HasNonDefaultValue =
458 AlignPackStack.hasValue() &&
459 (AlignPackIncludeStack.empty() ||
460 AlignPackIncludeStack.back().CurrentPragmaLocation != PrevLocation);
461 AlignPackIncludeStack.push_back(
462 {AlignPackStack.CurrentValue,
463 AlignPackStack.hasValue() ? PrevLocation : SourceLocation(),
464 HasNonDefaultValue, /*ShouldWarnOnInclude*/ false});
465 return;
466 }
467
469 "invalid kind");
470 AlignPackIncludeState PrevAlignPackState =
471 AlignPackIncludeStack.pop_back_val();
472 // FIXME: AlignPackStack may contain both #pragma align and #pragma pack
473 // information, diagnostics below might not be accurate if we have mixed
474 // pragmas.
475 if (PrevAlignPackState.ShouldWarnOnInclude) {
476 // Emit the delayed non-default alignment at #include warning.
477 Diag(IncludeLoc, diag::warn_pragma_pack_non_default_at_include);
478 Diag(PrevAlignPackState.CurrentPragmaLocation, diag::note_pragma_pack_here);
479 }
480 // Warn about modified alignment after #includes.
481 if (PrevAlignPackState.CurrentValue != AlignPackStack.CurrentValue) {
482 Diag(IncludeLoc, diag::warn_pragma_pack_modified_after_include);
483 Diag(AlignPackStack.CurrentPragmaLocation, diag::note_pragma_pack_here);
484 }
485}
486
488 if (AlignPackStack.Stack.empty())
489 return;
490 bool IsInnermost = true;
491
492 // FIXME: AlignPackStack may contain both #pragma align and #pragma pack
493 // information, diagnostics below might not be accurate if we have mixed
494 // pragmas.
495 for (const auto &StackSlot : llvm::reverse(AlignPackStack.Stack)) {
496 Diag(StackSlot.PragmaPushLocation, diag::warn_pragma_pack_no_pop_eof);
497 // The user might have already reset the alignment, so suggest replacing
498 // the reset with a pop.
499 if (IsInnermost &&
500 AlignPackStack.CurrentValue == AlignPackStack.DefaultValue) {
501 auto DB = Diag(AlignPackStack.CurrentPragmaLocation,
502 diag::note_pragma_pack_pop_instead_reset);
503 SourceLocation FixItLoc =
504 Lexer::findLocationAfterToken(AlignPackStack.CurrentPragmaLocation,
505 tok::l_paren, SourceMgr, LangOpts,
506 /*SkipTrailing=*/false);
507 if (FixItLoc.isValid())
508 DB << FixItHint::CreateInsertion(FixItLoc, "pop");
509 }
510 IsInnermost = false;
511 }
512}
513
515 MSStructPragmaOn = (Kind == PMSST_ON);
516}
517
519 PragmaMSCommentKind Kind, StringRef Arg) {
520 auto *PCD = PragmaCommentDecl::Create(
521 Context, Context.getTranslationUnitDecl(), CommentLoc, Kind, Arg);
524}
525
527 StringRef Value) {
532}
533
537 switch (Value) {
538 default:
539 llvm_unreachable("invalid pragma eval_method kind");
541 NewFPFeatures.setFPEvalMethodOverride(LangOptions::FEM_Source);
542 break;
544 NewFPFeatures.setFPEvalMethodOverride(LangOptions::FEM_Double);
545 break;
547 NewFPFeatures.setFPEvalMethodOverride(LangOptions::FEM_Extended);
548 break;
549 }
550 if (getLangOpts().ApproxFunc)
551 Diag(Loc, diag::err_setting_eval_method_used_in_unsafe_context) << 0 << 0;
552 if (getLangOpts().AllowFPReassoc)
553 Diag(Loc, diag::err_setting_eval_method_used_in_unsafe_context) << 0 << 1;
554 if (getLangOpts().AllowRecip)
555 Diag(Loc, diag::err_setting_eval_method_used_in_unsafe_context) << 0 << 2;
556 FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
557 CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
559}
560
562 PragmaMsStackAction Action,
565 if ((Action == PSK_Push_Set || Action == PSK_Push || Action == PSK_Pop) &&
567 // Push and pop can only occur at file or namespace scope, or within a
568 // language linkage declaration.
569 Diag(Loc, diag::err_pragma_fc_pp_scope);
570 return;
571 }
572 switch (Value) {
573 default:
574 llvm_unreachable("invalid pragma float_control kind");
575 case PFC_Precise:
576 NewFPFeatures.setFPPreciseEnabled(true);
577 FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
578 break;
579 case PFC_NoPrecise:
581 Diag(Loc, diag::err_pragma_fc_noprecise_requires_noexcept);
582 else if (CurFPFeatures.getAllowFEnvAccess())
583 Diag(Loc, diag::err_pragma_fc_noprecise_requires_nofenv);
584 else
585 NewFPFeatures.setFPPreciseEnabled(false);
586 FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
587 break;
588 case PFC_Except:
589 if (!isPreciseFPEnabled())
590 Diag(Loc, diag::err_pragma_fc_except_requires_precise);
591 else
592 NewFPFeatures.setSpecifiedExceptionModeOverride(LangOptions::FPE_Strict);
593 FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
594 break;
595 case PFC_NoExcept:
596 NewFPFeatures.setSpecifiedExceptionModeOverride(LangOptions::FPE_Ignore);
597 FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
598 break;
599 case PFC_Push:
600 FpPragmaStack.Act(Loc, Sema::PSK_Push_Set, StringRef(), NewFPFeatures);
601 break;
602 case PFC_Pop:
603 if (FpPragmaStack.Stack.empty()) {
604 Diag(Loc, diag::warn_pragma_pop_failed) << "float_control"
605 << "stack empty";
606 return;
607 }
608 FpPragmaStack.Act(Loc, Action, StringRef(), NewFPFeatures);
609 NewFPFeatures = FpPragmaStack.CurrentValue;
610 break;
611 }
612 CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
613}
614
617 SourceLocation PragmaLoc) {
618 MSPointerToMemberRepresentationMethod = RepresentationMethod;
620}
621
623 SourceLocation PragmaLoc,
624 MSVtorDispMode Mode) {
625 if (Action & PSK_Pop && VtorDispStack.Stack.empty())
626 Diag(PragmaLoc, diag::warn_pragma_pop_failed) << "vtordisp"
627 << "stack empty";
628 VtorDispStack.Act(PragmaLoc, Action, StringRef(), Mode);
629}
630
631template <>
633 PragmaMsStackAction Action,
634 llvm::StringRef StackSlotLabel,
635 AlignPackInfo Value) {
636 if (Action == PSK_Reset) {
637 CurrentValue = DefaultValue;
638 CurrentPragmaLocation = PragmaLocation;
639 return;
640 }
641 if (Action & PSK_Push)
642 Stack.emplace_back(Slot(StackSlotLabel, CurrentValue, CurrentPragmaLocation,
643 PragmaLocation));
644 else if (Action & PSK_Pop) {
645 if (!StackSlotLabel.empty()) {
646 // If we've got a label, try to find it and jump there.
647 auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
648 return x.StackSlotLabel == StackSlotLabel;
649 });
650 // We found the label, so pop from there.
651 if (I != Stack.rend()) {
652 CurrentValue = I->Value;
653 CurrentPragmaLocation = I->PragmaLocation;
654 Stack.erase(std::prev(I.base()), Stack.end());
655 }
656 } else if (Value.IsXLStack() && Value.IsAlignAttr() &&
657 CurrentValue.IsPackAttr()) {
658 // XL '#pragma align(reset)' would pop the stack until
659 // a current in effect pragma align is popped.
660 auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) {
661 return x.Value.IsAlignAttr();
662 });
663 // If we found pragma align so pop from there.
664 if (I != Stack.rend()) {
665 Stack.erase(std::prev(I.base()), Stack.end());
666 if (Stack.empty()) {
667 CurrentValue = DefaultValue;
668 CurrentPragmaLocation = PragmaLocation;
669 } else {
670 CurrentValue = Stack.back().Value;
671 CurrentPragmaLocation = Stack.back().PragmaLocation;
672 Stack.pop_back();
673 }
674 }
675 } else if (!Stack.empty()) {
676 // xl '#pragma align' sets the baseline, and `#pragma pack` cannot pop
677 // over the baseline.
678 if (Value.IsXLStack() && Value.IsPackAttr() && CurrentValue.IsAlignAttr())
679 return;
680
681 // We don't have a label, just pop the last entry.
682 CurrentValue = Stack.back().Value;
683 CurrentPragmaLocation = Stack.back().PragmaLocation;
684 Stack.pop_back();
685 }
686 }
687 if (Action & PSK_Set) {
688 CurrentValue = Value;
689 CurrentPragmaLocation = PragmaLocation;
690 }
691}
692
693bool Sema::UnifySection(StringRef SectionName, int SectionFlags,
694 NamedDecl *Decl) {
695 SourceLocation PragmaLocation;
696 if (auto A = Decl->getAttr<SectionAttr>())
697 if (A->isImplicit())
698 PragmaLocation = A->getLocation();
699 auto SectionIt = Context.SectionInfos.find(SectionName);
700 if (SectionIt == Context.SectionInfos.end()) {
701 Context.SectionInfos[SectionName] =
702 ASTContext::SectionInfo(Decl, PragmaLocation, SectionFlags);
703 return false;
704 }
705 // A pre-declared section takes precedence w/o diagnostic.
706 const auto &Section = SectionIt->second;
707 if (Section.SectionFlags == SectionFlags ||
708 ((SectionFlags & ASTContext::PSF_Implicit) &&
709 !(Section.SectionFlags & ASTContext::PSF_Implicit)))
710 return false;
711 Diag(Decl->getLocation(), diag::err_section_conflict) << Decl << Section;
712 if (Section.Decl)
713 Diag(Section.Decl->getLocation(), diag::note_declared_at)
714 << Section.Decl->getName();
715 if (PragmaLocation.isValid())
716 Diag(PragmaLocation, diag::note_pragma_entered_here);
717 if (Section.PragmaSectionLocation.isValid())
718 Diag(Section.PragmaSectionLocation, diag::note_pragma_entered_here);
719 return true;
720}
721
722bool Sema::UnifySection(StringRef SectionName,
723 int SectionFlags,
724 SourceLocation PragmaSectionLocation) {
725 auto SectionIt = Context.SectionInfos.find(SectionName);
726 if (SectionIt != Context.SectionInfos.end()) {
727 const auto &Section = SectionIt->second;
728 if (Section.SectionFlags == SectionFlags)
729 return false;
730 if (!(Section.SectionFlags & ASTContext::PSF_Implicit)) {
731 Diag(PragmaSectionLocation, diag::err_section_conflict)
732 << "this" << Section;
733 if (Section.Decl)
734 Diag(Section.Decl->getLocation(), diag::note_declared_at)
735 << Section.Decl->getName();
736 if (Section.PragmaSectionLocation.isValid())
737 Diag(Section.PragmaSectionLocation, diag::note_pragma_entered_here);
738 return true;
739 }
740 }
741 Context.SectionInfos[SectionName] =
742 ASTContext::SectionInfo(nullptr, PragmaSectionLocation, SectionFlags);
743 return false;
744}
745
746/// Called on well formed \#pragma bss_seg().
748 PragmaMsStackAction Action,
749 llvm::StringRef StackSlotLabel,
750 StringLiteral *SegmentName,
751 llvm::StringRef PragmaName) {
753 llvm::StringSwitch<PragmaStack<StringLiteral *> *>(PragmaName)
754 .Case("data_seg", &DataSegStack)
755 .Case("bss_seg", &BSSSegStack)
756 .Case("const_seg", &ConstSegStack)
757 .Case("code_seg", &CodeSegStack);
758 if (Action & PSK_Pop && Stack->Stack.empty())
759 Diag(PragmaLocation, diag::warn_pragma_pop_failed) << PragmaName
760 << "stack empty";
761 if (SegmentName) {
762 if (!checkSectionName(SegmentName->getBeginLoc(), SegmentName->getString()))
763 return;
764
765 if (SegmentName->getString() == ".drectve" &&
767 Diag(PragmaLocation, diag::warn_attribute_section_drectve) << PragmaName;
768 }
769
770 Stack->Act(PragmaLocation, Action, StackSlotLabel, SegmentName);
771}
772
773/// Called on well formed \#pragma strict_gs_check().
775 PragmaMsStackAction Action,
776 bool Value) {
777 if (Action & PSK_Pop && StrictGuardStackCheckStack.Stack.empty())
778 Diag(PragmaLocation, diag::warn_pragma_pop_failed) << "strict_gs_check"
779 << "stack empty";
780
781 StrictGuardStackCheckStack.Act(PragmaLocation, Action, StringRef(), Value);
782}
783
784/// Called on well formed \#pragma bss_seg().
786 int SectionFlags, StringLiteral *SegmentName) {
787 UnifySection(SegmentName->getString(), SectionFlags, PragmaLocation);
788}
789
791 StringLiteral *SegmentName) {
792 // There's no stack to maintain, so we just have a current section. When we
793 // see the default section, reset our current section back to null so we stop
794 // tacking on unnecessary attributes.
795 CurInitSeg = SegmentName->getString() == ".CRT$XCU" ? nullptr : SegmentName;
796 CurInitSegLoc = PragmaLocation;
797}
798
800 SourceLocation PragmaLocation, StringRef Section,
801 const SmallVector<std::tuple<IdentifierInfo *, SourceLocation>>
802 &Functions) {
804 Diag(PragmaLocation, diag::err_pragma_expected_file_scope) << "alloc_text";
805 return;
806 }
807
808 for (auto &Function : Functions) {
809 IdentifierInfo *II;
811 std::tie(II, Loc) = Function;
812
813 DeclarationName DN(II);
815 if (!ND) {
816 Diag(Loc, diag::err_undeclared_use) << II->getName();
817 return;
818 }
819
820 auto *FD = dyn_cast<FunctionDecl>(ND->getCanonicalDecl());
821 if (!FD) {
822 Diag(Loc, diag::err_pragma_alloc_text_not_function);
823 return;
824 }
825
826 if (getLangOpts().CPlusPlus && !FD->isInExternCContext()) {
827 Diag(Loc, diag::err_pragma_alloc_text_c_linkage);
828 return;
829 }
830
831 FunctionToSectionMap[II->getName()] = std::make_tuple(Section, Loc);
832 }
833}
834
835void Sema::ActOnPragmaUnused(const Token &IdTok, Scope *curScope,
836 SourceLocation PragmaLoc) {
837
838 IdentifierInfo *Name = IdTok.getIdentifierInfo();
839 LookupResult Lookup(*this, Name, IdTok.getLocation(), LookupOrdinaryName);
840 LookupName(Lookup, curScope, /*AllowBuiltinCreation=*/true);
841
842 if (Lookup.empty()) {
843 Diag(PragmaLoc, diag::warn_pragma_unused_undeclared_var)
844 << Name << SourceRange(IdTok.getLocation());
845 return;
846 }
847
848 VarDecl *VD = Lookup.getAsSingle<VarDecl>();
849 if (!VD) {
850 Diag(PragmaLoc, diag::warn_pragma_unused_expected_var_arg)
851 << Name << SourceRange(IdTok.getLocation());
852 return;
853 }
854
855 // Warn if this was used before being marked unused.
856 if (VD->isUsed())
857 Diag(PragmaLoc, diag::warn_used_but_marked_unused) << Name;
858
859 VD->addAttr(UnusedAttr::CreateImplicit(Context, IdTok.getLocation(),
860 UnusedAttr::GNU_unused));
861}
862
863namespace {
864
865std::optional<attr::SubjectMatchRule>
866getParentAttrMatcherRule(attr::SubjectMatchRule Rule) {
867 using namespace attr;
868 switch (Rule) {
869 default:
870 return std::nullopt;
871#define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
872#define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \
873 case Value: \
874 return Parent;
875#include "clang/Basic/AttrSubMatchRulesList.inc"
876 }
877}
878
879bool isNegatedAttrMatcherSubRule(attr::SubjectMatchRule Rule) {
880 using namespace attr;
881 switch (Rule) {
882 default:
883 return false;
884#define ATTR_MATCH_RULE(Value, Spelling, IsAbstract)
885#define ATTR_MATCH_SUB_RULE(Value, Spelling, IsAbstract, Parent, IsNegated) \
886 case Value: \
887 return IsNegated;
888#include "clang/Basic/AttrSubMatchRulesList.inc"
889 }
890}
891
892CharSourceRange replacementRangeForListElement(const Sema &S,
894 // Make sure that the ',' is removed as well.
896 Range.getEnd(), tok::comma, S.getSourceManager(), S.getLangOpts(),
897 /*SkipTrailingWhitespaceAndNewLine=*/false);
898 if (AfterCommaLoc.isValid())
899 return CharSourceRange::getCharRange(Range.getBegin(), AfterCommaLoc);
900 else
902}
903
904std::string
905attrMatcherRuleListToString(ArrayRef<attr::SubjectMatchRule> Rules) {
906 std::string Result;
907 llvm::raw_string_ostream OS(Result);
908 for (const auto &I : llvm::enumerate(Rules)) {
909 if (I.index())
910 OS << (I.index() == Rules.size() - 1 ? ", and " : ", ");
911 OS << "'" << attr::getSubjectMatchRuleSpelling(I.value()) << "'";
912 }
913 return Result;
914}
915
916} // end anonymous namespace
917
919 ParsedAttr &Attribute, SourceLocation PragmaLoc,
921 Attribute.setIsPragmaClangAttribute();
923 // Gather the subject match rules that are supported by the attribute.
925 StrictSubjectMatchRuleSet;
926 Attribute.getMatchRules(LangOpts, StrictSubjectMatchRuleSet);
927
928 // Figure out which subject matching rules are valid.
929 if (StrictSubjectMatchRuleSet.empty()) {
930 // Check for contradicting match rules. Contradicting match rules are
931 // either:
932 // - a top-level rule and one of its sub-rules. E.g. variable and
933 // variable(is_parameter).
934 // - a sub-rule and a sibling that's negated. E.g.
935 // variable(is_thread_local) and variable(unless(is_parameter))
936 llvm::SmallDenseMap<int, std::pair<int, SourceRange>, 2>
937 RulesToFirstSpecifiedNegatedSubRule;
938 for (const auto &Rule : Rules) {
939 attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
940 std::optional<attr::SubjectMatchRule> ParentRule =
941 getParentAttrMatcherRule(MatchRule);
942 if (!ParentRule)
943 continue;
944 auto It = Rules.find(*ParentRule);
945 if (It != Rules.end()) {
946 // A sub-rule contradicts a parent rule.
947 Diag(Rule.second.getBegin(),
948 diag::err_pragma_attribute_matcher_subrule_contradicts_rule)
950 << attr::getSubjectMatchRuleSpelling(*ParentRule) << It->second
952 replacementRangeForListElement(*this, Rule.second));
953 // Keep going without removing this rule as it won't change the set of
954 // declarations that receive the attribute.
955 continue;
956 }
957 if (isNegatedAttrMatcherSubRule(MatchRule))
958 RulesToFirstSpecifiedNegatedSubRule.insert(
959 std::make_pair(*ParentRule, Rule));
960 }
961 bool IgnoreNegatedSubRules = false;
962 for (const auto &Rule : Rules) {
963 attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
964 std::optional<attr::SubjectMatchRule> ParentRule =
965 getParentAttrMatcherRule(MatchRule);
966 if (!ParentRule)
967 continue;
968 auto It = RulesToFirstSpecifiedNegatedSubRule.find(*ParentRule);
969 if (It != RulesToFirstSpecifiedNegatedSubRule.end() &&
970 It->second != Rule) {
971 // Negated sub-rule contradicts another sub-rule.
972 Diag(
973 It->second.second.getBegin(),
974 diag::
975 err_pragma_attribute_matcher_negated_subrule_contradicts_subrule)
977 attr::SubjectMatchRule(It->second.first))
978 << attr::getSubjectMatchRuleSpelling(MatchRule) << Rule.second
980 replacementRangeForListElement(*this, It->second.second));
981 // Keep going but ignore all of the negated sub-rules.
982 IgnoreNegatedSubRules = true;
983 RulesToFirstSpecifiedNegatedSubRule.erase(It);
984 }
985 }
986
987 if (!IgnoreNegatedSubRules) {
988 for (const auto &Rule : Rules)
989 SubjectMatchRules.push_back(attr::SubjectMatchRule(Rule.first));
990 } else {
991 for (const auto &Rule : Rules) {
992 if (!isNegatedAttrMatcherSubRule(attr::SubjectMatchRule(Rule.first)))
993 SubjectMatchRules.push_back(attr::SubjectMatchRule(Rule.first));
994 }
995 }
996 Rules.clear();
997 } else {
998 // Each rule in Rules must be a strict subset of the attribute's
999 // SubjectMatch rules. I.e. we're allowed to use
1000 // `apply_to=variables(is_global)` on an attrubute with SubjectList<[Var]>,
1001 // but should not allow `apply_to=variables` on an attribute which has
1002 // `SubjectList<[GlobalVar]>`.
1003 for (const auto &StrictRule : StrictSubjectMatchRuleSet) {
1004 // First, check for exact match.
1005 if (Rules.erase(StrictRule.first)) {
1006 // Add the rule to the set of attribute receivers only if it's supported
1007 // in the current language mode.
1008 if (StrictRule.second)
1009 SubjectMatchRules.push_back(StrictRule.first);
1010 }
1011 }
1012 // Check remaining rules for subset matches.
1013 auto RulesToCheck = Rules;
1014 for (const auto &Rule : RulesToCheck) {
1015 attr::SubjectMatchRule MatchRule = attr::SubjectMatchRule(Rule.first);
1016 if (auto ParentRule = getParentAttrMatcherRule(MatchRule)) {
1017 if (llvm::any_of(StrictSubjectMatchRuleSet,
1018 [ParentRule](const auto &StrictRule) {
1019 return StrictRule.first == *ParentRule &&
1020 StrictRule.second; // IsEnabled
1021 })) {
1022 SubjectMatchRules.push_back(MatchRule);
1023 Rules.erase(MatchRule);
1024 }
1025 }
1026 }
1027 }
1028
1029 if (!Rules.empty()) {
1030 auto Diagnostic =
1031 Diag(PragmaLoc, diag::err_pragma_attribute_invalid_matchers)
1032 << Attribute;
1034 for (const auto &Rule : Rules) {
1035 ExtraRules.push_back(attr::SubjectMatchRule(Rule.first));
1037 replacementRangeForListElement(*this, Rule.second));
1038 }
1039 Diagnostic << attrMatcherRuleListToString(ExtraRules);
1040 }
1041
1042 if (PragmaAttributeStack.empty()) {
1043 Diag(PragmaLoc, diag::err_pragma_attr_attr_no_push);
1044 return;
1045 }
1046
1047 PragmaAttributeStack.back().Entries.push_back(
1048 {PragmaLoc, &Attribute, std::move(SubjectMatchRules), /*IsUsed=*/false});
1049}
1050
1052 const IdentifierInfo *Namespace) {
1053 PragmaAttributeStack.emplace_back();
1054 PragmaAttributeStack.back().Loc = PragmaLoc;
1055 PragmaAttributeStack.back().Namespace = Namespace;
1056}
1057
1059 const IdentifierInfo *Namespace) {
1060 if (PragmaAttributeStack.empty()) {
1061 Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
1062 return;
1063 }
1064
1065 // Dig back through the stack trying to find the most recently pushed group
1066 // that in Namespace. Note that this works fine if no namespace is present,
1067 // think of push/pops without namespaces as having an implicit "nullptr"
1068 // namespace.
1069 for (size_t Index = PragmaAttributeStack.size(); Index;) {
1070 --Index;
1071 if (PragmaAttributeStack[Index].Namespace == Namespace) {
1072 for (const PragmaAttributeEntry &Entry :
1073 PragmaAttributeStack[Index].Entries) {
1074 if (!Entry.IsUsed) {
1075 assert(Entry.Attribute && "Expected an attribute");
1076 Diag(Entry.Attribute->getLoc(), diag::warn_pragma_attribute_unused)
1077 << *Entry.Attribute;
1078 Diag(PragmaLoc, diag::note_pragma_attribute_region_ends_here);
1079 }
1080 }
1081 PragmaAttributeStack.erase(PragmaAttributeStack.begin() + Index);
1082 return;
1083 }
1084 }
1085
1086 if (Namespace)
1087 Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch)
1088 << 0 << Namespace->getName();
1089 else
1090 Diag(PragmaLoc, diag::err_pragma_attribute_stack_mismatch) << 1;
1091}
1092
1094 if (PragmaAttributeStack.empty())
1095 return;
1096 for (auto &Group : PragmaAttributeStack) {
1097 for (auto &Entry : Group.Entries) {
1098 ParsedAttr *Attribute = Entry.Attribute;
1099 assert(Attribute && "Expected an attribute");
1100 assert(Attribute->isPragmaClangAttribute() &&
1101 "expected #pragma clang attribute");
1102
1103 // Ensure that the attribute can be applied to the given declaration.
1104 bool Applies = false;
1105 for (const auto &Rule : Entry.MatchRules) {
1106 if (Attribute->appliesToDecl(D, Rule)) {
1107 Applies = true;
1108 break;
1109 }
1110 }
1111 if (!Applies)
1112 continue;
1113 Entry.IsUsed = true;
1116 Attrs.addAtEnd(Attribute);
1117 ProcessDeclAttributeList(S, D, Attrs);
1119 }
1120 }
1121}
1122
1124 assert(PragmaAttributeCurrentTargetDecl && "Expected an active declaration");
1126 diag::note_pragma_attribute_applied_decl_here);
1127}
1128
1130 if (PragmaAttributeStack.empty())
1131 return;
1132 Diag(PragmaAttributeStack.back().Loc, diag::err_pragma_attribute_no_pop_eof);
1133}
1134
1136 if(On)
1138 else
1139 OptimizeOffPragmaLocation = PragmaLoc;
1140}
1141
1144 Diag(Loc, diag::err_pragma_expected_file_scope) << "optimize";
1145 return;
1146 }
1147
1148 MSPragmaOptimizeIsOn = IsOn;
1149}
1150
1154 Diag(Loc, diag::err_pragma_expected_file_scope) << "function";
1155 return;
1156 }
1157
1158 MSFunctionNoBuiltins.insert(NoBuiltins.begin(), NoBuiltins.end());
1159}
1160
1162 // In the future, check other pragmas if they're implemented (e.g. pragma
1163 // optimize 0 will probably map to this functionality too).
1166}
1167
1169 if (!FD->getIdentifier())
1170 return;
1171
1172 StringRef Name = FD->getName();
1173 auto It = FunctionToSectionMap.find(Name);
1174 if (It != FunctionToSectionMap.end()) {
1175 StringRef Section;
1177 std::tie(Section, Loc) = It->second;
1178
1179 if (!FD->hasAttr<SectionAttr>())
1180 FD->addAttr(SectionAttr::CreateImplicit(Context, Section));
1181 }
1182}
1183
1185 // Don't modify the function attributes if it's "on". "on" resets the
1186 // optimizations to the ones listed on the command line
1189}
1190
1193 // Don't add a conflicting attribute. No diagnostic is needed.
1194 if (FD->hasAttr<MinSizeAttr>() || FD->hasAttr<AlwaysInlineAttr>())
1195 return;
1196
1197 // Add attributes only if required. Optnone requires noinline as well, but if
1198 // either is already present then don't bother adding them.
1199 if (!FD->hasAttr<OptimizeNoneAttr>())
1200 FD->addAttr(OptimizeNoneAttr::CreateImplicit(Context, Loc));
1201 if (!FD->hasAttr<NoInlineAttr>())
1202 FD->addAttr(NoInlineAttr::CreateImplicit(Context, Loc));
1203}
1204
1207 MSFunctionNoBuiltins.end());
1208 if (!MSFunctionNoBuiltins.empty())
1209 FD->addAttr(NoBuiltinAttr::CreateImplicit(Context, V.data(), V.size()));
1210}
1211
1212typedef std::vector<std::pair<unsigned, SourceLocation> > VisStack;
1213enum : unsigned { NoVisibility = ~0U };
1214
1216 if (!VisContext)
1217 return;
1218
1219 NamedDecl *ND = dyn_cast<NamedDecl>(D);
1221 return;
1222
1223 VisStack *Stack = static_cast<VisStack*>(VisContext);
1224 unsigned rawType = Stack->back().first;
1225 if (rawType == NoVisibility) return;
1226
1227 VisibilityAttr::VisibilityType type
1228 = (VisibilityAttr::VisibilityType) rawType;
1229 SourceLocation loc = Stack->back().second;
1230
1231 D->addAttr(VisibilityAttr::CreateImplicit(Context, type, loc));
1232}
1233
1234/// FreeVisContext - Deallocate and null out VisContext.
1236 delete static_cast<VisStack*>(VisContext);
1237 VisContext = nullptr;
1238}
1239
1240static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc) {
1241 // Put visibility on stack.
1242 if (!S.VisContext)
1243 S.VisContext = new VisStack;
1244
1245 VisStack *Stack = static_cast<VisStack*>(S.VisContext);
1246 Stack->push_back(std::make_pair(type, loc));
1247}
1248
1250 SourceLocation PragmaLoc) {
1251 if (VisType) {
1252 // Compute visibility to use.
1253 VisibilityAttr::VisibilityType T;
1254 if (!VisibilityAttr::ConvertStrToVisibilityType(VisType->getName(), T)) {
1255 Diag(PragmaLoc, diag::warn_attribute_unknown_visibility) << VisType;
1256 return;
1257 }
1258 PushPragmaVisibility(*this, T, PragmaLoc);
1259 } else {
1260 PopPragmaVisibility(false, PragmaLoc);
1261 }
1262}
1263
1266 FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1267 switch (FPC) {
1269 NewFPFeatures.setAllowFPContractWithinStatement();
1270 break;
1272 NewFPFeatures.setAllowFPContractAcrossStatement();
1273 break;
1275 NewFPFeatures.setDisallowFPContract();
1276 break;
1278 llvm_unreachable("Should not happen");
1279 }
1280 FpPragmaStack.Act(Loc, Sema::PSK_Set, StringRef(), NewFPFeatures);
1281 CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
1282}
1283
1285 PragmaFPKind Kind, bool IsEnabled) {
1286 if (IsEnabled) {
1287 // For value unsafe context, combining this pragma with eval method
1288 // setting is not recommended. See comment in function FixupInvocation#506.
1289 int Reason = -1;
1290 if (getLangOpts().getFPEvalMethod() != LangOptions::FEM_UnsetOnCommandLine)
1291 // Eval method set using the option 'ffp-eval-method'.
1292 Reason = 1;
1294 // Eval method set using the '#pragma clang fp eval_method'.
1295 // We could have both an option and a pragma used to the set the eval
1296 // method. The pragma overrides the option in the command line. The Reason
1297 // of the diagnostic is overriden too.
1298 Reason = 0;
1299 if (Reason != -1)
1300 Diag(Loc, diag::err_setting_eval_method_used_in_unsafe_context)
1301 << Reason << (Kind == PFK_Reassociate ? 4 : 5);
1302 }
1303
1304 FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1305 switch (Kind) {
1306 case PFK_Reassociate:
1307 NewFPFeatures.setAllowFPReassociateOverride(IsEnabled);
1308 break;
1309 case PFK_Reciprocal:
1310 NewFPFeatures.setAllowReciprocalOverride(IsEnabled);
1311 break;
1312 default:
1313 llvm_unreachable("unhandled value changing pragma fp");
1314 }
1315
1316 FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
1317 CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
1318}
1319
1320void Sema::ActOnPragmaFEnvRound(SourceLocation Loc, llvm::RoundingMode FPR) {
1321 FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1322 NewFPFeatures.setConstRoundingModeOverride(FPR);
1323 FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
1324 CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
1325}
1326
1329 FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1330 NewFPFeatures.setSpecifiedExceptionModeOverride(FPE);
1331 FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
1332 CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
1333}
1334
1336 FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1337 if (IsEnabled) {
1338 // Verify Microsoft restriction:
1339 // You can't enable fenv_access unless precise semantics are enabled.
1340 // Precise semantics can be enabled either by the float_control
1341 // pragma, or by using the /fp:precise or /fp:strict compiler options
1342 if (!isPreciseFPEnabled())
1343 Diag(Loc, diag::err_pragma_fenv_requires_precise);
1344 }
1345 NewFPFeatures.setAllowFEnvAccessOverride(IsEnabled);
1346 NewFPFeatures.setRoundingMathOverride(IsEnabled);
1347 FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
1348 CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
1349}
1350
1353 FPOptionsOverride NewFPFeatures = CurFPFeatureOverrides();
1354 NewFPFeatures.setComplexRangeOverride(Range);
1355 FpPragmaStack.Act(Loc, PSK_Set, StringRef(), NewFPFeatures);
1356 CurFPFeatures = NewFPFeatures.applyOverrides(getLangOpts());
1357}
1358
1361 setExceptionMode(Loc, FPE);
1362}
1363
1364void Sema::PushNamespaceVisibilityAttr(const VisibilityAttr *Attr,
1366 // Visibility calculations will consider the namespace's visibility.
1367 // Here we just want to note that we're in a visibility context
1368 // which overrides any enclosing #pragma context, but doesn't itself
1369 // contribute visibility.
1371}
1372
1373void Sema::PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc) {
1374 if (!VisContext) {
1375 Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
1376 return;
1377 }
1378
1379 // Pop visibility from stack
1380 VisStack *Stack = static_cast<VisStack*>(VisContext);
1381
1382 const std::pair<unsigned, SourceLocation> *Back = &Stack->back();
1383 bool StartsWithPragma = Back->first != NoVisibility;
1384 if (StartsWithPragma && IsNamespaceEnd) {
1385 Diag(Back->second, diag::err_pragma_push_visibility_mismatch);
1386 Diag(EndLoc, diag::note_surrounding_namespace_ends_here);
1387
1388 // For better error recovery, eat all pushes inside the namespace.
1389 do {
1390 Stack->pop_back();
1391 Back = &Stack->back();
1392 StartsWithPragma = Back->first != NoVisibility;
1393 } while (StartsWithPragma);
1394 } else if (!StartsWithPragma && !IsNamespaceEnd) {
1395 Diag(EndLoc, diag::err_pragma_pop_visibility_mismatch);
1396 Diag(Back->second, diag::note_surrounding_namespace_starts_here);
1397 return;
1398 }
1399
1400 Stack->pop_back();
1401 // To simplify the implementation, never keep around an empty stack.
1402 if (Stack->empty())
1404}
1405
1406template <typename Ty>
1407static bool checkCommonAttributeFeatures(Sema &S, const Ty *Node,
1408 const ParsedAttr &A,
1409 bool SkipArgCountCheck) {
1410 // Several attributes carry different semantics than the parsing requires, so
1411 // those are opted out of the common argument checks.
1412 //
1413 // We also bail on unknown and ignored attributes because those are handled
1414 // as part of the target-specific handling logic.
1416 return false;
1417 // Check whether the attribute requires specific language extensions to be
1418 // enabled.
1419 if (!A.diagnoseLangOpts(S))
1420 return true;
1421 // Check whether the attribute appertains to the given subject.
1422 if (!A.diagnoseAppertainsTo(S, Node))
1423 return true;
1424 // Check whether the attribute is mutually exclusive with other attributes
1425 // that have already been applied to the declaration.
1426 if (!A.diagnoseMutualExclusion(S, Node))
1427 return true;
1428 // Check whether the attribute exists in the target architecture.
1429 if (S.CheckAttrTarget(A))
1430 return true;
1431
1432 if (A.hasCustomParsing())
1433 return false;
1434
1435 if (!SkipArgCountCheck) {
1436 if (A.getMinArgs() == A.getMaxArgs()) {
1437 // If there are no optional arguments, then checking for the argument
1438 // count is trivial.
1439 if (!A.checkExactlyNumArgs(S, A.getMinArgs()))
1440 return true;
1441 } else {
1442 // There are optional arguments, so checking is slightly more involved.
1443 if (A.getMinArgs() && !A.checkAtLeastNumArgs(S, A.getMinArgs()))
1444 return true;
1445 else if (!A.hasVariadicArg() && A.getMaxArgs() &&
1446 !A.checkAtMostNumArgs(S, A.getMaxArgs()))
1447 return true;
1448 }
1449 }
1450
1451 return false;
1452}
1453
1455 bool SkipArgCountCheck) {
1456 return ::checkCommonAttributeFeatures(*this, D, A, SkipArgCountCheck);
1457}
1459 bool SkipArgCountCheck) {
1460 return ::checkCommonAttributeFeatures(*this, S, A, SkipArgCountCheck);
1461}
#define V(N, I)
Definition: ASTContext.h:3285
NodeId Parent
Definition: ASTDiff.cpp:191
DynTypedNode Node
llvm::MachO::Record Record
Definition: MachO.h:31
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:1212
static void PushPragmaVisibility(Sema &S, unsigned type, SourceLocation loc)
Definition: SemaAttr.cpp:1240
static void addGslOwnerPointerAttributeIfNotExisting(ASTContext &Context, CXXRecordDecl *Record)
Definition: SemaAttr.cpp:102
@ NoVisibility
Definition: SemaAttr.cpp:1213
SourceRange Range
Definition: SemaObjC.cpp:754
SourceLocation Loc
Definition: SemaObjC.cpp:755
bool hasValue() const
Definition: APValue.h:399
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:1073
llvm::StringMap< SectionInfo > SectionInfos
Definition: ASTContext.h:3401
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:757
PtrTy get() const
Definition: Ownership.h:170
Attr - This represents one attribute.
Definition: Attr.h:42
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
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:350
bool isFileContext() const
Definition: DeclBase.h:2137
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1938
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1716
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Decl()=delete
bool isInStdNamespace() const
Definition: DeclBase.cpp:403
T * getAttr() const
Definition: DeclBase.h:579
void addAttr(Attr *A)
Definition: DeclBase.cpp:991
SourceLocation getLocation() const
Definition: DeclBase.h:445
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:1039
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition: DeclBase.cpp:530
DeclContext * getDeclContext()
Definition: DeclBase.h:454
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:437
bool hasAttr() const
Definition: DeclBase.h:583
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:968
The name of a declaration.
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Decl.h:822
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1571
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1547
This represents one expression.
Definition: Expr.h:110
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:175
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:192
bool isLValue() const
isLValue - True if this expression is an "l-value" according to the rules of the current language.
Definition: Expr.h:277
bool EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx, ConstantExprKind Kind=ConstantExprKind::Normal) const
Evaluate an expression that is required to be a constant expression.
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc=nullptr) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
QualType getType() const
Definition: Expr.h:142
Represents difference between two FPOptions values.
Definition: LangOptions.h:915
void setAllowFPContractAcrossStatement()
Definition: LangOptions.h:947
void setFPPreciseEnabled(bool Value)
Definition: LangOptions.h:955
void setAllowFPContractWithinStatement()
Definition: LangOptions.h:943
FPOptions applyOverrides(FPOptions Base)
Definition: LangOptions.h:985
LangOptions::FPExceptionModeKind getExceptionMode() const
Definition: LangOptions.h:861
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:1971
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:2074
ComplexRangeKind
Controls the various implementations for complex multiplication and.
Definition: LangOptions.h:413
FPEvalMethodKind
Possible float expression evaluation method choices.
Definition: LangOptions.h:288
@ FEM_Extended
Use extended type for fp arithmetic.
Definition: LangOptions.h:297
@ FEM_Double
Use the type double for fp arithmetic.
Definition: LangOptions.h:295
@ 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:302
@ FEM_Source
Use the declared type for fp arithmetic.
Definition: LangOptions.h:293
FPExceptionModeKind
Possible floating point exception behavior.
Definition: LangOptions.h:276
@ FPE_Strict
Strictly preserve the floating-point exception semantics.
Definition: LangOptions.h:282
@ FPE_Ignore
Assume that floating-point exceptions are masked.
Definition: LangOptions.h:278
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:1358
Represents the results of name lookup.
Definition: Lookup.h:46
DeclClass * getAsSingle() const
Definition: Lookup.h:558
bool empty() const
Return true if no decls were found.
Definition: Lookup.h:362
This represents a decl that may have a name.
Definition: Decl.h:249
@ VisibilityForValue
Do an LV computation for, ultimately, a non-type declaration.
Definition: Decl.h:436
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
std::optional< Visibility > getExplicitVisibility(ExplicitVisibilityKind kind) const
If visibility was explicitly specified for this declaration, return that visibility.
Definition: Decl.cpp:1304
ParsedAttr - Represents a syntactic attribute.
Definition: ParsedAttr.h:129
bool hasCustomParsing() const
Definition: ParsedAttr.cpp:158
bool appliesToDecl(const Decl *D, attr::SubjectMatchRule MatchRule) const
Definition: ParsedAttr.cpp:174
unsigned getMinArgs() const
Definition: ParsedAttr.cpp:148
bool checkExactlyNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has exactly as many args as Num.
Definition: ParsedAttr.cpp:298
bool hasVariadicArg() const
Definition: ParsedAttr.cpp:266
bool diagnoseMutualExclusion(class Sema &S, const Decl *D) const
Definition: ParsedAttr.cpp:170
bool diagnoseAppertainsTo(class Sema &S, const Decl *D) const
Definition: ParsedAttr.cpp:162
bool checkAtLeastNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has at least as many args as Num.
Definition: ParsedAttr.cpp:303
unsigned getMaxArgs() const
Definition: ParsedAttr.cpp:150
bool isPragmaClangAttribute() const
True if the attribute is specified using '#pragma clang attribute'.
Definition: ParsedAttr.h:378
AttributeCommonInfo::Kind getKind() const
Definition: ParsedAttr.h:627
void getMatchRules(const LangOptions &LangOpts, SmallVectorImpl< std::pair< attr::SubjectMatchRule, bool > > &MatchRules) const
Definition: ParsedAttr.cpp:179
bool diagnoseLangOpts(class Sema &S) const
Definition: ParsedAttr.cpp:186
void setIsPragmaClangAttribute()
Definition: ParsedAttr.h:380
bool checkAtMostNumArgs(class Sema &S, unsigned Num) const
Check if the attribute has at most as many args as Num.
Definition: ParsedAttr.cpp:308
void addAtEnd(ParsedAttr *newAttr)
Definition: ParsedAttr.h:848
static PragmaCommentDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation CommentLoc, PragmaMSCommentKind CommentKind, StringRef Arg)
Definition: Decl.cpp:5285
static PragmaDetectMismatchDecl * Create(const ASTContext &C, TranslationUnitDecl *DC, SourceLocation Loc, StringRef Name, StringRef Value)
Definition: Decl.cpp:5308
SourceLocation getLastFPEvalPragmaLocation() const
void setCurrentFPEvalMethod(SourceLocation PragmaLoc, LangOptions::FPEvalMethodKind Val)
A (possibly-)qualified type.
Definition: Type.h:940
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7359
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:7560
QualType getCanonicalType() const
Definition: Type.h:7411
Represents a struct/union/class.
Definition: Decl.h:4168
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: Redeclarable.h:296
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:41
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: SemaBase.cpp:56
unsigned getPackNumber() const
Definition: Sema.h:1268
bool IsPackSet() const
Definition: Sema.h:1270
bool IsAlignAttr() const
Definition: Sema.h:1264
Mode getAlignMode() const
Definition: Sema.h:1266
PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct)
Definition: SemaAttr.cpp:28
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:451
void ActOnPragmaMSOptimize(SourceLocation Loc, bool IsOn)
#pragma optimize("[optimization-list]", on | off).
Definition: SemaAttr.cpp:1142
bool ConstantFoldAttrArgs(const AttributeCommonInfo &CI, MutableArrayRef< Expr * > Args)
ConstantFoldAttrArgs - Folds attribute arguments into ConstantExprs (unless they are value dependent ...
Definition: SemaAttr.cpp:400
void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
Definition: SemaAttr.cpp:1051
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition: Sema.h:7289
void ActOnPragmaAttributePop(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
Called on well-formed '#pragma clang attribute pop'.
Definition: SemaAttr.cpp:1058
void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value)
ActOnPragmaDetectMismatch - Call on well-formed #pragma detect_mismatch.
Definition: SemaAttr.cpp:526
const Decl * PragmaAttributeCurrentTargetDecl
The declaration that is currently receiving an attribute from the #pragma attribute stack.
Definition: Sema.h:1483
void ActOnPragmaFEnvRound(SourceLocation Loc, llvm::RoundingMode)
Called to set constant rounding mode for floating point operations.
Definition: SemaAttr.cpp:1320
PragmaClangSection PragmaClangRodataSection
Definition: Sema.h:1190
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:1093
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:1454
PragmaClangSectionAction
Definition: Sema.h:1180
@ PCSA_Clear
Definition: Sema.h:1180
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:1191
PragmaStack< FPOptionsOverride > FpPragmaStack
Definition: Sema.h:1421
PragmaStack< StringLiteral * > CodeSegStack
Definition: Sema.h:1415
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:1161
void ActOnPragmaMSComment(SourceLocation CommentLoc, PragmaMSCommentKind Kind, StringRef Arg)
ActOnPragmaMSComment - Called on well formed #pragma comment(kind, "arg").
Definition: SemaAttr.cpp:518
SmallVector< AlignPackIncludeState, 8 > AlignPackIncludeStack
Definition: Sema.h:1410
void AddAlignmentAttributesForRecord(RecordDecl *RD)
AddAlignmentAttributesForRecord - Adds any needed alignment attributes to a the record decl,...
Definition: SemaAttr.cpp:53
FPOptionsOverride CurFPFeatureOverrides()
Definition: Sema.h:1422
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:747
NamedDecl * LookupSingleName(Scope *S, DeclarationName Name, SourceLocation Loc, LookupNameKind NameKind, RedeclarationKind Redecl=RedeclarationKind::NotForRedeclaration)
Look up a name, looking for a single declaration.
void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action, PragmaFloatControlKind Value)
ActOnPragmaFloatControl - Call on well-formed #pragma float_control.
Definition: SemaAttr.cpp:561
void ActOnPragmaMSPointersToMembers(LangOptions::PragmaMSPointersToMembersKind Kind, SourceLocation PragmaLoc)
ActOnPragmaMSPointersToMembers - called on well formed #pragma pointers_to_members(representation met...
Definition: SemaAttr.cpp:615
ASTContext & Context
Definition: Sema.h:848
void ActOnPragmaUnused(const Token &Identifier, Scope *curScope, SourceLocation PragmaLoc)
ActOnPragmaUnused - Called on well-formed '#pragma unused'.
Definition: SemaAttr.cpp:835
void ActOnPragmaMSAllocText(SourceLocation PragmaLocation, StringRef Section, const SmallVector< std::tuple< IdentifierInfo *, SourceLocation > > &Functions)
Called on well-formed #pragma alloc_text().
Definition: SemaAttr.cpp:799
PragmaStack< bool > StrictGuardStackCheckStack
Definition: Sema.h:1418
void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, SourceLocation PragmaLoc, attr::ParsedSubjectMatchRuleSet Rules)
Definition: SemaAttr.cpp:918
PragmaStack< StringLiteral * > ConstSegStack
Definition: Sema.h:1414
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_PRValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CheckedConversionKind::Implicit)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
Definition: Sema.cpp:645
void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, SourceLocation PragmaLoc)
ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
Definition: SemaAttr.cpp:230
void ActOnPragmaCXLimitedRange(SourceLocation Loc, LangOptions::ComplexRangeKind Range)
ActOnPragmaCXLimitedRange - Called on well formed #pragma STDC CX_LIMITED_RANGE.
Definition: SemaAttr.cpp:1351
void ActOnPragmaFPExceptions(SourceLocation Loc, LangOptions::FPExceptionModeKind)
Called on well formed '#pragma clang fp' that has option 'exceptions'.
Definition: SemaAttr.cpp:1359
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:534
void ActOnPragmaClangSection(SourceLocation PragmaLoc, PragmaClangSectionAction Action, PragmaClangSectionKind SecKind, StringRef SecName)
ActOnPragmaClangSection - Called on well formed #pragma clang section.
Definition: SemaAttr.cpp:285
bool UnifySection(StringRef SectionName, int SectionFlags, NamedDecl *TheDecl)
Definition: SemaAttr.cpp:693
void setExceptionMode(SourceLocation Loc, LangOptions::FPExceptionModeKind)
Called to set exception behavior for floating point operations.
Definition: SemaAttr.cpp:1327
void PrintPragmaAttributeInstantiationPoint()
Definition: SemaAttr.cpp:1123
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:510
SourceLocation CurInitSegLoc
Definition: Sema.h:1454
void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, SourceLocation PragmaLoc, MSVtorDispMode Value)
Called on well formed #pragma vtordisp().
Definition: SemaAttr.cpp:622
Preprocessor & PP
Definition: Sema.h:847
bool MSPragmaOptimizeIsOn
The "on" or "off" argument passed by #pragma optimize, that denotes whether the optimizations in the ...
Definition: Sema.h:1501
SmallVector< PragmaAttributeGroup, 2 > PragmaAttributeStack
Definition: Sema.h:1479
const LangOptions & LangOpts
Definition: Sema.h:846
PragmaClangSection PragmaClangRelroSection
Definition: Sema.h:1191
SourceLocation ImplicitMSInheritanceAttrLoc
Source location for newly created implicit MSInheritanceAttrs.
Definition: Sema.h:1168
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:1205
PragmaStack< AlignPackInfo > AlignPackStack
Definition: Sema.h:1403
PragmaStack< StringLiteral * > BSSSegStack
Definition: Sema.h:1413
llvm::StringMap< std::tuple< StringRef, SourceLocation > > FunctionToSectionMap
Sections used with #pragma alloc_text.
Definition: Sema.h:1457
llvm::SmallSetVector< StringRef, 4 > MSFunctionNoBuiltins
Set of no-builtin functions listed by #pragma function.
Definition: Sema.h:1504
void AddPushedVisibilityAttribute(Decl *RD)
AddPushedVisibilityAttribute - If '#pragma GCC visibility' was used, add an appropriate visibility at...
Definition: SemaAttr.cpp:1215
StringLiteral * CurInitSeg
Last section used with #pragma init_seg.
Definition: Sema.h:1453
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:986
void ActOnPragmaMSFunction(SourceLocation Loc, const llvm::SmallVectorImpl< StringRef > &NoBuiltins)
Call on well formed #pragma function.
Definition: SemaAttr.cpp:1151
void ActOnPragmaMSStruct(PragmaMSStructKind Kind)
ActOnPragmaMSStruct - Called on well formed #pragma ms_struct [on|off].
Definition: SemaAttr.cpp:514
bool isPreciseFPEnabled()
Are precise floating point semantics currently enabled?
Definition: Sema.h:1579
void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, StringLiteral *SegmentName)
Called on well-formed #pragma init_seg().
Definition: SemaAttr.cpp:790
bool MSStructPragmaOn
Definition: Sema.h:1165
SourceManager & getSourceManager() const
Definition: Sema.h:515
void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind, SourceLocation IncludeLoc)
Definition: SemaAttr.cpp:448
PragmaClangSection PragmaClangTextSection
Definition: Sema.h:1192
void ActOnPragmaFPValueChangingOption(SourceLocation Loc, PragmaFPKind Kind, bool IsEnabled)
Called on well formed #pragma clang fp reassociate or #pragma clang fp reciprocal.
Definition: SemaAttr.cpp:1284
PragmaClangSection PragmaClangDataSection
Definition: Sema.h:1189
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:1364
PragmaStack< MSVtorDispMode > VtorDispStack
Whether to insert vtordisps prior to virtual bases in the Microsoft C++ ABI.
Definition: Sema.h:1402
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:1460
bool CheckAttrTarget(const ParsedAttr &CurrAttr)
ASTConsumer & Consumer
Definition: Sema.h:849
PragmaAlignPackDiagnoseKind
Definition: Sema.h:1557
Scope * TUScope
Translation Unit Scope - useful to Objective-C actions that need to lookup file scope declarations in...
Definition: Sema.h:820
void DiagnoseUnterminatedPragmaAttribute()
Definition: SemaAttr.cpp:1129
void FreeVisContext()
FreeVisContext - Deallocate and null out VisContext.
Definition: SemaAttr.cpp:1235
void ModifyFnAttributesMSPragmaOptimize(FunctionDecl *FD)
Only called on function definitions; if there is a MSVC #pragma optimize in scope,...
Definition: SemaAttr.cpp:1184
void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc)
PopPragmaVisibility - Pop the top element of the visibility stack; used for '#pragma GCC visibility' ...
Definition: SemaAttr.cpp:1373
SourceManager & SourceMgr
Definition: Sema.h:851
void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, StringRef SlotLabel, Expr *Alignment)
ActOnPragmaPack - Called on well formed #pragma pack(...).
Definition: SemaAttr.cpp:334
DiagnosticsEngine & Diags
Definition: Sema.h:850
void DiagnoseUnterminatedPragmaAlignPack()
Definition: SemaAttr.cpp:487
FPOptions CurFPFeatures
Definition: Sema.h:844
PragmaStack< StringLiteral * > DataSegStack
Definition: Sema.h:1412
void ActOnPragmaVisibility(const IdentifierInfo *VisType, SourceLocation PragmaLoc)
ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
Definition: SemaAttr.cpp:1249
SourceLocation OptimizeOffPragmaLocation
This represents the last location of a "#pragma clang optimize off" directive if such a directive has...
Definition: Sema.h:1488
LangOptions::PragmaMSPointersToMembersKind MSPointerToMemberRepresentationMethod
Controls member pointer representation format under the MS ABI.
Definition: Sema.h:1163
void ActOnPragmaMSStrictGuardStackCheck(SourceLocation PragmaLocation, PragmaMsStackAction Action, bool Value)
ActOnPragmaMSStrictGuardStackCheck - Called on well formed #pragma strict_gs_check.
Definition: SemaAttr.cpp:774
PragmaClangSection PragmaClangBSSSection
Definition: Sema.h:1188
PragmaOptionsAlignKind
Definition: Sema.h:1527
@ POAK_Power
Definition: Sema.h:1531
@ POAK_Reset
Definition: Sema.h:1533
@ POAK_Packed
Definition: Sema.h:1530
@ POAK_Mac68k
Definition: Sema.h:1532
@ POAK_Natural
Definition: Sema.h:1529
@ POAK_Native
Definition: Sema.h:1528
void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC)
ActOnPragmaFPContract - Called on well formed #pragma {STDC,OPENCL} FP_CONTRACT and #pragma clang fp ...
Definition: SemaAttr.cpp:1264
void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc)
Called on well formed #pragma clang optimize.
Definition: SemaAttr.cpp:1135
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false, bool ForceNoCPlusPlus=false)
Perform unqualified name lookup starting from a given scope.
void ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled)
ActOnPragmaFenvAccess - Called on well formed #pragma STDC FENV_ACCESS.
Definition: SemaAttr.cpp:1335
void AddSectionMSAllocText(FunctionDecl *FD)
Only called on function definitions; if there is a #pragma alloc_text that decides which code section...
Definition: SemaAttr.cpp:1168
void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags, StringLiteral *SegmentName)
Called on well formed #pragma section().
Definition: SemaAttr.cpp:785
PragmaClangSectionKind
pragma clang section kind
Definition: Sema.h:1171
@ PCSK_BSS
Definition: Sema.h:1173
@ PCSK_Data
Definition: Sema.h:1174
@ PCSK_Text
Definition: Sema.h:1176
@ PCSK_Relro
Definition: Sema.h:1177
@ PCSK_Rodata
Definition: Sema.h:1175
void inferNullableClassAttribute(CXXRecordDecl *CRD)
Add _Nullable attributes for std:: types.
Definition: SemaAttr.cpp:218
PragmaMsStackAction
Definition: Sema.h:1194
@ PSK_Push_Set
Definition: Sema.h:1200
@ PSK_Reset
Definition: Sema.h:1195
@ PSK_Show
Definition: Sema.h:1199
@ PSK_Pop
Definition: Sema.h:1198
@ PSK_Set
Definition: Sema.h:1196
@ PSK_Push
Definition: Sema.h:1197
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.
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
Definition: Stmt.h:84
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:338
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1773
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:1954
StringRef getString() const
Definition: Expr.h:1850
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:956
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:1327
Token - This structure provides full information about a lexed token.
Definition: Token.h:36
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:187
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:132
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1871
bool isArrayType() const
Definition: Type.h:7678
bool isFunctionType() const
Definition: Type.h:7608
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3432
QualType getUnderlyingType() const
Definition: Decl.h:3487
Represents a variable declaration or definition.
Definition: Decl.h:918
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:69
The JSON file list parser is used to communicate input to InstallAPI.
PragmaFPKind
Definition: PragmaKinds.h:38
@ PFK_Reassociate
Definition: PragmaKinds.h:40
@ PFK_Reciprocal
Definition: PragmaKinds.h:41
@ CPlusPlus
Definition: LangStandard.h:55
PragmaMSCommentKind
Definition: PragmaKinds.h:14
@ Nullable
Values of this type can be null.
@ AANT_ArgumentConstantExpr
Definition: ParsedAttr.h:1084
@ 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:35
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:132
const FunctionProtoType * T
EvalResult is a struct with detailed info about an evaluated expression.
Definition: Expr.h:642
APValue Val
Val - This is the value the expression can be folded to.
Definition: Expr.h:644
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:630
SourceLocation CurrentPragmaLocation
Definition: Sema.h:1407
This an attribute introduced by #pragma clang attribute.
Definition: Sema.h:1463
SourceLocation PragmaLocation
Definition: Sema.h:1185
ValueType CurrentValue
Definition: Sema.h:1388
void SentinelAction(PragmaMsStackAction Action, StringRef Label)
Definition: Sema.h:1374
SmallVector< Slot, 2 > Stack
Definition: Sema.h:1386
void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, llvm::StringRef StackSlotLabel, ValueType Value)
Definition: Sema.h:1325