r375443 - SemaTemplateDeduction - silence static analyzer getAs<> null dereference warnings. NFCI.

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 21 12:08:31 PDT 2019


Author: rksimon
Date: Mon Oct 21 12:08:31 2019
New Revision: 375443

URL: http://llvm.org/viewvc/llvm-project?rev=375443&view=rev
Log:
SemaTemplateDeduction - silence static analyzer getAs<> null dereference warnings. NFCI.

The static analyzer is warning about potential null dereferences, but in these cases we should be able to use castAs<> directly and if not assert will fire for us.

Modified:
    cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=375443&r1=375442&r2=375443&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Mon Oct 21 12:08:31 2019
@@ -3826,8 +3826,7 @@ Sema::TemplateDeductionResult Sema::Dedu
   if (Args.size() < Function->getMinRequiredArguments() && !PartialOverloading)
     return TDK_TooFewArguments;
   else if (TooManyArguments(NumParams, Args.size(), PartialOverloading)) {
-    const FunctionProtoType *Proto
-      = Function->getType()->getAs<FunctionProtoType>();
+    const auto *Proto = Function->getType()->castAs<FunctionProtoType>();
     if (Proto->isTemplateVariadic())
       /* Do nothing */;
     else if (!Proto->isVariadic())
@@ -3965,11 +3964,8 @@ QualType Sema::adjustCCAndNoReturn(QualT
   if (ArgFunctionType.isNull())
     return ArgFunctionType;
 
-  const FunctionProtoType *FunctionTypeP =
-      FunctionType->castAs<FunctionProtoType>();
-  const FunctionProtoType *ArgFunctionTypeP =
-      ArgFunctionType->getAs<FunctionProtoType>();
-
+  const auto *FunctionTypeP = FunctionType->castAs<FunctionProtoType>();
+  const auto *ArgFunctionTypeP = ArgFunctionType->castAs<FunctionProtoType>();
   FunctionProtoType::ExtProtoInfo EPI = ArgFunctionTypeP->getExtProtoInfo();
   bool Rebuild = false;
 




More information about the cfe-commits mailing list