← Back to Pull requests

[clang] Replace PointerUnion::dyn_cast with llvm::dyn_cast (NFC) #235396

Merged
kazutakahirata merged 3 files (16 lines) on Oct 25, 2026 15:07 UTC
View on GitHub
kazutakahirata kazutakahirata commented on Oct 25, 2026 05:27 UTC
Author

PointerUnion::dyn_cast has been soft-deprecated in favor of
llvm::dyn_cast and llvm::dyn_cast_if_present. This patch replaces
PointerUnion::dyn_cast with llvm::dyn_cast at 7 call sites across 3
files under clang/lib/AST/.

All tests in check-clang pass with these changes, and LLM-based static
analysis of the surrounding data structures and call sites confirms that
the PointerUnion operand at each site is nonnull either by construction
or because callers ensure it is nonnull before reaching llvm::dyn_cast.

Assisted-by: Antigravity

Diff: 16 lines (+8 / -8) across 3 files Reviewer: nikic Review duration: 579m
All Vouch review confidence checks passed
Residual risk 0.09 = Change Risk (0.28) × (1 − Review Confidence (0.68)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.28 · 16 lines diff across 3 files
0.28
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.48 · 1 substantive comment(s)
0.48
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
67%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.170
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
3 items
llvmorg-github-actions[bot] llvmorg-github-actions[bot] commented on Oct 25, 2026 05:27 UTC
Bot

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

PointerUnion::dyn_cast has been soft-deprecated in favor of
llvm::dyn_cast and llvm::dyn_cast_if_present. This patch replaces
PointerUnion::dyn_cast with llvm::dyn_cast at 7 call sites across 3
files under clang/lib/AST/.

All tests in check-clang pass with these changes, and LLM-based static
analysis of the surrounding data structures and call sites confirms that
the PointerUnion operand at each site is nonnull either by construction
or because callers ensure it is nonnull before reaching llvm::dyn_cast.

Assisted-by: Antigravity

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

3 Files Affected:

  • (modified) clang/lib/AST/ByteCode/DeclOrExpr.h (+2-2)

  • (modified) clang/lib/AST/Decl.cpp (+1-1)

  • (modified) clang/lib/AST/TemplateName.cpp (+5-5)
  • ``````

    diff --git a/clang/lib/AST/ByteCode/DeclOrExpr.h b/clang/lib/AST/ByteCode/DeclOrExpr.h
    index b844c5644a2332..14608f379001bf 100644
    --- a/clang/lib/AST/ByteCode/DeclOrExpr.h
    +++ b/clang/lib/AST/ByteCode/DeclOrExpr.h
    @@ -30,8 +30,8 @@ struct DeclOrExpr {
       bool isValueDecl() const { return isa_and_nonnull<ValueDecl>(asDecl()); }
       bool isVarDecl() const { return isa_and_nonnull<VarDecl>(asDecl()); }
     
    -  const Expr *asExpr() const { return V.dyn_cast<const Expr *>(); }
    -  const Decl *asDecl() const { return V.dyn_cast<const Decl *>(); }
    +  const Expr *asExpr() const { return dyn_cast<const Expr *>(V); }
    +  const Decl *asDecl() const { return dyn_cast<const Decl *>(V); }
       const ValueDecl *asValueDecl() const {
         return dyn_cast_if_present<ValueDecl>(asDecl());
       }
    diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
    index f920a1e9b8fd85..f9f38230cd0782 100644
    --- a/clang/lib/AST/Decl.cpp
    +++ b/clang/lib/AST/Decl.cpp
    @@ -4273,7 +4273,7 @@ void FunctionDecl::setInstantiatedFromDecl(FunctionDecl *FD) {
     
     FunctionDecl *FunctionDecl::getInstantiatedFromDecl() const {
       return dyn_cast_if_present<FunctionDecl>(
    -      TemplateOrSpecialization.dyn_cast<NamedDecl *>());
    +      dyn_cast<NamedDecl *>(TemplateOrSpecialization));
     }
     
     bool FunctionDecl::isImplicitlyInstantiable() const {
    diff --git a/clang/lib/AST/TemplateName.cpp b/clang/lib/AST/TemplateName.cpp
    index d55259daec7111..d99c4e0f53f084 100644
    --- a/clang/lib/AST/TemplateName.cpp
    +++ b/clang/lib/AST/TemplateName.cpp
    @@ -354,7 +354,7 @@ std::optional<TemplateName> TemplateName::desugar(bool IgnoreDeduced) const {
     
     OverloadedTemplateStorage *TemplateName::getAsOverloadedTemplate() const {
       if (UncommonTemplateNameStorage *Uncommon =
    -          Storage.dyn_cast<UncommonTemplateNameStorage *>())
    +          dyn_cast<UncommonTemplateNameStorage *>(Storage))
         return Uncommon->getAsOverloadedStorage();
     
       return nullptr;
    @@ -362,7 +362,7 @@ OverloadedTemplateStorage *TemplateName::getAsOverloadedTemplate() const {
     
     AssumedTemplateStorage *TemplateName::getAsAssumedTemplateName() const {
       if (UncommonTemplateNameStorage *Uncommon =
    -          Storage.dyn_cast<UncommonTemplateNameStorage *>())
    +          dyn_cast<UncommonTemplateNameStorage *>(Storage))
         return Uncommon->getAsAssumedTemplateName();
     
       return nullptr;
    @@ -380,7 +380,7 @@ TemplateName::getAsSubstTemplateTemplateParm() const {
     SubstTemplateTemplateParmPackStorage *
     TemplateName::getAsSubstTemplateTemplateParmPack() const {
       if (UncommonTemplateNameStorage *Uncommon =
    -          Storage.dyn_cast<UncommonTemplateNameStorage *>())
    +          dyn_cast<UncommonTemplateNameStorage *>(Storage))
         return Uncommon->getAsSubstTemplateTemplateParmPack();
     
       return nullptr;
    @@ -391,7 +391,7 @@ QualifiedTemplateName *TemplateName::getAsQualifiedTemplateName() const {
     }
     
     DependentTemplateName *TemplateName::getAsDependentTemplateName() const {
    -  return Storage.dyn_cast<DependentTemplateName *>();
    +  return dyn_cast<DependentTemplateName *>(Storage);
     }
     
     std::tuple<NestedNameSpecifier, bool>
    @@ -411,7 +411,7 @@ TemplateName::getQualifierAndTemplateKeyword() const {
     }
     
     UsingShadowDecl *TemplateName::getAsUsingShadowDecl() const {
    -  if (Decl *D = Storage.dyn_cast<Decl *>())
    +  if (Decl *D = dyn_cast<Decl *>(Storage))
         if (UsingShadowDecl *USD = dyn_cast<UsingShadowDecl>(D))
           return USD;
       if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName())
    
    
    ``````

    </details>

    nikic nikic approved these changes on Oct 25, 2026 07:52 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    kazutakahirata kazutakahirata
    Labels
    risk: low confidence: 67.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 27.9% (LOW) · Higher = larger blast radius
    27.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 67.7% · Lower = rushed or shallow review
    67.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 9% · Safe to merge
    9%