/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/ARCMigrate/TransARCAssign.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- TransARCAssign.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 | | // makeAssignARCSafe: |
10 | | // |
11 | | // Add '__strong' where appropriate. |
12 | | // |
13 | | // for (id x in collection) { |
14 | | // x = 0; |
15 | | // } |
16 | | // ----> |
17 | | // for (__strong id x in collection) { |
18 | | // x = 0; |
19 | | // } |
20 | | // |
21 | | //===----------------------------------------------------------------------===// |
22 | | |
23 | | #include "Transforms.h" |
24 | | #include "Internals.h" |
25 | | #include "clang/AST/ASTContext.h" |
26 | | #include "clang/Sema/SemaDiagnostic.h" |
27 | | |
28 | | using namespace clang; |
29 | | using namespace arcmt; |
30 | | using namespace trans; |
31 | | |
32 | | namespace { |
33 | | |
34 | | class ARCAssignChecker : public RecursiveASTVisitor<ARCAssignChecker> { |
35 | | MigrationPass &Pass; |
36 | | llvm::DenseSet<VarDecl *> ModifiedVars; |
37 | | |
38 | | public: |
39 | 85 | ARCAssignChecker(MigrationPass &pass) : Pass(pass) { } |
40 | | |
41 | 162 | bool VisitBinaryOperator(BinaryOperator *Exp) { |
42 | 162 | if (Exp->getType()->isDependentType()) |
43 | 0 | return true; |
44 | | |
45 | 162 | Expr *E = Exp->getLHS(); |
46 | 162 | SourceLocation OrigLoc = E->getExprLoc(); |
47 | 162 | SourceLocation Loc = OrigLoc; |
48 | 162 | DeclRefExpr *declRef = dyn_cast<DeclRefExpr>(E->IgnoreParenCasts()); |
49 | 162 | if (declRef && isa<VarDecl>(declRef->getDecl())88 ) { |
50 | 88 | ASTContext &Ctx = Pass.Ctx; |
51 | 88 | Expr::isModifiableLvalueResult IsLV = E->isModifiableLvalue(Ctx, &Loc); |
52 | 88 | if (IsLV != Expr::MLV_ConstQualified) |
53 | 82 | return true; |
54 | 6 | VarDecl *var = cast<VarDecl>(declRef->getDecl()); |
55 | 6 | if (var->isARCPseudoStrong()) { |
56 | 6 | Transaction Trans(Pass.TA); |
57 | 6 | if (Pass.TA.clearDiagnostic(diag::err_typecheck_arr_assign_enumeration, |
58 | 6 | Exp->getOperatorLoc())) { |
59 | 5 | if (!ModifiedVars.count(var)) { |
60 | 3 | TypeLoc TLoc = var->getTypeSourceInfo()->getTypeLoc(); |
61 | 3 | Pass.TA.insert(TLoc.getBeginLoc(), "__strong "); |
62 | 3 | ModifiedVars.insert(var); |
63 | 3 | } |
64 | 5 | } |
65 | 6 | } |
66 | 6 | } |
67 | | |
68 | 80 | return true; |
69 | 162 | } |
70 | | }; |
71 | | |
72 | | } // anonymous namespace |
73 | | |
74 | 85 | void trans::makeAssignARCSafe(MigrationPass &pass) { |
75 | 85 | ARCAssignChecker assignCheck(pass); |
76 | 85 | assignCheck.TraverseDecl(pass.Ctx.getTranslationUnitDecl()); |
77 | 85 | } |