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

via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 4 00:17:19 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-temporal-safety

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

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


---
Full diff: https://github.com/llvm/llvm-project/pull/228843.diff


1 Files Affected:

- (modified) clang/lib/Analysis/LifetimeSafety/Checker.cpp (+2-2) 


``````````diff
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.

``````````

</details>


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


More information about the cfe-commits mailing list