[clang] [clang] Migrate away from PointerUnion::dyn_cast (NFC) (PR #228843)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 4 01:38:14 PDT 2026


https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/228843

>From 7354e9e6ee12a35dc811cd904e1aa7d88622191a Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 3 Oct 2026 08:47:54 -0700
Subject: [PATCH 1/2] [clang] Migrate away from PointerUnion::dyn_cast (NFC)

Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

    // FIXME: Replace the uses of is(), get() and dyn_cast() with
    //        isa<T>, cast<T> and the llvm::dyn_cast<T>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast.
Note that the if-then-else chain ends with:

    } else
      llvm_unreachable("Unhandled CausingFact type");

which guarantees that CausingFact is nonnull.

Assisted-by: Antigravity
---
 clang/lib/Analysis/LifetimeSafety/Checker.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Analysis/LifetimeSafety/Checker.cpp b/clang/lib/Analysis/LifetimeSafety/Checker.cpp
index c4cc872dcd568..29063398bfcd8 100644
--- a/clang/lib/Analysis/LifetimeSafety/Checker.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/Checker.cpp
@@ -277,7 +277,7 @@ class LifetimeChecker {
       const Expr *MovedExpr = Warning.MovedExpr;
       SourceLocation ExpiryLoc = Warning.ExpiryLoc;
 
-      if (const auto *UF = CausingFact.dyn_cast<const UseFact *>()) {
+      if (const auto *UF = dyn_cast<const UseFact *>(CausingFact)) {
         llvm::SmallVector<const Expr *> ExprChain =
             getExprChain(LoanPropagation.buildOriginFlowChain(UF, LID, Cfg));
         if (Warning.InvalidatedByExpr) {
@@ -298,7 +298,7 @@ class LifetimeChecker {
                                           MovedExpr, ExpiryLoc, ExprChain);
 
       } else if (const auto *OEF =
-                     CausingFact.dyn_cast<const OriginEscapesFact *>()) {
+                     dyn_cast<const OriginEscapesFact *>(CausingFact)) {
         if (Warning.InvalidatedByExpr) {
           if (const auto *FieldEscape = dyn_cast<FieldEscapeFact>(OEF)) {
             // Invalidated object escapes to a field.

>From 567093ad133b911ceab1a88c98607156d20d36da Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 4 Oct 2026 01:37:47 -0700
Subject: [PATCH 2/2] Empty commit




More information about the cfe-commits mailing list