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);
161 if (VD->hasLocalStorage() && VD->hasAttr<OMPAllocateDeclAttr>())
162 return ScopePair(diag::note_protected_by_omp_allocate,
163 diag::note_exits_omp_allocate);
165 if (VD->hasLocalStorage()) {
166 switch (VD->getType().isDestructedType()) {
168 return ScopePair(diag::note_protected_by_objc_strong_init,
169 diag::note_exits_objc_strong);
172 return ScopePair(diag::note_protected_by_objc_weak_init,
173 diag::note_exits_objc_weak);
176 return ScopePair(diag::note_protected_by_non_trivial_c_struct_init,
177 diag::note_exits_dtor);
180 OutDiag = diag::note_exits_dtor;
190 if (
const Expr *
Init = VD->getInit();
191 !InDiag && VD->hasLocalStorage() &&
Init && !
Init->containsErrors()) {
206 InDiag = diag::note_protected_by_variable_init;
216 InDiag = diag::note_protected_by_variable_nontriv_destructor;
218 InDiag = diag::note_protected_by_variable_non_pod;
229 if (TD->getUnderlyingType()->isVariablyModifiedType())
231 ? diag::note_protected_by_vla_typedef
232 : diag::note_protected_by_vla_type_alias,
240void JumpScopeChecker::BuildScopeInformation(Decl *D,
unsigned &ParentScope) {
243 if (Diags.first || Diags.second) {
244 Scopes.push_back(GotoScope(ParentScope, Diags.first, Diags.second,
246 ParentScope = Scopes.size()-1;
251 if (VarDecl *VD = dyn_cast<VarDecl>(D))
252 if (Expr *
Init = VD->getInit())
253 BuildScopeInformation(
Init, ParentScope);
257void JumpScopeChecker::BuildScopeInformation(VarDecl *D,
258 const BlockDecl *BDecl,
259 unsigned &ParentScope) {
267 std::pair<unsigned,unsigned> Diags;
268 switch (destructKind) {
270 Diags =
ScopePair(diag::note_enters_block_captures_cxx_obj,
271 diag::note_exits_block_captures_cxx_obj);
274 Diags =
ScopePair(diag::note_enters_block_captures_strong,
275 diag::note_exits_block_captures_strong);
278 Diags =
ScopePair(diag::note_enters_block_captures_weak,
279 diag::note_exits_block_captures_weak);
282 Diags =
ScopePair(diag::note_enters_block_captures_non_trivial_c_struct,
283 diag::note_exits_block_captures_non_trivial_c_struct);
286 llvm_unreachable(
"non-lifetime captured variable");
291 Scopes.push_back(GotoScope(ParentScope,
292 Diags.first, Diags.second, Loc));
293 ParentScope = Scopes.size()-1;
299void JumpScopeChecker::BuildScopeInformation(CompoundLiteralExpr *CLE,
300 unsigned &ParentScope) {
303 unsigned InDiag = diag::note_enters_compound_literal_scope;
304 unsigned OutDiag = diag::note_exits_compound_literal_scope;
305 Scopes.push_back(GotoScope(ParentScope, InDiag, OutDiag, CLE->
getExprLoc()));
306 ParentScope = Scopes.size() - 1;
313void JumpScopeChecker::BuildScopeInformation(Stmt *S,
314 unsigned &origParentScope) {
318 unsigned independentParentScope = origParentScope;
320 ? origParentScope : independentParentScope);
322 unsigned StmtsToSkip = 0u;
326 case Stmt::AddrLabelExprClass:
330 case Stmt::ObjCForCollectionStmtClass: {
332 unsigned Diag = diag::note_protected_by_objc_fast_enumeration;
333 unsigned NewParentScope = Scopes.size();
335 BuildScopeInformation(CS->getBody(), NewParentScope);
339 case Stmt::IndirectGotoStmtClass:
346 goto RecordJumpScope;
348 LabelAndGotoScopes[S] = ParentScope;
349 IndirectJumps.push_back(S);
352 case Stmt::SwitchStmtClass:
356 BuildScopeInformation(
Init, ParentScope);
360 BuildScopeInformation(Var, ParentScope);
363 goto RecordJumpScope;
365 case Stmt::GCCAsmStmtClass:
370 case Stmt::GotoStmtClass:
374 LabelAndGotoScopes[S] = ParentScope;
378 case Stmt::IfStmtClass: {
380 bool AMDGPUPredicate =
false;
383 (AMDGPUPredicate = this->S.AMDGPU().IsPredicate(IS->
getCond()))))
386 unsigned Diag = diag::note_protected_by_if_available;
388 Diag = diag::note_protected_by_constexpr_if;
390 Diag = diag::note_protected_by_consteval_if;
391 else if (AMDGPUPredicate)
392 Diag = diag::note_amdgcn_protected_by_predicate;
395 BuildScopeInformation(Var, ParentScope);
398 unsigned NewParentScope = Scopes.size();
402 BuildScopeInformation(IS->
getCond(), NewParentScope);
405 NewParentScope = Scopes.size();
407 BuildScopeInformation(IS->
getThen(), NewParentScope);
408 if (Stmt *Else = IS->
getElse()) {
409 NewParentScope = Scopes.size();
411 BuildScopeInformation(Else, NewParentScope);
416 case Stmt::CXXTryStmtClass: {
419 unsigned NewParentScope = Scopes.size();
420 Scopes.push_back(GotoScope(ParentScope,
421 diag::note_protected_by_cxx_try,
422 diag::note_exits_cxx_try,
425 BuildScopeInformation(TryBlock, NewParentScope);
431 unsigned NewParentScope = Scopes.size();
432 Scopes.push_back(GotoScope(ParentScope,
433 diag::note_protected_by_cxx_catch,
434 diag::note_exits_cxx_catch,
441 case Stmt::SEHTryStmtClass: {
444 unsigned NewParentScope = Scopes.size();
445 Scopes.push_back(GotoScope(ParentScope,
446 diag::note_protected_by_seh_try,
447 diag::note_exits_seh_try,
450 BuildScopeInformation(TryBlock, NewParentScope);
455 unsigned NewParentScope = Scopes.size();
456 Scopes.push_back(GotoScope(ParentScope,
457 diag::note_protected_by_seh_except,
458 diag::note_exits_seh_except,
459 Except->getSourceRange().getBegin()));
460 BuildScopeInformation(Except->getBlock(), NewParentScope);
462 unsigned NewParentScope = Scopes.size();
463 Scopes.push_back(GotoScope(ParentScope,
464 diag::note_protected_by_seh_finally,
465 diag::note_exits_seh_finally,
466 Finally->getSourceRange().getBegin()));
467 BuildScopeInformation(Finally->getBlock(), NewParentScope);
473 case Stmt::DeclStmtClass: {
479 for (
auto *I : DS->
decls())
480 BuildScopeInformation(I, origParentScope);
484 case Stmt::StmtExprClass: {
491 unsigned NewParentScope = Scopes.size();
492 Scopes.push_back(GotoScope(ParentScope,
493 diag::note_enters_statement_expression,
495 BuildScopeInformation(SE->
getSubStmt(), NewParentScope);
499 case Stmt::ObjCAtTryStmtClass: {
505 unsigned NewParentScope = Scopes.size();
506 Scopes.push_back(GotoScope(ParentScope,
507 diag::note_protected_by_objc_try,
508 diag::note_exits_objc_try,
511 BuildScopeInformation(TryPart, NewParentScope);
516 unsigned NewParentScope = Scopes.size();
517 Scopes.push_back(GotoScope(ParentScope,
518 diag::note_protected_by_objc_catch,
519 diag::note_exits_objc_catch,
520 AC->getAtCatchLoc()));
522 BuildScopeInformation(AC->getCatchBody(), NewParentScope);
527 unsigned NewParentScope = Scopes.size();
528 Scopes.push_back(GotoScope(ParentScope,
529 diag::note_protected_by_objc_finally,
530 diag::note_exits_objc_finally,
531 AF->getAtFinallyLoc()));
532 BuildScopeInformation(AF, NewParentScope);
538 case Stmt::ObjCAtSynchronizedStmtClass: {
548 unsigned NewParentScope = Scopes.size();
549 Scopes.push_back(GotoScope(ParentScope,
550 diag::note_protected_by_objc_synchronized,
551 diag::note_exits_objc_synchronized,
553 BuildScopeInformation(AS->
getSynchBody(), NewParentScope);
557 case Stmt::ObjCAutoreleasePoolStmtClass: {
562 unsigned NewParentScope = Scopes.size();
563 Scopes.push_back(GotoScope(ParentScope,
564 diag::note_protected_by_objc_autoreleasepool,
565 diag::note_exits_objc_autoreleasepool,
567 BuildScopeInformation(AS->
getSubStmt(), NewParentScope);
571 case Stmt::ExprWithCleanupsClass: {
576 for (
unsigned i = 0, e = EWC->
getNumObjects(); i != e; ++i) {
577 if (
auto *BDecl = dyn_cast<BlockDecl *>(EWC->
getObject(i)))
578 for (
const auto &CI : BDecl->
captures()) {
579 VarDecl *variable = CI.getVariable();
580 BuildScopeInformation(variable, BDecl, origParentScope);
582 else if (
auto *CLE = dyn_cast<CompoundLiteralExpr *>(EWC->
getObject(i)))
583 BuildScopeInformation(CLE, origParentScope);
585 llvm_unreachable(
"unexpected cleanup object type");
590 case Stmt::MaterializeTemporaryExprClass: {
595 const Expr *ExtendedObject =
598 Scopes.push_back(GotoScope(ParentScope, 0,
599 diag::note_exits_temporary_dtor,
601 origParentScope = Scopes.size()-1;
607 case Stmt::DeferStmtClass: {
612 unsigned NewParentScope = Scopes.size();
613 Scopes.emplace_back(ParentScope, diag::note_protected_by_defer_stmt, 0,
615 origParentScope = NewParentScope;
620 unsigned NewParentScope = Scopes.size();
621 Scopes.emplace_back(ParentScope, diag::note_enters_defer_stmt,
622 diag::note_exits_defer_stmt, D->getDeferLoc());
623 BuildScopeInformation(D->
getBody(), NewParentScope);
628 case Stmt::CaseStmtClass:
629 case Stmt::DefaultStmtClass:
630 case Stmt::LabelStmtClass:
631 LabelAndGotoScopes[S] = ParentScope;
634 case Stmt::OpenACCComputeConstructClass: {
635 unsigned NewParentScope = Scopes.size();
637 Scopes.push_back(GotoScope(
638 ParentScope, diag::note_acc_branch_into_compute_construct,
639 diag::note_acc_branch_out_of_compute_construct, CC->getBeginLoc()));
642 if (CC->getStructuredBlock())
643 BuildScopeInformation(CC->getStructuredBlock(), NewParentScope);
647 case Stmt::OpenACCCombinedConstructClass: {
648 unsigned NewParentScope = Scopes.size();
650 Scopes.push_back(GotoScope(
651 ParentScope, diag::note_acc_branch_into_compute_construct,
652 diag::note_acc_branch_out_of_compute_construct, CC->getBeginLoc()));
656 BuildScopeInformation(CC->
getLoop(), NewParentScope);
661 if (
auto *ED = dyn_cast<OMPExecutableDirective>(S)) {
662 if (!ED->isStandaloneDirective()) {
663 unsigned NewParentScope = Scopes.size();
664 Scopes.emplace_back(ParentScope,
665 diag::note_omp_protected_structured_block,
666 diag::note_omp_exits_structured_block,
667 ED->getStructuredBlock()->getBeginLoc());
668 BuildScopeInformation(ED->getStructuredBlock(), NewParentScope);
675 for (Stmt *SubStmt : S->
children()) {
688 if (SwitchCase *SC = dyn_cast<SwitchCase>(SubStmt))
689 Next = SC->getSubStmt();
690 else if (LabelStmt *LS = dyn_cast<LabelStmt>(SubStmt))
691 Next = LS->getSubStmt();
692 else if (AttributedStmt *AS = dyn_cast<AttributedStmt>(SubStmt)) {
693 if (GetMustTailAttr(AS)) {
694 LabelAndGotoScopes[AS] = ParentScope;
695 MustTailStmts.push_back(AS);
701 LabelAndGotoScopes[SubStmt] = ParentScope;
706 BuildScopeInformation(SubStmt, ParentScope);
712void JumpScopeChecker::VerifyJumps() {
713 while (!Jumps.empty()) {
714 Stmt *Jump = Jumps.pop_back_val();
717 if (GotoStmt *GS = dyn_cast<GotoStmt>(Jump)) {
719 if (GS->getLabel()->getStmt()) {
720 CheckJump(GS, GS->getLabel()->getStmt(), GS->getGotoLoc(),
721 diag::err_goto_into_protected_scope,
722 diag::ext_goto_into_protected_scope,
723 S.getLangOpts().CPlusPlus
724 ? diag::warn_cxx98_compat_goto_into_protected_scope
725 : diag::warn_cpp_compat_goto_into_protected_scope);
736 if (
auto *G = dyn_cast<GCCAsmStmt>(Jump)) {
737 for (AddrLabelExpr *L : G->labels()) {
738 LabelDecl *LD = L->getLabel();
739 unsigned JumpScope = LabelAndGotoScopes[G];
740 unsigned TargetScope = LabelAndGotoScopes[LD->
getStmt()];
741 if (JumpScope != TargetScope)
742 DiagnoseIndirectOrAsmJump(G, JumpScope, LD, TargetScope);
748 if (IndirectGotoStmt *IGS = dyn_cast<IndirectGotoStmt>(Jump)) {
749 LabelDecl *
Target = IGS->getConstantTarget();
750 CheckJump(IGS,
Target->getStmt(), IGS->getGotoLoc(),
751 diag::err_goto_into_protected_scope,
752 diag::ext_goto_into_protected_scope,
753 S.getLangOpts().CPlusPlus
754 ? diag::warn_cxx98_compat_goto_into_protected_scope
755 : diag::warn_cpp_compat_goto_into_protected_scope);
765 if (CaseStmt *CS = dyn_cast<CaseStmt>(SC))
767 else if (DefaultStmt *DS = dyn_cast<DefaultStmt>(SC))
770 Loc = SC->getBeginLoc();
771 CheckJump(SS, SC, Loc, diag::err_switch_into_protected_scope, 0,
772 S.getLangOpts().CPlusPlus
773 ? diag::warn_cxx98_compat_switch_into_protected_scope
774 : diag::warn_cpp_compat_switch_into_protected_scope);
796void JumpScopeChecker::VerifyIndirectJumps() {
797 if (IndirectJumps.empty())
801 if (IndirectJumpTargets.empty()) {
802 S.Diag(IndirectJumps[0]->getBeginLoc(),
803 diag::err_indirect_goto_without_addrlabel);
809 using JumpScope = std::pair<unsigned, Stmt *>;
810 SmallVector<JumpScope, 32> JumpScopes;
812 llvm::DenseMap<unsigned, Stmt*> JumpScopesMap;
813 for (Stmt *IG : IndirectJumps) {
816 unsigned IGScope = LabelAndGotoScopes[IG];
817 JumpScopesMap.try_emplace(IGScope, IG);
819 JumpScopes.reserve(JumpScopesMap.size());
820 for (
auto &Pair : JumpScopesMap)
821 JumpScopes.emplace_back(Pair);
827 llvm::DenseMap<unsigned, LabelDecl*> TargetScopes;
828 for (LabelDecl *TheLabel : IndirectJumpTargets) {
831 unsigned LabelScope = LabelAndGotoScopes[TheLabel->getStmt()];
832 TargetScopes.try_emplace(LabelScope, TheLabel);
843 llvm::BitVector Reachable(Scopes.size(),
false);
844 for (
auto [TargetScope, TargetLabel] : TargetScopes) {
850 unsigned Min = TargetScope;
858 if (Scopes[
Min].InDiag)
break;
860 Min = Scopes[
Min].ParentScope;
865 for (
auto [JumpScope, JumpStmt] : JumpScopes) {
866 unsigned Scope = JumpScope;
872 bool IsReachable =
false;
874 if (Reachable.test(Scope)) {
877 for (
unsigned S = JumpScope; S != Scope; S = Scopes[S].ParentScope)
885 if (Scope == 0 || Scope <
Min)
break;
888 if (Scopes[Scope].OutDiag)
break;
890 Scope = Scopes[Scope].ParentScope;
894 if (IsReachable)
continue;
896 DiagnoseIndirectOrAsmJump(JumpStmt, JumpScope, TargetLabel, TargetScope);
904 return (JumpDiag == diag::err_goto_into_protected_scope &&
905 (InDiagNote == diag::note_protected_by_variable_init ||
906 InDiagNote == diag::note_protected_by_variable_nontriv_destructor));
913 InDiagNote == diag::note_protected_by_variable_non_pod;
920 InDiagNote == diag::note_protected_by_variable_init;
929 S.
Diag(Jump->
getBeginLoc(), diag::err_indirect_goto_in_protected_scope)
931 S.
Diag(
Target->getStmt()->getIdentLoc(), diag::note_indirect_goto_target)
937void JumpScopeChecker::NoteJumpIntoScopes(ArrayRef<unsigned> ToScopes) {
940 for (
unsigned I = 0, E = ToScopes.size(); I != E; ++I)
941 if (Scopes[ToScopes[I]].InDiag)
942 S.Diag(Scopes[ToScopes[I]].Loc, Scopes[ToScopes[I]].InDiag);
946void JumpScopeChecker::DiagnoseIndirectOrAsmJump(Stmt *Jump,
unsigned JumpScope,
948 unsigned TargetScope) {
952 unsigned Common = GetDeepestCommonScope(JumpScope, TargetScope);
953 bool Diagnosed =
false;
956 for (
unsigned I = JumpScope; I != Common; I = Scopes[I].ParentScope)
957 if (Scopes[I].OutDiag) {
959 S.Diag(Scopes[I].Loc, Scopes[I].OutDiag);
962 SmallVector<unsigned, 10> ToScopesCXX98Compat, ToScopesCppCompat;
965 for (
unsigned I = TargetScope; I != Common; I = Scopes[I].ParentScope)
967 ToScopesCXX98Compat.push_back(I);
969 ToScopesCppCompat.push_back(I);
970 else if (Scopes[I].InDiag) {
972 S.Diag(Scopes[I].Loc, Scopes[I].InDiag);
978 auto Diag = [&](
unsigned DiagId,
const SmallVectorImpl<unsigned> &Notes) {
980 S.Diag(
Target->getStmt()->getIdentLoc(), diag::note_indirect_goto_target)
982 NoteJumpIntoScopes(Notes);
984 if (!ToScopesCXX98Compat.empty())
985 Diag(diag::warn_cxx98_compat_indirect_goto_in_protected_scope,
986 ToScopesCXX98Compat);
987 else if (!ToScopesCppCompat.empty())
988 Diag(diag::warn_cpp_compat_indirect_goto_in_protected_scope,
995void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc,
996 unsigned JumpDiagError,
997 unsigned JumpDiagWarning,
998 unsigned JumpDiagCompat) {
1004 unsigned FromScope = LabelAndGotoScopes[From];
1005 unsigned ToScope = LabelAndGotoScopes[To];
1008 if (FromScope == ToScope)
return;
1014 for (
unsigned I = FromScope; I > ToScope; I = Scopes[I].ParentScope) {
1015 if (Scopes[I].InDiag == diag::note_protected_by_seh_finally) {
1016 S.Diag(From->
getBeginLoc(), diag::warn_jump_out_of_seh_finally);
1018 }
else if (Scopes[I].InDiag ==
1019 diag::note_omp_protected_structured_block) {
1020 S.Diag(From->
getBeginLoc(), diag::err_goto_into_protected_scope);
1021 S.Diag(To->
getBeginLoc(), diag::note_omp_exits_structured_block);
1023 }
else if (Scopes[I].InDiag ==
1024 diag::note_acc_branch_into_compute_construct) {
1025 S.Diag(From->
getBeginLoc(), diag::err_goto_into_protected_scope);
1026 S.Diag(Scopes[I].Loc, diag::note_acc_branch_out_of_compute_construct);
1028 }
else if (Scopes[I].OutDiag == diag::note_exits_defer_stmt) {
1029 S.Diag(From->
getBeginLoc(), diag::err_goto_into_protected_scope);
1030 S.Diag(Scopes[I].Loc, diag::note_exits_defer_stmt);
1036 unsigned CommonScope = GetDeepestCommonScope(FromScope, ToScope);
1039 if (CommonScope == ToScope)
return;
1042 SmallVector<unsigned, 10> ToScopesCompat;
1043 SmallVector<unsigned, 10> ToScopesError;
1044 SmallVector<unsigned, 10> ToScopesWarning;
1045 for (
unsigned I = ToScope; I != CommonScope; I = Scopes[I].ParentScope) {
1046 if (S.getLangOpts().MSVCCompat && S.getLangOpts().CPlusPlus &&
1047 JumpDiagWarning != 0 &&
1049 ToScopesWarning.push_back(I);
1052 ToScopesCompat.push_back(I);
1053 else if (Scopes[I].InDiag)
1054 ToScopesError.push_back(I);
1058 if (!ToScopesWarning.empty()) {
1059 S.Diag(DiagLoc, JumpDiagWarning);
1060 NoteJumpIntoScopes(ToScopesWarning);
1067 if (!ToScopesError.empty()) {
1068 S.Diag(DiagLoc, JumpDiagError);
1069 NoteJumpIntoScopes(ToScopesError);
1073 if (ToScopesError.empty() && !ToScopesCompat.empty()) {
1074 S.Diag(DiagLoc, JumpDiagCompat);
1075 NoteJumpIntoScopes(ToScopesCompat);
1079void JumpScopeChecker::CheckGotoStmt(GotoStmt *GS) {
1081 S.Diag(GS->
getGotoLoc(), diag::err_goto_ms_asm_label)
1088void JumpScopeChecker::VerifyMustTailStmts() {
1089 for (AttributedStmt *AS : MustTailStmts) {
1090 for (
unsigned I = LabelAndGotoScopes[AS]; I; I = Scopes[I].ParentScope) {
1091 if (Scopes[I].OutDiag) {
1092 S.Diag(AS->
getBeginLoc(), diag::err_musttail_scope);
1093 S.Diag(Scopes[I].Loc, Scopes[I].OutDiag);
1099const Attr *JumpScopeChecker::GetMustTailAttr(AttributedStmt *AS) {
1100 ArrayRef<const Attr *> Attrs = AS->
getAttrs();
1103 return Iter != Attrs.end() ? *Iter :
nullptr;
1107 (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).
U cast(CodeGen::Address addr)