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) {
296 unsigned InDiag = diag::note_enters_compound_literal_scope;
297 unsigned OutDiag = diag::note_exits_compound_literal_scope;
298 Scopes.push_back(GotoScope(ParentScope, InDiag, OutDiag, CLE->
getExprLoc()));
299 ParentScope = Scopes.size() - 1;
306void JumpScopeChecker::BuildScopeInformation(Stmt *S,
307 unsigned &origParentScope) {
311 unsigned independentParentScope = origParentScope;
313 ? origParentScope : independentParentScope);
315 unsigned StmtsToSkip = 0u;
319 case Stmt::AddrLabelExprClass:
323 case Stmt::ObjCForCollectionStmtClass: {
325 unsigned Diag = diag::note_protected_by_objc_fast_enumeration;
326 unsigned NewParentScope = Scopes.size();
328 BuildScopeInformation(CS->getBody(), NewParentScope);
332 case Stmt::IndirectGotoStmtClass:
339 goto RecordJumpScope;
341 LabelAndGotoScopes[S] = ParentScope;
342 IndirectJumps.push_back(S);
345 case Stmt::SwitchStmtClass:
349 BuildScopeInformation(
Init, ParentScope);
353 BuildScopeInformation(Var, ParentScope);
356 goto RecordJumpScope;
358 case Stmt::GCCAsmStmtClass:
363 case Stmt::GotoStmtClass:
367 LabelAndGotoScopes[S] = ParentScope;
371 case Stmt::IfStmtClass: {
373 bool AMDGPUPredicate =
false;
376 (AMDGPUPredicate = this->S.AMDGPU().IsPredicate(IS->
getCond()))))
379 unsigned Diag = diag::note_protected_by_if_available;
381 Diag = diag::note_protected_by_constexpr_if;
383 Diag = diag::note_protected_by_consteval_if;
384 else if (AMDGPUPredicate)
385 Diag = diag::note_amdgcn_protected_by_predicate;
388 BuildScopeInformation(Var, ParentScope);
391 unsigned NewParentScope = Scopes.size();
395 BuildScopeInformation(IS->
getCond(), NewParentScope);
398 NewParentScope = Scopes.size();
400 BuildScopeInformation(IS->
getThen(), NewParentScope);
401 if (Stmt *Else = IS->
getElse()) {
402 NewParentScope = Scopes.size();
404 BuildScopeInformation(Else, NewParentScope);
409 case Stmt::CXXTryStmtClass: {
412 unsigned NewParentScope = Scopes.size();
413 Scopes.push_back(GotoScope(ParentScope,
414 diag::note_protected_by_cxx_try,
415 diag::note_exits_cxx_try,
418 BuildScopeInformation(TryBlock, NewParentScope);
424 unsigned NewParentScope = Scopes.size();
425 Scopes.push_back(GotoScope(ParentScope,
426 diag::note_protected_by_cxx_catch,
427 diag::note_exits_cxx_catch,
434 case Stmt::SEHTryStmtClass: {
437 unsigned NewParentScope = Scopes.size();
438 Scopes.push_back(GotoScope(ParentScope,
439 diag::note_protected_by_seh_try,
440 diag::note_exits_seh_try,
443 BuildScopeInformation(TryBlock, NewParentScope);
448 unsigned NewParentScope = Scopes.size();
449 Scopes.push_back(GotoScope(ParentScope,
450 diag::note_protected_by_seh_except,
451 diag::note_exits_seh_except,
452 Except->getSourceRange().getBegin()));
453 BuildScopeInformation(Except->getBlock(), NewParentScope);
455 unsigned NewParentScope = Scopes.size();
456 Scopes.push_back(GotoScope(ParentScope,
457 diag::note_protected_by_seh_finally,
458 diag::note_exits_seh_finally,
459 Finally->getSourceRange().getBegin()));
460 BuildScopeInformation(Finally->getBlock(), NewParentScope);
466 case Stmt::DeclStmtClass: {
472 for (
auto *I : DS->
decls())
473 BuildScopeInformation(I, origParentScope);
477 case Stmt::StmtExprClass: {
484 unsigned NewParentScope = Scopes.size();
485 Scopes.push_back(GotoScope(ParentScope,
486 diag::note_enters_statement_expression,
488 BuildScopeInformation(SE->
getSubStmt(), NewParentScope);
492 case Stmt::ObjCAtTryStmtClass: {
498 unsigned NewParentScope = Scopes.size();
499 Scopes.push_back(GotoScope(ParentScope,
500 diag::note_protected_by_objc_try,
501 diag::note_exits_objc_try,
504 BuildScopeInformation(TryPart, NewParentScope);
509 unsigned NewParentScope = Scopes.size();
510 Scopes.push_back(GotoScope(ParentScope,
511 diag::note_protected_by_objc_catch,
512 diag::note_exits_objc_catch,
513 AC->getAtCatchLoc()));
515 BuildScopeInformation(AC->getCatchBody(), NewParentScope);
520 unsigned NewParentScope = Scopes.size();
521 Scopes.push_back(GotoScope(ParentScope,
522 diag::note_protected_by_objc_finally,
523 diag::note_exits_objc_finally,
524 AF->getAtFinallyLoc()));
525 BuildScopeInformation(AF, NewParentScope);
531 case Stmt::ObjCAtSynchronizedStmtClass: {
541 unsigned NewParentScope = Scopes.size();
542 Scopes.push_back(GotoScope(ParentScope,
543 diag::note_protected_by_objc_synchronized,
544 diag::note_exits_objc_synchronized,
546 BuildScopeInformation(AS->
getSynchBody(), NewParentScope);
550 case Stmt::ObjCAutoreleasePoolStmtClass: {
555 unsigned NewParentScope = Scopes.size();
556 Scopes.push_back(GotoScope(ParentScope,
557 diag::note_protected_by_objc_autoreleasepool,
558 diag::note_exits_objc_autoreleasepool,
560 BuildScopeInformation(AS->
getSubStmt(), NewParentScope);
564 case Stmt::ExprWithCleanupsClass: {
569 for (
unsigned i = 0, e = EWC->
getNumObjects(); i != e; ++i) {
570 if (
auto *BDecl = dyn_cast<BlockDecl *>(EWC->
getObject(i)))
571 for (
const auto &CI : BDecl->
captures()) {
572 VarDecl *variable = CI.getVariable();
573 BuildScopeInformation(variable, BDecl, origParentScope);
575 else if (
auto *CLE = dyn_cast<CompoundLiteralExpr *>(EWC->
getObject(i)))
576 BuildScopeInformation(CLE, origParentScope);
578 llvm_unreachable(
"unexpected cleanup object type");
583 case Stmt::MaterializeTemporaryExprClass: {
588 const Expr *ExtendedObject =
591 Scopes.push_back(GotoScope(ParentScope, 0,
592 diag::note_exits_temporary_dtor,
594 origParentScope = Scopes.size()-1;
600 case Stmt::DeferStmtClass: {
605 unsigned NewParentScope = Scopes.size();
606 Scopes.emplace_back(ParentScope, diag::note_protected_by_defer_stmt, 0,
608 origParentScope = NewParentScope;
613 unsigned NewParentScope = Scopes.size();
614 Scopes.emplace_back(ParentScope, diag::note_enters_defer_stmt,
615 diag::note_exits_defer_stmt, D->getDeferLoc());
616 BuildScopeInformation(D->
getBody(), NewParentScope);
621 case Stmt::CaseStmtClass:
622 case Stmt::DefaultStmtClass:
623 case Stmt::LabelStmtClass:
624 LabelAndGotoScopes[S] = ParentScope;
627 case Stmt::OpenACCComputeConstructClass: {
628 unsigned NewParentScope = Scopes.size();
630 Scopes.push_back(GotoScope(
631 ParentScope, diag::note_acc_branch_into_compute_construct,
632 diag::note_acc_branch_out_of_compute_construct, CC->getBeginLoc()));
635 if (CC->getStructuredBlock())
636 BuildScopeInformation(CC->getStructuredBlock(), NewParentScope);
640 case Stmt::OpenACCCombinedConstructClass: {
641 unsigned NewParentScope = Scopes.size();
643 Scopes.push_back(GotoScope(
644 ParentScope, diag::note_acc_branch_into_compute_construct,
645 diag::note_acc_branch_out_of_compute_construct, CC->getBeginLoc()));
649 BuildScopeInformation(CC->
getLoop(), NewParentScope);
654 if (
auto *ED = dyn_cast<OMPExecutableDirective>(S)) {
655 if (!ED->isStandaloneDirective()) {
656 unsigned NewParentScope = Scopes.size();
657 Scopes.emplace_back(ParentScope,
658 diag::note_omp_protected_structured_block,
659 diag::note_omp_exits_structured_block,
660 ED->getStructuredBlock()->getBeginLoc());
661 BuildScopeInformation(ED->getStructuredBlock(), NewParentScope);
668 for (Stmt *SubStmt : S->
children()) {
681 if (SwitchCase *SC = dyn_cast<SwitchCase>(SubStmt))
682 Next = SC->getSubStmt();
683 else if (LabelStmt *LS = dyn_cast<LabelStmt>(SubStmt))
684 Next = LS->getSubStmt();
685 else if (AttributedStmt *AS = dyn_cast<AttributedStmt>(SubStmt)) {
686 if (GetMustTailAttr(AS)) {
687 LabelAndGotoScopes[AS] = ParentScope;
688 MustTailStmts.push_back(AS);
694 LabelAndGotoScopes[SubStmt] = ParentScope;
699 BuildScopeInformation(SubStmt, ParentScope);
705void JumpScopeChecker::VerifyJumps() {
706 while (!Jumps.empty()) {
707 Stmt *Jump = Jumps.pop_back_val();
710 if (GotoStmt *GS = dyn_cast<GotoStmt>(Jump)) {
712 if (GS->getLabel()->getStmt()) {
713 CheckJump(GS, GS->getLabel()->getStmt(), GS->getGotoLoc(),
714 diag::err_goto_into_protected_scope,
715 diag::ext_goto_into_protected_scope,
716 S.getLangOpts().CPlusPlus
717 ? diag::warn_cxx98_compat_goto_into_protected_scope
718 : diag::warn_cpp_compat_goto_into_protected_scope);
729 if (
auto *G = dyn_cast<GCCAsmStmt>(Jump)) {
730 for (AddrLabelExpr *L : G->labels()) {
731 LabelDecl *LD = L->getLabel();
732 unsigned JumpScope = LabelAndGotoScopes[G];
733 unsigned TargetScope = LabelAndGotoScopes[LD->
getStmt()];
734 if (JumpScope != TargetScope)
735 DiagnoseIndirectOrAsmJump(G, JumpScope, LD, TargetScope);
741 if (IndirectGotoStmt *IGS = dyn_cast<IndirectGotoStmt>(Jump)) {
742 LabelDecl *
Target = IGS->getConstantTarget();
743 CheckJump(IGS,
Target->getStmt(), IGS->getGotoLoc(),
744 diag::err_goto_into_protected_scope,
745 diag::ext_goto_into_protected_scope,
746 S.getLangOpts().CPlusPlus
747 ? diag::warn_cxx98_compat_goto_into_protected_scope
748 : diag::warn_cpp_compat_goto_into_protected_scope);
758 if (CaseStmt *CS = dyn_cast<CaseStmt>(SC))
760 else if (DefaultStmt *DS = dyn_cast<DefaultStmt>(SC))
763 Loc = SC->getBeginLoc();
764 CheckJump(SS, SC, Loc, diag::err_switch_into_protected_scope, 0,
765 S.getLangOpts().CPlusPlus
766 ? diag::warn_cxx98_compat_switch_into_protected_scope
767 : diag::warn_cpp_compat_switch_into_protected_scope);
789void JumpScopeChecker::VerifyIndirectJumps() {
790 if (IndirectJumps.empty())
794 if (IndirectJumpTargets.empty()) {
795 S.Diag(IndirectJumps[0]->getBeginLoc(),
796 diag::err_indirect_goto_without_addrlabel);
802 using JumpScope = std::pair<unsigned, Stmt *>;
803 SmallVector<JumpScope, 32> JumpScopes;
805 llvm::DenseMap<unsigned, Stmt*> JumpScopesMap;
806 for (Stmt *IG : IndirectJumps) {
809 unsigned IGScope = LabelAndGotoScopes[IG];
810 JumpScopesMap.try_emplace(IGScope, IG);
812 JumpScopes.reserve(JumpScopesMap.size());
813 for (
auto &Pair : JumpScopesMap)
814 JumpScopes.emplace_back(Pair);
820 llvm::DenseMap<unsigned, LabelDecl*> TargetScopes;
821 for (LabelDecl *TheLabel : IndirectJumpTargets) {
824 unsigned LabelScope = LabelAndGotoScopes[TheLabel->getStmt()];
825 TargetScopes.try_emplace(LabelScope, TheLabel);
836 llvm::BitVector Reachable(Scopes.size(),
false);
837 for (
auto [TargetScope, TargetLabel] : TargetScopes) {
843 unsigned Min = TargetScope;
851 if (Scopes[
Min].InDiag)
break;
853 Min = Scopes[
Min].ParentScope;
858 for (
auto [JumpScope, JumpStmt] : JumpScopes) {
859 unsigned Scope = JumpScope;
865 bool IsReachable =
false;
867 if (Reachable.test(Scope)) {
870 for (
unsigned S = JumpScope; S != Scope; S = Scopes[S].ParentScope)
878 if (Scope == 0 || Scope <
Min)
break;
881 if (Scopes[Scope].OutDiag)
break;
883 Scope = Scopes[Scope].ParentScope;
887 if (IsReachable)
continue;
889 DiagnoseIndirectOrAsmJump(JumpStmt, JumpScope, TargetLabel, TargetScope);
897 return (JumpDiag == diag::err_goto_into_protected_scope &&
898 (InDiagNote == diag::note_protected_by_variable_init ||
899 InDiagNote == diag::note_protected_by_variable_nontriv_destructor));
906 InDiagNote == diag::note_protected_by_variable_non_pod;
913 InDiagNote == diag::note_protected_by_variable_init;
922 S.
Diag(Jump->
getBeginLoc(), diag::err_indirect_goto_in_protected_scope)
924 S.
Diag(
Target->getStmt()->getIdentLoc(), diag::note_indirect_goto_target)
930void JumpScopeChecker::NoteJumpIntoScopes(ArrayRef<unsigned> ToScopes) {
933 for (
unsigned I = 0, E = ToScopes.size(); I != E; ++I)
934 if (Scopes[ToScopes[I]].InDiag)
935 S.Diag(Scopes[ToScopes[I]].Loc, Scopes[ToScopes[I]].InDiag);
939void JumpScopeChecker::DiagnoseIndirectOrAsmJump(Stmt *Jump,
unsigned JumpScope,
941 unsigned TargetScope) {
945 unsigned Common = GetDeepestCommonScope(JumpScope, TargetScope);
946 bool Diagnosed =
false;
949 for (
unsigned I = JumpScope; I != Common; I = Scopes[I].ParentScope)
950 if (Scopes[I].OutDiag) {
952 S.Diag(Scopes[I].Loc, Scopes[I].OutDiag);
955 SmallVector<unsigned, 10> ToScopesCXX98Compat, ToScopesCppCompat;
958 for (
unsigned I = TargetScope; I != Common; I = Scopes[I].ParentScope)
960 ToScopesCXX98Compat.push_back(I);
962 ToScopesCppCompat.push_back(I);
963 else if (Scopes[I].InDiag) {
965 S.Diag(Scopes[I].Loc, Scopes[I].InDiag);
971 auto Diag = [&](
unsigned DiagId,
const SmallVectorImpl<unsigned> &Notes) {
973 S.Diag(
Target->getStmt()->getIdentLoc(), diag::note_indirect_goto_target)
975 NoteJumpIntoScopes(Notes);
977 if (!ToScopesCXX98Compat.empty())
978 Diag(diag::warn_cxx98_compat_indirect_goto_in_protected_scope,
979 ToScopesCXX98Compat);
980 else if (!ToScopesCppCompat.empty())
981 Diag(diag::warn_cpp_compat_indirect_goto_in_protected_scope,
988void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc,
989 unsigned JumpDiagError,
990 unsigned JumpDiagWarning,
991 unsigned JumpDiagCompat) {
997 unsigned FromScope = LabelAndGotoScopes[From];
998 unsigned ToScope = LabelAndGotoScopes[To];
1001 if (FromScope == ToScope)
return;
1007 for (
unsigned I = FromScope; I > ToScope; I = Scopes[I].ParentScope) {
1008 if (Scopes[I].InDiag == diag::note_protected_by_seh_finally) {
1009 S.Diag(From->
getBeginLoc(), diag::warn_jump_out_of_seh_finally);
1011 }
else if (Scopes[I].InDiag ==
1012 diag::note_omp_protected_structured_block) {
1013 S.Diag(From->
getBeginLoc(), diag::err_goto_into_protected_scope);
1014 S.Diag(To->
getBeginLoc(), diag::note_omp_exits_structured_block);
1016 }
else if (Scopes[I].InDiag ==
1017 diag::note_acc_branch_into_compute_construct) {
1018 S.Diag(From->
getBeginLoc(), diag::err_goto_into_protected_scope);
1019 S.Diag(Scopes[I].Loc, diag::note_acc_branch_out_of_compute_construct);
1021 }
else if (Scopes[I].OutDiag == diag::note_exits_defer_stmt) {
1022 S.Diag(From->
getBeginLoc(), diag::err_goto_into_protected_scope);
1023 S.Diag(Scopes[I].Loc, diag::note_exits_defer_stmt);
1029 unsigned CommonScope = GetDeepestCommonScope(FromScope, ToScope);
1032 if (CommonScope == ToScope)
return;
1035 SmallVector<unsigned, 10> ToScopesCompat;
1036 SmallVector<unsigned, 10> ToScopesError;
1037 SmallVector<unsigned, 10> ToScopesWarning;
1038 for (
unsigned I = ToScope; I != CommonScope; I = Scopes[I].ParentScope) {
1039 if (S.getLangOpts().MSVCCompat && S.getLangOpts().CPlusPlus &&
1040 JumpDiagWarning != 0 &&
1042 ToScopesWarning.push_back(I);
1045 ToScopesCompat.push_back(I);
1046 else if (Scopes[I].InDiag)
1047 ToScopesError.push_back(I);
1051 if (!ToScopesWarning.empty()) {
1052 S.Diag(DiagLoc, JumpDiagWarning);
1053 NoteJumpIntoScopes(ToScopesWarning);
1060 if (!ToScopesError.empty()) {
1061 S.Diag(DiagLoc, JumpDiagError);
1062 NoteJumpIntoScopes(ToScopesError);
1066 if (ToScopesError.empty() && !ToScopesCompat.empty()) {
1067 S.Diag(DiagLoc, JumpDiagCompat);
1068 NoteJumpIntoScopes(ToScopesCompat);
1072void JumpScopeChecker::CheckGotoStmt(GotoStmt *GS) {
1074 S.Diag(GS->
getGotoLoc(), diag::err_goto_ms_asm_label)
1081void JumpScopeChecker::VerifyMustTailStmts() {
1082 for (AttributedStmt *AS : MustTailStmts) {
1083 for (
unsigned I = LabelAndGotoScopes[AS]; I; I = Scopes[I].ParentScope) {
1084 if (Scopes[I].OutDiag) {
1085 S.Diag(AS->
getBeginLoc(), diag::err_musttail_scope);
1086 S.Diag(Scopes[I].Loc, Scopes[I].OutDiag);
1092const Attr *JumpScopeChecker::GetMustTailAttr(AttributedStmt *AS) {
1093 ArrayRef<const Attr *> Attrs = AS->
getAttrs();
1096 return Iter != Attrs.end() ? *Iter :
nullptr;
1100 (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.
__device__ __2f16 float __ockl_bool s
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)
The JSON file list parser is used to communicate input to InstallAPI.
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).
U cast(CodeGen::Address addr)