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

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 28 22:06:27 PST 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/124883

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>

This patch migrates the use of PointerUnion::dyn_cast to
dyn_cast_if_present because ShadowMapEntry::Add starts with:

  if (DeclOrVector.isNull()) {

implying that DeclOrVector is not guaranteed to be nonnull.


>From 404c9809a8a99eb50e5802f03e7bbe01848ec8eb Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 28 Jan 2025 17:15:20 -0800
Subject: [PATCH] [Sema] 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>

This patch migrates the use of PointerUnion::dyn_cast to
dyn_cast_if_present because ShadowMapEntry::Add starts with:

  if (DeclOrVector.isNull()) {

implying that DeclOrVector is not guaranteed to be nonnull.
---
 clang/lib/Sema/SemaCodeComplete.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index bc0f6a9435f958..f10f7f4768f8e8 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -137,7 +137,7 @@ class ResultBuilder {
 
     ~ShadowMapEntry() {
       if (DeclIndexPairVector *Vec =
-              DeclOrVector.dyn_cast<DeclIndexPairVector *>()) {
+              dyn_cast_if_present<DeclIndexPairVector *>(DeclOrVector)) {
         delete Vec;
         DeclOrVector = ((NamedDecl *)nullptr);
       }



More information about the cfe-commits mailing list