[llvm-branch-commits] [clang] 25f5df7 - SemaType.cpp - use castAs<> instead of getAs<> for dereferenced pointers

Simon Pilgrim via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Dec 8 08:46:22 PST 2020


Author: Simon Pilgrim
Date: 2020-12-08T16:37:20Z
New Revision: 25f5df7e0bc950ad244e8da000ce4248bd41c140

URL: https://github.com/llvm/llvm-project/commit/25f5df7e0bc950ad244e8da000ce4248bd41c140
DIFF: https://github.com/llvm/llvm-project/commit/25f5df7e0bc950ad244e8da000ce4248bd41c140.diff

LOG: SemaType.cpp - use castAs<> instead of getAs<> for dereferenced pointers

Fix static analyzer warnings - castAs<> will assert the type is correct, but getAs<> just returns null, which would just result in a dereferenced null pointer.

Added: 
    

Modified: 
    clang/lib/Sema/SemaType.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index df46aa3bfc1f..fbdbfbc9f8ec 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -7967,7 +7967,7 @@ static void HandleOpenCLAccessAttr(QualType &CurType, const ParsedAttr &Attr,
            diag::note_opencl_typedef_access_qualifier) << PrevAccessQual;
   } else if (CurType->isPipeType()) {
     if (Attr.getSemanticSpelling() == OpenCLAccessAttr::Keyword_write_only) {
-      QualType ElemType = CurType->getAs<PipeType>()->getElementType();
+      QualType ElemType = CurType->castAs<PipeType>()->getElementType();
       CurType = S.Context.getWritePipeType(ElemType);
     }
   }
@@ -9021,7 +9021,7 @@ QualType Sema::BuildUnaryTransformType(QualType BaseType,
           return QualType();
         }
 
-        EnumDecl *ED = BaseType->getAs<EnumType>()->getDecl();
+        EnumDecl *ED = BaseType->castAs<EnumType>()->getDecl();
         assert(ED && "EnumType has no EnumDecl");
 
         DiagnoseUseOfDecl(ED, Loc);


        


More information about the llvm-branch-commits mailing list