clang 22.0.0git
JumpDiagnostics.cpp
Go to the documentation of this file.
1//===--- JumpDiagnostics.cpp - Protected scope jump analysis ------*- C++ -*-=//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the JumpScopeChecker class, which is used to diagnose
10// jumps that enter a protected scope in an invalid way.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/DeclCXX.h"
15#include "clang/AST/Expr.h"
16#include "clang/AST/ExprCXX.h"
17#include "clang/AST/StmtCXX.h"
18#include "clang/AST/StmtObjC.h"
23#include "llvm/ADT/BitVector.h"
24using namespace clang;
25
26namespace {
27
28/// JumpScopeChecker - This object is used by Sema to diagnose invalid jumps
29/// into VLA and other protected scopes. For example, this rejects:
30/// goto L;
31/// int a[n];
32/// L:
33///
34/// We also detect jumps out of protected scopes when it's not possible to do
35/// cleanups properly. Indirect jumps and ASM jumps can't do cleanups because
36/// the target is unknown. Return statements with \c [[clang::musttail]] cannot
37/// handle any cleanups due to the nature of a tail call.
38class JumpScopeChecker {
39 Sema &S;
40
41 /// Permissive - True when recovering from errors, in which case precautions
42 /// are taken to handle incomplete scope information.
43 const bool Permissive;
44
45 /// GotoScope - This is a record that we use to keep track of all of the
46 /// scopes that are introduced by VLAs and other things that scope jumps like
47 /// gotos. This scope tree has nothing to do with the source scope tree,
48 /// because you can have multiple VLA scopes per compound statement, and most
49 /// compound statements don't introduce any scopes.
50 struct GotoScope {
51 /// ParentScope - The index in ScopeMap of the parent scope. This is 0 for
52 /// the parent scope is the function body.
53 unsigned ParentScope;
54
55 /// InDiag - The note to emit if there is a jump into this scope.
56 unsigned InDiag;
57
58 /// OutDiag - The note to emit if there is an indirect jump out
59 /// of this scope. Direct jumps always clean up their current scope
60 /// in an orderly way.
61 unsigned OutDiag;
62
63 /// Loc - Location to emit the diagnostic.
64 SourceLocation Loc;
65
66 GotoScope(unsigned parentScope, unsigned InDiag, unsigned OutDiag,
67 SourceLocation L)
68 : ParentScope(parentScope), InDiag(InDiag), OutDiag(OutDiag), Loc(L) {}
69 };
70
71 SmallVector<GotoScope, 48> Scopes;
72 llvm::DenseMap<Stmt*, unsigned> LabelAndGotoScopes;
73 SmallVector<Stmt*, 16> Jumps;
74
75 SmallVector<Stmt*, 4> IndirectJumps;
76 SmallVector<LabelDecl *, 4> IndirectJumpTargets;
77 SmallVector<AttributedStmt *, 4> MustTailStmts;
78
79public:
80 JumpScopeChecker(Stmt *Body, Sema &S);
81private:
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);
87
88 void VerifyJumps();
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);
99
100 unsigned GetDeepestCommonScope(unsigned A, unsigned B);
101};
102} // end anonymous namespace
103
104#define CHECK_PERMISSIVE(x) (assert(Permissive || !(x)), (Permissive && (x)))
105
106JumpScopeChecker::JumpScopeChecker(Stmt *Body, Sema &s)
107 : S(s), Permissive(s.hasAnyUnrecoverableErrorsInThisFunction()) {
108 // Add a scope entry for function scope.
109 Scopes.push_back(GotoScope(~0U, ~0U, ~0U, SourceLocation()));
110
111 // Build information for the top level compound statement, so that we have a
112 // defined scope record for every "goto" and label.
113 unsigned BodyParentScope = 0;
114 BuildScopeInformation(Body, BodyParentScope);
115
116 // Check that all jumps we saw are kosher.
117 VerifyJumps();
118 VerifyIndirectJumps();
119 VerifyMustTailStmts();
120}
121
122/// GetDeepestCommonScope - Finds the innermost scope enclosing the
123/// two scopes.
124unsigned JumpScopeChecker::GetDeepestCommonScope(unsigned A, unsigned B) {
125 while (A != B) {
126 // Inner scopes are created after outer scopes and therefore have
127 // higher indices.
128 if (A < B) {
129 assert(Scopes[B].ParentScope < B);
130 B = Scopes[B].ParentScope;
131 } else {
132 assert(Scopes[A].ParentScope < A);
133 A = Scopes[A].ParentScope;
134 }
135 }
136 return A;
137}
138
139typedef std::pair<unsigned,unsigned> ScopePair;
140
141/// GetDiagForGotoScopeDecl - If this decl induces a new goto scope, return a
142/// diagnostic that should be emitted if control goes over it. If not, return 0.
144 if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
145 unsigned InDiag = 0;
146 unsigned OutDiag = 0;
147
148 if (VD->getType()->isVariablyModifiedType())
149 InDiag = diag::note_protected_by_vla;
150
151 if (VD->hasAttr<BlocksAttr>())
152 return ScopePair(diag::note_protected_by___block,
153 diag::note_exits___block);
154
155 if (VD->hasAttr<CleanupAttr>())
156 return ScopePair(diag::note_protected_by_cleanup,
157 diag::note_exits_cleanup);
158
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);
164
166 return ScopePair(diag::note_protected_by_objc_weak_init,
167 diag::note_exits_objc_weak);
168
170 return ScopePair(diag::note_protected_by_non_trivial_c_struct_init,
171 diag::note_exits_dtor);
172
174 OutDiag = diag::note_exits_dtor;
175 break;
176
178 break;
179 }
180 }
181
182 if (const Expr *Init = VD->getInit();
183 VD->hasLocalStorage() && Init && !Init->containsErrors()) {
184 // C++11 [stmt.dcl]p3:
185 // A program that jumps from a point where a variable with automatic
186 // storage duration is not in scope to a point where it is in scope
187 // is ill-formed unless the variable has scalar type, class type with
188 // a trivial default constructor and a trivial destructor, a
189 // cv-qualified version of one of these types, or an array of one of
190 // the preceding types and is declared without an initializer.
191
192 // C++03 [stmt.dcl.p3:
193 // A program that jumps from a point where a local variable
194 // with automatic storage duration is not in scope to a point
195 // where it is in scope is ill-formed unless the variable has
196 // POD type and is declared without an initializer.
197
198 InDiag = diag::note_protected_by_variable_init;
199
200 // For a variable of (array of) class type declared without an
201 // initializer, we will have call-style initialization and the initializer
202 // will be the CXXConstructExpr with no intervening nodes.
203 if (const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(Init)) {
204 const CXXConstructorDecl *Ctor = CCE->getConstructor();
205 if (Ctor->isTrivial() && Ctor->isDefaultConstructor() &&
206 VD->getInitStyle() == VarDecl::CallInit) {
207 if (OutDiag)
208 InDiag = diag::note_protected_by_variable_nontriv_destructor;
209 else if (!Ctor->getParent()->isPOD())
210 InDiag = diag::note_protected_by_variable_non_pod;
211 else
212 InDiag = 0;
213 }
214 }
215 }
216
217 return ScopePair(InDiag, OutDiag);
218 }
219
220 if (const TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(D)) {
221 if (TD->getUnderlyingType()->isVariablyModifiedType())
222 return ScopePair(isa<TypedefDecl>(TD)
223 ? diag::note_protected_by_vla_typedef
224 : diag::note_protected_by_vla_type_alias,
225 0);
226 }
227
228 return ScopePair(0U, 0U);
229}
230
231/// Build scope information for a declaration that is part of a DeclStmt.
232void JumpScopeChecker::BuildScopeInformation(Decl *D, unsigned &ParentScope) {
233 // If this decl causes a new scope, push and switch to it.
234 std::pair<unsigned,unsigned> Diags = GetDiagForGotoScopeDecl(S, D);
235 if (Diags.first || Diags.second) {
236 Scopes.push_back(GotoScope(ParentScope, Diags.first, Diags.second,
237 D->getLocation()));
238 ParentScope = Scopes.size()-1;
239 }
240
241 // If the decl has an initializer, walk it with the potentially new
242 // scope we just installed.
243 if (VarDecl *VD = dyn_cast<VarDecl>(D))
244 if (Expr *Init = VD->getInit())
245 BuildScopeInformation(Init, ParentScope);
246}
247
248/// Build scope information for a captured block literal variables.
249void JumpScopeChecker::BuildScopeInformation(VarDecl *D,
250 const BlockDecl *BDecl,
251 unsigned &ParentScope) {
252 // exclude captured __block variables; there's no destructor
253 // associated with the block literal for them.
254 if (D->hasAttr<BlocksAttr>())
255 return;
256 QualType T = D->getType();
257 QualType::DestructionKind destructKind = T.isDestructedType();
258 if (destructKind != QualType::DK_none) {
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);
264 break;
266 Diags = ScopePair(diag::note_enters_block_captures_strong,
267 diag::note_exits_block_captures_strong);
268 break;
270 Diags = ScopePair(diag::note_enters_block_captures_weak,
271 diag::note_exits_block_captures_weak);
272 break;
274 Diags = ScopePair(diag::note_enters_block_captures_non_trivial_c_struct,
275 diag::note_exits_block_captures_non_trivial_c_struct);
276 break;
278 llvm_unreachable("non-lifetime captured variable");
279 }
280 SourceLocation Loc = D->getLocation();
281 if (Loc.isInvalid())
282 Loc = BDecl->getLocation();
283 Scopes.push_back(GotoScope(ParentScope,
284 Diags.first, Diags.second, Loc));
285 ParentScope = Scopes.size()-1;
286 }
287}
288
289/// Build scope information for compound literals of C struct types that are
290/// non-trivial to destruct.
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;
297}
298
299/// BuildScopeInformation - The statements from CI to CE are known to form a
300/// coherent VLA scope with a specified parent node. Walk through the
301/// statements, adding any labels or gotos to LabelAndGotoScopes and recursively
302/// walking the AST as needed.
303void JumpScopeChecker::BuildScopeInformation(Stmt *S,
304 unsigned &origParentScope) {
305 // If this is a statement, rather than an expression, scopes within it don't
306 // propagate out into the enclosing scope. Otherwise we have to worry
307 // about block literals, which have the lifetime of their enclosing statement.
308 unsigned independentParentScope = origParentScope;
309 unsigned &ParentScope = ((isa<Expr>(S) && !isa<StmtExpr>(S))
310 ? origParentScope : independentParentScope);
311
312 unsigned StmtsToSkip = 0u;
313
314 // If we found a label, remember that it is in ParentScope scope.
315 switch (S->getStmtClass()) {
316 case Stmt::AddrLabelExprClass:
317 IndirectJumpTargets.push_back(cast<AddrLabelExpr>(S)->getLabel());
318 break;
319
320 case Stmt::ObjCForCollectionStmtClass: {
321 auto *CS = cast<ObjCForCollectionStmt>(S);
322 unsigned Diag = diag::note_protected_by_objc_fast_enumeration;
323 unsigned NewParentScope = Scopes.size();
324 Scopes.push_back(GotoScope(ParentScope, Diag, 0, S->getBeginLoc()));
325 BuildScopeInformation(CS->getBody(), NewParentScope);
326 return;
327 }
328
329 case Stmt::IndirectGotoStmtClass:
330 // "goto *&&lbl;" is a special case which we treat as equivalent
331 // to a normal goto. In addition, we don't calculate scope in the
332 // operand (to avoid recording the address-of-label use), which
333 // works only because of the restricted set of expressions which
334 // we detect as constant targets.
335 if (cast<IndirectGotoStmt>(S)->getConstantTarget())
336 goto RecordJumpScope;
337
338 LabelAndGotoScopes[S] = ParentScope;
339 IndirectJumps.push_back(S);
340 break;
341
342 case Stmt::SwitchStmtClass:
343 // Evaluate the C++17 init stmt and condition variable
344 // before entering the scope of the switch statement.
345 if (Stmt *Init = cast<SwitchStmt>(S)->getInit()) {
346 BuildScopeInformation(Init, ParentScope);
347 ++StmtsToSkip;
348 }
349 if (VarDecl *Var = cast<SwitchStmt>(S)->getConditionVariable()) {
350 BuildScopeInformation(Var, ParentScope);
351 ++StmtsToSkip;
352 }
353 goto RecordJumpScope;
354
355 case Stmt::GCCAsmStmtClass:
356 if (!cast<GCCAsmStmt>(S)->isAsmGoto())
357 break;
358 [[fallthrough]];
359
360 case Stmt::GotoStmtClass:
361 RecordJumpScope:
362 // Remember both what scope a goto is in as well as the fact that we have
363 // it. This makes the second scan not have to walk the AST again.
364 LabelAndGotoScopes[S] = ParentScope;
365 Jumps.push_back(S);
366 break;
367
368 case Stmt::IfStmtClass: {
369 IfStmt *IS = cast<IfStmt>(S);
370 if (!(IS->isConstexpr() || IS->isConsteval() ||
372 break;
373
374 unsigned Diag = diag::note_protected_by_if_available;
375 if (IS->isConstexpr())
376 Diag = diag::note_protected_by_constexpr_if;
377 else if (IS->isConsteval())
378 Diag = diag::note_protected_by_consteval_if;
379
380 if (VarDecl *Var = IS->getConditionVariable())
381 BuildScopeInformation(Var, ParentScope);
382
383 // Cannot jump into the middle of the condition.
384 unsigned NewParentScope = Scopes.size();
385 Scopes.push_back(GotoScope(ParentScope, Diag, 0, IS->getBeginLoc()));
386
387 if (!IS->isConsteval())
388 BuildScopeInformation(IS->getCond(), NewParentScope);
389
390 // Jumps into either arm of an 'if constexpr' are not allowed.
391 NewParentScope = Scopes.size();
392 Scopes.push_back(GotoScope(ParentScope, Diag, 0, IS->getBeginLoc()));
393 BuildScopeInformation(IS->getThen(), NewParentScope);
394 if (Stmt *Else = IS->getElse()) {
395 NewParentScope = Scopes.size();
396 Scopes.push_back(GotoScope(ParentScope, Diag, 0, IS->getBeginLoc()));
397 BuildScopeInformation(Else, NewParentScope);
398 }
399 return;
400 }
401
402 case Stmt::CXXTryStmtClass: {
403 CXXTryStmt *TS = cast<CXXTryStmt>(S);
404 {
405 unsigned NewParentScope = Scopes.size();
406 Scopes.push_back(GotoScope(ParentScope,
407 diag::note_protected_by_cxx_try,
408 diag::note_exits_cxx_try,
409 TS->getSourceRange().getBegin()));
410 if (Stmt *TryBlock = TS->getTryBlock())
411 BuildScopeInformation(TryBlock, NewParentScope);
412 }
413
414 // Jump from the catch into the try is not allowed either.
415 for (unsigned I = 0, E = TS->getNumHandlers(); I != E; ++I) {
416 CXXCatchStmt *CS = TS->getHandler(I);
417 unsigned NewParentScope = Scopes.size();
418 Scopes.push_back(GotoScope(ParentScope,
419 diag::note_protected_by_cxx_catch,
420 diag::note_exits_cxx_catch,
421 CS->getSourceRange().getBegin()));
422 BuildScopeInformation(CS->getHandlerBlock(), NewParentScope);
423 }
424 return;
425 }
426
427 case Stmt::SEHTryStmtClass: {
428 SEHTryStmt *TS = cast<SEHTryStmt>(S);
429 {
430 unsigned NewParentScope = Scopes.size();
431 Scopes.push_back(GotoScope(ParentScope,
432 diag::note_protected_by_seh_try,
433 diag::note_exits_seh_try,
434 TS->getSourceRange().getBegin()));
435 if (Stmt *TryBlock = TS->getTryBlock())
436 BuildScopeInformation(TryBlock, NewParentScope);
437 }
438
439 // Jump from __except or __finally into the __try are not allowed either.
440 if (SEHExceptStmt *Except = TS->getExceptHandler()) {
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);
447 } else if (SEHFinallyStmt *Finally = TS->getFinallyHandler()) {
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);
454 }
455
456 return;
457 }
458
459 case Stmt::DeclStmtClass: {
460 // If this is a declstmt with a VLA definition, it defines a scope from here
461 // to the end of the containing context.
462 DeclStmt *DS = cast<DeclStmt>(S);
463 // The decl statement creates a scope if any of the decls in it are VLAs
464 // or have the cleanup attribute.
465 for (auto *I : DS->decls())
466 BuildScopeInformation(I, origParentScope);
467 return;
468 }
469
470 case Stmt::StmtExprClass: {
471 // [GNU]
472 // Jumping into a statement expression with goto or using
473 // a switch statement outside the statement expression with
474 // a case or default label inside the statement expression is not permitted.
475 // Jumping out of a statement expression is permitted.
476 StmtExpr *SE = cast<StmtExpr>(S);
477 unsigned NewParentScope = Scopes.size();
478 Scopes.push_back(GotoScope(ParentScope,
479 diag::note_enters_statement_expression,
480 /*OutDiag=*/0, SE->getBeginLoc()));
481 BuildScopeInformation(SE->getSubStmt(), NewParentScope);
482 return;
483 }
484
485 case Stmt::ObjCAtTryStmtClass: {
486 // Disallow jumps into any part of an @try statement by pushing a scope and
487 // walking all sub-stmts in that scope.
488 ObjCAtTryStmt *AT = cast<ObjCAtTryStmt>(S);
489 // Recursively walk the AST for the @try part.
490 {
491 unsigned NewParentScope = Scopes.size();
492 Scopes.push_back(GotoScope(ParentScope,
493 diag::note_protected_by_objc_try,
494 diag::note_exits_objc_try,
495 AT->getAtTryLoc()));
496 if (Stmt *TryPart = AT->getTryBody())
497 BuildScopeInformation(TryPart, NewParentScope);
498 }
499
500 // Jump from the catch to the finally or try is not valid.
501 for (ObjCAtCatchStmt *AC : AT->catch_stmts()) {
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()));
507 // @catches are nested and it isn't
508 BuildScopeInformation(AC->getCatchBody(), NewParentScope);
509 }
510
511 // Jump from the finally to the try or catch is not valid.
512 if (ObjCAtFinallyStmt *AF = AT->getFinallyStmt()) {
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);
519 }
520
521 return;
522 }
523
524 case Stmt::ObjCAtSynchronizedStmtClass: {
525 // Disallow jumps into the protected statement of an @synchronized, but
526 // allow jumps into the object expression it protects.
527 ObjCAtSynchronizedStmt *AS = cast<ObjCAtSynchronizedStmt>(S);
528 // Recursively walk the AST for the @synchronized object expr, it is
529 // evaluated in the normal scope.
530 BuildScopeInformation(AS->getSynchExpr(), ParentScope);
531
532 // Recursively walk the AST for the @synchronized part, protected by a new
533 // scope.
534 unsigned NewParentScope = Scopes.size();
535 Scopes.push_back(GotoScope(ParentScope,
536 diag::note_protected_by_objc_synchronized,
537 diag::note_exits_objc_synchronized,
538 AS->getAtSynchronizedLoc()));
539 BuildScopeInformation(AS->getSynchBody(), NewParentScope);
540 return;
541 }
542
543 case Stmt::ObjCAutoreleasePoolStmtClass: {
544 // Disallow jumps into the protected statement of an @autoreleasepool.
545 ObjCAutoreleasePoolStmt *AS = cast<ObjCAutoreleasePoolStmt>(S);
546 // Recursively walk the AST for the @autoreleasepool part, protected by a
547 // new scope.
548 unsigned NewParentScope = Scopes.size();
549 Scopes.push_back(GotoScope(ParentScope,
550 diag::note_protected_by_objc_autoreleasepool,
551 diag::note_exits_objc_autoreleasepool,
552 AS->getAtLoc()));
553 BuildScopeInformation(AS->getSubStmt(), NewParentScope);
554 return;
555 }
556
557 case Stmt::ExprWithCleanupsClass: {
558 // Disallow jumps past full-expressions that use blocks with
559 // non-trivial cleanups of their captures. This is theoretically
560 // implementable but a lot of work which we haven't felt up to doing.
561 ExprWithCleanups *EWC = cast<ExprWithCleanups>(S);
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);
567 }
568 else if (auto *CLE = dyn_cast<CompoundLiteralExpr *>(EWC->getObject(i)))
569 BuildScopeInformation(CLE, origParentScope);
570 else
571 llvm_unreachable("unexpected cleanup object type");
572 }
573 break;
574 }
575
576 case Stmt::MaterializeTemporaryExprClass: {
577 // Disallow jumps out of scopes containing temporaries lifetime-extended to
578 // automatic storage duration.
579 MaterializeTemporaryExpr *MTE = cast<MaterializeTemporaryExpr>(S);
580 if (MTE->getStorageDuration() == SD_Automatic) {
581 const Expr *ExtendedObject =
583 if (ExtendedObject->getType().isDestructedType()) {
584 Scopes.push_back(GotoScope(ParentScope, 0,
585 diag::note_exits_temporary_dtor,
586 ExtendedObject->getExprLoc()));
587 origParentScope = Scopes.size()-1;
588 }
589 }
590 break;
591 }
592
593 case Stmt::DeferStmtClass: {
594 auto *D = cast<DeferStmt>(S);
595
596 {
597 // Disallow jumps over defer statements.
598 unsigned NewParentScope = Scopes.size();
599 Scopes.emplace_back(ParentScope, diag::note_protected_by_defer_stmt, 0,
600 D->getDeferLoc());
601 origParentScope = NewParentScope;
602 }
603
604 // Disallow jumps into or out of defer statements.
605 {
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);
610 }
611 return;
612 }
613
614 case Stmt::CaseStmtClass:
615 case Stmt::DefaultStmtClass:
616 case Stmt::LabelStmtClass:
617 LabelAndGotoScopes[S] = ParentScope;
618 break;
619
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()));
626 // This can be 'null' if the 'body' is a break that we diagnosed, so no
627 // reason to put the scope into place.
628 if (CC->getStructuredBlock())
629 BuildScopeInformation(CC->getStructuredBlock(), NewParentScope);
630 return;
631 }
632
633 case Stmt::OpenACCCombinedConstructClass: {
634 unsigned NewParentScope = Scopes.size();
635 OpenACCCombinedConstruct *CC = cast<OpenACCCombinedConstruct>(S);
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()));
639 // This can be 'null' if the 'body' is a break that we diagnosed, so no
640 // reason to put the scope into place.
641 if (CC->getLoop())
642 BuildScopeInformation(CC->getLoop(), NewParentScope);
643 return;
644 }
645
646 default:
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);
655 return;
656 }
657 }
658 break;
659 }
660
661 for (Stmt *SubStmt : S->children()) {
662 if (!SubStmt)
663 continue;
664 if (StmtsToSkip) {
665 --StmtsToSkip;
666 continue;
667 }
668
669 // Cases, labels, attributes, and defaults aren't "scope parents". It's also
670 // important to handle these iteratively instead of recursively in
671 // order to avoid blowing out the stack.
672 while (true) {
673 Stmt *Next;
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);
682 }
683 Next = AS->getSubStmt();
684 } else
685 break;
686
687 LabelAndGotoScopes[SubStmt] = ParentScope;
688 SubStmt = Next;
689 }
690
691 // Recursively walk the AST.
692 BuildScopeInformation(SubStmt, ParentScope);
693 }
694}
695
696/// VerifyJumps - Verify each element of the Jumps array to see if they are
697/// valid, emitting diagnostics if not.
698void JumpScopeChecker::VerifyJumps() {
699 while (!Jumps.empty()) {
700 Stmt *Jump = Jumps.pop_back_val();
701
702 // With a goto,
703 if (GotoStmt *GS = dyn_cast<GotoStmt>(Jump)) {
704 // The label may not have a statement if it's coming from inline MS ASM.
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);
712 }
713 CheckGotoStmt(GS);
714 continue;
715 }
716
717 // If an asm goto jumps to a different scope, things like destructors or
718 // initializers might not be run which may be suprising to users. Perhaps
719 // this behavior can be changed in the future, but today Clang will not
720 // generate such code. Produce a diagnostic instead. See also the
721 // discussion here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110728.
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);
729 }
730 continue;
731 }
732
733 // We only get indirect gotos here when they have a constant target.
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);
742 continue;
743 }
744
745 SwitchStmt *SS = cast<SwitchStmt>(Jump);
746 for (SwitchCase *SC = SS->getSwitchCaseList(); SC;
747 SC = SC->getNextSwitchCase()) {
748 if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(SC)))
749 continue;
750 SourceLocation Loc;
751 if (CaseStmt *CS = dyn_cast<CaseStmt>(SC))
752 Loc = CS->getBeginLoc();
753 else if (DefaultStmt *DS = dyn_cast<DefaultStmt>(SC))
754 Loc = DS->getBeginLoc();
755 else
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);
761 }
762 }
763}
764
765/// VerifyIndirectJumps - Verify whether any possible indirect goto jump might
766/// cross a protection boundary. Unlike direct jumps, indirect goto jumps
767/// count cleanups as protection boundaries: since there's no way to know where
768/// the jump is going, we can't implicitly run the right cleanups the way we
769/// can with direct jumps. Thus, an indirect/asm jump is "trivial" if it
770/// bypasses no initializations and no teardowns. More formally, an
771/// indirect/asm jump from A to B is trivial if the path out from A to DCA(A,B)
772/// is trivial and the path in from DCA(A,B) to B is trivial, where DCA(A,B) is
773/// the deepest common ancestor of A and B. Jump-triviality is transitive but
774/// asymmetric.
775///
776/// A path in is trivial if none of the entered scopes have an InDiag.
777/// A path out is trivial is none of the exited scopes have an OutDiag.
778///
779/// Under these definitions, this function checks that the indirect
780/// jump between A and B is trivial for every indirect goto statement A
781/// and every label B whose address was taken in the function.
782void JumpScopeChecker::VerifyIndirectJumps() {
783 if (IndirectJumps.empty())
784 return;
785 // If there aren't any address-of-label expressions in this function,
786 // complain about the first indirect goto.
787 if (IndirectJumpTargets.empty()) {
788 S.Diag(IndirectJumps[0]->getBeginLoc(),
789 diag::err_indirect_goto_without_addrlabel);
790 return;
791 }
792 // Collect a single representative of every scope containing an indirect
793 // goto. For most code bases, this substantially cuts down on the number of
794 // jump sites we'll have to consider later.
795 using JumpScope = std::pair<unsigned, Stmt *>;
796 SmallVector<JumpScope, 32> JumpScopes;
797 {
798 llvm::DenseMap<unsigned, Stmt*> JumpScopesMap;
799 for (Stmt *IG : IndirectJumps) {
800 if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(IG)))
801 continue;
802 unsigned IGScope = LabelAndGotoScopes[IG];
803 JumpScopesMap.try_emplace(IGScope, IG);
804 }
805 JumpScopes.reserve(JumpScopesMap.size());
806 for (auto &Pair : JumpScopesMap)
807 JumpScopes.emplace_back(Pair);
808 }
809
810 // Collect a single representative of every scope containing a
811 // label whose address was taken somewhere in the function.
812 // For most code bases, there will be only one such scope.
813 llvm::DenseMap<unsigned, LabelDecl*> TargetScopes;
814 for (LabelDecl *TheLabel : IndirectJumpTargets) {
815 if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(TheLabel->getStmt())))
816 continue;
817 unsigned LabelScope = LabelAndGotoScopes[TheLabel->getStmt()];
818 TargetScopes.try_emplace(LabelScope, TheLabel);
819 }
820
821 // For each target scope, make sure it's trivially reachable from
822 // every scope containing a jump site.
823 //
824 // A path between scopes always consists of exitting zero or more
825 // scopes, then entering zero or more scopes. We build a set of
826 // of scopes S from which the target scope can be trivially
827 // entered, then verify that every jump scope can be trivially
828 // exitted to reach a scope in S.
829 llvm::BitVector Reachable(Scopes.size(), false);
830 for (auto [TargetScope, TargetLabel] : TargetScopes) {
831 Reachable.reset();
832
833 // Mark all the enclosing scopes from which you can safely jump
834 // into the target scope. 'Min' will end up being the index of
835 // the shallowest such scope.
836 unsigned Min = TargetScope;
837 while (true) {
838 Reachable.set(Min);
839
840 // Don't go beyond the outermost scope.
841 if (Min == 0) break;
842
843 // Stop if we can't trivially enter the current scope.
844 if (Scopes[Min].InDiag) break;
845
846 Min = Scopes[Min].ParentScope;
847 }
848
849 // Walk through all the jump sites, checking that they can trivially
850 // reach this label scope.
851 for (auto [JumpScope, JumpStmt] : JumpScopes) {
852 unsigned Scope = JumpScope;
853 // Walk out the "scope chain" for this scope, looking for a scope
854 // we've marked reachable. For well-formed code this amortizes
855 // to O(JumpScopes.size() / Scopes.size()): we only iterate
856 // when we see something unmarked, and in well-formed code we
857 // mark everything we iterate past.
858 bool IsReachable = false;
859 while (true) {
860 if (Reachable.test(Scope)) {
861 // If we find something reachable, mark all the scopes we just
862 // walked through as reachable.
863 for (unsigned S = JumpScope; S != Scope; S = Scopes[S].ParentScope)
864 Reachable.set(S);
865 IsReachable = true;
866 break;
867 }
868
869 // Don't walk out if we've reached the top-level scope or we've
870 // gotten shallower than the shallowest reachable scope.
871 if (Scope == 0 || Scope < Min) break;
872
873 // Don't walk out through an out-diagnostic.
874 if (Scopes[Scope].OutDiag) break;
875
876 Scope = Scopes[Scope].ParentScope;
877 }
878
879 // Only diagnose if we didn't find something.
880 if (IsReachable) continue;
881
882 DiagnoseIndirectOrAsmJump(JumpStmt, JumpScope, TargetLabel, TargetScope);
883 }
884 }
885}
886
887/// Return true if a particular error+note combination must be downgraded to a
888/// warning in Microsoft mode.
889static bool IsMicrosoftJumpWarning(unsigned JumpDiag, unsigned InDiagNote) {
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));
893}
894
895/// Return true if a particular note should be downgraded to a compatibility
896/// warning in C++11 mode.
897static bool IsCXX98CompatWarning(Sema &S, unsigned InDiagNote) {
898 return S.getLangOpts().CPlusPlus11 &&
899 InDiagNote == diag::note_protected_by_variable_non_pod;
900}
901
902/// Returns true if a particular note should be a C++ compatibility warning in
903/// C mode with -Wc++-compat.
904static bool IsCppCompatWarning(Sema &S, unsigned InDiagNote) {
905 return !S.getLangOpts().CPlusPlus &&
906 InDiagNote == diag::note_protected_by_variable_init;
907}
908
909/// Produce primary diagnostic for an indirect jump statement.
911 LabelDecl *Target, bool &Diagnosed) {
912 if (Diagnosed)
913 return;
914 bool IsAsmGoto = isa<GCCAsmStmt>(Jump);
915 S.Diag(Jump->getBeginLoc(), diag::err_indirect_goto_in_protected_scope)
916 << IsAsmGoto;
917 S.Diag(Target->getStmt()->getIdentLoc(), diag::note_indirect_goto_target)
918 << IsAsmGoto;
919 Diagnosed = true;
920}
921
922/// Produce note diagnostics for a jump into a protected scope.
923void JumpScopeChecker::NoteJumpIntoScopes(ArrayRef<unsigned> ToScopes) {
924 if (CHECK_PERMISSIVE(ToScopes.empty()))
925 return;
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);
929}
930
931/// Diagnose an indirect jump which is known to cross scopes.
932void JumpScopeChecker::DiagnoseIndirectOrAsmJump(Stmt *Jump, unsigned JumpScope,
933 LabelDecl *Target,
934 unsigned TargetScope) {
935 if (CHECK_PERMISSIVE(JumpScope == TargetScope))
936 return;
937
938 unsigned Common = GetDeepestCommonScope(JumpScope, TargetScope);
939 bool Diagnosed = false;
940
941 // Walk out the scope chain until we reach the common ancestor.
942 for (unsigned I = JumpScope; I != Common; I = Scopes[I].ParentScope)
943 if (Scopes[I].OutDiag) {
944 DiagnoseIndirectOrAsmJumpStmt(S, Jump, Target, Diagnosed);
945 S.Diag(Scopes[I].Loc, Scopes[I].OutDiag);
946 }
947
948 SmallVector<unsigned, 10> ToScopesCXX98Compat, ToScopesCppCompat;
949
950 // Now walk into the scopes containing the label whose address was taken.
951 for (unsigned I = TargetScope; I != Common; I = Scopes[I].ParentScope)
952 if (IsCXX98CompatWarning(S, Scopes[I].InDiag))
953 ToScopesCXX98Compat.push_back(I);
954 else if (IsCppCompatWarning(S, Scopes[I].InDiag))
955 ToScopesCppCompat.push_back(I);
956 else if (Scopes[I].InDiag) {
957 DiagnoseIndirectOrAsmJumpStmt(S, Jump, Target, Diagnosed);
958 S.Diag(Scopes[I].Loc, Scopes[I].InDiag);
959 }
960
961 // Diagnose this jump if it would be ill-formed in C++[98].
962 if (!Diagnosed) {
963 bool IsAsmGoto = isa<GCCAsmStmt>(Jump);
964 auto Diag = [&](unsigned DiagId, const SmallVectorImpl<unsigned> &Notes) {
965 S.Diag(Jump->getBeginLoc(), DiagId) << IsAsmGoto;
966 S.Diag(Target->getStmt()->getIdentLoc(), diag::note_indirect_goto_target)
967 << IsAsmGoto;
968 NoteJumpIntoScopes(Notes);
969 };
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,
975 ToScopesCppCompat);
976 }
977}
978
979/// CheckJump - Validate that the specified jump statement is valid: that it is
980/// jumping within or out of its current scope, not into a deeper one.
981void JumpScopeChecker::CheckJump(Stmt *From, Stmt *To, SourceLocation DiagLoc,
982 unsigned JumpDiagError,
983 unsigned JumpDiagWarning,
984 unsigned JumpDiagCompat) {
985 if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(From)))
986 return;
987 if (CHECK_PERMISSIVE(!LabelAndGotoScopes.count(To)))
988 return;
989
990 unsigned FromScope = LabelAndGotoScopes[From];
991 unsigned ToScope = LabelAndGotoScopes[To];
992
993 // Common case: exactly the same scope, which is fine.
994 if (FromScope == ToScope) return;
995
996 // Warn on gotos out of __finally blocks and defer statements.
997 if (isa<GotoStmt>(From) || isa<IndirectGotoStmt>(From)) {
998 // If FromScope > ToScope, FromScope is more nested and the jump goes to a
999 // less nested scope. Check if it crosses a __finally along the way.
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);
1003 break;
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);
1008 break;
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);
1013 return;
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);
1017 return;
1018 }
1019 }
1020 }
1021
1022 unsigned CommonScope = GetDeepestCommonScope(FromScope, ToScope);
1023
1024 // It's okay to jump out from a nested scope.
1025 if (CommonScope == ToScope) return;
1026
1027 // Pull out (and reverse) any scopes we might need to diagnose skipping.
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 &&
1034 IsMicrosoftJumpWarning(JumpDiagError, Scopes[I].InDiag))
1035 ToScopesWarning.push_back(I);
1036 else if (IsCXX98CompatWarning(S, Scopes[I].InDiag) ||
1037 IsCppCompatWarning(S, Scopes[I].InDiag))
1038 ToScopesCompat.push_back(I);
1039 else if (Scopes[I].InDiag)
1040 ToScopesError.push_back(I);
1041 }
1042
1043 // Handle warnings.
1044 if (!ToScopesWarning.empty()) {
1045 S.Diag(DiagLoc, JumpDiagWarning);
1046 NoteJumpIntoScopes(ToScopesWarning);
1047 assert(isa<LabelStmt>(To));
1048 LabelStmt *Label = cast<LabelStmt>(To);
1049 Label->setSideEntry(true);
1050 }
1051
1052 // Handle errors.
1053 if (!ToScopesError.empty()) {
1054 S.Diag(DiagLoc, JumpDiagError);
1055 NoteJumpIntoScopes(ToScopesError);
1056 }
1057
1058 // Handle -Wc++98-compat or -Wc++-compat warnings if the jump is well-formed.
1059 if (ToScopesError.empty() && !ToScopesCompat.empty()) {
1060 S.Diag(DiagLoc, JumpDiagCompat);
1061 NoteJumpIntoScopes(ToScopesCompat);
1062 }
1063}
1064
1065void JumpScopeChecker::CheckGotoStmt(GotoStmt *GS) {
1066 if (GS->getLabel()->isMSAsmLabel()) {
1067 S.Diag(GS->getGotoLoc(), diag::err_goto_ms_asm_label)
1068 << GS->getLabel()->getIdentifier();
1069 S.Diag(GS->getLabel()->getLocation(), diag::note_goto_ms_asm_label)
1070 << GS->getLabel()->getIdentifier();
1071 }
1072}
1073
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);
1080 }
1081 }
1082 }
1083}
1084
1085const Attr *JumpScopeChecker::GetMustTailAttr(AttributedStmt *AS) {
1086 ArrayRef<const Attr *> Attrs = AS->getAttrs();
1087 const auto *Iter =
1088 llvm::find_if(Attrs, [](const Attr *A) { return isa<MustTailAttr>(A); });
1089 return Iter != Attrs.end() ? *Iter : nullptr;
1090}
1091
1093 (void)JumpScopeChecker(Body, *this);
1094}
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the clang::Expr interface and subclasses for C++ expressions.
FormatToken * Next
The next token in the unwrapped line.
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
Definition MachO.h:51
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
Definition Stmt.h:2225
ArrayRef< Capture > captures() const
Definition Decl.h:4795
Stmt * getHandlerBlock() const
Definition StmtCXX.h:51
SourceLocation getBeginLoc() const LLVM_READONLY
Definition StmtCXX.h:43
Represents a call to a C++ constructor.
Definition ExprCXX.h:1548
Represents a C++ constructor within a class.
Definition DeclCXX.h:2604
bool isDefaultConstructor() const
Whether this constructor is a default constructor (C++ [class.ctor]p5), which can be used to default-...
Definition DeclCXX.cpp:2999
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition DeclCXX.h:2255
bool isPOD() const
Whether this class is a POD-type (C++ [class]p4)
Definition DeclCXX.h:1171
CXXCatchStmt * getHandler(unsigned i)
Definition StmtCXX.h:108
unsigned getNumHandlers() const
Definition StmtCXX.h:107
CompoundStmt * getTryBlock()
Definition StmtCXX.h:100
decl_range decls()
Definition Stmt.h:1669
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:1647
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
Definition DeclBase.h:1087
SourceLocation getLocation() const
Definition DeclBase.h:439
bool hasAttr() const
Definition DeclBase.h:577
CleanupObject getObject(unsigned i) const
Definition ExprCXX.h:3691
unsigned getNumObjects() const
Definition ExprCXX.h:3689
This represents one expression.
Definition Expr.h:112
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...
Definition Expr.cpp:83
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:276
QualType getType() const
Definition Expr.h:144
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
Definition Decl.h:2377
SourceLocation getGotoLoc() const
Definition Stmt.h:2975
LabelDecl * getLabel() const
Definition Stmt.h:2972
Stmt * getThen()
Definition Stmt.h:2338
Expr * getCond()
Definition Stmt.h:2326
bool isConstexpr() const
Definition Stmt.h:2442
bool isObjCAvailabilityCheck() const
Definition Stmt.cpp:1051
Stmt * getElse()
Definition Stmt.h:2347
SourceLocation getBeginLoc() const
Definition Stmt.h:2461
bool isConsteval() const
Definition Stmt.h:2429
VarDecl * getConditionVariable()
Retrieve the variable declared in this "if" statement, if any.
Definition Stmt.cpp:1030
Represents the declaration of a label.
Definition Decl.h:524
LabelStmt * getStmt() const
Definition Decl.h:548
bool isMSAsmLabel() const
Definition Decl.h:558
void setSideEntry(bool SE)
Definition Stmt.h:2184
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Definition ExprCXX.h:4945
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
Definition ExprCXX.h:4937
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:295
const Expr * getSynchExpr() const
Definition StmtObjC.h:331
const CompoundStmt * getSynchBody() const
Definition StmtObjC.h:323
SourceLocation getAtSynchronizedLoc() const
Definition StmtObjC.h:320
const ObjCAtFinallyStmt * getFinallyStmt() const
Retrieve the @finally statement, if any.
Definition StmtObjC.h:241
const Stmt * getTryBody() const
Retrieve the @try body.
Definition StmtObjC.h:214
SourceLocation getAtTryLoc() const
Retrieve the location of the @ in the @try.
Definition StmtObjC.h:210
catch_range catch_stmts()
Definition StmtObjC.h:282
SourceLocation getAtLoc() const
Definition StmtObjC.h:414
SourceLocation getBeginLoc() const LLVM_READONLY
Definition StmtObjC.h:409
const Stmt * getSubStmt() const
Definition StmtObjC.h:405
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
Definition TypeBase.h:1545
CompoundStmt * getTryBlock() const
Definition Stmt.h:3854
SEHFinallyStmt * getFinallyHandler() const
Definition Stmt.cpp:1305
SEHExceptStmt * getExceptHandler() const
Returns 0 if not defined.
Definition Stmt.cpp:1301
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition SemaBase.cpp:61
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:854
const LangOptions & getLangOpts() const
Definition Sema.h:918
void DiagnoseInvalidJumps(Stmt *Body)
Encodes a location in the source.
SourceLocation getBegin() const
CompoundStmt * getSubStmt()
Definition Expr.h:4546
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Expr.h:4550
Stmt - This represents one statement.
Definition Stmt.h:85
child_range children()
Definition Stmt.cpp:299
StmtClass getStmtClass() const
Definition Stmt.h:1483
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:338
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.cpp:350
const SwitchCase * getNextSwitchCase() const
Definition Stmt.h:1883
SwitchCase * getSwitchCaseList()
Definition Stmt.h:2630
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3562
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:926
@ CallInit
Call-style initialization (C++98)
Definition Decl.h:934
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
@ SD_Automatic
Automatic storage duration (most local variables).
Definition Specifiers.h:341
const FunctionProtoType * T
U cast(CodeGen::Address addr)
Definition Address.h:327