Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/ARCMigrate/TransGCCalls.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- TransGCCalls.cpp - Transformations to ARC mode -------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "Transforms.h"
10
#include "Internals.h"
11
#include "clang/AST/ASTContext.h"
12
#include "clang/Sema/SemaDiagnostic.h"
13
14
using namespace clang;
15
using namespace arcmt;
16
using namespace trans;
17
18
namespace {
19
20
class GCCollectableCallsChecker :
21
                         public RecursiveASTVisitor<GCCollectableCallsChecker> {
22
  MigrationContext &MigrateCtx;
23
  IdentifierInfo *NSMakeCollectableII;
24
  IdentifierInfo *CFMakeCollectableII;
25
26
public:
27
  GCCollectableCallsChecker(MigrationContext &ctx)
28
71
    : MigrateCtx(ctx) {
29
71
    IdentifierTable &Ids = MigrateCtx.Pass.Ctx.Idents;
30
71
    NSMakeCollectableII = &Ids.get("NSMakeCollectable");
31
71
    CFMakeCollectableII = &Ids.get("CFMakeCollectable");
32
71
  }
33
34
50
  bool shouldWalkTypesOfTypeLocs() const { return false; }
35
36
51
  bool VisitCallExpr(CallExpr *E) {
37
51
    TransformActions &TA = MigrateCtx.Pass.TA;
38
51
39
51
    if (MigrateCtx.isGCOwnedNonObjC(E->getType())) {
40
4
      TA.report(E->getBeginLoc(), diag::warn_arcmt_nsalloc_realloc,
41
4
                E->getSourceRange());
42
4
      return true;
43
4
    }
44
47
45
47
    Expr *CEE = E->getCallee()->IgnoreParenImpCasts();
46
47
    if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) {
47
47
      if (FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(DRE->getDecl())) {
48
47
        if (!FD->getDeclContext()->getRedeclContext()->isFileContext())
49
0
          return true;
50
47
51
47
        if (FD->getIdentifier() == NSMakeCollectableII) {
52
18
          Transaction Trans(TA);
53
18
          TA.clearDiagnostic(diag::err_unavailable,
54
18
                             diag::err_unavailable_message,
55
18
                             diag::err_ovl_deleted_call, // ObjC++
56
18
                             DRE->getSourceRange());
57
18
          TA.replace(DRE->getSourceRange(), "CFBridgingRelease");
58
18
59
29
        } else if (FD->getIdentifier() == CFMakeCollectableII) {
60
2
          TA.reportError("CFMakeCollectable will leak the object that it "
61
2
                         "receives in ARC", DRE->getLocation(),
62
2
                         DRE->getSourceRange());
63
2
        }
64
47
      }
65
47
    }
66
47
67
47
    return true;
68
47
  }
69
};
70
71
} // anonymous namespace
72
73
71
void GCCollectableCallsTraverser::traverseBody(BodyContext &BodyCtx) {
74
71
  GCCollectableCallsChecker(BodyCtx.getMigrationContext())
75
71
                                            .TraverseStmt(BodyCtx.getTopStmt());
76
71
}