Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Analysis/ThreadSafetyCommon.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- ThreadSafetyCommon.cpp ---------------------------------------------===//
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
// Implementation of the interfaces declared in ThreadSafetyCommon.h
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/Analysis/Analyses/ThreadSafetyCommon.h"
14
#include "clang/AST/Attr.h"
15
#include "clang/AST/Decl.h"
16
#include "clang/AST/DeclCXX.h"
17
#include "clang/AST/DeclGroup.h"
18
#include "clang/AST/DeclObjC.h"
19
#include "clang/AST/Expr.h"
20
#include "clang/AST/ExprCXX.h"
21
#include "clang/AST/OperationKinds.h"
22
#include "clang/AST/Stmt.h"
23
#include "clang/AST/Type.h"
24
#include "clang/Analysis/Analyses/ThreadSafetyTIL.h"
25
#include "clang/Analysis/CFG.h"
26
#include "clang/Basic/LLVM.h"
27
#include "clang/Basic/OperatorKinds.h"
28
#include "clang/Basic/Specifiers.h"
29
#include "llvm/ADT/StringRef.h"
30
#include "llvm/Support/Casting.h"
31
#include <algorithm>
32
#include <cassert>
33
#include <string>
34
#include <utility>
35
36
using namespace clang;
37
using namespace threadSafety;
38
39
// From ThreadSafetyUtil.h
40
12
std::string threadSafety::getSourceLiteralString(const Expr *CE) {
41
12
  switch (CE->getStmtClass()) {
42
12
    case Stmt::IntegerLiteralClass:
43
12
      return cast<IntegerLiteral>(CE)->getValue().toString(10, true);
44
12
    case Stmt::StringLiteralClass: {
45
0
      std::string ret("\"");
46
0
      ret += cast<StringLiteral>(CE)->getString();
47
0
      ret += "\"";
48
0
      return ret;
49
12
    }
50
12
    case Stmt::CharacterLiteralClass:
51
0
    case Stmt::CXXNullPtrLiteralExprClass:
52
0
    case Stmt::GNUNullExprClass:
53
0
    case Stmt::CXXBoolLiteralExprClass:
54
0
    case Stmt::FloatingLiteralClass:
55
0
    case Stmt::ImaginaryLiteralClass:
56
0
    case Stmt::ObjCStringLiteralClass:
57
0
    default:
58
0
      return "#lit";
59
12
  }
60
12
}
61
62
// Return true if E is a variable that points to an incomplete Phi node.
63
0
static bool isIncompletePhi(const til::SExpr *E) {
64
0
  if (const auto *Ph = dyn_cast<til::Phi>(E))
65
0
    return Ph->status() == til::Phi::PH_Incomplete;
66
0
  return false;
67
0
}
68
69
using CallingContext = SExprBuilder::CallingContext;
70
71
21.7k
til::SExpr *SExprBuilder::lookupStmt(const Stmt *S) {
72
21.7k
  auto It = SMap.find(S);
73
21.7k
  if (It != SMap.end())
74
0
    return It->second;
75
21.7k
  return nullptr;
76
21.7k
}
77
78
0
til::SCFG *SExprBuilder::buildCFG(CFGWalker &Walker) {
79
0
  Walker.walk(*this);
80
0
  return Scfg;
81
0
}
82
83
4.06k
static bool isCalleeArrow(const Expr *E) {
84
4.06k
  const auto *ME = dyn_cast<MemberExpr>(E->IgnoreParenCasts());
85
4.06k
  return ME ? ME->isArrow() : 
false0
;
86
4.06k
}
87
88
/// Translate a clang expression in an attribute to a til::SExpr.
89
/// Constructs the context from D, DeclExp, and SelfDecl.
90
///
91
/// \param AttrExp The expression to translate.
92
/// \param D       The declaration to which the attribute is attached.
93
/// \param DeclExp An expression involving the Decl to which the attribute
94
///                is attached.  E.g. the call to a function.
95
CapabilityExpr SExprBuilder::translateAttrExpr(const Expr *AttrExp,
96
                                               const NamedDecl *D,
97
                                               const Expr *DeclExp,
98
7.91k
                                               VarDecl *SelfDecl) {
99
7.91k
  // If we are processing a raw attribute expression, with no substitutions.
100
7.91k
  if (!DeclExp)
101
788
    return translateAttrExpr(AttrExp, nullptr);
102
7.12k
103
7.12k
  CallingContext Ctx(nullptr, D);
104
7.12k
105
7.12k
  // Examine DeclExp to find SelfArg and FunArgs, which are used to substitute
106
7.12k
  // for formal parameters when we call buildMutexID later.
107
7.12k
  if (const auto *ME = dyn_cast<MemberExpr>(DeclExp)) {
108
2.04k
    Ctx.SelfArg   = ME->getBase();
109
2.04k
    Ctx.SelfArrow = ME->isArrow();
110
5.08k
  } else if (const auto *CE = dyn_cast<CXXMemberCallExpr>(DeclExp)) {
111
4.06k
    Ctx.SelfArg   = CE->getImplicitObjectArgument();
112
4.06k
    Ctx.SelfArrow = isCalleeArrow(CE->getCallee());
113
4.06k
    Ctx.NumArgs   = CE->getNumArgs();
114
4.06k
    Ctx.FunArgs   = CE->getArgs();
115
4.06k
  } else 
if (const auto *1.02k
CE1.02k
= dyn_cast<CallExpr>(DeclExp)) {
116
290
    Ctx.NumArgs = CE->getNumArgs();
117
290
    Ctx.FunArgs = CE->getArgs();
118
736
  } else if (const auto *CE = dyn_cast<CXXConstructExpr>(DeclExp)) {
119
262
    Ctx.SelfArg = nullptr;  // Will be set below
120
262
    Ctx.NumArgs = CE->getNumArgs();
121
262
    Ctx.FunArgs = CE->getArgs();
122
474
  } else if (D && isa<CXXDestructorDecl>(D)) {
123
214
    // There's no such thing as a "destructor call" in the AST.
124
214
    Ctx.SelfArg = DeclExp;
125
214
  }
126
7.12k
127
7.12k
  // Hack to handle constructors, where self cannot be recovered from
128
7.12k
  // the expression.
129
7.12k
  if (SelfDecl && 
!Ctx.SelfArg238
) {
130
238
    DeclRefExpr SelfDRE(SelfDecl->getASTContext(), SelfDecl, false,
131
238
                        SelfDecl->getType(), VK_LValue,
132
238
                        SelfDecl->getLocation());
133
238
    Ctx.SelfArg = &SelfDRE;
134
238
135
238
    // If the attribute has no arguments, then assume the argument is "this".
136
238
    if (!AttrExp)
137
4
      return translateAttrExpr(Ctx.SelfArg, nullptr);
138
234
    else  // For most attributes.
139
234
      return translateAttrExpr(AttrExp, &Ctx);
140
6.88k
  }
141
6.88k
142
6.88k
  // If the attribute has no arguments, then assume the argument is "this".
143
6.88k
  if (!AttrExp)
144
2.89k
    return translateAttrExpr(Ctx.SelfArg, nullptr);
145
3.99k
  else  // For most attributes.
146
3.99k
    return translateAttrExpr(AttrExp, &Ctx);
147
6.88k
}
148
149
/// Translate a clang expression in an attribute to a til::SExpr.
150
// This assumes a CallingContext has already been created.
151
CapabilityExpr SExprBuilder::translateAttrExpr(const Expr *AttrExp,
152
8.46k
                                               CallingContext *Ctx) {
153
8.46k
  if (!AttrExp)
154
0
    return CapabilityExpr(nullptr, false);
155
8.46k
156
8.46k
  if (const auto* SLit = dyn_cast<StringLiteral>(AttrExp)) {
157
96
    if (SLit->getString() == StringRef("*"))
158
64
      // The "*" expr is a universal lock, which essentially turns off
159
64
      // checks until it is removed from the lockset.
160
64
      return CapabilityExpr(new (Arena) til::Wildcard(), false);
161
32
    else
162
32
      // Ignore other string literals for now.
163
32
      return CapabilityExpr(nullptr, false);
164
8.36k
  }
165
8.36k
166
8.36k
  bool Neg = false;
167
8.36k
  if (const auto *OE = dyn_cast<CXXOperatorCallExpr>(AttrExp)) {
168
172
    if (OE->getOperator() == OO_Exclaim) {
169
44
      Neg = true;
170
44
      AttrExp = OE->getArg(0);
171
44
    }
172
172
  }
173
8.19k
  else if (const auto *UO = dyn_cast<UnaryOperator>(AttrExp)) {
174
96
    if (UO->getOpcode() == UO_LNot) {
175
12
      Neg = true;
176
12
      AttrExp = UO->getSubExpr();
177
12
    }
178
96
  }
179
8.36k
180
8.36k
  til::SExpr *E = translate(AttrExp, Ctx);
181
8.36k
182
8.36k
  // Trap mutex expressions like nullptr, or 0.
183
8.36k
  // Any literal value is nonsense.
184
8.36k
  if (!E || 
isa<til::Literal>(E)8.35k
)
185
16
    return CapabilityExpr(nullptr, false);
186
8.34k
187
8.34k
  // Hack to deal with smart pointers -- strip off top-level pointer casts.
188
8.34k
  if (const auto *CE = dyn_cast_or_null<til::Cast>(E)) {
189
272
    if (CE->castOpcode() == til::CAST_objToPtr)
190
272
      return CapabilityExpr(CE->expr(), Neg);
191
8.07k
  }
192
8.07k
  return CapabilityExpr(E, Neg);
193
8.07k
}
194
195
// Translate a clang statement or expression to a TIL expression.
196
// Also performs substitution of variables; Ctx provides the context.
197
// Dispatches on the type of S.
198
21.7k
til::SExpr *SExprBuilder::translate(const Stmt *S, CallingContext *Ctx) {
199
21.7k
  if (!S)
200
0
    return nullptr;
201
21.7k
202
21.7k
  // Check if S has already been translated and cached.
203
21.7k
  // This handles the lookup of SSA names for DeclRefExprs here.
204
21.7k
  if (til::SExpr *E = lookupStmt(S))
205
0
    return E;
206
21.7k
207
21.7k
  switch (S->getStmtClass()) {
208
21.7k
  case Stmt::DeclRefExprClass:
209
4.80k
    return translateDeclRefExpr(cast<DeclRefExpr>(S), Ctx);
210
21.7k
  case Stmt::CXXThisExprClass:
211
7.20k
    return translateCXXThisExpr(cast<CXXThisExpr>(S), Ctx);
212
21.7k
  case Stmt::MemberExprClass:
213
6.27k
    return translateMemberExpr(cast<MemberExpr>(S), Ctx);
214
21.7k
  case Stmt::ObjCIvarRefExprClass:
215
2
    return translateObjCIVarRefExpr(cast<ObjCIvarRefExpr>(S), Ctx);
216
21.7k
  case Stmt::CallExprClass:
217
104
    return translateCallExpr(cast<CallExpr>(S), Ctx);
218
21.7k
  case Stmt::CXXMemberCallExprClass:
219
388
    return translateCXXMemberCallExpr(cast<CXXMemberCallExpr>(S), Ctx);
220
21.7k
  case Stmt::CXXOperatorCallExprClass:
221
272
    return translateCXXOperatorCallExpr(cast<CXXOperatorCallExpr>(S), Ctx);
222
21.7k
  case Stmt::UnaryOperatorClass:
223
417
    return translateUnaryOperator(cast<UnaryOperator>(S), Ctx);
224
21.7k
  case Stmt::BinaryOperatorClass:
225
36
  case Stmt::CompoundAssignOperatorClass:
226
36
    return translateBinaryOperator(cast<BinaryOperator>(S), Ctx);
227
36
228
48
  case Stmt::ArraySubscriptExprClass:
229
48
    return translateArraySubscriptExpr(cast<ArraySubscriptExpr>(S), Ctx);
230
36
  case Stmt::ConditionalOperatorClass:
231
24
    return translateAbstractConditionalOperator(
232
24
             cast<ConditionalOperator>(S), Ctx);
233
36
  case Stmt::BinaryConditionalOperatorClass:
234
0
    return translateAbstractConditionalOperator(
235
0
             cast<BinaryConditionalOperator>(S), Ctx);
236
36
237
36
  // We treat these as no-ops
238
36
  case Stmt::ConstantExprClass:
239
0
    return translate(cast<ConstantExpr>(S)->getSubExpr(), Ctx);
240
94
  case Stmt::ParenExprClass:
241
94
    return translate(cast<ParenExpr>(S)->getSubExpr(), Ctx);
242
36
  case Stmt::ExprWithCleanupsClass:
243
0
    return translate(cast<ExprWithCleanups>(S)->getSubExpr(), Ctx);
244
36
  case Stmt::CXXBindTemporaryExprClass:
245
36
    return translate(cast<CXXBindTemporaryExpr>(S)->getSubExpr(), Ctx);
246
40
  case Stmt::MaterializeTemporaryExprClass:
247
40
    return translate(cast<MaterializeTemporaryExpr>(S)->GetTemporaryExpr(),
248
40
                     Ctx);
249
36
250
36
  // Collect all literals
251
72
  case Stmt::CharacterLiteralClass:
252
72
  case Stmt::CXXNullPtrLiteralExprClass:
253
72
  case Stmt::GNUNullExprClass:
254
72
  case Stmt::CXXBoolLiteralExprClass:
255
72
  case Stmt::FloatingLiteralClass:
256
72
  case Stmt::ImaginaryLiteralClass:
257
72
  case Stmt::IntegerLiteralClass:
258
72
  case Stmt::StringLiteralClass:
259
72
  case Stmt::ObjCStringLiteralClass:
260
72
    return new (Arena) til::Literal(cast<Expr>(S));
261
72
262
72
  case Stmt::DeclStmtClass:
263
0
    return translateDeclStmt(cast<DeclStmt>(S), Ctx);
264
1.91k
  default:
265
1.91k
    break;
266
1.91k
  }
267
1.91k
  if (const auto *CE = dyn_cast<CastExpr>(S))
268
1.88k
    return translateCastExpr(CE, Ctx);
269
28
270
28
  return new (Arena) til::Undefined(S);
271
28
}
272
273
til::SExpr *SExprBuilder::translateDeclRefExpr(const DeclRefExpr *DRE,
274
4.80k
                                               CallingContext *Ctx) {
275
4.80k
  const auto *VD = cast<ValueDecl>(DRE->getDecl()->getCanonicalDecl());
276
4.80k
277
4.80k
  // Function parameters require substitution and/or renaming.
278
4.80k
  if (const auto *PV = dyn_cast_or_null<ParmVarDecl>(VD)) {
279
972
    unsigned I = PV->getFunctionScopeIndex();
280
972
    const DeclContext *D = PV->getDeclContext();
281
972
    if (Ctx && 
Ctx->FunArgs552
) {
282
552
      const Decl *Canonical = Ctx->AttrDecl->getCanonicalDecl();
283
552
      if (isa<FunctionDecl>(D)
284
552
              ? (cast<FunctionDecl>(D)->getCanonicalDecl() == Canonical)
285
552
              : 
(cast<ObjCMethodDecl>(D)->getCanonicalDecl() == Canonical)0
) {
286
552
        // Substitute call arguments for references to function parameters
287
552
        assert(I < Ctx->NumArgs);
288
552
        return translate(Ctx->FunArgs[I], Ctx->Prev);
289
552
      }
290
420
    }
291
420
    // Map the param back to the param of the original function declaration
292
420
    // for consistent comparisons.
293
420
    VD = isa<FunctionDecl>(D)
294
420
             ? 
cast<FunctionDecl>(D)->getCanonicalDecl()->getParamDecl(I)419
295
420
             : 
cast<ObjCMethodDecl>(D)->getCanonicalDecl()->getParamDecl(I)1
;
296
420
  }
297
4.80k
298
4.80k
  // For non-local variables, treat it as a reference to a named object.
299
4.80k
  
return new (Arena) til::LiteralPtr(VD)4.25k
;
300
4.80k
}
301
302
til::SExpr *SExprBuilder::translateCXXThisExpr(const CXXThisExpr *TE,
303
7.20k
                                               CallingContext *Ctx) {
304
7.20k
  // Substitute for 'this'
305
7.20k
  if (Ctx && 
Ctx->SelfArg3.12k
)
306
3.12k
    return translate(Ctx->SelfArg, Ctx->Prev);
307
4.08k
  assert(SelfVar && "We have no variable for 'this'!");
308
4.08k
  return SelfVar;
309
4.08k
}
310
311
6.27k
static const ValueDecl *getValueDeclFromSExpr(const til::SExpr *E) {
312
6.27k
  if (const auto *V = dyn_cast<til::Variable>(E))
313
4.05k
    return V->clangDecl();
314
2.21k
  if (const auto *Ph = dyn_cast<til::Phi>(E))
315
0
    return Ph->clangDecl();
316
2.21k
  if (const auto *P = dyn_cast<til::Project>(E))
317
180
    return P->clangDecl();
318
2.03k
  if (const auto *L = dyn_cast<til::LiteralPtr>(E))
319
1.72k
    return L->clangDecl();
320
308
  return nullptr;
321
308
}
322
323
6.27k
static bool hasAnyPointerType(const til::SExpr *E) {
324
6.27k
  auto *VD = getValueDeclFromSExpr(E);
325
6.27k
  if (VD && 
VD->getType()->isAnyPointerType()1.90k
)
326
634
    return true;
327
5.63k
  if (const auto *C = dyn_cast<til::Cast>(E))
328
120
    return C->castOpcode() == til::CAST_objToPtr;
329
5.51k
330
5.51k
  return false;
331
5.51k
}
332
333
// Grab the very first declaration of virtual method D
334
136
static const CXXMethodDecl *getFirstVirtualDecl(const CXXMethodDecl *D) {
335
148
  while (true) {
336
148
    D = D->getCanonicalDecl();
337
148
    auto OverriddenMethods = D->overridden_methods();
338
148
    if (OverriddenMethods.begin() == OverriddenMethods.end())
339
136
      return D;  // Method does not override anything
340
12
    // FIXME: this does not work with multiple inheritance.
341
12
    D = *OverriddenMethods.begin();
342
12
  }
343
136
  
return nullptr0
;
344
136
}
345
346
til::SExpr *SExprBuilder::translateMemberExpr(const MemberExpr *ME,
347
6.27k
                                              CallingContext *Ctx) {
348
6.27k
  til::SExpr *BE = translate(ME->getBase(), Ctx);
349
6.27k
  til::SExpr *E  = new (Arena) til::SApply(BE);
350
6.27k
351
6.27k
  const auto *D = cast<ValueDecl>(ME->getMemberDecl()->getCanonicalDecl());
352
6.27k
  if (const auto *VD = dyn_cast<CXXMethodDecl>(D))
353
136
    D = getFirstVirtualDecl(VD);
354
6.27k
355
6.27k
  til::Project *P = new (Arena) til::Project(E, D);
356
6.27k
  if (hasAnyPointerType(BE))
357
752
    P->setArrow(true);
358
6.27k
  return P;
359
6.27k
}
360
361
til::SExpr *SExprBuilder::translateObjCIVarRefExpr(const ObjCIvarRefExpr *IVRE,
362
2
                                                   CallingContext *Ctx) {
363
2
  til::SExpr *BE = translate(IVRE->getBase(), Ctx);
364
2
  til::SExpr *E = new (Arena) til::SApply(BE);
365
2
366
2
  const auto *D = cast<ObjCIvarDecl>(IVRE->getDecl()->getCanonicalDecl());
367
2
368
2
  til::Project *P = new (Arena) til::Project(E, D);
369
2
  if (hasAnyPointerType(BE))
370
2
    P->setArrow(true);
371
2
  return P;
372
2
}
373
374
til::SExpr *SExprBuilder::translateCallExpr(const CallExpr *CE,
375
                                            CallingContext *Ctx,
376
372
                                            const Expr *SelfE) {
377
372
  if (CapabilityExprMode) {
378
372
    // Handle LOCK_RETURNED
379
372
    if (const FunctionDecl *FD = CE->getDirectCallee()) {
380
360
      FD = FD->getMostRecentDecl();
381
360
      if (LockReturnedAttr *At = FD->getAttr<LockReturnedAttr>()) {
382
172
        CallingContext LRCallCtx(Ctx);
383
172
        LRCallCtx.AttrDecl = CE->getDirectCallee();
384
172
        LRCallCtx.SelfArg = SelfE;
385
172
        LRCallCtx.NumArgs = CE->getNumArgs();
386
172
        LRCallCtx.FunArgs = CE->getArgs();
387
172
        return const_cast<til::SExpr *>(
388
172
            translateAttrExpr(At->getArg(), &LRCallCtx).sexpr());
389
172
      }
390
200
    }
391
372
  }
392
200
393
200
  til::SExpr *E = translate(CE->getCallee(), Ctx);
394
200
  for (const auto *Arg : CE->arguments()) {
395
200
    til::SExpr *A = translate(Arg, Ctx);
396
200
    E = new (Arena) til::Apply(E, A);
397
200
  }
398
200
  return new (Arena) til::Call(E, CE);
399
200
}
400
401
til::SExpr *SExprBuilder::translateCXXMemberCallExpr(
402
388
    const CXXMemberCallExpr *ME, CallingContext *Ctx) {
403
388
  if (CapabilityExprMode) {
404
388
    // Ignore calls to get() on smart pointers.
405
388
    if (ME->getMethodDecl()->getNameAsString() == "get" &&
406
388
        
ME->getNumArgs() == 0148
) {
407
148
      auto *E = translate(ME->getImplicitObjectArgument(), Ctx);
408
148
      return new (Arena) til::Cast(til::CAST_objToPtr, E);
409
148
      // return E;
410
148
    }
411
240
  }
412
240
  return translateCallExpr(cast<CallExpr>(ME), Ctx,
413
240
                           ME->getImplicitObjectArgument());
414
240
}
415
416
til::SExpr *SExprBuilder::translateCXXOperatorCallExpr(
417
272
    const CXXOperatorCallExpr *OCE, CallingContext *Ctx) {
418
272
  if (CapabilityExprMode) {
419
272
    // Ignore operator * and operator -> on smart pointers.
420
272
    OverloadedOperatorKind k = OCE->getOperator();
421
272
    if (k == OO_Star || 
k == OO_Arrow164
) {
422
244
      auto *E = translate(OCE->getArg(0), Ctx);
423
244
      return new (Arena) til::Cast(til::CAST_objToPtr, E);
424
244
      // return E;
425
244
    }
426
28
  }
427
28
  return translateCallExpr(cast<CallExpr>(OCE), Ctx);
428
28
}
429
430
til::SExpr *SExprBuilder::translateUnaryOperator(const UnaryOperator *UO,
431
417
                                                 CallingContext *Ctx) {
432
417
  switch (UO->getOpcode()) {
433
417
  case UO_PostInc:
434
0
  case UO_PostDec:
435
0
  case UO_PreInc:
436
0
  case UO_PreDec:
437
0
    return new (Arena) til::Undefined(UO);
438
0
439
403
  case UO_AddrOf:
440
403
    if (CapabilityExprMode) {
441
403
      // interpret &Graph::mu_ as an existential.
442
403
      if (const auto *DRE = dyn_cast<DeclRefExpr>(UO->getSubExpr())) {
443
283
        if (DRE->getDecl()->isCXXInstanceMember()) {
444
84
          // This is a pointer-to-member expression, e.g. &MyClass::mu_.
445
84
          // We interpret this syntax specially, as a wildcard.
446
84
          auto *W = new (Arena) til::Wildcard();
447
84
          return new (Arena) til::Project(W, DRE->getDecl());
448
84
        }
449
319
      }
450
403
    }
451
319
    // otherwise, & is a no-op
452
319
    return translate(UO->getSubExpr(), Ctx);
453
319
454
319
  // We treat these as no-ops
455
319
  case UO_Deref:
456
14
  case UO_Plus:
457
14
    return translate(UO->getSubExpr(), Ctx);
458
14
459
14
  case UO_Minus:
460
0
    return new (Arena)
461
0
      til::UnaryOp(til::UOP_Minus, translate(UO->getSubExpr(), Ctx));
462
14
  case UO_Not:
463
0
    return new (Arena)
464
0
      til::UnaryOp(til::UOP_BitNot, translate(UO->getSubExpr(), Ctx));
465
14
  case UO_LNot:
466
0
    return new (Arena)
467
0
      til::UnaryOp(til::UOP_LogicNot, translate(UO->getSubExpr(), Ctx));
468
14
469
14
  // Currently unsupported
470
14
  case UO_Real:
471
0
  case UO_Imag:
472
0
  case UO_Extension:
473
0
  case UO_Coawait:
474
0
    return new (Arena) til::Undefined(UO);
475
0
  }
476
0
  return new (Arena) til::Undefined(UO);
477
0
}
478
479
til::SExpr *SExprBuilder::translateBinOp(til::TIL_BinaryOpcode Op,
480
                                         const BinaryOperator *BO,
481
36
                                         CallingContext *Ctx, bool Reverse) {
482
36
   til::SExpr *E0 = translate(BO->getLHS(), Ctx);
483
36
   til::SExpr *E1 = translate(BO->getRHS(), Ctx);
484
36
   if (Reverse)
485
24
     return new (Arena) til::BinaryOp(Op, E1, E0);
486
12
   else
487
12
     return new (Arena) til::BinaryOp(Op, E0, E1);
488
36
}
489
490
til::SExpr *SExprBuilder::translateBinAssign(til::TIL_BinaryOpcode Op,
491
                                             const BinaryOperator *BO,
492
                                             CallingContext *Ctx,
493
0
                                             bool Assign) {
494
0
  const Expr *LHS = BO->getLHS();
495
0
  const Expr *RHS = BO->getRHS();
496
0
  til::SExpr *E0 = translate(LHS, Ctx);
497
0
  til::SExpr *E1 = translate(RHS, Ctx);
498
0
499
0
  const ValueDecl *VD = nullptr;
500
0
  til::SExpr *CV = nullptr;
501
0
  if (const auto *DRE = dyn_cast<DeclRefExpr>(LHS)) {
502
0
    VD = DRE->getDecl();
503
0
    CV = lookupVarDecl(VD);
504
0
  }
505
0
506
0
  if (!Assign) {
507
0
    til::SExpr *Arg = CV ? CV : new (Arena) til::Load(E0);
508
0
    E1 = new (Arena) til::BinaryOp(Op, Arg, E1);
509
0
    E1 = addStatement(E1, nullptr, VD);
510
0
  }
511
0
  if (VD && CV)
512
0
    return updateVarDecl(VD, E1);
513
0
  return new (Arena) til::Store(E0, E1);
514
0
}
515
516
til::SExpr *SExprBuilder::translateBinaryOperator(const BinaryOperator *BO,
517
36
                                                  CallingContext *Ctx) {
518
36
  switch (BO->getOpcode()) {
519
36
  case BO_PtrMemD:
520
0
  case BO_PtrMemI:
521
0
    return new (Arena) til::Undefined(BO);
522
0
523
0
  case BO_Mul:  return translateBinOp(til::BOP_Mul, BO, Ctx);
524
0
  case BO_Div:  return translateBinOp(til::BOP_Div, BO, Ctx);
525
0
  case BO_Rem:  return translateBinOp(til::BOP_Rem, BO, Ctx);
526
12
  case BO_Add:  return translateBinOp(til::BOP_Add, BO, Ctx);
527
0
  case BO_Sub:  return translateBinOp(til::BOP_Sub, BO, Ctx);
528
0
  case BO_Shl:  return translateBinOp(til::BOP_Shl, BO, Ctx);
529
0
  case BO_Shr:  return translateBinOp(til::BOP_Shr, BO, Ctx);
530
0
  case BO_LT:   return translateBinOp(til::BOP_Lt,  BO, Ctx);
531
24
  case BO_GT:   return translateBinOp(til::BOP_Lt,  BO, Ctx, true);
532
0
  case BO_LE:   return translateBinOp(til::BOP_Leq, BO, Ctx);
533
0
  case BO_GE:   return translateBinOp(til::BOP_Leq, BO, Ctx, true);
534
0
  case BO_EQ:   return translateBinOp(til::BOP_Eq,  BO, Ctx);
535
0
  case BO_NE:   return translateBinOp(til::BOP_Neq, BO, Ctx);
536
0
  case BO_Cmp:  return translateBinOp(til::BOP_Cmp, BO, Ctx);
537
0
  case BO_And:  return translateBinOp(til::BOP_BitAnd,   BO, Ctx);
538
0
  case BO_Xor:  return translateBinOp(til::BOP_BitXor,   BO, Ctx);
539
0
  case BO_Or:   return translateBinOp(til::BOP_BitOr,    BO, Ctx);
540
0
  case BO_LAnd: return translateBinOp(til::BOP_LogicAnd, BO, Ctx);
541
0
  case BO_LOr:  return translateBinOp(til::BOP_LogicOr,  BO, Ctx);
542
0
543
0
  case BO_Assign:    return translateBinAssign(til::BOP_Eq,  BO, Ctx, true);
544
0
  case BO_MulAssign: return translateBinAssign(til::BOP_Mul, BO, Ctx);
545
0
  case BO_DivAssign: return translateBinAssign(til::BOP_Div, BO, Ctx);
546
0
  case BO_RemAssign: return translateBinAssign(til::BOP_Rem, BO, Ctx);
547
0
  case BO_AddAssign: return translateBinAssign(til::BOP_Add, BO, Ctx);
548
0
  case BO_SubAssign: return translateBinAssign(til::BOP_Sub, BO, Ctx);
549
0
  case BO_ShlAssign: return translateBinAssign(til::BOP_Shl, BO, Ctx);
550
0
  case BO_ShrAssign: return translateBinAssign(til::BOP_Shr, BO, Ctx);
551
0
  case BO_AndAssign: return translateBinAssign(til::BOP_BitAnd, BO, Ctx);
552
0
  case BO_XorAssign: return translateBinAssign(til::BOP_BitXor, BO, Ctx);
553
0
  case BO_OrAssign:  return translateBinAssign(til::BOP_BitOr,  BO, Ctx);
554
0
555
0
  case BO_Comma:
556
0
    // The clang CFG should have already processed both sides.
557
0
    return translate(BO->getRHS(), Ctx);
558
0
  }
559
0
  return new (Arena) til::Undefined(BO);
560
0
}
561
562
til::SExpr *SExprBuilder::translateCastExpr(const CastExpr *CE,
563
1.88k
                                            CallingContext *Ctx) {
564
1.88k
  CastKind K = CE->getCastKind();
565
1.88k
  switch (K) {
566
1.88k
  case CK_LValueToRValue: {
567
1.19k
    if (const auto *DRE = dyn_cast<DeclRefExpr>(CE->getSubExpr())) {
568
1.06k
      til::SExpr *E0 = lookupVarDecl(DRE->getDecl());
569
1.06k
      if (E0)
570
0
        return E0;
571
1.19k
    }
572
1.19k
    til::SExpr *E0 = translate(CE->getSubExpr(), Ctx);
573
1.19k
    return E0;
574
1.19k
    // FIXME!! -- get Load working properly
575
1.19k
    // return new (Arena) til::Load(E0);
576
1.19k
  }
577
1.19k
  case CK_NoOp:
578
668
  case CK_DerivedToBase:
579
668
  case CK_UncheckedDerivedToBase:
580
668
  case CK_ArrayToPointerDecay:
581
668
  case CK_FunctionToPointerDecay: {
582
668
    til::SExpr *E0 = translate(CE->getSubExpr(), Ctx);
583
668
    return E0;
584
668
  }
585
668
  default: {
586
28
    // FIXME: handle different kinds of casts.
587
28
    til::SExpr *E0 = translate(CE->getSubExpr(), Ctx);
588
28
    if (CapabilityExprMode)
589
28
      return E0;
590
0
    return new (Arena) til::Cast(til::CAST_none, E0);
591
0
  }
592
1.88k
  }
593
1.88k
}
594
595
til::SExpr *
596
SExprBuilder::translateArraySubscriptExpr(const ArraySubscriptExpr *E,
597
48
                                          CallingContext *Ctx) {
598
48
  til::SExpr *E0 = translate(E->getBase(), Ctx);
599
48
  til::SExpr *E1 = translate(E->getIdx(), Ctx);
600
48
  return new (Arena) til::ArrayIndex(E0, E1);
601
48
}
602
603
til::SExpr *
604
SExprBuilder::translateAbstractConditionalOperator(
605
24
    const AbstractConditionalOperator *CO, CallingContext *Ctx) {
606
24
  auto *C = translate(CO->getCond(), Ctx);
607
24
  auto *T = translate(CO->getTrueExpr(), Ctx);
608
24
  auto *E = translate(CO->getFalseExpr(), Ctx);
609
24
  return new (Arena) til::IfThenElse(C, T, E);
610
24
}
611
612
til::SExpr *
613
0
SExprBuilder::translateDeclStmt(const DeclStmt *S, CallingContext *Ctx) {
614
0
  DeclGroupRef DGrp = S->getDeclGroup();
615
0
  for (auto I : DGrp) {
616
0
    if (auto *VD = dyn_cast_or_null<VarDecl>(I)) {
617
0
      Expr *E = VD->getInit();
618
0
      til::SExpr* SE = translate(E, Ctx);
619
0
620
0
      // Add local variables with trivial type to the variable map
621
0
      QualType T = VD->getType();
622
0
      if (T.isTrivialType(VD->getASTContext()))
623
0
        return addVarDecl(VD, SE);
624
0
      else {
625
0
        // TODO: add alloca
626
0
      }
627
0
    }
628
0
  }
629
0
  return nullptr;
630
0
}
631
632
// If (E) is non-trivial, then add it to the current basic block, and
633
// update the statement map so that S refers to E.  Returns a new variable
634
// that refers to E.
635
// If E is trivial returns E.
636
til::SExpr *SExprBuilder::addStatement(til::SExpr* E, const Stmt *S,
637
0
                                       const ValueDecl *VD) {
638
0
  if (!E || !CurrentBB || E->block() || til::ThreadSafetyTIL::isTrivial(E))
639
0
    return E;
640
0
  if (VD)
641
0
    E = new (Arena) til::Variable(E, VD);
642
0
  CurrentInstructions.push_back(E);
643
0
  if (S)
644
0
    insertStmt(S, E);
645
0
  return E;
646
0
}
647
648
// Returns the current value of VD, if known, and nullptr otherwise.
649
1.06k
til::SExpr *SExprBuilder::lookupVarDecl(const ValueDecl *VD) {
650
1.06k
  auto It = LVarIdxMap.find(VD);
651
1.06k
  if (It != LVarIdxMap.end()) {
652
0
    assert(CurrentLVarMap[It->second].first == VD);
653
0
    return CurrentLVarMap[It->second].second;
654
0
  }
655
1.06k
  return nullptr;
656
1.06k
}
657
658
// if E is a til::Variable, update its clangDecl.
659
0
static void maybeUpdateVD(til::SExpr *E, const ValueDecl *VD) {
660
0
  if (!E)
661
0
    return;
662
0
  if (auto *V = dyn_cast<til::Variable>(E)) {
663
0
    if (!V->clangDecl())
664
0
      V->setClangDecl(VD);
665
0
  }
666
0
}
667
668
// Adds a new variable declaration.
669
0
til::SExpr *SExprBuilder::addVarDecl(const ValueDecl *VD, til::SExpr *E) {
670
0
  maybeUpdateVD(E, VD);
671
0
  LVarIdxMap.insert(std::make_pair(VD, CurrentLVarMap.size()));
672
0
  CurrentLVarMap.makeWritable();
673
0
  CurrentLVarMap.push_back(std::make_pair(VD, E));
674
0
  return E;
675
0
}
676
677
// Updates a current variable declaration.  (E.g. by assignment)
678
0
til::SExpr *SExprBuilder::updateVarDecl(const ValueDecl *VD, til::SExpr *E) {
679
0
  maybeUpdateVD(E, VD);
680
0
  auto It = LVarIdxMap.find(VD);
681
0
  if (It == LVarIdxMap.end()) {
682
0
    til::SExpr *Ptr = new (Arena) til::LiteralPtr(VD);
683
0
    til::SExpr *St  = new (Arena) til::Store(Ptr, E);
684
0
    return St;
685
0
  }
686
0
  CurrentLVarMap.makeWritable();
687
0
  CurrentLVarMap.elem(It->second).second = E;
688
0
  return E;
689
0
}
690
691
// Make a Phi node in the current block for the i^th variable in CurrentVarMap.
692
// If E != null, sets Phi[CurrentBlockInfo->ArgIndex] = E.
693
// If E == null, this is a backedge and will be set later.
694
0
void SExprBuilder::makePhiNodeVar(unsigned i, unsigned NPreds, til::SExpr *E) {
695
0
  unsigned ArgIndex = CurrentBlockInfo->ProcessedPredecessors;
696
0
  assert(ArgIndex > 0 && ArgIndex < NPreds);
697
0
698
0
  til::SExpr *CurrE = CurrentLVarMap[i].second;
699
0
  if (CurrE->block() == CurrentBB) {
700
0
    // We already have a Phi node in the current block,
701
0
    // so just add the new variable to the Phi node.
702
0
    auto *Ph = dyn_cast<til::Phi>(CurrE);
703
0
    assert(Ph && "Expecting Phi node.");
704
0
    if (E)
705
0
      Ph->values()[ArgIndex] = E;
706
0
    return;
707
0
  }
708
0
709
0
  // Make a new phi node: phi(..., E)
710
0
  // All phi args up to the current index are set to the current value.
711
0
  til::Phi *Ph = new (Arena) til::Phi(Arena, NPreds);
712
0
  Ph->values().setValues(NPreds, nullptr);
713
0
  for (unsigned PIdx = 0; PIdx < ArgIndex; ++PIdx)
714
0
    Ph->values()[PIdx] = CurrE;
715
0
  if (E)
716
0
    Ph->values()[ArgIndex] = E;
717
0
  Ph->setClangDecl(CurrentLVarMap[i].first);
718
0
  // If E is from a back-edge, or either E or CurrE are incomplete, then
719
0
  // mark this node as incomplete; we may need to remove it later.
720
0
  if (!E || isIncompletePhi(E) || isIncompletePhi(CurrE))
721
0
    Ph->setStatus(til::Phi::PH_Incomplete);
722
0
723
0
  // Add Phi node to current block, and update CurrentLVarMap[i]
724
0
  CurrentArguments.push_back(Ph);
725
0
  if (Ph->status() == til::Phi::PH_Incomplete)
726
0
    IncompleteArgs.push_back(Ph);
727
0
728
0
  CurrentLVarMap.makeWritable();
729
0
  CurrentLVarMap.elem(i).second = Ph;
730
0
}
731
732
// Merge values from Map into the current variable map.
733
// This will construct Phi nodes in the current basic block as necessary.
734
0
void SExprBuilder::mergeEntryMap(LVarDefinitionMap Map) {
735
0
  assert(CurrentBlockInfo && "Not processing a block!");
736
0
737
0
  if (!CurrentLVarMap.valid()) {
738
0
    // Steal Map, using copy-on-write.
739
0
    CurrentLVarMap = std::move(Map);
740
0
    return;
741
0
  }
742
0
  if (CurrentLVarMap.sameAs(Map))
743
0
    return;  // Easy merge: maps from different predecessors are unchanged.
744
0
745
0
  unsigned NPreds = CurrentBB->numPredecessors();
746
0
  unsigned ESz = CurrentLVarMap.size();
747
0
  unsigned MSz = Map.size();
748
0
  unsigned Sz  = std::min(ESz, MSz);
749
0
750
0
  for (unsigned i = 0; i < Sz; ++i) {
751
0
    if (CurrentLVarMap[i].first != Map[i].first) {
752
0
      // We've reached the end of variables in common.
753
0
      CurrentLVarMap.makeWritable();
754
0
      CurrentLVarMap.downsize(i);
755
0
      break;
756
0
    }
757
0
    if (CurrentLVarMap[i].second != Map[i].second)
758
0
      makePhiNodeVar(i, NPreds, Map[i].second);
759
0
  }
760
0
  if (ESz > MSz) {
761
0
    CurrentLVarMap.makeWritable();
762
0
    CurrentLVarMap.downsize(Map.size());
763
0
  }
764
0
}
765
766
// Merge a back edge into the current variable map.
767
// This will create phi nodes for all variables in the variable map.
768
0
void SExprBuilder::mergeEntryMapBackEdge() {
769
0
  // We don't have definitions for variables on the backedge, because we
770
0
  // haven't gotten that far in the CFG.  Thus, when encountering a back edge,
771
0
  // we conservatively create Phi nodes for all variables.  Unnecessary Phi
772
0
  // nodes will be marked as incomplete, and stripped out at the end.
773
0
  //
774
0
  // An Phi node is unnecessary if it only refers to itself and one other
775
0
  // variable, e.g. x = Phi(y, y, x)  can be reduced to x = y.
776
0
777
0
  assert(CurrentBlockInfo && "Not processing a block!");
778
0
779
0
  if (CurrentBlockInfo->HasBackEdges)
780
0
    return;
781
0
  CurrentBlockInfo->HasBackEdges = true;
782
0
783
0
  CurrentLVarMap.makeWritable();
784
0
  unsigned Sz = CurrentLVarMap.size();
785
0
  unsigned NPreds = CurrentBB->numPredecessors();
786
0
787
0
  for (unsigned i = 0; i < Sz; ++i)
788
0
    makePhiNodeVar(i, NPreds, nullptr);
789
0
}
790
791
// Update the phi nodes that were initially created for a back edge
792
// once the variable definitions have been computed.
793
// I.e., merge the current variable map into the phi nodes for Blk.
794
0
void SExprBuilder::mergePhiNodesBackEdge(const CFGBlock *Blk) {
795
0
  til::BasicBlock *BB = lookupBlock(Blk);
796
0
  unsigned ArgIndex = BBInfo[Blk->getBlockID()].ProcessedPredecessors;
797
0
  assert(ArgIndex > 0 && ArgIndex < BB->numPredecessors());
798
0
799
0
  for (til::SExpr *PE : BB->arguments()) {
800
0
    auto *Ph = dyn_cast_or_null<til::Phi>(PE);
801
0
    assert(Ph && "Expecting Phi Node.");
802
0
    assert(Ph->values()[ArgIndex] == nullptr && "Wrong index for back edge.");
803
0
804
0
    til::SExpr *E = lookupVarDecl(Ph->clangDecl());
805
0
    assert(E && "Couldn't find local variable for Phi node.");
806
0
    Ph->values()[ArgIndex] = E;
807
0
  }
808
0
}
809
810
void SExprBuilder::enterCFG(CFG *Cfg, const NamedDecl *D,
811
0
                            const CFGBlock *First) {
812
0
  // Perform initial setup operations.
813
0
  unsigned NBlocks = Cfg->getNumBlockIDs();
814
0
  Scfg = new (Arena) til::SCFG(Arena, NBlocks);
815
0
816
0
  // allocate all basic blocks immediately, to handle forward references.
817
0
  BBInfo.resize(NBlocks);
818
0
  BlockMap.resize(NBlocks, nullptr);
819
0
  // create map from clang blockID to til::BasicBlocks
820
0
  for (auto *B : *Cfg) {
821
0
    auto *BB = new (Arena) til::BasicBlock(Arena);
822
0
    BB->reserveInstructions(B->size());
823
0
    BlockMap[B->getBlockID()] = BB;
824
0
  }
825
0
826
0
  CurrentBB = lookupBlock(&Cfg->getEntry());
827
0
  auto Parms = isa<ObjCMethodDecl>(D) ? cast<ObjCMethodDecl>(D)->parameters()
828
0
                                      : cast<FunctionDecl>(D)->parameters();
829
0
  for (auto *Pm : Parms) {
830
0
    QualType T = Pm->getType();
831
0
    if (!T.isTrivialType(Pm->getASTContext()))
832
0
      continue;
833
0
834
0
    // Add parameters to local variable map.
835
0
    // FIXME: right now we emulate params with loads; that should be fixed.
836
0
    til::SExpr *Lp = new (Arena) til::LiteralPtr(Pm);
837
0
    til::SExpr *Ld = new (Arena) til::Load(Lp);
838
0
    til::SExpr *V  = addStatement(Ld, nullptr, Pm);
839
0
    addVarDecl(Pm, V);
840
0
  }
841
0
}
842
843
0
void SExprBuilder::enterCFGBlock(const CFGBlock *B) {
844
0
  // Initialize TIL basic block and add it to the CFG.
845
0
  CurrentBB = lookupBlock(B);
846
0
  CurrentBB->reservePredecessors(B->pred_size());
847
0
  Scfg->add(CurrentBB);
848
0
849
0
  CurrentBlockInfo = &BBInfo[B->getBlockID()];
850
0
851
0
  // CurrentLVarMap is moved to ExitMap on block exit.
852
0
  // FIXME: the entry block will hold function parameters.
853
0
  // assert(!CurrentLVarMap.valid() && "CurrentLVarMap already initialized.");
854
0
}
855
856
0
void SExprBuilder::handlePredecessor(const CFGBlock *Pred) {
857
0
  // Compute CurrentLVarMap on entry from ExitMaps of predecessors
858
0
859
0
  CurrentBB->addPredecessor(BlockMap[Pred->getBlockID()]);
860
0
  BlockInfo *PredInfo = &BBInfo[Pred->getBlockID()];
861
0
  assert(PredInfo->UnprocessedSuccessors > 0);
862
0
863
0
  if (--PredInfo->UnprocessedSuccessors == 0)
864
0
    mergeEntryMap(std::move(PredInfo->ExitMap));
865
0
  else
866
0
    mergeEntryMap(PredInfo->ExitMap.clone());
867
0
868
0
  ++CurrentBlockInfo->ProcessedPredecessors;
869
0
}
870
871
0
void SExprBuilder::handlePredecessorBackEdge(const CFGBlock *Pred) {
872
0
  mergeEntryMapBackEdge();
873
0
}
874
875
0
void SExprBuilder::enterCFGBlockBody(const CFGBlock *B) {
876
0
  // The merge*() methods have created arguments.
877
0
  // Push those arguments onto the basic block.
878
0
  CurrentBB->arguments().reserve(
879
0
    static_cast<unsigned>(CurrentArguments.size()), Arena);
880
0
  for (auto *A : CurrentArguments)
881
0
    CurrentBB->addArgument(A);
882
0
}
883
884
0
void SExprBuilder::handleStatement(const Stmt *S) {
885
0
  til::SExpr *E = translate(S, nullptr);
886
0
  addStatement(E, S);
887
0
}
888
889
void SExprBuilder::handleDestructorCall(const VarDecl *VD,
890
0
                                        const CXXDestructorDecl *DD) {
891
0
  til::SExpr *Sf = new (Arena) til::LiteralPtr(VD);
892
0
  til::SExpr *Dr = new (Arena) til::LiteralPtr(DD);
893
0
  til::SExpr *Ap = new (Arena) til::Apply(Dr, Sf);
894
0
  til::SExpr *E = new (Arena) til::Call(Ap);
895
0
  addStatement(E, nullptr);
896
0
}
897
898
0
void SExprBuilder::exitCFGBlockBody(const CFGBlock *B) {
899
0
  CurrentBB->instructions().reserve(
900
0
    static_cast<unsigned>(CurrentInstructions.size()), Arena);
901
0
  for (auto *V : CurrentInstructions)
902
0
    CurrentBB->addInstruction(V);
903
0
904
0
  // Create an appropriate terminator
905
0
  unsigned N = B->succ_size();
906
0
  auto It = B->succ_begin();
907
0
  if (N == 1) {
908
0
    til::BasicBlock *BB = *It ? lookupBlock(*It) : nullptr;
909
0
    // TODO: set index
910
0
    unsigned Idx = BB ? BB->findPredecessorIndex(CurrentBB) : 0;
911
0
    auto *Tm = new (Arena) til::Goto(BB, Idx);
912
0
    CurrentBB->setTerminator(Tm);
913
0
  }
914
0
  else if (N == 2) {
915
0
    til::SExpr *C = translate(B->getTerminatorCondition(true), nullptr);
916
0
    til::BasicBlock *BB1 = *It ? lookupBlock(*It) : nullptr;
917
0
    ++It;
918
0
    til::BasicBlock *BB2 = *It ? lookupBlock(*It) : nullptr;
919
0
    // FIXME: make sure these aren't critical edges.
920
0
    auto *Tm = new (Arena) til::Branch(C, BB1, BB2);
921
0
    CurrentBB->setTerminator(Tm);
922
0
  }
923
0
}
924
925
0
void SExprBuilder::handleSuccessor(const CFGBlock *Succ) {
926
0
  ++CurrentBlockInfo->UnprocessedSuccessors;
927
0
}
928
929
0
void SExprBuilder::handleSuccessorBackEdge(const CFGBlock *Succ) {
930
0
  mergePhiNodesBackEdge(Succ);
931
0
  ++BBInfo[Succ->getBlockID()].ProcessedPredecessors;
932
0
}
933
934
0
void SExprBuilder::exitCFGBlock(const CFGBlock *B) {
935
0
  CurrentArguments.clear();
936
0
  CurrentInstructions.clear();
937
0
  CurrentBlockInfo->ExitMap = std::move(CurrentLVarMap);
938
0
  CurrentBB = nullptr;
939
0
  CurrentBlockInfo = nullptr;
940
0
}
941
942
0
void SExprBuilder::exitCFG(const CFGBlock *Last) {
943
0
  for (auto *Ph : IncompleteArgs) {
944
0
    if (Ph->status() == til::Phi::PH_Incomplete)
945
0
      simplifyIncompleteArg(Ph);
946
0
  }
947
0
948
0
  CurrentArguments.clear();
949
0
  CurrentInstructions.clear();
950
0
  IncompleteArgs.clear();
951
0
}
952
953
/*
954
namespace {
955
956
class TILPrinter :
957
    public til::PrettyPrinter<TILPrinter, llvm::raw_ostream> {};
958
959
} // namespace
960
961
namespace clang {
962
namespace threadSafety {
963
964
void printSCFG(CFGWalker &Walker) {
965
  llvm::BumpPtrAllocator Bpa;
966
  til::MemRegionRef Arena(&Bpa);
967
  SExprBuilder SxBuilder(Arena);
968
  til::SCFG *Scfg = SxBuilder.buildCFG(Walker);
969
  TILPrinter::print(Scfg, llvm::errs());
970
}
971
972
} // namespace threadSafety
973
} // namespace clang
974
*/