Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

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

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

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 563c7c5
Author: Kazu Hirata [email protected]
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.

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 563c7c5
  Author: Kazu Hirata <[email protected]>
  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.
@kazutakahirata kazutakahirata requested a review from nikic February 2, 2025 05:08
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Feb 2, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 2, 2025

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

Changes

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 563c7c5
Author: Kazu Hirata <[email protected]>
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.


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

1 Files Affected:

  • (modified) clang/include/clang/AST/ExprCXX.h (+1-1)
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() {

@kazutakahirata kazutakahirata merged commit 43b7124 into llvm:main Feb 2, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_PointerUnion_clang_AST_ExprCXX branch February 2, 2025 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants