clang 8.0.0

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