clang 24.0.0git
SemaLifetimeSafety.h
Go to the documentation of this file.
1//===--- SemaLifetimeSafety.h - Sema support for lifetime safety =---------==//
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 defines the Sema-specific implementation for lifetime safety
10// analysis. It provides diagnostic reporting and helper functions that bridge
11// the lifetime safety analysis framework with Sema's diagnostic engine.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_LIB_SEMA_SEMALIFETIMESAFETY_H
16#define LLVM_CLANG_LIB_SEMA_SEMALIFETIMESAFETY_H
17
21#include "clang/Lex/Lexer.h"
23#include "clang/Sema/Sema.h"
24#include <string>
25
26namespace clang::lifetimes {
27
28inline bool ShouldCheckSafety(Sema &S, const Decl *D) {
30 constexpr unsigned DiagIDs[] = {
31 diag::warn_lifetime_safety_use_after_scope,
32 diag::warn_lifetime_safety_use_after_scope_moved,
33 diag::warn_lifetime_safety_use_after_free,
34 diag::warn_lifetime_safety_return_stack_addr,
35 diag::warn_lifetime_safety_return_stack_addr_moved,
36 diag::warn_lifetime_safety_invalidation,
37 diag::warn_lifetime_safety_dangling_field,
38 diag::warn_lifetime_safety_dangling_field_moved,
39 diag::warn_lifetime_safety_dangling_field_lambda_capture,
40 diag::warn_lifetime_safety_dangling_global,
41 diag::warn_lifetime_safety_dangling_global_moved,
42 diag::warn_lifetime_safety_dangling_global_in_main,
43 diag::warn_lifetime_safety_invalidated_field,
44 diag::warn_lifetime_safety_invalidated_global};
45 for (unsigned DiagID : DiagIDs)
46 if (!Diags.isIgnored(DiagID, D->getBeginLoc()))
47 return true;
48 return false;
49}
50
51inline bool ShouldCheckNoescapeViolations(Sema &S, const Decl *D) {
52 return !S.getDiagnostics().isIgnored(
53 diag::warn_lifetime_safety_noescape_escapes, D->getBeginLoc());
54}
55
56inline bool ShouldCheckLifetimeboundViolations(Sema &S, const Decl *D) {
57 return !S.getDiagnostics().isIgnored(
58 diag::warn_lifetime_safety_lifetimebound_violation, D->getBeginLoc());
59}
60
61inline bool ShouldCheckCaptureByViolations(Sema &S, const Decl *D) {
62 return !S.getDiagnostics().isIgnored(
63 diag::warn_lifetime_safety_capture_by_violation, D->getBeginLoc());
64}
65
66inline bool ShouldCheckMisplacedLifetimebound(Sema &S, const Decl *D) {
68 constexpr unsigned DiagIDs[] = {
69 diag::warn_lifetime_safety_cross_tu_misplaced_lifetimebound,
70 diag::warn_lifetime_safety_intra_tu_misplaced_lifetimebound};
71 for (unsigned DiagID : DiagIDs)
72 if (!Diags.isIgnored(DiagID, D->getBeginLoc()))
73 return true;
74 return false;
75}
76
78 return !S.getDiagnostics().isIgnored(
79 diag::warn_lifetime_safety_inapplicable_lifetimebound, D->getBeginLoc());
80}
81
82inline bool ShouldCheckFieldOriginEscape(Sema &S, const Decl *D) {
83 return !S.getDiagnostics().isIgnored(
84 diag::warn_lifetime_safety_field_origin_escape, D->getBeginLoc());
85}
86
87inline bool ShouldCheckDestructorUses(Sema &S, const Decl *D) {
89 constexpr unsigned DiagIDs[] = {
90 diag::warn_lifetime_safety_destructor_use_after_scope,
91 diag::warn_lifetime_safety_destructor_use_after_invalidation};
92 for (unsigned DiagID : DiagIDs)
93 if (!Diags.isIgnored(DiagID, D->getBeginLoc()))
94 return true;
95 return false;
96}
97
98inline bool ShouldSuggestLifetimeAnnotations(Sema &S, const Decl *D) {
100 constexpr unsigned DiagIDs[] = {
101 diag::warn_lifetime_safety_intra_tu_param_suggestion,
102 diag::warn_lifetime_safety_cross_tu_param_suggestion,
103 diag::warn_lifetime_safety_intra_tu_ctor_param_suggestion,
104 diag::warn_lifetime_safety_cross_tu_ctor_param_suggestion,
105 diag::warn_lifetime_safety_intra_tu_this_suggestion,
106 diag::warn_lifetime_safety_cross_tu_this_suggestion};
107 for (unsigned DiagID : DiagIDs)
108 if (!Diags.isIgnored(DiagID, D->getBeginLoc()))
109 return true;
110 return false;
111}
112
113inline bool IsLifetimeSafetyEnabled(Sema &S, const Decl *D) {
114 // TODO: Enable ObjectiveC later when we know it's stable enough.
115 if (S.getLangOpts().ObjC)
116 return false;
117
118 // TODO: Default this flag to on in the future.
119 if (!S.getLangOpts().CPlusPlus && !S.getLangOpts().EnableLifetimeSafetyInC)
120 return false;
121
122 // Translation-unit mode: whole-program analysis runs once on TU.
123 // Individual function analysis is disabled when TU mode is enabled.
124 if (S.getLangOpts().EnableLifetimeSafetyTUAnalysis)
125 return isa<TranslationUnitDecl>(D);
126
127 // Per-function mode: analysis runs on each function/method individually.
128 // Skip TU-level calls when per-function mode is enabled.
130 return false;
131
132 // Enable per-function mode via debug flag or specific diagnostics.
133 if (S.getLangOpts().DebugRunLifetimeSafety)
134 return true;
135
136 return ShouldCheckSafety(S, D) || ShouldCheckNoescapeViolations(S, D) ||
144}
145
161
163
164public:
166
167 void reportUseAfterScope(const Expr *IssueExpr, const UseSite &Use,
168 const Expr *MovedExpr, SourceLocation FreeLoc,
169 llvm::ArrayRef<const Expr *> ExprChain) override {
170 unsigned DiagID;
171 if (Use.getKind() == UseKind::Destructor)
172 DiagID = diag::warn_lifetime_safety_destructor_use_after_scope;
173 else
174 DiagID = MovedExpr ? diag::warn_lifetime_safety_use_after_scope_moved
175 : diag::warn_lifetime_safety_use_after_scope;
176 std::string DestroyedSubject = getDiagSubjectDescription(IssueExpr);
177
178 S.Diag(IssueExpr->getExprLoc(), DiagID)
179 << DestroyedSubject << IssueExpr->getSourceRange();
180 if (MovedExpr)
181 S.Diag(MovedExpr->getExprLoc(), diag::note_lifetime_safety_moved_here)
182 << MovedExpr->getSourceRange();
183 S.Diag(FreeLoc, diag::note_lifetime_safety_destroyed_here)
184 << DestroyedSubject;
185 reportAliasingChain(ExprChain);
186 reportUseNote(Use);
187 }
188
189 void reportUseAfterReturn(const Expr *IssueExpr, const Expr *ReturnExpr,
190 const Expr *MovedExpr,
191 llvm::ArrayRef<const Expr *> ExprChain) override {
192 unsigned DiagID = MovedExpr
193 ? diag::warn_lifetime_safety_return_stack_addr_moved
194 : diag::warn_lifetime_safety_return_stack_addr;
195
196 S.Diag(IssueExpr->getExprLoc(), DiagID)
197 << getDiagSubjectDescription(IssueExpr) << IssueExpr->getSourceRange();
198
199 if (MovedExpr)
200 S.Diag(MovedExpr->getExprLoc(), diag::note_lifetime_safety_moved_here)
201 << MovedExpr->getSourceRange();
202 reportAliasingChain(ExprChain);
203 S.Diag(ReturnExpr->getExprLoc(), diag::note_lifetime_safety_returned_here)
204 << ReturnExpr->getSourceRange();
205 }
206
207 void reportDanglingField(const Expr *IssueExpr,
208 const FieldDecl *DanglingField,
209 const Expr *MovedExpr, bool IsCapturedByLambda,
210 SourceLocation ExpiryLoc,
211 llvm::ArrayRef<const Expr *> ExprChain) override {
212 unsigned DiagID =
213 IsCapturedByLambda
214 ? diag::warn_lifetime_safety_dangling_field_lambda_capture
215 : (MovedExpr ? diag::warn_lifetime_safety_dangling_field_moved
216 : diag::warn_lifetime_safety_dangling_field);
217
218 S.Diag(IssueExpr->getExprLoc(), DiagID)
219 << getDiagSubjectDescription(IssueExpr)
220 << getDiagSubjectDescription(DanglingField)
221 << IssueExpr->getSourceRange();
222 if (MovedExpr)
223 S.Diag(MovedExpr->getExprLoc(), diag::note_lifetime_safety_moved_here)
224 << MovedExpr->getSourceRange();
225 reportAliasingChain(ExprChain);
226 S.Diag(DanglingField->getLocation(),
227 diag::note_lifetime_safety_dangling_field_here)
228 << DanglingField->getEndLoc();
229 }
230
231 void reportDanglingGlobal(const Expr *IssueExpr,
232 const VarDecl *DanglingGlobal,
233 const Expr *MovedExpr, SourceLocation ExpiryLoc,
235 bool IsMain = false) override {
236 unsigned DiagID;
237 if (IsMain) {
238 DiagID = MovedExpr ? diag::warn_lifetime_safety_dangling_global_moved
239 : diag::warn_lifetime_safety_dangling_global_in_main;
240 } else {
241 DiagID = MovedExpr ? diag::warn_lifetime_safety_dangling_global_moved
242 : diag::warn_lifetime_safety_dangling_global;
243 }
244
245 S.Diag(IssueExpr->getExprLoc(), DiagID)
246 << getDiagSubjectDescription(IssueExpr)
247 << getDiagSubjectDescription(DanglingGlobal)
248 << IssueExpr->getSourceRange();
249 if (MovedExpr)
250 S.Diag(MovedExpr->getExprLoc(), diag::note_lifetime_safety_moved_here)
251 << MovedExpr->getSourceRange();
252 reportAliasingChain(ExprChain);
253 if (DanglingGlobal->isStaticLocal() || DanglingGlobal->isStaticDataMember())
254 S.Diag(DanglingGlobal->getLocation(),
255 diag::note_lifetime_safety_dangling_static_here)
256 << DanglingGlobal->getEndLoc();
257 else
258 S.Diag(DanglingGlobal->getLocation(),
259 diag::note_lifetime_safety_dangling_global_here)
260 << DanglingGlobal->getEndLoc();
261 }
262
263 void
264 reportUseAfterInvalidation(const Expr *IssueExpr, const UseSite &Use,
265 const Expr *InvalidationExpr,
266 llvm::ArrayRef<const Expr *> ExprChain) override {
267 reportUseAfterInvalidationImpl(
268 IssueExpr->getExprLoc(), IssueExpr->getSourceRange(),
269 getDiagSubjectDescription(IssueExpr), InvalidationExpr, ExprChain, Use);
270 }
271 void
273 const Expr *InvalidationExpr,
274 llvm::ArrayRef<const Expr *> ExprChain) override {
275 reportUseAfterInvalidationImpl(
276 PVD->getSourceRange().getBegin(), PVD->getSourceRange(),
277 getDiagSubjectDescription(PVD), InvalidationExpr, ExprChain, Use);
278 }
279
280 void reportInvalidatedField(const Expr *IssueExpr,
281 const FieldDecl *DanglingField,
282 const Expr *InvalidationExpr,
283 llvm::ArrayRef<const Expr *> ExprChain) override {
284 std::string InvalidatedSubject = getDiagSubjectDescription(IssueExpr);
285 S.Diag(IssueExpr->getExprLoc(),
286 diag::warn_lifetime_safety_invalidated_field)
287 << InvalidatedSubject << getDiagSubjectDescription(DanglingField)
288 << IssueExpr->getSourceRange();
289 reportInvalidationSite(InvalidationExpr, InvalidatedSubject);
290 reportAliasingChain(ExprChain);
291 S.Diag(DanglingField->getLocation(),
292 diag::note_lifetime_safety_dangling_field_here)
293 << DanglingField->getEndLoc();
294 }
295
297 const FieldDecl *DanglingField,
298 const Expr *InvalidationExpr,
299 llvm::ArrayRef<const Expr *> ExprChain) override {
300 std::string InvalidatedSubject = getDiagSubjectDescription(PVD);
301 S.Diag(PVD->getSourceRange().getBegin(),
302 diag::warn_lifetime_safety_invalidated_field)
303 << InvalidatedSubject << getDiagSubjectDescription(DanglingField)
304 << PVD->getSourceRange();
305 reportInvalidationSite(InvalidationExpr, InvalidatedSubject);
306 reportAliasingChain(ExprChain);
307 S.Diag(DanglingField->getLocation(),
308 diag::note_lifetime_safety_dangling_field_here)
309 << DanglingField->getEndLoc();
310 }
311
312 void
313 reportInvalidatedGlobal(const Expr *IssueExpr, const VarDecl *DanglingGlobal,
314 const Expr *InvalidationExpr,
315 llvm::ArrayRef<const Expr *> ExprChain) override {
316 std::string InvalidatedSubject = getDiagSubjectDescription(IssueExpr);
317 S.Diag(IssueExpr->getExprLoc(),
318 diag::warn_lifetime_safety_invalidated_global)
319 << InvalidatedSubject << getDiagSubjectDescription(DanglingGlobal)
320 << IssueExpr->getSourceRange();
321 reportInvalidationSite(InvalidationExpr, InvalidatedSubject);
322 reportAliasingChain(ExprChain);
323 if (DanglingGlobal->isStaticLocal() || DanglingGlobal->isStaticDataMember())
324 S.Diag(DanglingGlobal->getLocation(),
325 diag::note_lifetime_safety_dangling_static_here)
326 << DanglingGlobal->getEndLoc();
327 else
328 S.Diag(DanglingGlobal->getLocation(),
329 diag::note_lifetime_safety_dangling_global_here)
330 << DanglingGlobal->getEndLoc();
331 }
332
333 void
334 reportInvalidatedGlobal(const ParmVarDecl *PVD, const VarDecl *DanglingGlobal,
335 const Expr *InvalidationExpr,
336 llvm::ArrayRef<const Expr *> ExprChain) override {
337 std::string InvalidatedSubject = getDiagSubjectDescription(PVD);
338 S.Diag(PVD->getSourceRange().getBegin(),
339 diag::warn_lifetime_safety_invalidated_global)
340 << InvalidatedSubject << getDiagSubjectDescription(DanglingGlobal)
341 << PVD->getSourceRange();
342 reportInvalidationSite(InvalidationExpr, InvalidatedSubject);
343 reportAliasingChain(ExprChain);
344 if (DanglingGlobal->isStaticLocal() || DanglingGlobal->isStaticDataMember())
345 S.Diag(DanglingGlobal->getLocation(),
346 diag::note_lifetime_safety_dangling_static_here)
347 << DanglingGlobal->getEndLoc();
348 else
349 S.Diag(DanglingGlobal->getLocation(),
350 diag::note_lifetime_safety_dangling_global_here)
351 << DanglingGlobal->getEndLoc();
352 }
353
355 const ParmVarDecl *ParmToAnnotate,
356 EscapingTarget Target) override {
357 unsigned DiagID;
358 if (isa<CXXConstructorDecl>(ParmToAnnotate->getDeclContext()))
359 DiagID = (Scope == WarningScope::CrossTU)
360 ? diag::warn_lifetime_safety_cross_tu_ctor_param_suggestion
361 : diag::warn_lifetime_safety_intra_tu_ctor_param_suggestion;
362 else
363 DiagID = (Scope == WarningScope::CrossTU)
364 ? diag::warn_lifetime_safety_cross_tu_param_suggestion
365 : diag::warn_lifetime_safety_intra_tu_param_suggestion;
366
367 auto [InsertionPoint, FixItText] = getLifetimeBoundFixIt(ParmToAnnotate);
368
369 S.Diag(InsertionPoint, DiagID)
370 << ParmToAnnotate->getSourceRange()
371 << FixItHint::CreateInsertion(InsertionPoint, FixItText);
372
373 if (const auto *EscapeExpr = dyn_cast<const Expr *>(Target))
374 S.Diag(EscapeExpr->getBeginLoc(),
375 diag::note_lifetime_safety_suggestion_returned_here)
376 << EscapeExpr->getSourceRange();
377 else if (const auto *EscapeField = dyn_cast<const FieldDecl *>(Target))
378 S.Diag(EscapeField->getLocation(),
379 diag::note_lifetime_safety_escapes_to_field_here)
380 << EscapeField->getSourceRange();
381 }
382
384 const ParmVarDecl *ParmWithLifetimebound) override {
385 const auto *Attr = ParmWithLifetimebound->getAttr<LifetimeBoundAttr>();
386 StringRef ParamName = ParmWithLifetimebound->getName();
387 bool HasName = ParamName.size() > 0;
388 S.Diag(Attr->getLocation(),
389 diag::warn_lifetime_safety_lifetimebound_violation)
390 << HasName << ParamName << Attr->getRange();
391 }
392
394 const CXXMethodDecl *MDWithLifetimebound) override {
395 const auto *Attr =
396 getImplicitObjectParamLifetimeBoundAttr(MDWithLifetimebound);
397 assert(Attr && "Expected lifetimebound attribute");
398 S.Diag(Attr->getLocation(),
399 diag::warn_lifetime_safety_lifetimebound_violation)
400 << 2 << "" << Attr->getRange();
401 }
402
404 const LifetimeCaptureByAttr *Attr,
405 int CapturerIdx,
406 const ValueDecl *CapturedBy) override {
407 assert(!Attr->isImplicit() && "only written attributes are verified");
408 assert((CapturerIdx == LifetimeCaptureByAttr::This ||
409 CapturerIdx == LifetimeCaptureByAttr::Global) &&
410 "only this and global capturers are verified");
411 S.Diag(Attr->getLocation(), diag::warn_lifetime_safety_capture_by_violation)
412 << PVD << (CapturerIdx == LifetimeCaptureByAttr::Global)
413 << Attr->getRange();
414 if (!CapturedBy)
415 return;
416 unsigned NoteID = diag::note_lifetime_safety_escapes_to_global_here;
417 if (isa<FieldDecl>(CapturedBy))
418 NoteID = diag::note_lifetime_safety_escapes_to_field_here;
419 else if (const auto *VD = cast<VarDecl>(CapturedBy);
420 VD->isStaticLocal() || VD->isStaticDataMember())
421 NoteID = diag::note_lifetime_safety_escapes_to_static_storage_here;
422 S.Diag(CapturedBy->getLocation(), NoteID) << CapturedBy->getEndLoc();
423 }
424
426 const CXXMethodDecl *FDef,
427 const CXXMethodDecl *FDecl) override {
429 assert(Attr && "Expected lifetimebound attribute");
430 unsigned DiagID =
432 ? diag::warn_lifetime_safety_cross_tu_misplaced_lifetimebound
433 : diag::warn_lifetime_safety_intra_tu_misplaced_lifetimebound;
434
435 auto [InsertionPoint, FixItText] = getLifetimeBoundFixIt(FDecl);
436
437 // Do not emit fix-its in macros or at invalid locations.
438 bool IsMacro =
439 FDecl->getBeginLoc().isMacroID() || InsertionPoint.isMacroID();
440
441 if (IsMacro || InsertionPoint.isInvalid())
442 S.Diag(FDecl->getLocation(), DiagID);
443 else
444 S.Diag(InsertionPoint, DiagID)
445 << FixItHint::CreateInsertion(InsertionPoint, FixItText);
446
447 S.Diag(Attr->getLocation(), diag::note_lifetime_safety_lifetimebound_here)
448 << Attr->getRange();
449 }
450
452 const ParmVarDecl *PVDDef,
453 const ParmVarDecl *PVDDecl) override {
454
455 const auto *Attr = PVDDef->getAttr<LifetimeBoundAttr>();
456 assert(Attr && "Expected lifetimebound attribute");
457 unsigned DiagID =
459 ? diag::warn_lifetime_safety_cross_tu_misplaced_lifetimebound
460 : diag::warn_lifetime_safety_intra_tu_misplaced_lifetimebound;
461
462 auto [InsertionPoint, FixItText] = getLifetimeBoundFixIt(PVDDecl);
463
464 // Do not emit fix-its in macros or at invalid locations.
465 bool IsMacro =
466 PVDDecl->getBeginLoc().isMacroID() || InsertionPoint.isMacroID();
467
468 if (IsMacro || InsertionPoint.isInvalid())
469 S.Diag(PVDDecl->getBeginLoc(), DiagID) << PVDDecl->getSourceRange();
470 else
471 S.Diag(InsertionPoint, DiagID)
472 << PVDDecl->getSourceRange()
473 << FixItHint::CreateInsertion(InsertionPoint, FixItText);
474
475 S.Diag(Attr->getLocation(), diag::note_lifetime_safety_lifetimebound_here)
476 << Attr->getRange();
477 }
478
480 assert(PVD->hasAttr<LifetimeBoundAttr>() &&
481 "Expected parameter to have lifetimebound attribute");
482 const auto *Attr = PVD->getAttr<LifetimeBoundAttr>();
483 S.Diag(Attr->getLocation(),
484 diag::warn_lifetime_safety_inapplicable_lifetimebound)
485 << PVD->getType() << Attr->getRange();
486 }
487
489 const CXXMethodDecl *MD,
490 const Expr *EscapeExpr) override {
491 unsigned DiagID = (Scope == WarningScope::CrossTU)
492 ? diag::warn_lifetime_safety_cross_tu_this_suggestion
493 : diag::warn_lifetime_safety_intra_tu_this_suggestion;
494
495 auto [InsertionPoint, FixItText] = getLifetimeBoundFixIt(MD);
496
497 S.Diag(InsertionPoint, DiagID)
498 << MD->getNameInfo().getSourceRange()
499 << FixItHint::CreateInsertion(InsertionPoint, FixItText);
500
501 S.Diag(EscapeExpr->getBeginLoc(),
502 diag::note_lifetime_safety_suggestion_returned_here)
503 << EscapeExpr->getSourceRange();
504 }
505
507 const Expr *EscapeExpr) override {
508 std::string FieldDesc = getDiagSubjectDescription(FD);
509 S.Diag(MD->getLocation(), diag::warn_lifetime_safety_field_origin_escape)
510 << FieldDesc << MD->getNameInfo().getSourceRange();
511
512 S.Diag(EscapeExpr->getBeginLoc(), diag::note_lifetime_safety_returned_here)
513 << EscapeExpr->getSourceRange();
514
515 // A raw pointer field may own its storage (e.g., Vector::data()).
516 if (FD->getType()->isPointerType())
517 S.Diag(FD->getLocation(),
518 diag::note_lifetime_safety_owned_field_suggestion)
519 << FieldDesc << FD->getSourceRange();
520 }
521
522 void reportNoescapeViolation(const ParmVarDecl *ParmWithNoescape,
523 const Expr *EscapeExpr) override {
524 S.Diag(ParmWithNoescape->getBeginLoc(),
525 diag::warn_lifetime_safety_noescape_escapes)
526 << ParmWithNoescape->getSourceRange();
527
528 S.Diag(EscapeExpr->getBeginLoc(),
529 diag::note_lifetime_safety_suggestion_returned_here)
530 << EscapeExpr->getSourceRange();
531 }
532
533 void reportNoescapeViolation(const ParmVarDecl *ParmWithNoescape,
534 const FieldDecl *EscapeField) override {
535 S.Diag(ParmWithNoescape->getBeginLoc(),
536 diag::warn_lifetime_safety_noescape_escapes)
537 << ParmWithNoescape->getSourceRange();
538
539 S.Diag(EscapeField->getLocation(),
540 diag::note_lifetime_safety_escapes_to_field_here)
541 << EscapeField->getEndLoc();
542 }
543
544 void reportNoescapeViolation(const ParmVarDecl *ParmWithNoescape,
545 const VarDecl *EscapeGlobal) override {
546 S.Diag(ParmWithNoescape->getBeginLoc(),
547 diag::warn_lifetime_safety_noescape_escapes)
548 << ParmWithNoescape->getSourceRange();
549 if (EscapeGlobal->isStaticLocal() || EscapeGlobal->isStaticDataMember())
550 S.Diag(EscapeGlobal->getLocation(),
551 diag::note_lifetime_safety_escapes_to_static_storage_here)
552 << EscapeGlobal->getEndLoc();
553 else
554 S.Diag(EscapeGlobal->getLocation(),
555 diag::note_lifetime_safety_escapes_to_global_here)
556 << EscapeGlobal->getEndLoc();
557 }
558
560 S.addLifetimeBoundToImplicitThis(const_cast<CXXMethodDecl *>(MD));
561 }
562
563private:
564 // Returns true if the expression frees memory: a `delete` expression or a
565 // call to a freeing function (e.g. annotated with `ownership_takes`).
566 static bool isFreeingExpr(const Expr *InvalidationExpr) {
567 if (isa<CXXDeleteExpr>(InvalidationExpr))
568 return true;
569 const FunctionDecl *FD = FunctionCallInfo(InvalidationExpr).FD;
570 return FD && isFreeingFunction(*FD);
571 }
572
573 struct LifetimeBoundMacroCache {
574 bool IsBuilt = false;
576 };
577
578 void buildLifetimeBoundMacroCache(LifetimeBoundMacroCache &Cache,
579 ArrayRef<TokenValue> Tokens) {
580 if (Cache.IsBuilt)
581 return;
582
583 const Preprocessor &PP = S.getPreprocessor();
584 // Collect macro names that were ever defined as a lifetimebound attribute.
585 for (const auto &M : PP.macros()) {
586 const IdentifierInfo *II = M.first;
587 const MacroDirective *MD = PP.getLocalMacroDirectiveHistory(II);
588 if (!MD)
589 continue;
590
591 // Include earlier matching definitions to handle redefinitions.
592 for (MacroDirective::DefInfo Def = MD->getDefinition(); Def;
593 Def = Def.getPreviousDefinition()) {
594 const MacroInfo *MI = Def.getMacroInfo();
595 if (MI->isObjectLike() && Tokens.size() == MI->getNumTokens() &&
596 std::equal(Tokens.begin(), Tokens.end(), MI->tokens_begin())) {
597 Cache.Candidates.push_back(II);
598 break;
599 }
600 }
601 }
602 Cache.IsBuilt = true;
603 }
604
605 StringRef getLastCachedMacroWithSpelling(SourceLocation Loc,
606 llvm::ArrayRef<TokenValue> Tokens,
607 LifetimeBoundMacroCache &Cache) {
608 if (Loc.isInvalid())
609 return {};
610
611 buildLifetimeBoundMacroCache(Cache, Tokens);
612
613 const Preprocessor &PP = S.getPreprocessor();
614 const SourceManager &SM = S.getSourceManager();
615 SourceLocation BestLocation;
616 StringRef BestSpelling;
617 for (const IdentifierInfo *II : Cache.Candidates) {
618 const MacroDirective *MD = PP.getLocalMacroDirectiveHistory(II);
619 const MacroDirective::DefInfo Def = MD->findDirectiveAtLoc(Loc, SM);
620 if (!Def || !Def.getMacroInfo())
621 continue;
622
623 // Ensure the macro definition active at Loc still has this spelling.
624 const MacroInfo *MI = Def.getMacroInfo();
625 if (!MI->isObjectLike() || Tokens.size() != MI->getNumTokens() ||
626 !std::equal(Tokens.begin(), Tokens.end(), MI->tokens_begin()))
627 continue;
628
629 // Choose the matching macro defined latest before Loc.
630 SourceLocation Location = Def.getLocation();
631 assert(Location.isInvalid() ||
632 SM.isBeforeInTranslationUnit(Location, Loc));
633 if (BestLocation.isInvalid() ||
634 (Location.isValid() &&
635 SM.isBeforeInTranslationUnit(BestLocation, Location))) {
636 BestLocation = Location;
637 BestSpelling = II->getName();
638 }
639 }
640 return BestSpelling;
641 }
642
643 void reportInvalidationSite(const Expr *InvalidationExpr,
644 StringRef InvalidatedSubject) {
645 auto Diag = isFreeingExpr(InvalidationExpr)
646 ? diag::note_lifetime_safety_freed_here
647 : diag::note_lifetime_safety_invalidated_here;
648 S.Diag(InvalidationExpr->getExprLoc(), Diag)
649 << InvalidatedSubject << InvalidationExpr->getSourceRange();
650 }
651
652 void reportUseAfterInvalidationImpl(SourceLocation IssueLoc,
653 SourceRange IssueRange,
654 StringRef InvalidatedSubject,
655 const Expr *InvalidationExpr,
656 llvm::ArrayRef<const Expr *> ExprChain,
657 const UseSite &Use) {
658 S.Diag(IssueLoc, getInvalidationWarnDiag(isFreeingExpr(InvalidationExpr),
659 Use.getKind()))
660 << InvalidatedSubject << IssueRange;
661 reportInvalidationSite(InvalidationExpr, InvalidatedSubject);
662 reportAliasingChain(ExprChain);
663 reportUseNote(Use);
664 }
665
666 static unsigned getInvalidationWarnDiag(bool IsFree, UseKind Kind) {
667 if (Kind == UseKind::Destructor)
668 return IsFree
669 ? diag::warn_lifetime_safety_destructor_use_after_scope
670 : diag::warn_lifetime_safety_destructor_use_after_invalidation;
671 return IsFree ? diag::warn_lifetime_safety_use_after_free
672 : diag::warn_lifetime_safety_invalidation;
673 }
674
675 void reportUseNote(const UseSite &Use) {
676 switch (Use.getKind()) {
678 S.Diag(Use.getLoc(), diag::note_lifetime_safety_used_here)
679 << Use.getRange();
680 return;
682 S.Diag(Use.getLoc(), diag::note_lifetime_safety_used_by_destructor)
683 << Use.getScopeExitVD();
684 return;
685 case UseKind::Cleanup:
686 S.Diag(Use.getLoc(), diag::note_lifetime_safety_used_by_cleanup)
687 << Use.getScopeExitVD();
688 return;
689 }
690 llvm_unreachable("unknown UseKind");
691 }
692
693 std::string getLifetimeBoundFixItText(SourceLocation Loc, bool LeadingSpace,
694 bool AllowGNUAttrMacro = true) {
695 const bool UseCXX11AttrSpelling =
696 S.getLangOpts().CPlusPlus || S.getLangOpts().C23;
697 const StringRef Fallback = UseCXX11AttrSpelling
698 ? "[[clang::lifetimebound]]"
699 : "__attribute__((lifetimebound))";
700 StringRef Spelling = S.getLangOpts().LifetimeSafetyLifetimeBoundMacro;
701 if (Spelling.empty() && Loc.isValid()) {
702 const Preprocessor &PP = S.getPreprocessor();
703 if (UseCXX11AttrSpelling)
704 Spelling = getLastCachedMacroWithSpelling(
705 Loc,
706 {tok::l_square, tok::l_square, PP.getIdentifierInfo("clang"),
707 tok::coloncolon, PP.getIdentifierInfo("lifetimebound"),
708 tok::r_square, tok::r_square},
709 ClangLifetimeBoundMacroCache);
710
711 if (Spelling.empty() && AllowGNUAttrMacro)
712 Spelling = getLastCachedMacroWithSpelling(
713 Loc,
714 {tok::kw___attribute, tok::l_paren, tok::l_paren,
715 PP.getIdentifierInfo("lifetimebound"), tok::r_paren, tok::r_paren},
716 GNULifetimeBoundMacroCache);
717 }
718 const std::string Text = Spelling.empty() ? Fallback.str() : Spelling.str();
719 return LeadingSpace ? " " + Text : Text + " ";
720 }
721
722 std::pair<SourceLocation, std::string>
723 getLifetimeBoundFixIt(const ParmVarDecl *Decl) {
724 SourceLocation InsertionPoint = Lexer::getLocForEndOfToken(
725 Decl->getEndLoc(), 0, S.getSourceManager(), S.getLangOpts());
726 bool LeadingSpace = true;
727
728 if (!Decl->getIdentifier()) {
729 // For unnamed parameters, placing attributes after the type would be
730 // parsed as a type attribute, not a parameter attribute.
731 InsertionPoint = Decl->getBeginLoc();
732 LeadingSpace = false;
733 } else if (Decl->hasDefaultArg()) {
734 // If the parameter has a default argument, place the attribute after the
735 // named argument.
736 InsertionPoint = Lexer::getLocForEndOfToken(
737 Decl->getLocation(), 0, S.getSourceManager(), S.getLangOpts());
738 }
739 return {InsertionPoint,
740 getLifetimeBoundFixItText(InsertionPoint, LeadingSpace)};
741 }
742
743 std::pair<SourceLocation, std::string>
744 getLifetimeBoundFixIt(const CXXMethodDecl *MD) {
745 const auto MDL = MD->getTypeSourceInfo()->getTypeLoc();
746 SourceLocation InsertionPoint = Lexer::getLocForEndOfToken(
747 MDL.getEndLoc(), 0, S.getSourceManager(), S.getLangOpts());
748
749 if (const auto *FPT = MD->getType()->getAs<FunctionProtoType>();
750 FPT && FPT->hasTrailingReturn()) {
751 // For trailing return types, 'getEndLoc()' includes the return type
752 // after '->', placing the attribute in an invalid position.
753 // Instead use 'getLocalRangeEnd()' which gives the '->' location
754 // for trailing returns, so find the last token before it.
755 const auto FTL = MDL.getAs<FunctionTypeLoc>();
756 assert(FTL);
757 InsertionPoint = Lexer::getLocForEndOfToken(
758 Lexer::findPreviousToken(FTL.getLocalRangeEnd(), S.getSourceManager(),
759 S.getLangOpts(),
760 /*IncludeComments=*/false)
761 ->getLocation(),
762 0, S.getSourceManager(), S.getLangOpts());
763 }
764 return {InsertionPoint,
765 getLifetimeBoundFixItText(InsertionPoint, /*LeadingSpace=*/true,
766 /*AllowGNUAttrMacro=*/false)};
767 }
768
769 std::string getDiagSubjectDescription(const ValueDecl *VD) {
770 std::string Res;
771 llvm::raw_string_ostream OS(Res);
772 if (isa<FieldDecl>(VD)) {
773 OS << "field";
774 } else if (isa<ParmVarDecl>(VD)) {
775 OS << "parameter";
776 } else if (const auto *Var = dyn_cast<VarDecl>(VD)) {
777 if (Var->isStaticLocal() || Var->isStaticDataMember())
778 OS << "static variable";
779 else if (Var->hasGlobalStorage())
780 OS << "global variable";
781 else
782 OS << "local variable";
783 } else {
784 OS << "variable";
785 }
786 OS << " '";
787 VD->getNameForDiagnostic(OS, S.getPrintingPolicy(), /*Qualified=*/false);
788 OS << "'";
789 return Res;
790 }
791
792 std::string getDiagSubjectDescription(const Expr *E) {
794 if (const auto *DAE = dyn_cast<CXXDefaultArgExpr>(E))
795 return getDiagSubjectDescription(DAE->getExpr()->IgnoreParenBaseCasts());
797 return "temporary object";
798 if (isa<CXXNewExpr>(E))
799 return "allocated object";
800 if (const auto *DRE = dyn_cast<DeclRefExpr>(E))
801 return getDiagSubjectDescription(DRE->getDecl());
802 if (const auto *ME = dyn_cast<MemberExpr>(E))
803 if (const auto *VD = dyn_cast<VarDecl>(ME->getMemberDecl()))
804 return getDiagSubjectDescription(VD);
805
806 if (const auto *CE = dyn_cast<CallExpr>(E)) {
807 const auto *FD = CE->getDirectCallee();
808 if (!FD)
809 return "result of call";
810 std::string Name;
811 llvm::raw_string_ostream OS(Name);
812 FD->getNameForDiagnostic(OS, S.getPrintingPolicy(),
813 /*Qualified=*/false);
814 if (isAllocatingFunction(*FD))
815 return "object allocated by '" + Name + "'";
816 return "result of call to '" + Name + "'";
817 }
818
819 // TODO: Handle other expression types.
820 return "expression";
821 }
822
823 bool shouldShowInAliasChain(const Expr *CurrExpr, const Expr *LastExpr) {
824 CurrExpr = ignoreParensAndImpCasts(CurrExpr);
825 LastExpr = ignoreParensAndImpCasts(LastExpr);
826
827 if (!isa<CallExpr, DeclRefExpr>(CurrExpr))
828 return false;
829 // Source ranges can be used to filter out many implicit expressions,
830 // because operations between class objects often involve numerous implicit
831 // conversions, yet they share the same source range.
832 return CurrExpr->getSourceRange() != LastExpr->getSourceRange();
833 }
834
835 void reportAliasingChain(llvm::ArrayRef<const Expr *> OriginExprChain) {
836 if (OriginExprChain.empty())
837 return;
838
839 const Expr *LastExpr = OriginExprChain.back();
840 const Expr *VisibleLastExpr = LastExpr;
841 std::string IssueStr = getDiagSubjectDescription(VisibleLastExpr);
842
843 for (const Expr *CurrExpr : reverse(OriginExprChain.drop_back())) {
844 if (!shouldShowInAliasChain(CurrExpr, VisibleLastExpr)) {
845 LastExpr = CurrExpr;
846 continue;
847 }
848 std::optional<LifetimeBoundParamInfo> ParamInfo =
849 getTrackingInfoForCallArg(CurrExpr, LastExpr);
850 LastExpr = CurrExpr;
851 if (ParamInfo) {
852 bool IsImplicitObject = isa<const CXXMethodDecl *>(*ParamInfo);
853 bool IsInferred = true;
854 std::string ParamName;
855 if (!IsImplicitObject) {
856 const auto *Param = cast<const ParmVarDecl *>(*ParamInfo);
857 if (const auto *Attr = Param->getAttr<LifetimeBoundAttr>())
858 IsInferred = Attr->isImplicit();
859 ParamName = Param->getIdentifier()
860 ? "'" + Param->getNameAsString() + "'"
861 : "'<unnamed>'";
862 } else if (const auto *Attr = getImplicitObjectParamLifetimeBoundAttr(
863 cast<const CXXMethodDecl *>(*ParamInfo))) {
864 IsInferred = Attr->isImplicit();
865 }
866 S.Diag(CurrExpr->getBeginLoc(),
867 diag::note_lifetime_safety_aliases_storage_lifetimebound)
868 << CurrExpr->getSourceRange() << getDiagSubjectDescription(CurrExpr)
869 << IssueStr << IsImplicitObject << ParamName << IsInferred;
870 } else
871 S.Diag(CurrExpr->getBeginLoc(),
872 diag::note_lifetime_safety_aliases_storage)
873 << CurrExpr->getSourceRange() << getDiagSubjectDescription(CurrExpr)
874 << IssueStr;
875 VisibleLastExpr = CurrExpr;
876 }
877 }
878
879 LifetimeBoundMacroCache ClangLifetimeBoundMacroCache;
880 LifetimeBoundMacroCache GNULifetimeBoundMacroCache;
881 Sema &S;
882};
883
884} // namespace clang::lifetimes
885
886#endif // LLVM_CLANG_LIB_SEMA_SEMALIFETIMESAFETY_H
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.
Defines the clang::Preprocessor interface.
TypePropertyCache< Private > Cache
Definition Type.cpp:5094
Attr - This represents one attribute.
Definition Attr.h:47
bool isImplicit() const
Returns true if the attribute has been implicitly created instead of explicitly written by the user.
Definition Attr.h:106
SourceLocation getLocation() const
Definition Attr.h:100
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2153
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition DeclBase.h:444
T * getAttr() const
Definition DeclBase.h:582
SourceLocation getLocation() const
Definition DeclBase.h:448
DeclContext * getDeclContext()
Definition DeclBase.h:457
SourceLocation getBeginLoc() const LLVM_READONLY
Definition DeclBase.h:440
bool hasAttr() const
Definition DeclBase.h:586
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:833
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:241
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
Definition Diagnostic.h:992
This represents one expression.
Definition Expr.h:114
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
Represents a member of a struct/union/class.
Definition Decl.h:3341
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:4929
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Definition Diagnostic.h:103
Represents a function declaration or definition.
Definition Decl.h:2082
DeclarationNameInfo getNameInfo() const
Definition Decl.h:2367
static std::optional< Token > findPreviousToken(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeComments)
Finds the token that comes before the given location.
Definition Lexer.cpp:1412
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
Definition Lexer.cpp:882
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:303
Represents a parameter to a function.
Definition Decl.h:1832
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:2986
Scope - A scope is a transient data structure that is used while parsing the program.
Definition Scope.h:41
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:863
Preprocessor & getPreprocessor() const
Definition Sema.h:934
DiagnosticsEngine & getDiagnostics() const
Definition Sema.h:932
const LangOptions & getLangOpts() const
Definition Sema.h:928
Encodes a location in the source.
SourceLocation getBegin() const
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
bool isPointerType() const
Definition TypeBase.h:8815
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:714
QualType getType() const
Definition Decl.h:725
Represents a variable declaration or definition.
Definition Decl.h:934
bool isStaticDataMember() const
Determines whether this is a static data member.
Definition Decl.h:1308
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
Definition Decl.h:1216
void reportInvalidatedField(const Expr *IssueExpr, const FieldDecl *DanglingField, const Expr *InvalidationExpr, llvm::ArrayRef< const Expr * > ExprChain) override
void reportMisplacedLifetimebound(WarningScope Scope, const ParmVarDecl *PVDDef, const ParmVarDecl *PVDDecl) override
void reportNoescapeViolation(const ParmVarDecl *ParmWithNoescape, const Expr *EscapeExpr) override
void reportInvalidatedGlobal(const Expr *IssueExpr, const VarDecl *DanglingGlobal, const Expr *InvalidationExpr, llvm::ArrayRef< const Expr * > ExprChain) override
void reportLifetimeboundViolation(const CXXMethodDecl *MDWithLifetimebound) override
void reportNoescapeViolation(const ParmVarDecl *ParmWithNoescape, const VarDecl *EscapeGlobal) override
void suggestLifetimeboundToImplicitThis(WarningScope Scope, const CXXMethodDecl *MD, const Expr *EscapeExpr) override
void reportUseAfterReturn(const Expr *IssueExpr, const Expr *ReturnExpr, const Expr *MovedExpr, llvm::ArrayRef< const Expr * > ExprChain) override
void reportUseAfterScope(const Expr *IssueExpr, const UseSite &Use, const Expr *MovedExpr, SourceLocation FreeLoc, llvm::ArrayRef< const Expr * > ExprChain) override
void reportInvalidatedField(const ParmVarDecl *PVD, const FieldDecl *DanglingField, const Expr *InvalidationExpr, llvm::ArrayRef< const Expr * > ExprChain) override
void reportFieldOriginEscape(const CXXMethodDecl *MD, const FieldDecl *FD, const Expr *EscapeExpr) override
void suggestLifetimeboundToParmVar(WarningScope Scope, const ParmVarDecl *ParmToAnnotate, EscapingTarget Target) override
void reportCaptureByViolation(const ParmVarDecl *PVD, const LifetimeCaptureByAttr *Attr, int CapturerIdx, const ValueDecl *CapturedBy) override
void reportInapplicableLifetimebound(const ParmVarDecl *PVD) override
void reportDanglingField(const Expr *IssueExpr, const FieldDecl *DanglingField, const Expr *MovedExpr, bool IsCapturedByLambda, SourceLocation ExpiryLoc, llvm::ArrayRef< const Expr * > ExprChain) override
void addLifetimeBoundToImplicitThis(const CXXMethodDecl *MD) override
void reportUseAfterInvalidation(const Expr *IssueExpr, const UseSite &Use, const Expr *InvalidationExpr, llvm::ArrayRef< const Expr * > ExprChain) override
void reportMisplacedLifetimebound(WarningScope Scope, const CXXMethodDecl *FDef, const CXXMethodDecl *FDecl) override
void reportInvalidatedGlobal(const ParmVarDecl *PVD, const VarDecl *DanglingGlobal, const Expr *InvalidationExpr, llvm::ArrayRef< const Expr * > ExprChain) override
void reportUseAfterInvalidation(const ParmVarDecl *PVD, const UseSite &Use, const Expr *InvalidationExpr, llvm::ArrayRef< const Expr * > ExprChain) override
void reportNoescapeViolation(const ParmVarDecl *ParmWithNoescape, const FieldDecl *EscapeField) override
void reportDanglingGlobal(const Expr *IssueExpr, const VarDecl *DanglingGlobal, const Expr *MovedExpr, SourceLocation ExpiryLoc, llvm::ArrayRef< const Expr * > ExprChain, bool IsMain=false) override
void reportLifetimeboundViolation(const ParmVarDecl *ParmWithLifetimebound) override
llvm::PointerUnion< const Expr *, const FieldDecl *, const VarDecl * > EscapingTarget
Where and how an origin is used, for diagnostics.
Definition Facts.h:40
UseKind getKind() const
Definition Facts.h:67
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
bool ShouldCheckCaptureByViolations(Sema &S, const Decl *D)
UseKind
How an origin is used: by an expression, or implicitly at scope exit by a destructor or a cleanup cal...
Definition Facts.h:37
const Expr * ignoreParensAndImpCasts(const Expr *E)
bool isFreeingFunction(const FunctionDecl &FD)
const LifetimeBoundAttr * getDirectImplicitObjectLifetimeBoundAttr(const FunctionDecl *FD)
bool ShouldCheckLifetimeboundViolations(Sema &S, const Decl *D)
bool ShouldCheckFieldOriginEscape(Sema &S, const Decl *D)
LifetimeSafetyOpts GetLifetimeSafetyOpts(Sema &S, const Decl *D)
WarningScope
Enum to track functions visible across or within TU.
bool ShouldCheckDestructorUses(Sema &S, const Decl *D)
bool ShouldCheckNoescapeViolations(Sema &S, const Decl *D)
bool ShouldCheckInapplicableLifetimebound(Sema &S, const Decl *D)
const LifetimeBoundAttr * getImplicitObjectParamLifetimeBoundAttr(const FunctionDecl *FD)
std::optional< LifetimeBoundParamInfo > getTrackingInfoForCallArg(const Expr *Call, const Expr *Source)
bool ShouldSuggestLifetimeAnnotations(Sema &S, const Decl *D)
bool isAllocatingFunction(const FunctionDecl &FD)
bool ShouldCheckMisplacedLifetimebound(Sema &S, const Decl *D)
bool ShouldCheckSafety(Sema &S, const Decl *D)
bool IsLifetimeSafetyEnabled(Sema &S, const Decl *D)
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
bool isa(CodeGen::Address addr)
Definition Address.h:330
U cast(CodeGen::Address addr)
Definition Address.h:327
SourceRange getSourceRange() const LLVM_READONLY
getSourceRange - The range of the declaration name.
bool SuggestAnnotations
Whether to suggest lifetime annotations.
size_t MaxCFGBlocks
Maximum number of CFG blocks to analyze.
bool CheckDestructorUses
Whether to model non-trivial destructors at scope exit as uses.