[clang] 4d167fb - [Sema] TransformTypeOfExprType / TransformTypeOfType - don't dereference getAs<> results

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 27 05:10:07 PDT 2024


Author: Simon Pilgrim
Date: 2024-06-27T13:09:48+01:00
New Revision: 4d167fb28b8c8b2e278fb09b1c435db6d6393d56

URL: https://github.com/llvm/llvm-project/commit/4d167fb28b8c8b2e278fb09b1c435db6d6393d56
DIFF: https://github.com/llvm/llvm-project/commit/4d167fb28b8c8b2e278fb09b1c435db6d6393d56.diff

LOG: [Sema] TransformTypeOfExprType / TransformTypeOfType - don't dereference getAs<> results

Use castAs<> to assert the cast is valid to help avoid null dereferences

Fixes static analyser warnings

Added: 
    

Modified: 
    clang/lib/Sema/TreeTransform.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index ec678a55b11b7..51ba22f99e3a3 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6551,7 +6551,7 @@ QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
     return QualType();
 
   QualType Result = TL.getType();
-  TypeOfKind Kind = Result->getAs<TypeOfExprType>()->getKind();
+  TypeOfKind Kind = Result->castAs<TypeOfExprType>()->getKind();
   if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
     Result =
         getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
@@ -6576,7 +6576,7 @@ QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
     return QualType();
 
   QualType Result = TL.getType();
-  TypeOfKind Kind = Result->getAs<TypeOfType>()->getKind();
+  TypeOfKind Kind = Result->castAs<TypeOfType>()->getKind();
   if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
     Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
     if (Result.isNull())


        


More information about the cfe-commits mailing list