[all-commits] [llvm/llvm-project] d41006: [LifetimeSafety] Revamp how accesses and uses are ...

Gábor Horváth via All-commits all-commits at lists.llvm.org
Thu Sep 24 08:18:16 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d41006c17bfc36cf899f39e93f839ae8ed3db637
      https://github.com/llvm/llvm-project/commit/d41006c17bfc36cf899f39e93f839ae8ed3db637
  Author: Gábor Horváth <xazax.hun at gmail.com>
  Date:   2026-09-24 (Thu, 24 Sep 2026)

  Changed paths:
    M clang/include/clang/Analysis/Analyses/LifetimeSafety/Facts.h
    M clang/include/clang/Analysis/Analyses/LifetimeSafety/FactsGenerator.h
    M clang/include/clang/Analysis/Analyses/LifetimeSafety/LifetimeSafety.h
    M clang/include/clang/Analysis/Analyses/LifetimeSafety/LoanPropagation.h
    M clang/include/clang/Analysis/Analyses/LifetimeSafety/Origins.h
    M clang/lib/Analysis/LifetimeSafety/Facts.cpp
    M clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp
    M clang/lib/Analysis/LifetimeSafety/LifetimeAnnotations.cpp
    M clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp
    M clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp
    M clang/lib/Analysis/LifetimeSafety/Origins.cpp
    M clang/test/Sema/LifetimeSafety/Inputs/lifetime-analysis.h
    M clang/test/Sema/LifetimeSafety/annotation-suggestions.cpp
    M clang/test/Sema/LifetimeSafety/capture-by.cpp
    M clang/test/Sema/LifetimeSafety/cfg-bailout.cpp
    M clang/test/Sema/LifetimeSafety/dangling-field.cpp
    M clang/test/Sema/LifetimeSafety/dangling-global.cpp
    M clang/test/Sema/LifetimeSafety/inapplicable-lifetimebound.cpp
    M clang/test/Sema/LifetimeSafety/invalidations.cpp
    M clang/test/Sema/LifetimeSafety/lifetime-facts.cpp
    M clang/test/Sema/LifetimeSafety/lifetimebound-violation.cpp
    M clang/test/Sema/LifetimeSafety/nocfg.cpp
    M clang/test/Sema/LifetimeSafety/noescape-violation.cpp
    M clang/test/Sema/LifetimeSafety/safety.cpp
    M clang/unittests/Analysis/LifetimeSafetyTest.cpp

  Log Message:
  -----------
  [LifetimeSafety] Revamp how accesses and uses are handled (#225799)

Previously every DeclRefExpr was a use, so naming a pointer, taking its
address
or copying it counted as reading what it points to. Writes were then
exempted
after the fact through a UseFact -> Expr map and a special case for
writes
through references.

Now a use is an access: an lvalue-to-rvalue conversion, a write through
an
assignment, increment or asm output, or a copy of a class object from a
glvalue.
It is recorded on the accessed lvalue's outer origin, the loans saying
which
storage it may name. The visitors for `*p`, `p->f` and `p[i]` already
flow the
base pointer there, so dereferences need no special handling. Reads of a
value
go through readValue(), which records the access; writes peel the outer
origin
directly. Values handed to opaque code still use every level.

Consequences:
- Copying a pointer, taking an address, `(void)p` and `p++` are not
uses.
- Writing through a dangling pointer (`*p = 1`, `p->f = 1`) is now
diagnosed.
- An access of an origin that names a declaration outright is skipped:
it
only holds a loan to that declaration, which is valid wherever it is
named.
- UseFact::IsWritten and markUseAsWrite are removed; kills on assignment
already come from the destination's OriginFlowFact or KillOriginFact.

Fewer use facts are generated, e.g. on the lifetime-safety lit tests:
  safety.cpp          1886 -> 882
  invalidations.cpp    616 -> 451
  nocfg.cpp            544 -> 415
  capture-by.cpp       395 -> 324

Assisted by: Opus 5.5

---------

Co-authored-by: Gabor Horvath <gaborh at apple.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list