[clang] 4b43209 - [clang][sema] Use castAs<> instead of getAs<> to avoid dereference of nullptr

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 13 05:14:22 PST 2022


Author: Simon Pilgrim
Date: 2022-02-13T13:14:05Z
New Revision: 4b432096839e719ec0b78cd0299e7950a59dce0b

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

LOG: [clang][sema] Use castAs<> instead of getAs<> to avoid dereference of nullptr

The pointers are referenced immediately, so assert the cast is correct instead of returning nullptr

Added: 
    

Modified: 
    clang/lib/Sema/SemaExpr.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 6629f3e061f80..22b3f371afe79 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3022,7 +3022,7 @@ Sema::PerformObjectMemberConversion(Expr *From,
     QualType QType = QualType(Qualifier->getAsType(), 0);
     assert(QType->isRecordType() && "lookup done with non-record type");
 
-    QualType QRecordType = QualType(QType->getAs<RecordType>(), 0);
+    QualType QRecordType = QualType(QType->castAs<RecordType>(), 0);
 
     // In C++98, the qualifier type doesn't actually have to be a base
     // type of the object type, in which case we just ignore it.
@@ -10035,7 +10035,7 @@ static bool tryGCCVectorConvertAndSplat(Sema &S, ExprResult *Scalar,
                                         ExprResult *Vector) {
   QualType ScalarTy = Scalar->get()->getType().getUnqualifiedType();
   QualType VectorTy = Vector->get()->getType().getUnqualifiedType();
-  const VectorType *VT = VectorTy->getAs<VectorType>();
+  const auto *VT = VectorTy->castAs<VectorType>();
 
   assert(!isa<ExtVectorType>(VT) &&
          "ExtVectorTypes should not be handled here!");


        


More information about the cfe-commits mailing list