[clang] [AST] Migrate away from PointerUnion::dyn_cast (NFC) (PR #125379)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 1 21:08:37 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/125379
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 the non-const variant of
getInitializedFieldInUnion is known to encounter null in
ArrayFillerOrUnionFieldInit. See:
commit 563c7c5539f05e7f8cbb42565c1f24466019f38b
Author: Kazu Hirata <kazu at google.com>
Date: Sat Jan 25 14:05:01 2025 -0800
FWIW, I am not aware of any test case in check-clang that triggers
null here.
>From 6eda70bfeacd2ac76227d8b06f6def48c7020eb4 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 1 Feb 2025 12:36:01 -0800
Subject: [PATCH] [AST] 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 the non-const variant of
getInitializedFieldInUnion is known to encounter null in
ArrayFillerOrUnionFieldInit. See:
commit 563c7c5539f05e7f8cbb42565c1f24466019f38b
Author: Kazu Hirata <kazu at google.com>
Date: Sat Jan 25 14:05:01 2025 -0800
FWIW, I am not aware of any test case in check-clang that triggers
null here.
---
clang/include/clang/AST/ExprCXX.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h
index 0b6c8cfb163c958..98ba2bb41bb54d9 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -5040,7 +5040,7 @@ class CXXParenListInitExpr final
}
const FieldDecl *getInitializedFieldInUnion() const {
- return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>();
+ return dyn_cast_if_present<FieldDecl *>(ArrayFillerOrUnionFieldInit);
}
child_range children() {
More information about the cfe-commits
mailing list