24#include "llvm/ADT/BitVector.h"
39class JumpScopeChecker {
44 const bool Permissive;
67 GotoScope(
unsigned parentScope,
unsigned InDiag,
unsigned OutDiag,
69 : ParentScope(parentScope), InDiag(InDiag), OutDiag(OutDiag), Loc(L) {}
72 SmallVector<GotoScope, 48> Scopes;
73 llvm::DenseMap<Stmt*, unsigned> LabelAndGotoScopes;
74 SmallVector<Stmt*, 16> Jumps;
76 SmallVector<Stmt*, 4> IndirectJumps;
77 SmallVector<LabelDecl *, 4> IndirectJumpTargets;
78 SmallVector<AttributedStmt *, 4> MustTailStmts;
81 JumpScopeChecker(Stmt *Body, Sema &S);
83 void BuildScopeInformation(Decl *D,
unsigned &ParentScope);
84 void BuildScopeInformation(VarDecl *D,
const BlockDecl *BDecl,
85 unsigned &ParentScope);
86 void BuildScopeInformation(CompoundLiteralExpr *CLE,
unsigned &ParentScope);
87 void BuildScopeInformation(Stmt *S,
unsigned &origParentScope);
90 void VerifyIndirectJumps();
91 void VerifyMustTailStmts();
92 void NoteJumpIntoScopes(ArrayRef<unsigned> ToScopes);
93 void DiagnoseIndirectOrAsmJump(Stmt *IG,
unsigned IGScope, LabelDecl *
Target,
94 unsigned TargetScope);
95 void CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc,
96 unsigned JumpDiag,
unsigned JumpDiagWarning,
97 unsigned JumpDiagCompat);
98 void CheckGotoStmt(GotoStmt *GS);
99 const Attr *GetMustTailAttr(AttributedStmt *AS);
101 unsigned GetDeepestCommonScope(
unsigned A,
unsigned B);
105#define CHECK_PERMISSIVE(x) (assert(Permissive || !(x)), (Permissive && (x)))
107JumpScopeChecker::JumpScopeChecker(
Stmt *Body,
Sema &s)
108 : S(s), Permissive(s.hasAnyUnrecoverableErrorsInThisFunction()) {
114 unsigned BodyParentScope = 0;
115 BuildScopeInformation(Body, BodyParentScope);
119 VerifyIndirectJumps();
120 VerifyMustTailStmts();
125unsigned JumpScopeChecker::GetDeepestCommonScope(
unsigned A,
unsigned B) {
130 assert(Scopes[B].ParentScope < B);
131 B = Scopes[B].ParentScope;
133 assert(Scopes[A].ParentScope < A);
134 A = Scopes[A].ParentScope;
145 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
147 unsigned OutDiag = 0;
149 if (VD->getType()->isVariablyModifiedType())
150 InDiag = diag::note_protected_by_vla;
152 if (VD->hasAttr<BlocksAttr>())
153 return ScopePair(diag::note_protected_by___block,
154 diag::note_exits___block);
156 if (VD->hasAttr<CleanupAttr>())
157 return ScopePair(diag::note_protected_by_cleanup,
158 diag::note_exits_cleanup);
160 if (VD->hasLocalStorage()) {
161 switch (VD->getType().isDestructedType()) {
163 return ScopePair(diag::note_protected_by_objc_strong_init,
164 diag::note_exits_objc_strong);
167 return ScopePair(diag::note_protected_by_objc_weak_init,
168 diag::note_exits_objc_weak);
171 return ScopePair(diag::note_protected_by_non_trivial_c_struct_init,
172 diag::note_exits_dtor);
175 OutDiag = diag::note_exits_dtor;
185 if (
const Expr *
Init = VD->getInit();
186 !InDiag && VD->hasLocalStorage() &&
Init && !
Init->containsErrors()) {
201 InDiag = diag::note_protected_by_variable_init;
211 InDiag = diag::note_protected_by_variable_nontriv_destructor;
213 InDiag = diag::note_protected_by_variable_non_pod;
224 if (TD->getUnderlyingType()->isVariablyModifiedType())
226 ? diag::note_protected_by_vla_typedef
227 : diag::note_protected_by_vla_type_alias,
235void JumpScopeChecker::BuildScopeInformation(Decl *D,
unsigned &ParentScope) {
238 if (Diags.first || Diags.second) {
239 Scopes.push_back(GotoScope(ParentScope, Diags.first, Diags.second,
241 ParentScope = Scopes.size()-1;
246 if (VarDecl *VD = dyn_cast<VarDecl>(D))
247 if (Expr *
Init = VD->getInit())
248 BuildScopeInformation(
Init, ParentScope);
252void JumpScopeChecker::BuildScopeInformation(VarDecl *D,
253 const BlockDecl *BDecl,
254 unsigned &ParentScope) {
262 std::pair<unsigned,unsigned> Diags;
263 switch (destructKind) {
265 Diags =
ScopePair(diag::note_enters_block_captures_cxx_obj,
266 diag::note_exits_block_captures_cxx_obj);
269 Diags =
ScopePair(diag::note_enters_block_captures_strong,
270 diag::note_exits_block_captures_strong);
273 Diags =
ScopePair(diag::note_enters_block_captures_weak,
274 diag::note_exits_block_captures_weak);
277 Diags =
ScopePair(diag::note_enters_block_captures_non_trivial_c_struct,
278 diag::note_exits_block_captures_non_trivial_c_struct);
281 llvm_unreachable(
"non-lifetime captured variable");
286 Scopes.push_back(GotoScope(ParentScope,
287 Diags.first, Diags.second, Loc));
288 ParentScope = Scopes.size()-1;
294void JumpScopeChecker::BuildScopeInformation(CompoundLiteralExpr *CLE,
295 unsigned &ParentScope) {
298 unsigned InDiag = diag::note_enters_compound_literal_scope;
299 unsigned OutDiag = diag::note_exits_compound_literal_scope;
300 Scopes.push_back(GotoScope(ParentScope, InDiag, OutDiag, CLE->
getExprLoc()));
301 ParentScope = Scopes.size() - 1;
308void JumpScopeChecker::BuildScopeInformation(Stmt *S,
309 unsigned &origParentScope) {
313 unsigned independentParentScope = origParentScope;
315 ? origParentScope : independentParentScope);
317 unsigned StmtsToSkip = 0u;
321 case Stmt::AddrLabelExprClass:
325 case Stmt::ObjCForCollectionStmtClass: {
327 unsigned Diag = diag::note_protected_by_objc_fast_enumeration;
328 unsigned NewParentScope = Scopes.size();
330 BuildScopeInformation(CS->getBody(), NewParentScope);
334 case Stmt::IndirectGotoStmtClass:
341 goto RecordJumpScope;
343 LabelAndGotoScopes[S] = ParentScope;
344 IndirectJumps.push_back(S);
347 case Stmt::SwitchStmtClass:
351 BuildScopeInformation(
Init, ParentScope);
355 BuildScopeInformation(Var, ParentScope);
358 goto RecordJumpScope;
360 case Stmt::GCCAsmStmtClass:
365 case Stmt::GotoStmtClass:
369 LabelAndGotoScopes[S] = ParentScope;
373 case Stmt::IfStmtClass: {
375 bool AMDGPUPredicate =
false;
378 (AMDGPUPredicate = this->S.AMDGPU().IsPredicate(IS->
getCond()))))
381 unsigned Diag = diag::note_protected_by_if_available;
383 Diag = diag::note_protected_by_constexpr_if;
385 Diag = diag::note_protected_by_consteval_if;
386 else if (AMDGPUPredicate)
387 Diag = diag::note_amdgcn_protected_by_predicate;
390 BuildScopeInformation(Var, ParentScope);
393 unsigned NewParentScope = Scopes.size();
397 BuildScopeInformation(IS->
getCond(), NewParentScope);
400 NewParentScope = Scopes.size();
402 BuildScopeInformation(IS->
getThen(), NewParentScope);
403 if (Stmt *Else = IS->
getElse()) {
404 NewParentScope = Scopes.size();
406 BuildScopeInformation(Else, NewParentScope);
411 case Stmt::CXXTryStmtClass: {
414 unsigned NewParentScope = Scopes.size();
415 Scopes.push_back(GotoScope(ParentScope,
416 diag::note_protected_by_cxx_try,
417 diag::note_exits_cxx_try,
420 BuildScopeInformation(TryBlock, NewParentScope);
426 unsigned NewParentScope = Scopes.size();
427 Scopes.push_back(GotoScope(ParentScope,
428 diag::note_protected_by_cxx_catch,
429 diag::note_exits_cxx_catch,
436 case Stmt::SEHTryStmtClass: {
439 unsigned NewParentScope = Scopes.size();
440 Scopes.push_back(GotoScope(ParentScope,
441 diag::note_protected_by_seh_try,
442 diag::note_exits_seh_try,
445 BuildScopeInformation(TryBlock, NewParentScope);
450 unsigned NewParentScope = Scopes.size();
451 Scopes.push_back(GotoScope(ParentScope,
452 diag::note_protected_by_seh_except,
453 diag::note_exits_seh_except,
454 Except->getSourceRange().getBegin()));
455 BuildScopeInformation(Except->getBlock(), NewParentScope);
457 unsigned NewParentScope = Scopes.size();
458 Scopes.push_back(GotoScope(ParentScope,
459 diag::note_protected_by_seh_finally,
460 diag::note_exits_seh_finally,
461 Finally->getSourceRange().getBegin()));
462 BuildScopeInformation(Finally->getBlock(), NewParentScope);
468 case Stmt::DeclStmtClass: {
474 for (
auto *I : DS->
decls())
475 BuildScopeInformation(I, origParentScope);
479 case Stmt::StmtExprClass: {
486 unsigned NewParentScope = Scopes.size();
487 Scopes.push_back(GotoScope(ParentScope,
488 diag::note_enters_statement_expression,
490 BuildScopeInformation(SE->
getSubStmt(), NewParentScope);
494 case Stmt::ObjCAtTryStmtClass: {
500 unsigned NewParentScope = Scopes.size();
501 Scopes.push_back(GotoScope(ParentScope,
502 diag::note_protected_by_objc_try,
503 diag::note_exits_objc_try,
506 BuildScopeInformation(TryPart, NewParentScope);
511 unsigned NewParentScope = Scopes.size();
512 Scopes.push_back(GotoScope(ParentScope,
513 diag::note_protected_by_objc_catch,
514 diag::note_exits_objc_catch,
515 AC->getAtCatchLoc()));
517 BuildScopeInformation(AC->getCatchBody(), NewParentScope);
522 unsigned NewParentScope = Scopes.size();
523 Scopes.push_back(GotoScope(ParentScope,
524 diag::note_protected_by_objc_finally,
525 diag::note_exits_objc_finally,
526 AF->getAtFinallyLoc()));
527 BuildScopeInformation(AF, NewParentScope);
533 case Stmt::ObjCAtSynchronizedStmtClass: {
543 unsigned NewParentScope = Scopes.size();
544 Scopes.push_back(GotoScope(ParentScope,
545 diag::note_protected_by_objc_synchronized,
546 diag::note_exits_objc_synchronized,
548 BuildScopeInformation(AS->
getSynchBody(), NewParentScope);
552 case Stmt::ObjCAutoreleasePoolStmtClass: {
557 unsigned NewParentScope = Scopes.size();
558 Scopes.push_back(GotoScope(ParentScope,
559 diag::note_protected_by_objc_autoreleasepool,
560 diag::note_exits_objc_autoreleasepool,
562 BuildScopeInformation(AS->
getSubStmt(), NewParentScope);
566 case Stmt::ExprWithCleanupsClass: {
571 for (
unsigned i = 0, e = EWC->
getNumObjects(); i != e; ++i) {
572 if (
auto *BDecl = dyn_cast<BlockDecl *>(EWC->
getObject(i)))
573 for (
const auto &CI : BDecl->
captures()) {
574 VarDecl *variable = CI.getVariable();
575 BuildScopeInformation(variable, BDecl, origParentScope);
577 else if (
auto *CLE = dyn_cast<CompoundLiteralExpr *>(EWC->
getObject(i)))
578 BuildScopeInformation(CLE, origParentScope);
580 llvm_unreachable(
"unexpected cleanup object type");
585 case Stmt::MaterializeTemporaryExprClass: {
590 const Expr *ExtendedObject =
593 Scopes.push_back(GotoScope(ParentScope, 0,
594 diag::note_exits_temporary_dtor,
596 origParentScope = Scopes.size()-1;
602 case Stmt::DeferStmtClass: {
607 unsigned NewParentScope = Scopes.size();
608 Scopes.emplace_back(ParentScope, diag::note_protected_by_defer_stmt, 0,
610 origParentScope = NewParentScope;
615 unsigned NewParentScope = Scopes.size();
616 Scopes.emplace_back(ParentScope, diag::note_enters_defer_stmt,
617 diag::note_exits_defer_stmt, D->getDeferLoc());
618 BuildScopeInformation(D->
getBody(), NewParentScope);
623 case Stmt::CaseStmtClass:
624 case Stmt::DefaultStmtClass:
625 case Stmt::LabelStmtClass:
626 LabelAndGotoScopes[S] = ParentScope;
629 case Stmt::OpenACCComputeConstructClass: {
630 unsigned NewParentScope = Scopes.size();
632 Scopes.push_back(GotoScope(
633 ParentScope, diag::note_acc_branch_into_compute_construct,
634 diag::note_acc_branch_out_of_compute_construct, CC->getBeginLoc()));
637 if (CC->getStructuredBlock())
638 BuildScopeInformation(CC->getStructuredBlock(), NewParentScope);
642 case Stmt::OpenACCCombinedConstructClass: {
643 unsigned NewParentScope = Scopes.size();
645 Scopes.push_back(GotoScope(
646 ParentScope, diag::note_acc_branch_into_compute_construct,
647 diag::note_acc_branch_out_of_compute_construct, CC->getBeginLoc()));
651 BuildScopeInformation(CC->
getLoop(), NewParentScope);
656 if (
auto *ED = dyn_cast<OMPExecutableDirective>(S)) {
657 if (!ED->isStandaloneDirective()) {
658 unsigned NewParentScope = Scopes.size();
659 Scopes.emplace_back(ParentScope,
660 diag::note_omp_protected_structured_block,
661 diag::note_omp_exits_structured_block,
662 ED->getStructuredBlock()->getBeginLoc());
663 BuildScopeInformation(ED->getStructuredBlock(), NewParentScope);
670 for (Stmt *SubStmt : S->
children()) {
683 if (SwitchCase *SC = dyn_cast<SwitchCase>(SubStmt))
684 Next = SC->getSubStmt();
685 else if (LabelStmt *LS = dyn_cast<LabelStmt>(SubStmt))
686 Next = LS->getSubStmt();
687 else if (AttributedStmt *AS = dyn_cast<AttributedStmt>(SubStmt)) {
688 if (GetMustTailAttr(AS)) {
689 LabelAndGotoScopes[AS] = ParentScope;
690 MustTailStmts.push_back(AS);
696 LabelAndGotoScopes[SubStmt] = ParentScope;
701 BuildScopeInformation(SubStmt, ParentScope);
707void JumpScopeChecker::VerifyJumps() {
708 while (!Jumps.empty()) {
709 Stmt *Jump = Jumps.pop_back_val();
712 if (GotoStmt *GS = dyn_cast<GotoStmt>(Jump)) {
714 if (GS->getLabel()->getStmt()) {
715 CheckJump(GS, GS->getLabel()->getStmt(), GS->getGotoLoc(),
716 diag::err_goto_into_protected_scope,
717 diag::ext_goto_into_protected_scope,
718 S.getLangOpts().CPlusPlus
719 ? diag::warn_cxx98_compat_goto_into_protected_scope
720 : diag::warn_cpp_compat_goto_into_protected_scope);
731 if (
auto *G = dyn_cast<GCCAsmStmt>(Jump)) {
732 for (AddrLabelExpr *L : G->labels()) {
733 LabelDecl *LD = L->getLabel();
734 unsigned JumpScope = LabelAndGotoScopes[G];
735 unsigned TargetScope = LabelAndGotoScopes[LD->
getStmt()];
736 if (JumpScope != TargetScope)
737 DiagnoseIndirectOrAsmJump(G, JumpScope, LD, TargetScope);
743 if (IndirectGotoStmt *IGS = dyn_cast<IndirectGotoStmt>(Jump)) {
744 LabelDecl *
Target = IGS->getConstantTarget();
745 CheckJump(IGS,
Target->getStmt(), IGS->getGotoLoc(),
746 diag::err_goto_into_protected_scope,
747 diag::ext_goto_into_protected_scope,
748 S.getLangOpts().CPlusPlus
749 ? diag::warn_cxx98_compat_goto_into_protected_scope
750 : diag::warn_cpp_compat_goto_into_protected_scope);
760 if (CaseStmt *CS = dyn_cast<CaseStmt>(SC))
762 else if (DefaultStmt *DS = dyn_cast<DefaultStmt>(SC))
765 Loc = SC->getBeginLoc();
766 CheckJump(SS, SC, Loc, diag::err_switch_into_protected_scope, 0,
767 S.getLangOpts().CPlusPlus
768 ? diag::warn_cxx98_compat_switch_into_protected_scope
769 : diag::warn_cpp_compat_switch_into_protected_scope);
791void JumpScopeChecker::VerifyIndirectJumps() {
792 if (IndirectJumps.empty())
796 if (IndirectJumpTargets.empty()) {
797 S.Diag(IndirectJumps[0]->getBeginLoc(),
798 diag::err_indirect_goto_without_addrlabel);
804 using JumpScope = std::pair<unsigned, Stmt *>;
805 SmallVector<JumpScope, 32> JumpScopes;
807 llvm::DenseMap<unsigned, Stmt*> JumpScopesMap;
808 for (Stmt *IG : IndirectJumps) {
811 unsigned IGScope = LabelAndGotoScopes[IG];
812 JumpScopesMap.try_emplace(IGScope, IG);
814 JumpScopes.reserve(JumpScopesMap.size());
815 for (
auto &Pair : JumpScopesMap)
816 JumpScopes.emplace_back(Pair);
822 llvm::DenseMap<unsigned, LabelDecl*> TargetScopes;
823 for (LabelDecl *TheLabel : IndirectJumpTargets) {
826 unsigned LabelScope = LabelAndGotoScopes[TheLabel->getStmt()];
827 TargetScopes.try_emplace(LabelScope, TheLabel);
838 llvm::BitVector Reachable(Scopes.size(),
false);
839 for (
auto [TargetScope, TargetLabel] : TargetScopes) {
845 unsigned Min = TargetScope;
853 if (Scopes[
Min].InDiag)
break;
855 Min = Scopes[
Min].ParentScope;
860 for (
auto [JumpScope, JumpStmt] : JumpScopes) {
861 unsigned Scope = JumpScope;
867 bool IsReachable =
false;
869 if (Reachable.test(Scope)) {
872 for (
unsigned S = JumpScope; S != Scope; S = Scopes[S].ParentScope)
880 if (Scope == 0 || Scope <
Min)
break;
883 if (Scopes[Scope].OutDiag)
break;
885 Scope = Scopes[Scope].ParentScope;
889 if (IsReachable)
continue;
891 DiagnoseIndirectOrAsmJump(JumpStmt, JumpScope, TargetLabel, TargetScope);
899 return (JumpDiag == diag::err_goto_into_protected_scope &&
900 (InDiagNote == diag::note_protected_by_variable_init ||
901 InDiagNote == diag::note_protected_by_variable_nontriv_destructor));
908 InDiagNote == diag::note_protected_by_variable_non_pod;
915 InDiagNote == diag::note_protected_by_variable_init;
924 S.
Diag(Jump->
getBeginLoc(), diag::err_indirect_goto_in_protected_scope)
926 S.
Diag(
Target->getStmt()->getIdentLoc(), diag::note_indirect_goto_target)
932void JumpScopeChecker::NoteJumpIntoScopes(ArrayRef<unsigned> ToScopes) {
935 for (
unsigned I = 0, E = ToScopes.size(); I != E; ++I)
936 if (Scopes[ToScopes[I]].InDiag)
937 S.Diag(Scopes[ToScopes[I]].Loc, Scopes[ToScopes[I]].InDiag);
941void JumpScopeChecker::DiagnoseIndirectOrAsmJump(Stmt *Jump,
unsigned JumpScope,
943 unsigned TargetScope) {
947 unsigned Common = GetDeepestCommonScope(JumpScope, TargetScope);
948 bool Diagnosed =
false;
951 for (
unsigned I = JumpScope; I != Common; I = Scopes[I].ParentScope)
952 if (Scopes[I].OutDiag) {
954 S.Diag(Scopes[I].Loc, Scopes[I].OutDiag);
957 SmallVector<unsigned, 10> ToScopesCXX98Compat, ToScopesCppCompat;
960 for (
unsigned I = TargetScope; I != Common; I = Scopes[I].ParentScope)
962 ToScopesCXX98Compat.push_back(I);
964 ToScopesCppCompat.push_back(I);
965 else if (Scopes[I].InDiag) {
967 S.Diag(Scopes[I].Loc, Scopes[I].InDiag);
973 auto Diag = [&](
unsigned DiagId,
const SmallVectorImpl<unsigned> &Notes) {
975 S.Diag(
Target->getStmt()->getIdentLoc(), diag::note_indirect_goto_target)
977 NoteJumpIntoScopes(Notes);
979 if (!ToScopesCXX98Compat.empty())
980 Diag(diag::warn_cxx98_compat_indirect_goto_in_protected_scope,
981 ToScopesCXX98Compat);
982 else if (!ToScopesCppCompat.empty())
983 Diag(diag::warn_cpp_compat_indirect_goto_in_protected_scope,
990void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc,
991 unsigned JumpDiagError,
992 unsigned JumpDiagWarning,
993 unsigned JumpDiagCompat) {
999 unsigned FromScope = LabelAndGotoScopes[From];
1000 unsigned ToScope = LabelAndGotoScopes[To];
1003 if (FromScope == ToScope)
return;
1009 for (
unsigned I = FromScope; I > ToScope; I = Scopes[I].ParentScope) {
1010 if (Scopes[I].InDiag == diag::note_protected_by_seh_finally) {
1011 S.Diag(From->
getBeginLoc(), diag::warn_jump_out_of_seh_finally);
1013 }
else if (Scopes[I].InDiag ==
1014 diag::note_omp_protected_structured_block) {
1015 S.Diag(From->
getBeginLoc(), diag::err_goto_into_protected_scope);
1016 S.Diag(To->
getBeginLoc(), diag::note_omp_exits_structured_block);
1018 }
else if (Scopes[I].InDiag ==
1019 diag::note_acc_branch_into_compute_construct) {
1020 S.Diag(From->
getBeginLoc(), diag::err_goto_into_protected_scope);
1021 S.Diag(Scopes[I].Loc, diag::note_acc_branch_out_of_compute_construct);
1023 }
else if (Scopes[I].OutDiag == diag::note_exits_defer_stmt) {
1024 S.Diag(From->
getBeginLoc(), diag::err_goto_into_protected_scope);
1025 S.Diag(Scopes[I].Loc, diag::note_exits_defer_stmt);
1031 unsigned CommonScope = GetDeepestCommonScope(FromScope, ToScope);
1034 if (CommonScope == ToScope)
return;
1037 SmallVector<unsigned, 10> ToScopesCompat;
1038 SmallVector<unsigned, 10> ToScopesError;
1039 SmallVector<unsigned, 10> ToScopesWarning;
1040 for (
unsigned I = ToScope; I != CommonScope; I = Scopes[I].ParentScope) {
1041 if (S.getLangOpts().MSVCCompat && S.getLangOpts().CPlusPlus &&
1042 JumpDiagWarning != 0 &&
1044 ToScopesWarning.push_back(I);
1047 ToScopesCompat.push_back(I);
1048 else if (Scopes[I].InDiag)
1049 ToScopesError.push_back(I);
1053 if (!ToScopesWarning.empty()) {
1054 S.Diag(DiagLoc, JumpDiagWarning);
1055 NoteJumpIntoScopes(ToScopesWarning);
1062 if (!ToScopesError.empty()) {
1063 S.Diag(DiagLoc, JumpDiagError);
1064 NoteJumpIntoScopes(ToScopesError);
1068 if (ToScopesError.empty() && !ToScopesCompat.empty()) {
1069 S.Diag(DiagLoc, JumpDiagCompat);
1070 NoteJumpIntoScopes(ToScopesCompat);
1074void JumpScopeChecker::CheckGotoStmt(GotoStmt *GS) {
1076 S.Diag(GS->
getGotoLoc(), diag::err_goto_ms_asm_label)
1083void JumpScopeChecker::VerifyMustTailStmts() {
1084 for (AttributedStmt *AS : MustTailStmts) {
1085 for (
unsigned I = LabelAndGotoScopes[AS]; I; I = Scopes[I].ParentScope) {
1086 if (Scopes[I].OutDiag) {
1087 S.Diag(AS->
getBeginLoc(), diag::err_musttail_scope);
1088 S.Diag(Scopes[I].Loc, Scopes[I].OutDiag);
1094const Attr *JumpScopeChecker::GetMustTailAttr(AttributedStmt *AS) {
1095 ArrayRef<const Attr *> Attrs = AS->
getAttrs();
1098 return Iter != Attrs.end() ? *Iter :
nullptr;
1102 (void)JumpScopeChecker(Body, *
this);
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Expr interface and subclasses for C++ expressions.
std::pair< unsigned, unsigned > ScopePair
static ScopePair GetDiagForGotoScopeDecl(Sema &S, const Decl *D)
GetDiagForGotoScopeDecl - If this decl induces a new goto scope, return a diagnostic that should be e...
static bool IsCXX98CompatWarning(Sema &S, unsigned InDiagNote)
Return true if a particular note should be downgraded to a compatibility warning in C++11 mode.
static bool IsMicrosoftJumpWarning(unsigned JumpDiag, unsigned InDiagNote)
Return true if a particular error+note combination must be downgraded to a warning in Microsoft mode.
static bool IsCppCompatWarning(Sema &S, unsigned InDiagNote)
Returns true if a particular note should be a C++ compatibility warning in C mode with -Wc++-compat.
#define CHECK_PERMISSIVE(x)
static void DiagnoseIndirectOrAsmJumpStmt(Sema &S, Stmt *Jump, LabelDecl *Target, bool &Diagnosed)
Produce primary diagnostic for an indirect jump statement.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::Target Target
This file declares semantic analysis functions specific to AMDGPU.
Defines the clang::SourceLocation class and associated facilities.
Defines the Objective-C statement AST node classes.
This file defines OpenACC AST classes for statement-level contructs.
This file defines OpenMP AST classes for executable directives and clauses.
ArrayRef< const Attr * > getAttrs() const
ArrayRef< Capture > captures() const
Stmt * getHandlerBlock() const
SourceLocation getBeginLoc() const LLVM_READONLY
Represents a call to a C++ constructor.
Represents a C++ constructor within a class.
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
bool isPOD() const
Whether this class is a POD-type (C++ [class]p4)
CXXCatchStmt * getHandler(unsigned i)
unsigned getNumHandlers() const
CompoundStmt * getTryBlock()
SourceLocation getBeginLoc() const LLVM_READONLY
Decl - This represents one declaration (or definition), e.g.
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
SourceLocation getLocation() const
CleanupObject getObject(unsigned i) const
unsigned getNumObjects() const
This represents one expression.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
SourceLocation getGotoLoc() const
LabelDecl * getLabel() const
bool isObjCAvailabilityCheck() const
SourceLocation getBeginLoc() const
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
Represents the declaration of a label.
LabelStmt * getStmt() const
bool isMSAsmLabel() const
void setSideEntry(bool SE)
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
const Expr * getSynchExpr() const
const CompoundStmt * getSynchBody() const
SourceLocation getAtSynchronizedLoc() const
const ObjCAtFinallyStmt * getFinallyStmt() const
Retrieve the @finally statement, if any.
const Stmt * getTryBody() const
Retrieve the @try body.
SourceLocation getAtTryLoc() const
Retrieve the location of the @ in the @try.
catch_range catch_stmts()
SourceLocation getAtLoc() const
SourceLocation getBeginLoc() const LLVM_READONLY
const Stmt * getSubStmt() const
@ DK_objc_strong_lifetime
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
CompoundStmt * getTryBlock() const
SEHFinallyStmt * getFinallyHandler() const
SEHExceptStmt * getExceptHandler() const
Returns 0 if not defined.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Sema - This implements semantic analysis and AST building for C.
const LangOptions & getLangOpts() const
void DiagnoseInvalidJumps(Stmt *Body)
Encodes a location in the source.
SourceLocation getBegin() const
CompoundStmt * getSubStmt()
SourceLocation getBeginLoc() const LLVM_READONLY
Stmt - This represents one statement.
StmtClass getStmtClass() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
const SwitchCase * getNextSwitchCase() const
SwitchCase * getSwitchCaseList()
Base class for declarations which introduce a typedef-name.
Represents a variable declaration or definition.
@ CallInit
Call-style initialization (C++98)
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
@ SD_Automatic
Automatic storage duration (most local variables).
const FunctionProtoType * T
U cast(CodeGen::Address addr)