[clang] 286955c - [Sema] HLSLCompareFloatingRank - don't dereference getAs<> results

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 27 04:30:11 PDT 2024


Author: Simon Pilgrim
Date: 2024-06-27T12:29:55+01:00
New Revision: 286955caa32b5b9fd959176c85ffb925e8093a0d

URL: https://github.com/llvm/llvm-project/commit/286955caa32b5b9fd959176c85ffb925e8093a0d
DIFF: https://github.com/llvm/llvm-project/commit/286955caa32b5b9fd959176c85ffb925e8093a0d.diff

LOG: [Sema] HLSLCompareFloatingRank - don't dereference getAs<> results

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

Fixes static analyser warning

Added: 
    

Modified: 
    clang/lib/Sema/SemaOverload.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index db77e5cfc1957..ee921c825b2a4 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -4372,8 +4372,8 @@ HLSLCompareFloatingRank(QualType LHS, QualType RHS) {
   if (const auto *VT = RHS->getAs<VectorType>())
     RHS = VT->getElementType();
 
-  const auto L = LHS->getAs<BuiltinType>()->getKind();
-  const auto R = RHS->getAs<BuiltinType>()->getKind();
+  const auto L = LHS->castAs<BuiltinType>()->getKind();
+  const auto R = RHS->castAs<BuiltinType>()->getKind();
   if (L == R)
     return ImplicitConversionSequence::Indistinguishable;
   return L < R ? ImplicitConversionSequence::Better


        


More information about the cfe-commits mailing list