[clang] 88bb265 - SemaExpr.cpp - use castAs<> instead of getAs<> as we dereference the pointer directly. NFCI.

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 25 03:39:11 PST 2020


Author: Simon Pilgrim
Date: 2020-11-25T11:38:30Z
New Revision: 88bb2656708050bdb012c9046b3e30f3975f9949

URL: https://github.com/llvm/llvm-project/commit/88bb2656708050bdb012c9046b3e30f3975f9949
DIFF: https://github.com/llvm/llvm-project/commit/88bb2656708050bdb012c9046b3e30f3975f9949.diff

LOG: SemaExpr.cpp - use castAs<> instead of getAs<> as we dereference the pointer directly. NFCI.

castAs<> will assert the correct cast type instead of just returning null, which we then try to dereference immediately.

Added: 
    

Modified: 
    clang/lib/Sema/SemaExpr.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 859caed8fd866..d25d91223826e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3778,8 +3778,7 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
 
     if (Ty == Context.DoubleTy) {
       if (getLangOpts().SinglePrecisionConstants) {
-        const BuiltinType *BTy = Ty->getAs<BuiltinType>();
-        if (BTy->getKind() != BuiltinType::Float) {
+        if (Ty->castAs<BuiltinType>()->getKind() != BuiltinType::Float) {
           Res = ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast).get();
         }
       } else if (getLangOpts().OpenCL &&


        


More information about the cfe-commits mailing list