فهرست منبع

AST - 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373904 91177308-0d34-0410-b5e6-96231b3b80d8
Simon Pilgrim 5 سال پیش
والد
کامیت
d55e66916d
6فایلهای تغییر یافته به همراه11 افزوده شده و 14 حذف شده
  1. 3 6
      lib/AST/ExprCXX.cpp
  2. 1 1
      lib/AST/Interp/Program.cpp
  3. 1 1
      lib/AST/Mangle.cpp
  4. 4 4
      lib/AST/StmtPrinter.cpp
  5. 1 1
      lib/AST/TemplateBase.cpp
  6. 1 1
      lib/AST/TypePrinter.cpp

+ 3 - 6
lib/AST/ExprCXX.cpp

@@ -251,7 +251,7 @@ QualType CXXDeleteExpr::getDestroyedType() const {
   if (ArgType->isDependentType() && !ArgType->isPointerType())
   if (ArgType->isDependentType() && !ArgType->isPointerType())
     return QualType();
     return QualType();
 
 
-  return ArgType->getAs<PointerType>()->getPointeeType();
+  return ArgType->castAs<PointerType>()->getPointeeType();
 }
 }
 
 
 // CXXPseudoDestructorExpr
 // CXXPseudoDestructorExpr
@@ -1512,11 +1512,8 @@ CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() {
   // Otherwise the naming class must have been the base class.
   // Otherwise the naming class must have been the base class.
   else {
   else {
     QualType BaseType = getBaseType().getNonReferenceType();
     QualType BaseType = getBaseType().getNonReferenceType();
-    if (isArrow()) {
-      const auto *PT = BaseType->getAs<PointerType>();
-      assert(PT && "base of arrow member access is not pointer");
-      BaseType = PT->getPointeeType();
-    }
+    if (isArrow())
+      BaseType = BaseType->castAs<PointerType>()->getPointeeType();
 
 
     Record = BaseType->getAsCXXRecordDecl();
     Record = BaseType->getAsCXXRecordDecl();
     assert(Record && "base of member expression does not name record");
     assert(Record && "base of member expression does not name record");

+ 1 - 1
lib/AST/Interp/Program.cpp

@@ -123,7 +123,7 @@ llvm::Optional<unsigned> Program::getOrCreateDummy(const ParmVarDecl *PD) {
   auto &ASTCtx = Ctx.getASTContext();
   auto &ASTCtx = Ctx.getASTContext();
 
 
   // Create a pointer to an incomplete array of the specified elements.
   // Create a pointer to an incomplete array of the specified elements.
-  QualType ElemTy = PD->getType()->getAs<PointerType>()->getPointeeType();
+  QualType ElemTy = PD->getType()->castAs<PointerType>()->getPointeeType();
   QualType Ty = ASTCtx.getIncompleteArrayType(ElemTy, ArrayType::Normal, 0);
   QualType Ty = ASTCtx.getIncompleteArrayType(ElemTy, ArrayType::Normal, 0);
 
 
   // Dedup blocks since they are immutable and pointers cannot be compared.
   // Dedup blocks since they are immutable and pointers cannot be compared.

+ 1 - 1
lib/AST/Mangle.cpp

@@ -386,7 +386,7 @@ public:
     auto hasDefaultCXXMethodCC = [](ASTContext &C, const CXXMethodDecl *MD) {
     auto hasDefaultCXXMethodCC = [](ASTContext &C, const CXXMethodDecl *MD) {
       auto DefaultCC = C.getDefaultCallingConvention(/*IsVariadic=*/false,
       auto DefaultCC = C.getDefaultCallingConvention(/*IsVariadic=*/false,
                                                      /*IsCXXMethod=*/true);
                                                      /*IsCXXMethod=*/true);
-      auto CC = MD->getType()->getAs<FunctionProtoType>()->getCallConv();
+      auto CC = MD->getType()->castAs<FunctionProtoType>()->getCallConv();
       return CC == DefaultCC;
       return CC == DefaultCC;
     };
     };
 
 

+ 4 - 4
lib/AST/StmtPrinter.cpp

@@ -1102,7 +1102,7 @@ void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) {
   OS << Node->getValue().toString(10, isSigned);
   OS << Node->getValue().toString(10, isSigned);
 
 
   // Emit suffixes.  Integer literals are always a builtin integer type.
   // Emit suffixes.  Integer literals are always a builtin integer type.
-  switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
+  switch (Node->getType()->castAs<BuiltinType>()->getKind()) {
   default: llvm_unreachable("Unexpected type for integer literal!");
   default: llvm_unreachable("Unexpected type for integer literal!");
   case BuiltinType::Char_S:
   case BuiltinType::Char_S:
   case BuiltinType::Char_U:    OS << "i8"; break;
   case BuiltinType::Char_U:    OS << "i8"; break;
@@ -1123,7 +1123,7 @@ void StmtPrinter::VisitFixedPointLiteral(FixedPointLiteral *Node) {
     return;
     return;
   OS << Node->getValueAsString(/*Radix=*/10);
   OS << Node->getValueAsString(/*Radix=*/10);
 
 
-  switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
+  switch (Node->getType()->castAs<BuiltinType>()->getKind()) {
     default: llvm_unreachable("Unexpected type for fixed point literal!");
     default: llvm_unreachable("Unexpected type for fixed point literal!");
     case BuiltinType::ShortFract:   OS << "hr"; break;
     case BuiltinType::ShortFract:   OS << "hr"; break;
     case BuiltinType::ShortAccum:   OS << "hk"; break;
     case BuiltinType::ShortAccum:   OS << "hk"; break;
@@ -1152,7 +1152,7 @@ static void PrintFloatingLiteral(raw_ostream &OS, FloatingLiteral *Node,
     return;
     return;
 
 
   // Emit suffixes.  Float literals are always a builtin float type.
   // Emit suffixes.  Float literals are always a builtin float type.
-  switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
+  switch (Node->getType()->castAs<BuiltinType>()->getKind()) {
   default: llvm_unreachable("Unexpected type for float literal!");
   default: llvm_unreachable("Unexpected type for float literal!");
   case BuiltinType::Half:       break; // FIXME: suffix?
   case BuiltinType::Half:       break; // FIXME: suffix?
   case BuiltinType::Double:     break; // no suffix.
   case BuiltinType::Double:     break; // no suffix.
@@ -1952,7 +1952,7 @@ void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) {
     if (Node->isMutable())
     if (Node->isMutable())
       OS << " mutable";
       OS << " mutable";
 
 
-    auto *Proto = Method->getType()->getAs<FunctionProtoType>();
+    auto *Proto = Method->getType()->castAs<FunctionProtoType>();
     Proto->printExceptionSpecification(OS, Policy);
     Proto->printExceptionSpecification(OS, Policy);
 
 
     // FIXME: Attributes
     // FIXME: Attributes

+ 1 - 1
lib/AST/TemplateBase.cpp

@@ -370,7 +370,7 @@ TemplateArgument TemplateArgument::getPackExpansionPattern() const {
 
 
   switch (getKind()) {
   switch (getKind()) {
   case Type:
   case Type:
-    return getAsType()->getAs<PackExpansionType>()->getPattern();
+    return getAsType()->castAs<PackExpansionType>()->getPattern();
 
 
   case Expression:
   case Expression:
     return cast<PackExpansionExpr>(getAsExpr())->getPattern();
     return cast<PackExpansionExpr>(getAsExpr())->getPattern();

+ 1 - 1
lib/AST/TypePrinter.cpp

@@ -1537,7 +1537,7 @@ void TypePrinter::printAttributedAfter(const AttributedType *T,
    QualType t = T->getEquivalentType();
    QualType t = T->getEquivalentType();
    while (!t->isFunctionType())
    while (!t->isFunctionType())
      t = t->getPointeeType();
      t = t->getPointeeType();
-   OS << (t->getAs<FunctionType>()->getCallConv() == CC_AAPCS ?
+   OS << (t->castAs<FunctionType>()->getCallConv() == CC_AAPCS ?
          "\"aapcs\"" : "\"aapcs-vfp\"");
          "\"aapcs\"" : "\"aapcs-vfp\"");
    OS << ')';
    OS << ')';
    break;
    break;