23#include "llvm/ADT/BitVector.h"
38class JumpScopeChecker {
43 const bool Permissive;
66 GotoScope(
unsigned parentScope,
unsigned InDiag,
unsigned OutDiag,
68 : ParentScope(parentScope), InDiag(InDiag), OutDiag(OutDiag), Loc(L) {}
71 SmallVector<GotoScope, 48> Scopes;
72 llvm::DenseMap<Stmt*, unsigned> LabelAndGotoScopes;
73 SmallVector<Stmt*, 16> Jumps;
75 SmallVector<Stmt*, 4> IndirectJumps;
76 SmallVector<LabelDecl *, 4> IndirectJumpTargets;
77 SmallVector<AttributedStmt *, 4> MustTailStmts;
80 JumpScopeChecker(Stmt *Body, Sema &S);
82 void BuildScopeInformation(Decl *D,
unsigned &ParentScope);
83 void BuildScopeInformation(VarDecl *D,
const BlockDecl *BDecl,
84 unsigned &ParentScope);
85 void BuildScopeInformation(CompoundLiteralExpr *CLE,
unsigned &ParentScope);
86 void BuildScopeInformation(Stmt *S,
unsigned &origParentScope);
89 void VerifyIndirectJumps();
90 void VerifyMustTailStmts();
91 void NoteJumpIntoScopes(ArrayRef<unsigned> ToScopes);
92 void DiagnoseIndirectOrAsmJump(Stmt *IG,
unsigned IGScope, LabelDecl *
Target,
93 unsigned TargetScope);
94 void CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc,
95 unsigned JumpDiag,
unsigned JumpDiagWarning,
96 unsigned JumpDiagCompat);
97 void CheckGotoStmt(GotoStmt *GS);
98 const Attr *GetMustTailAttr(AttributedStmt *AS);
100 unsigned GetDeepestCommonScope(
unsigned A,
unsigned B);
104#define CHECK_PERMISSIVE(x) (assert(Permissive || !(x)), (Permissive && (x)))
106JumpScopeChecker::JumpScopeChecker(
Stmt *Body,
Sema &
s)
107 : S(
s), Permissive(
s.hasAnyUnrecoverableErrorsInThisFunction()) {
113 unsigned BodyParentScope = 0;
114 BuildScopeInformation(Body, BodyParentScope);
118 VerifyIndirectJumps();
119 VerifyMustTailStmts();
124unsigned JumpScopeChecker::GetDeepestCommonScope(
unsigned A,
unsigned B) {
129 assert(Scopes[B].ParentScope < B);
130 B = Scopes[B].ParentScope;
132 assert(Scopes[A].ParentScope < A);
133 A = Scopes[A].ParentScope;
144 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
146 unsigned OutDiag = 0;
148 if (VD->getType()->isVariablyModifiedType())
149 InDiag = diag::note_protected_by_vla;
151 if (VD->hasAttr<BlocksAttr>())
152 return ScopePair(diag::note_protected_by___block,
153 diag::note_exits___block);
155 if (VD->hasAttr<CleanupAttr>())
156 return ScopePair(diag::note_protected_by_cleanup,
157 diag::note_exits_cleanup);
159 if (VD->hasLocalStorage()) {
160 switch (VD->getType().isDestructedType()) {
162 return ScopePair(diag::note_protected_by_objc_strong_init,
163 diag::note_exits_objc_strong);
166 return ScopePair(diag::note_protected_by_objc_weak_init,
167 diag::note_exits_objc_weak);
170 return ScopePair(diag::note_protected_by_non_trivial_c_struct_init,
171 diag::note_exits_dtor);
174 OutDiag = diag::note_exits_dtor;
182 if (
const Expr *
Init = VD->getInit();
183 VD->hasLocalStorage() &&
Init && !
Init->containsErrors()) {
198 InDiag = diag::note_protected_by_variable_init;
208 InDiag = diag::note_protected_by_variable_nontriv_destructor;
210 InDiag = diag::note_protected_by_variable_non_pod;
221 if (TD->getUnderlyingType()->isVariablyModifiedType())
223 ? diag::note_protected_by_vla_typedef
224 : diag::note_protected_by_vla_type_alias,
232void JumpScopeChecker::BuildScopeInformation(Decl *D,
unsigned &ParentScope) {
235 if (Diags.first || Diags.second) {
236 Scopes.push_back(GotoScope(ParentScope, Diags.first, Diags.second,
238 ParentScope = Scopes.size()-1;
243 if (VarDecl *VD = dyn_cast<VarDecl>(D))
244 if (Expr *
Init = VD->getInit())
245 BuildScopeInformation(
Init, ParentScope);
249void JumpScopeChecker::BuildScopeInformation(VarDecl *D,
250 const BlockDecl *BDecl,
251 unsigned &ParentScope) {
259 std::pair<unsigned,unsigned> Diags;
260 switch (destructKind) {
262 Diags =
ScopePair(diag::note_enters_block_captures_cxx_obj,
263 diag::note_exits_block_captures_cxx_obj);
266 Diags =
ScopePair(diag::note_enters_block_captures_strong,
267 diag::note_exits_block_captures_strong);
270 Diags =
ScopePair(diag::note_enters_block_captures_weak,
271 diag::note_exits_block_captures_weak);
274 Diags =
ScopePair(diag::note_enters_block_captures_non_trivial_c_struct,
275 diag::note_exits_block_captures_non_trivial_c_struct);
278 llvm_unreachable(
"non-lifetime captured variable");
283 Scopes.push_back(GotoScope(ParentScope,
284 Diags.first, Diags.second, Loc));
285 ParentScope = Scopes.size()-1;
291void JumpScopeChecker::BuildScopeInformation(CompoundLiteralExpr *CLE,
292 unsigned &ParentScope) {
293 unsigned InDiag = diag::note_enters_compound_literal_scope;
294 unsigned OutDiag = diag::note_exits_compound_literal_scope;
295 Scopes.push_back(GotoScope(ParentScope, InDiag, OutDiag, CLE->
getExprLoc()));
296 ParentScope = Scopes.size() - 1;
303void JumpScopeChecker::BuildScopeInformation(Stmt *S,
304 unsigned &origParentScope) {
308 unsigned independentParentScope = origParentScope;
310 ? origParentScope : independentParentScope);
312 unsigned StmtsToSkip = 0u;
316 case Stmt::AddrLabelExprClass:
320 case Stmt::ObjCForCollectionStmtClass: {
322 unsigned Diag = diag::note_protected_by_objc_fast_enumeration;
323 unsigned NewParentScope = Scopes.size();
325 BuildScopeInformation(CS->getBody(), NewParentScope);
329 case Stmt::IndirectGotoStmtClass:
336 goto RecordJumpScope;
338 LabelAndGotoScopes[S] = ParentScope;
339 IndirectJumps.push_back(S);
342 case Stmt::SwitchStmtClass:
346 BuildScopeInformation(
Init, ParentScope);
350 BuildScopeInformation(Var, ParentScope);
353 goto RecordJumpScope;
355 case Stmt::GCCAsmStmtClass:
360 case Stmt::GotoStmtClass:
364 LabelAndGotoScopes[S] = ParentScope;
368 case Stmt::IfStmtClass: {
374 unsigned Diag = diag::note_protected_by_if_available;
376 Diag = diag::note_protected_by_constexpr_if;
378 Diag = diag::note_protected_by_consteval_if;
381 BuildScopeInformation(Var, ParentScope);
384 unsigned NewParentScope = Scopes.size();
388 BuildScopeInformation(IS->
getCond(), NewParentScope);
391 NewParentScope = Scopes.size();
393 BuildScopeInformation(IS->
getThen(), NewParentScope);
394 if (Stmt *Else = IS->
getElse()) {
395 NewParentScope = Scopes.size();
397 BuildScopeInformation(Else, NewParentScope);
402 case Stmt::CXXTryStmtClass: {
405 unsigned NewParentScope = Scopes.size();
406 Scopes.push_back(GotoScope(ParentScope,
407 diag::note_protected_by_cxx_try,
408 diag::note_exits_cxx_try,
411 BuildScopeInformation(TryBlock, NewParentScope);
417 unsigned NewParentScope = Scopes.size();
418 Scopes.push_back(GotoScope(ParentScope,
419 diag::note_protected_by_cxx_catch,
420 diag::note_exits_cxx_catch,
427 case Stmt::SEHTryStmtClass: {
430 unsigned NewParentScope = Scopes.size();
431 Scopes.push_back(GotoScope(ParentScope,
432 diag::note_protected_by_seh_try,
433 diag::note_exits_seh_try,
436 BuildScopeInformation(TryBlock, NewParentScope);
441 unsigned NewParentScope = Scopes.size();
442 Scopes.push_back(GotoScope(ParentScope,
443 diag::note_protected_by_seh_except,
444 diag::note_exits_seh_except,
445 Except->getSourceRange().getBegin()));
446 BuildScopeInformation(Except->getBlock(), NewParentScope);
448 unsigned NewParentScope = Scopes.size();
449 Scopes.push_back(GotoScope(ParentScope,
450 diag::note_protected_by_seh_finally,
451 diag::note_exits_seh_finally,
452 Finally->getSourceRange().getBegin()));
453 BuildScopeInformation(Finally->getBlock(), NewParentScope);
459 case Stmt::DeclStmtClass: {
465 for (
auto *I : DS->
decls())
466 BuildScopeInformation(I, origParentScope);
470 case Stmt::StmtExprClass: {
477 unsigned NewParentScope = Scopes.size();
478 Scopes.push_back(GotoScope(ParentScope,
479 diag::note_enters_statement_expression,
481 BuildScopeInformation(SE->
getSubStmt(), NewParentScope);
485 case Stmt::ObjCAtTryStmtClass: {
491 unsigned NewParentScope = Scopes.size();
492 Scopes.push_back(GotoScope(ParentScope,
493 diag::note_protected_by_objc_try,
494 diag::note_exits_objc_try,
497 BuildScopeInformation(TryPart, NewParentScope);
502 unsigned NewParentScope = Scopes.size();
503 Scopes.push_back(GotoScope(ParentScope,
504 diag::note_protected_by_objc_catch,
505 diag::note_exits_objc_catch,
506 AC->getAtCatchLoc()));
508 BuildScopeInformation(AC->getCatchBody(), NewParentScope);
513 unsigned NewParentScope = Scopes.size();
514 Scopes.push_back(GotoScope(ParentScope,
515 diag::note_protected_by_objc_finally,
516 diag::note_exits_objc_finally,
517 AF->getAtFinallyLoc()));
518 BuildScopeInformation(AF, NewParentScope);
524 case Stmt::ObjCAtSynchronizedStmtClass: {
534 unsigned NewParentScope = Scopes.size();
535 Scopes.push_back(GotoScope(ParentScope,
536 diag::note_protected_by_objc_synchronized,
537 diag::note_exits_objc_synchronized,
539 BuildScopeInformation(AS->
getSynchBody(), NewParentScope);
543 case Stmt::ObjCAutoreleasePoolStmtClass: {
548 unsigned NewParentScope = Scopes.size();
549 Scopes.push_back(GotoScope(ParentScope,
550 diag::note_protected_by_objc_autoreleasepool,
551 diag::note_exits_objc_autoreleasepool,
553 BuildScopeInformation(AS->
getSubStmt(), NewParentScope);
557 case Stmt::ExprWithCleanupsClass: {
562 for (
unsigned i = 0, e = EWC->
getNumObjects(); i != e; ++i) {
563 if (
auto *BDecl = dyn_cast<BlockDecl *>(EWC->
getObject(i)))
564 for (
const auto &CI : BDecl->
captures()) {
565 VarDecl *variable = CI.getVariable();
566 BuildScopeInformation(variable, BDecl, origParentScope);
568 else if (
auto *CLE = dyn_cast<CompoundLiteralExpr *>(EWC->
getObject(i)))
569 BuildScopeInformation(CLE, origParentScope);
571 llvm_unreachable(
"unexpected cleanup object type");
576 case Stmt::MaterializeTemporaryExprClass: {
581 const Expr *ExtendedObject =
584 Scopes.push_back(GotoScope(ParentScope, 0,
585 diag::note_exits_temporary_dtor,
587 origParentScope = Scopes.size()-1;
593 case Stmt::DeferStmtClass: {
598 unsigned NewParentScope = Scopes.size();
599 Scopes.emplace_back(ParentScope, diag::note_protected_by_defer_stmt, 0,
601 origParentScope = NewParentScope;
606 unsigned NewParentScope = Scopes.size();
607 Scopes.emplace_back(ParentScope, diag::note_enters_defer_stmt,
608 diag::note_exits_defer_stmt, D->getDeferLoc());
609 BuildScopeInformation(D->
getBody(), NewParentScope);
614 case Stmt::CaseStmtClass:
615 case Stmt::DefaultStmtClass:
616 case Stmt::LabelStmtClass:
617 LabelAndGotoScopes[S] = ParentScope;
620 case Stmt::OpenACCComputeConstructClass: {
621 unsigned NewParentScope = Scopes.size();
623 Scopes.push_back(GotoScope(
624 ParentScope, diag::note_acc_branch_into_compute_construct,
625 diag::note_acc_branch_out_of_compute_construct, CC->getBeginLoc()));
628 if (CC->getStructuredBlock())
629 BuildScopeInformation(CC->getStructuredBlock(), NewParentScope);
633 case Stmt::OpenACCCombinedConstructClass: {
634 unsigned NewParentScope = Scopes.size();
636 Scopes.push_back(GotoScope(
637 ParentScope, diag::note_acc_branch_into_compute_construct,
638 diag::note_acc_branch_out_of_compute_construct, CC->getBeginLoc()));
642 BuildScopeInformation(CC->
getLoop(), NewParentScope);
647 if (
auto *ED = dyn_cast<OMPExecutableDirective>(S)) {
648 if (!ED->isStandaloneDirective()) {
649 unsigned NewParentScope = Scopes.size();
650 Scopes.emplace_back(ParentScope,
651 diag::note_omp_protected_structured_block,
652 diag::note_omp_exits_structured_block,
653 ED->getStructuredBlock()->getBeginLoc());
654 BuildScopeInformation(ED->getStructuredBlock(), NewParentScope);
661 for (Stmt *SubStmt : S->
children()) {
674 if (SwitchCase *SC = dyn_cast<SwitchCase>(SubStmt))
675 Next = SC->getSubStmt();
676 else if (LabelStmt *LS = dyn_cast<LabelStmt>(SubStmt))
677 Next = LS->getSubStmt();
678 else if (AttributedStmt *AS = dyn_cast<AttributedStmt>(SubStmt)) {
679 if (GetMustTailAttr(AS)) {
680 LabelAndGotoScopes[AS] = ParentScope;
681 MustTailStmts.push_back(AS);
687 LabelAndGotoScopes[SubStmt] = ParentScope;
692 BuildScopeInformation(SubStmt, ParentScope);
698void JumpScopeChecker::VerifyJumps() {
699 while (!Jumps.empty()) {
700 Stmt *Jump = Jumps.pop_back_val();
703 if (GotoStmt *GS = dyn_cast<GotoStmt>(Jump)) {
705 if (GS->getLabel()->getStmt()) {
706 CheckJump(GS, GS->getLabel()->getStmt(), GS->getGotoLoc(),
707 diag::err_goto_into_protected_scope,
708 diag::ext_goto_into_protected_scope,
709 S.getLangOpts().CPlusPlus
710 ? diag::warn_cxx98_compat_goto_into_protected_scope
711 : diag::warn_cpp_compat_goto_into_protected_scope);
722 if (
auto *G = dyn_cast<GCCAsmStmt>(Jump)) {
723 for (AddrLabelExpr *L : G->labels()) {
724 LabelDecl *LD = L->getLabel();
725 unsigned JumpScope = LabelAndGotoScopes[G];
726 unsigned TargetScope = LabelAndGotoScopes[LD->
getStmt()];
727 if (JumpScope != TargetScope)
728 DiagnoseIndirectOrAsmJump(G, JumpScope, LD, TargetScope);
734 if (IndirectGotoStmt *IGS = dyn_cast<IndirectGotoStmt>(Jump)) {
735 LabelDecl *
Target = IGS->getConstantTarget();
736 CheckJump(IGS,
Target->getStmt(), IGS->getGotoLoc(),
737 diag::err_goto_into_protected_scope,
738 diag::ext_goto_into_protected_scope,
739 S.getLangOpts().CPlusPlus
740 ? diag::warn_cxx98_compat_goto_into_protected_scope
741 : diag::warn_cpp_compat_goto_into_protected_scope);
751 if (CaseStmt *CS = dyn_cast<CaseStmt>(SC))
753 else if (DefaultStmt *DS = dyn_cast<DefaultStmt>(SC))
756 Loc = SC->getBeginLoc();
757 CheckJump(SS, SC, Loc, diag::err_switch_into_protected_scope, 0,
758 S.getLangOpts().CPlusPlus
759 ? diag::warn_cxx98_compat_switch_into_protected_scope
760 : diag::warn_cpp_compat_switch_into_protected_scope);
782void JumpScopeChecker::VerifyIndirectJumps() {
783 if (IndirectJumps.empty())
787 if (IndirectJumpTargets.empty()) {
788 S.Diag(IndirectJumps[0]->getBeginLoc(),
789 diag::err_indirect_goto_without_addrlabel);
795 using JumpScope = std::pair<unsigned, Stmt *>;
796 SmallVector<JumpScope, 32> JumpScopes;
798 llvm::DenseMap<unsigned, Stmt*> JumpScopesMap;
799 for (Stmt *IG : IndirectJumps) {
802 unsigned IGScope = LabelAndGotoScopes[IG];
803 JumpScopesMap.try_emplace(IGScope, IG);
805 JumpScopes.reserve(JumpScopesMap.size());
806 for (
auto &Pair : JumpScopesMap)
807 JumpScopes.emplace_back(Pair);
813 llvm::DenseMap<unsigned, LabelDecl*> TargetScopes;
814 for (LabelDecl *TheLabel : IndirectJumpTargets) {
817 unsigned LabelScope = LabelAndGotoScopes[TheLabel->getStmt()];
818 TargetScopes.try_emplace(LabelScope, TheLabel);
829 llvm::BitVector Reachable(Scopes.size(),
false);
830 for (
auto [TargetScope, TargetLabel] : TargetScopes) {
836 unsigned Min = TargetScope;
844 if (Scopes[
Min].InDiag)
break;
846 Min = Scopes[
Min].ParentScope;
851 for (
auto [JumpScope, JumpStmt] : JumpScopes) {
852 unsigned Scope = JumpScope;
858 bool IsReachable =
false;
860 if (Reachable.test(Scope)) {
863 for (
unsigned S = JumpScope; S != Scope; S = Scopes[S].ParentScope)
871 if (Scope == 0 || Scope <
Min)
break;
874 if (Scopes[Scope].OutDiag)
break;
876 Scope = Scopes[Scope].ParentScope;
880 if (IsReachable)
continue;
882 DiagnoseIndirectOrAsmJump(JumpStmt, JumpScope, TargetLabel, TargetScope);
890 return (JumpDiag == diag::err_goto_into_protected_scope &&
891 (InDiagNote == diag::note_protected_by_variable_init ||
892 InDiagNote == diag::note_protected_by_variable_nontriv_destructor));
899 InDiagNote == diag::note_protected_by_variable_non_pod;
906 InDiagNote == diag::note_protected_by_variable_init;
915 S.
Diag(Jump->
getBeginLoc(), diag::err_indirect_goto_in_protected_scope)
917 S.
Diag(
Target->getStmt()->getIdentLoc(), diag::note_indirect_goto_target)
923void JumpScopeChecker::NoteJumpIntoScopes(ArrayRef<unsigned> ToScopes) {
926 for (
unsigned I = 0, E = ToScopes.size(); I != E; ++I)
927 if (Scopes[ToScopes[I]].InDiag)
928 S.Diag(Scopes[ToScopes[I]].Loc, Scopes[ToScopes[I]].InDiag);
932void JumpScopeChecker::DiagnoseIndirectOrAsmJump(Stmt *Jump,
unsigned JumpScope,
934 unsigned TargetScope) {
938 unsigned Common = GetDeepestCommonScope(JumpScope, TargetScope);
939 bool Diagnosed =
false;
942 for (
unsigned I = JumpScope; I != Common; I = Scopes[I].ParentScope)
943 if (Scopes[I].OutDiag) {
945 S.Diag(Scopes[I].Loc, Scopes[I].OutDiag);
948 SmallVector<unsigned, 10> ToScopesCXX98Compat, ToScopesCppCompat;
951 for (
unsigned I = TargetScope; I != Common; I = Scopes[I].ParentScope)
953 ToScopesCXX98Compat.push_back(I);
955 ToScopesCppCompat.push_back(I);
956 else if (Scopes[I].InDiag) {
958 S.Diag(Scopes[I].Loc, Scopes[I].InDiag);
964 auto Diag = [&](
unsigned DiagId,
const SmallVectorImpl<unsigned> &Notes) {
966 S.Diag(
Target->getStmt()->getIdentLoc(), diag::note_indirect_goto_target)
968 NoteJumpIntoScopes(Notes);
970 if (!ToScopesCXX98Compat.empty())
971 Diag(diag::warn_cxx98_compat_indirect_goto_in_protected_scope,
972 ToScopesCXX98Compat);
973 else if (!ToScopesCppCompat.empty())
974 Diag(diag::warn_cpp_compat_indirect_goto_in_protected_scope,
981void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc,
982 unsigned JumpDiagError,
983 unsigned JumpDiagWarning,
984 unsigned JumpDiagCompat) {
990 unsigned FromScope = LabelAndGotoScopes[From];
991 unsigned ToScope = LabelAndGotoScopes[To];
994 if (FromScope == ToScope)
return;
1000 for (
unsigned I = FromScope; I > ToScope; I = Scopes[I].ParentScope) {
1001 if (Scopes[I].InDiag == diag::note_protected_by_seh_finally) {
1002 S.Diag(From->
getBeginLoc(), diag::warn_jump_out_of_seh_finally);
1004 }
else if (Scopes[I].InDiag ==
1005 diag::note_omp_protected_structured_block) {
1006 S.Diag(From->
getBeginLoc(), diag::err_goto_into_protected_scope);
1007 S.Diag(To->
getBeginLoc(), diag::note_omp_exits_structured_block);
1009 }
else if (Scopes[I].InDiag ==
1010 diag::note_acc_branch_into_compute_construct) {
1011 S.Diag(From->
getBeginLoc(), diag::err_goto_into_protected_scope);
1012 S.Diag(Scopes[I].Loc, diag::note_acc_branch_out_of_compute_construct);
1014 }
else if (Scopes[I].OutDiag == diag::note_exits_defer_stmt) {
1015 S.Diag(From->
getBeginLoc(), diag::err_goto_into_protected_scope);
1016 S.Diag(Scopes[I].Loc, diag::note_exits_defer_stmt);
1022 unsigned CommonScope = GetDeepestCommonScope(FromScope, ToScope);
1025 if (CommonScope == ToScope)
return;
1028 SmallVector<unsigned, 10> ToScopesCompat;
1029 SmallVector<unsigned, 10> ToScopesError;
1030 SmallVector<unsigned, 10> ToScopesWarning;
1031 for (
unsigned I = ToScope; I != CommonScope; I = Scopes[I].ParentScope) {
1032 if (S.getLangOpts().MSVCCompat && S.getLangOpts().CPlusPlus &&
1033 JumpDiagWarning != 0 &&
1035 ToScopesWarning.push_back(I);
1038 ToScopesCompat.push_back(I);
1039 else if (Scopes[I].InDiag)
1040 ToScopesError.push_back(I);
1044 if (!ToScopesWarning.empty()) {
1045 S.Diag(DiagLoc, JumpDiagWarning);
1046 NoteJumpIntoScopes(ToScopesWarning);
1053 if (!ToScopesError.empty()) {
1054 S.Diag(DiagLoc, JumpDiagError);
1055 NoteJumpIntoScopes(ToScopesError);
1059 if (ToScopesError.empty() && !ToScopesCompat.empty()) {
1060 S.Diag(DiagLoc, JumpDiagCompat);
1061 NoteJumpIntoScopes(ToScopesCompat);
1065void JumpScopeChecker::CheckGotoStmt(GotoStmt *GS) {
1067 S.Diag(GS->
getGotoLoc(), diag::err_goto_ms_asm_label)
1074void JumpScopeChecker::VerifyMustTailStmts() {
1075 for (AttributedStmt *AS : MustTailStmts) {
1076 for (
unsigned I = LabelAndGotoScopes[AS]; I; I = Scopes[I].ParentScope) {
1077 if (Scopes[I].OutDiag) {
1078 S.Diag(AS->
getBeginLoc(), diag::err_musttail_scope);
1079 S.Diag(Scopes[I].Loc, Scopes[I].OutDiag);
1085const Attr *JumpScopeChecker::GetMustTailAttr(AttributedStmt *AS) {
1086 ArrayRef<const Attr *> Attrs = AS->
getAttrs();
1089 return Iter != Attrs.end() ? *Iter :
nullptr;
1093 (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
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).
const FunctionProtoType * T
U cast(CodeGen::Address addr)