Coverage Report

Created: 2022-07-16 07:03

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