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