clang  14.0.0git
BodyFarm.cpp
Go to the documentation of this file.
1 //== BodyFarm.cpp - Factory for conjuring up fake bodies ----------*- C++ -*-//
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 // BodyFarm is a factory for creating faux implementations for functions/methods
10 // for analysis purposes.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/Decl.h"
18 #include "clang/AST/Expr.h"
19 #include "clang/AST/ExprCXX.h"
20 #include "clang/AST/ExprObjC.h"
24 #include "llvm/ADT/StringSwitch.h"
25 #include "llvm/Support/Debug.h"
26 
27 #define DEBUG_TYPE "body-farm"
28 
29 using namespace clang;
30 
31 //===----------------------------------------------------------------------===//
32 // Helper creation functions for constructing faux ASTs.
33 //===----------------------------------------------------------------------===//
34 
35 static bool isDispatchBlock(QualType Ty) {
36  // Is it a block pointer?
37  const BlockPointerType *BPT = Ty->getAs<BlockPointerType>();
38  if (!BPT)
39  return false;
40 
41  // Check if the block pointer type takes no arguments and
42  // returns void.
43  const FunctionProtoType *FT =
45  return FT && FT->getReturnType()->isVoidType() && FT->getNumParams() == 0;
46 }
47 
48 namespace {
49 class ASTMaker {
50 public:
51  ASTMaker(ASTContext &C) : C(C) {}
52 
53  /// Create a new BinaryOperator representing a simple assignment.
54  BinaryOperator *makeAssignment(const Expr *LHS, const Expr *RHS, QualType Ty);
55 
56  /// Create a new BinaryOperator representing a comparison.
57  BinaryOperator *makeComparison(const Expr *LHS, const Expr *RHS,
59 
60  /// Create a new compound stmt using the provided statements.
61  CompoundStmt *makeCompound(ArrayRef<Stmt*>);
62 
63  /// Create a new DeclRefExpr for the referenced variable.
64  DeclRefExpr *makeDeclRefExpr(const VarDecl *D,
65  bool RefersToEnclosingVariableOrCapture = false);
66 
67  /// Create a new UnaryOperator representing a dereference.
68  UnaryOperator *makeDereference(const Expr *Arg, QualType Ty);
69 
70  /// Create an implicit cast for an integer conversion.
71  Expr *makeIntegralCast(const Expr *Arg, QualType Ty);
72 
73  /// Create an implicit cast to a builtin boolean type.
74  ImplicitCastExpr *makeIntegralCastToBoolean(const Expr *Arg);
75 
76  /// Create an implicit cast for lvalue-to-rvaluate conversions.
77  ImplicitCastExpr *makeLvalueToRvalue(const Expr *Arg, QualType Ty);
78 
79  /// Make RValue out of variable declaration, creating a temporary
80  /// DeclRefExpr in the process.
82  makeLvalueToRvalue(const VarDecl *Decl,
83  bool RefersToEnclosingVariableOrCapture = false);
84 
85  /// Create an implicit cast of the given type.
86  ImplicitCastExpr *makeImplicitCast(const Expr *Arg, QualType Ty,
87  CastKind CK = CK_LValueToRValue);
88 
89  /// Create an Objective-C bool literal.
90  ObjCBoolLiteralExpr *makeObjCBool(bool Val);
91 
92  /// Create an Objective-C ivar reference.
93  ObjCIvarRefExpr *makeObjCIvarRef(const Expr *Base, const ObjCIvarDecl *IVar);
94 
95  /// Create a Return statement.
96  ReturnStmt *makeReturn(const Expr *RetVal);
97 
98  /// Create an integer literal expression of the given type.
99  IntegerLiteral *makeIntegerLiteral(uint64_t Value, QualType Ty);
100 
101  /// Create a member expression.
102  MemberExpr *makeMemberExpression(Expr *base, ValueDecl *MemberDecl,
103  bool IsArrow = false,
104  ExprValueKind ValueKind = VK_LValue);
105 
106  /// Returns a *first* member field of a record declaration with a given name.
107  /// \return an nullptr if no member with such a name exists.
108  ValueDecl *findMemberField(const RecordDecl *RD, StringRef Name);
109 
110 private:
111  ASTContext &C;
112 };
113 }
114 
115 BinaryOperator *ASTMaker::makeAssignment(const Expr *LHS, const Expr *RHS,
116  QualType Ty) {
117  return BinaryOperator::Create(
118  C, const_cast<Expr *>(LHS), const_cast<Expr *>(RHS), BO_Assign, Ty,
120 }
121 
122 BinaryOperator *ASTMaker::makeComparison(const Expr *LHS, const Expr *RHS,
124  assert(BinaryOperator::isLogicalOp(Op) ||
126  return BinaryOperator::Create(
127  C, const_cast<Expr *>(LHS), const_cast<Expr *>(RHS), Op,
128  C.getLogicalOperationType(), VK_PRValue, OK_Ordinary, SourceLocation(),
130 }
131 
132 CompoundStmt *ASTMaker::makeCompound(ArrayRef<Stmt *> Stmts) {
133  return CompoundStmt::Create(C, Stmts, SourceLocation(), SourceLocation());
134 }
135 
136 DeclRefExpr *ASTMaker::makeDeclRefExpr(
137  const VarDecl *D,
138  bool RefersToEnclosingVariableOrCapture) {
140 
142  C, NestedNameSpecifierLoc(), SourceLocation(), const_cast<VarDecl *>(D),
143  RefersToEnclosingVariableOrCapture, SourceLocation(), Type, VK_LValue);
144  return DR;
145 }
146 
147 UnaryOperator *ASTMaker::makeDereference(const Expr *Arg, QualType Ty) {
148  return UnaryOperator::Create(C, const_cast<Expr *>(Arg), UO_Deref, Ty,
150  /*CanOverflow*/ false, FPOptionsOverride());
151 }
152 
153 ImplicitCastExpr *ASTMaker::makeLvalueToRvalue(const Expr *Arg, QualType Ty) {
154  return makeImplicitCast(Arg, Ty, CK_LValueToRValue);
155 }
156 
158 ASTMaker::makeLvalueToRvalue(const VarDecl *Arg,
159  bool RefersToEnclosingVariableOrCapture) {
161  return makeLvalueToRvalue(makeDeclRefExpr(Arg,
162  RefersToEnclosingVariableOrCapture),
163  Type);
164 }
165 
166 ImplicitCastExpr *ASTMaker::makeImplicitCast(const Expr *Arg, QualType Ty,
167  CastKind CK) {
168  return ImplicitCastExpr::Create(C, Ty,
169  /* CastKind=*/CK,
170  /* Expr=*/const_cast<Expr *>(Arg),
171  /* CXXCastPath=*/nullptr,
172  /* ExprValueKind=*/VK_PRValue,
173  /* FPFeatures */ FPOptionsOverride());
174 }
175 
176 Expr *ASTMaker::makeIntegralCast(const Expr *Arg, QualType Ty) {
177  if (Arg->getType() == Ty)
178  return const_cast<Expr*>(Arg);
179  return makeImplicitCast(Arg, Ty, CK_IntegralCast);
180 }
181 
182 ImplicitCastExpr *ASTMaker::makeIntegralCastToBoolean(const Expr *Arg) {
183  return makeImplicitCast(Arg, C.BoolTy, CK_IntegralToBoolean);
184 }
185 
186 ObjCBoolLiteralExpr *ASTMaker::makeObjCBool(bool Val) {
187  QualType Ty = C.getBOOLDecl() ? C.getBOOLType() : C.ObjCBuiltinBoolTy;
188  return new (C) ObjCBoolLiteralExpr(Val, Ty, SourceLocation());
189 }
190 
191 ObjCIvarRefExpr *ASTMaker::makeObjCIvarRef(const Expr *Base,
192  const ObjCIvarDecl *IVar) {
193  return new (C) ObjCIvarRefExpr(const_cast<ObjCIvarDecl*>(IVar),
194  IVar->getType(), SourceLocation(),
195  SourceLocation(), const_cast<Expr*>(Base),
196  /*arrow=*/true, /*free=*/false);
197 }
198 
199 ReturnStmt *ASTMaker::makeReturn(const Expr *RetVal) {
200  return ReturnStmt::Create(C, SourceLocation(), const_cast<Expr *>(RetVal),
201  /* NRVOCandidate=*/nullptr);
202 }
203 
204 IntegerLiteral *ASTMaker::makeIntegerLiteral(uint64_t Value, QualType Ty) {
205  llvm::APInt APValue = llvm::APInt(C.getTypeSize(Ty), Value);
207 }
208 
209 MemberExpr *ASTMaker::makeMemberExpression(Expr *base, ValueDecl *MemberDecl,
210  bool IsArrow,
211  ExprValueKind ValueKind) {
212 
213  DeclAccessPair FoundDecl = DeclAccessPair::make(MemberDecl, AS_public);
214  return MemberExpr::Create(
215  C, base, IsArrow, SourceLocation(), NestedNameSpecifierLoc(),
216  SourceLocation(), MemberDecl, FoundDecl,
218  /* TemplateArgumentListInfo=*/ nullptr, MemberDecl->getType(), ValueKind,
220 }
221 
222 ValueDecl *ASTMaker::findMemberField(const RecordDecl *RD, StringRef Name) {
223 
224  CXXBasePaths Paths(
225  /* FindAmbiguities=*/false,
226  /* RecordPaths=*/false,
227  /* DetectVirtual=*/ false);
228  const IdentifierInfo &II = C.Idents.get(Name);
229  DeclarationName DeclName = C.DeclarationNames.getIdentifier(&II);
230 
231  DeclContextLookupResult Decls = RD->lookup(DeclName);
232  for (NamedDecl *FoundDecl : Decls)
233  if (!FoundDecl->getDeclContext()->isFunctionOrMethod())
234  return cast<ValueDecl>(FoundDecl);
235 
236  return nullptr;
237 }
238 
239 //===----------------------------------------------------------------------===//
240 // Creation functions for faux ASTs.
241 //===----------------------------------------------------------------------===//
242 
243 typedef Stmt *(*FunctionFarmer)(ASTContext &C, const FunctionDecl *D);
244 
246  const ParmVarDecl *Callback,
247  ArrayRef<Expr *> CallArgs) {
248 
249  QualType Ty = Callback->getType();
250  DeclRefExpr *Call = M.makeDeclRefExpr(Callback);
251  Expr *SubExpr;
252  if (Ty->isRValueReferenceType()) {
253  SubExpr = M.makeImplicitCast(
254  Call, Ty.getNonReferenceType(), CK_LValueToRValue);
255  } else if (Ty->isLValueReferenceType() &&
256  Call->getType()->isFunctionType()) {
257  Ty = C.getPointerType(Ty.getNonReferenceType());
258  SubExpr = M.makeImplicitCast(Call, Ty, CK_FunctionToPointerDecay);
259  } else if (Ty->isLValueReferenceType()
260  && Call->getType()->isPointerType()
261  && Call->getType()->getPointeeType()->isFunctionType()){
262  SubExpr = Call;
263  } else {
264  llvm_unreachable("Unexpected state");
265  }
266 
267  return CallExpr::Create(C, SubExpr, CallArgs, C.VoidTy, VK_PRValue,
269 }
270 
272  const ParmVarDecl *Callback,
273  CXXRecordDecl *CallbackDecl,
274  ArrayRef<Expr *> CallArgs) {
275  assert(CallbackDecl != nullptr);
276  assert(CallbackDecl->isLambda());
277  FunctionDecl *callOperatorDecl = CallbackDecl->getLambdaCallOperator();
278  assert(callOperatorDecl != nullptr);
279 
280  DeclRefExpr *callOperatorDeclRef =
281  DeclRefExpr::Create(/* Ctx =*/ C,
282  /* QualifierLoc =*/ NestedNameSpecifierLoc(),
283  /* TemplateKWLoc =*/ SourceLocation(),
284  const_cast<FunctionDecl *>(callOperatorDecl),
285  /* RefersToEnclosingVariableOrCapture=*/ false,
286  /* NameLoc =*/ SourceLocation(),
287  /* T =*/ callOperatorDecl->getType(),
288  /* VK =*/ VK_LValue);
289 
291  /*AstContext=*/C, OO_Call, callOperatorDeclRef,
292  /*Args=*/CallArgs,
293  /*QualType=*/C.VoidTy,
294  /*ExprValueType=*/VK_PRValue,
295  /*SourceLocation=*/SourceLocation(),
296  /*FPFeatures=*/FPOptionsOverride());
297 }
298 
299 /// Create a fake body for std::call_once.
300 /// Emulates the following function body:
301 ///
302 /// \code
303 /// typedef struct once_flag_s {
304 /// unsigned long __state = 0;
305 /// } once_flag;
306 /// template<class Callable>
307 /// void call_once(once_flag& o, Callable func) {
308 /// if (!o.__state) {
309 /// func();
310 /// }
311 /// o.__state = 1;
312 /// }
313 /// \endcode
315  LLVM_DEBUG(llvm::dbgs() << "Generating body for call_once\n");
316 
317  // We need at least two parameters.
318  if (D->param_size() < 2)
319  return nullptr;
320 
321  ASTMaker M(C);
322 
323  const ParmVarDecl *Flag = D->getParamDecl(0);
324  const ParmVarDecl *Callback = D->getParamDecl(1);
325 
326  if (!Callback->getType()->isReferenceType()) {
327  llvm::dbgs() << "libcxx03 std::call_once implementation, skipping.\n";
328  return nullptr;
329  }
330  if (!Flag->getType()->isReferenceType()) {
331  llvm::dbgs() << "unknown std::call_once implementation, skipping.\n";
332  return nullptr;
333  }
334 
335  QualType CallbackType = Callback->getType().getNonReferenceType();
336 
337  // Nullable pointer, non-null iff function is a CXXRecordDecl.
338  CXXRecordDecl *CallbackRecordDecl = CallbackType->getAsCXXRecordDecl();
339  QualType FlagType = Flag->getType().getNonReferenceType();
340  auto *FlagRecordDecl = FlagType->getAsRecordDecl();
341 
342  if (!FlagRecordDecl) {
343  LLVM_DEBUG(llvm::dbgs() << "Flag field is not a record: "
344  << "unknown std::call_once implementation, "
345  << "ignoring the call.\n");
346  return nullptr;
347  }
348 
349  // We initially assume libc++ implementation of call_once,
350  // where the once_flag struct has a field `__state_`.
351  ValueDecl *FlagFieldDecl = M.findMemberField(FlagRecordDecl, "__state_");
352 
353  // Otherwise, try libstdc++ implementation, with a field
354  // `_M_once`
355  if (!FlagFieldDecl) {
356  FlagFieldDecl = M.findMemberField(FlagRecordDecl, "_M_once");
357  }
358 
359  if (!FlagFieldDecl) {
360  LLVM_DEBUG(llvm::dbgs() << "No field _M_once or __state_ found on "
361  << "std::once_flag struct: unknown std::call_once "
362  << "implementation, ignoring the call.");
363  return nullptr;
364  }
365 
366  bool isLambdaCall = CallbackRecordDecl && CallbackRecordDecl->isLambda();
367  if (CallbackRecordDecl && !isLambdaCall) {
368  LLVM_DEBUG(llvm::dbgs()
369  << "Not supported: synthesizing body for functors when "
370  << "body farming std::call_once, ignoring the call.");
371  return nullptr;
372  }
373 
374  SmallVector<Expr *, 5> CallArgs;
375  const FunctionProtoType *CallbackFunctionType;
376  if (isLambdaCall) {
377 
378  // Lambda requires callback itself inserted as a first parameter.
379  CallArgs.push_back(
380  M.makeDeclRefExpr(Callback,
381  /* RefersToEnclosingVariableOrCapture=*/ true));
382  CallbackFunctionType = CallbackRecordDecl->getLambdaCallOperator()
383  ->getType()
385  } else if (!CallbackType->getPointeeType().isNull()) {
386  CallbackFunctionType =
387  CallbackType->getPointeeType()->getAs<FunctionProtoType>();
388  } else {
389  CallbackFunctionType = CallbackType->getAs<FunctionProtoType>();
390  }
391 
392  if (!CallbackFunctionType)
393  return nullptr;
394 
395  // First two arguments are used for the flag and for the callback.
396  if (D->getNumParams() != CallbackFunctionType->getNumParams() + 2) {
397  LLVM_DEBUG(llvm::dbgs() << "Types of params of the callback do not match "
398  << "params passed to std::call_once, "
399  << "ignoring the call\n");
400  return nullptr;
401  }
402 
403  // All arguments past first two ones are passed to the callback,
404  // and we turn lvalues into rvalues if the argument is not passed by
405  // reference.
406  for (unsigned int ParamIdx = 2; ParamIdx < D->getNumParams(); ParamIdx++) {
407  const ParmVarDecl *PDecl = D->getParamDecl(ParamIdx);
408  assert(PDecl);
409  if (CallbackFunctionType->getParamType(ParamIdx - 2)
411  .getCanonicalType() !=
413  LLVM_DEBUG(llvm::dbgs() << "Types of params of the callback do not match "
414  << "params passed to std::call_once, "
415  << "ignoring the call\n");
416  return nullptr;
417  }
418  Expr *ParamExpr = M.makeDeclRefExpr(PDecl);
419  if (!CallbackFunctionType->getParamType(ParamIdx - 2)->isReferenceType()) {
420  QualType PTy = PDecl->getType().getNonReferenceType();
421  ParamExpr = M.makeLvalueToRvalue(ParamExpr, PTy);
422  }
423  CallArgs.push_back(ParamExpr);
424  }
425 
426  CallExpr *CallbackCall;
427  if (isLambdaCall) {
428 
429  CallbackCall = create_call_once_lambda_call(C, M, Callback,
430  CallbackRecordDecl, CallArgs);
431  } else {
432 
433  // Function pointer case.
434  CallbackCall = create_call_once_funcptr_call(C, M, Callback, CallArgs);
435  }
436 
437  DeclRefExpr *FlagDecl =
438  M.makeDeclRefExpr(Flag,
439  /* RefersToEnclosingVariableOrCapture=*/true);
440 
441 
442  MemberExpr *Deref = M.makeMemberExpression(FlagDecl, FlagFieldDecl);
443  assert(Deref->isLValue());
444  QualType DerefType = Deref->getType();
445 
446  // Negation predicate.
448  C,
449  /* input=*/
450  M.makeImplicitCast(M.makeLvalueToRvalue(Deref, DerefType), DerefType,
451  CK_IntegralToBoolean),
452  /* opc=*/UO_LNot,
453  /* QualType=*/C.IntTy,
454  /* ExprValueKind=*/VK_PRValue,
455  /* ExprObjectKind=*/OK_Ordinary, SourceLocation(),
456  /* CanOverflow*/ false, FPOptionsOverride());
457 
458  // Create assignment.
459  BinaryOperator *FlagAssignment = M.makeAssignment(
460  Deref, M.makeIntegralCast(M.makeIntegerLiteral(1, C.IntTy), DerefType),
461  DerefType);
462 
463  auto *Out =
465  /* Init=*/nullptr,
466  /* Var=*/nullptr,
467  /* Cond=*/FlagCheck,
468  /* LPL=*/SourceLocation(),
469  /* RPL=*/SourceLocation(),
470  /* Then=*/M.makeCompound({CallbackCall, FlagAssignment}));
471 
472  return Out;
473 }
474 
475 /// Create a fake body for dispatch_once.
477  // Check if we have at least two parameters.
478  if (D->param_size() != 2)
479  return nullptr;
480 
481  // Check if the first parameter is a pointer to integer type.
482  const ParmVarDecl *Predicate = D->getParamDecl(0);
483  QualType PredicateQPtrTy = Predicate->getType();
484  const PointerType *PredicatePtrTy = PredicateQPtrTy->getAs<PointerType>();
485  if (!PredicatePtrTy)
486  return nullptr;
487  QualType PredicateTy = PredicatePtrTy->getPointeeType();
488  if (!PredicateTy->isIntegerType())
489  return nullptr;
490 
491  // Check if the second parameter is the proper block type.
492  const ParmVarDecl *Block = D->getParamDecl(1);
493  QualType Ty = Block->getType();
494  if (!isDispatchBlock(Ty))
495  return nullptr;
496 
497  // Everything checks out. Create a fakse body that checks the predicate,
498  // sets it, and calls the block. Basically, an AST dump of:
499  //
500  // void dispatch_once(dispatch_once_t *predicate, dispatch_block_t block) {
501  // if (*predicate != ~0l) {
502  // *predicate = ~0l;
503  // block();
504  // }
505  // }
506 
507  ASTMaker M(C);
508 
509  // (1) Create the call.
511  /*ASTContext=*/C,
512  /*StmtClass=*/M.makeLvalueToRvalue(/*Expr=*/Block),
513  /*Args=*/None,
514  /*QualType=*/C.VoidTy,
515  /*ExprValueType=*/VK_PRValue,
516  /*SourceLocation=*/SourceLocation(), FPOptionsOverride());
517 
518  // (2) Create the assignment to the predicate.
519  Expr *DoneValue =
520  UnaryOperator::Create(C, M.makeIntegerLiteral(0, C.LongTy), UO_Not,
521  C.LongTy, VK_PRValue, OK_Ordinary, SourceLocation(),
522  /*CanOverflow*/ false, FPOptionsOverride());
523 
524  BinaryOperator *B =
525  M.makeAssignment(
526  M.makeDereference(
527  M.makeLvalueToRvalue(
528  M.makeDeclRefExpr(Predicate), PredicateQPtrTy),
529  PredicateTy),
530  M.makeIntegralCast(DoneValue, PredicateTy),
531  PredicateTy);
532 
533  // (3) Create the compound statement.
534  Stmt *Stmts[] = { B, CE };
535  CompoundStmt *CS = M.makeCompound(Stmts);
536 
537  // (4) Create the 'if' condition.
538  ImplicitCastExpr *LValToRval =
539  M.makeLvalueToRvalue(
540  M.makeDereference(
541  M.makeLvalueToRvalue(
542  M.makeDeclRefExpr(Predicate),
543  PredicateQPtrTy),
544  PredicateTy),
545  PredicateTy);
546 
547  Expr *GuardCondition = M.makeComparison(LValToRval, DoneValue, BO_NE);
548  // (5) Create the 'if' statement.
550  /* Init=*/nullptr,
551  /* Var=*/nullptr,
552  /* Cond=*/GuardCondition,
553  /* LPL=*/SourceLocation(),
554  /* RPL=*/SourceLocation(),
555  /* Then=*/CS);
556  return If;
557 }
558 
559 /// Create a fake body for dispatch_sync.
561  // Check if we have at least two parameters.
562  if (D->param_size() != 2)
563  return nullptr;
564 
565  // Check if the second parameter is a block.
566  const ParmVarDecl *PV = D->getParamDecl(1);
567  QualType Ty = PV->getType();
568  if (!isDispatchBlock(Ty))
569  return nullptr;
570 
571  // Everything checks out. Create a fake body that just calls the block.
572  // This is basically just an AST dump of:
573  //
574  // void dispatch_sync(dispatch_queue_t queue, void (^block)(void)) {
575  // block();
576  // }
577  //
578  ASTMaker M(C);
579  DeclRefExpr *DR = M.makeDeclRefExpr(PV);
580  ImplicitCastExpr *ICE = M.makeLvalueToRvalue(DR, Ty);
581  CallExpr *CE = CallExpr::Create(C, ICE, None, C.VoidTy, VK_PRValue,
583  return CE;
584 }
585 
587 {
588  // There are exactly 3 arguments.
589  if (D->param_size() != 3)
590  return nullptr;
591 
592  // Signature:
593  // _Bool OSAtomicCompareAndSwapPtr(void *__oldValue,
594  // void *__newValue,
595  // void * volatile *__theValue)
596  // Generate body:
597  // if (oldValue == *theValue) {
598  // *theValue = newValue;
599  // return YES;
600  // }
601  // else return NO;
602 
603  QualType ResultTy = D->getReturnType();
604  bool isBoolean = ResultTy->isBooleanType();
605  if (!isBoolean && !ResultTy->isIntegralType(C))
606  return nullptr;
607 
608  const ParmVarDecl *OldValue = D->getParamDecl(0);
609  QualType OldValueTy = OldValue->getType();
610 
611  const ParmVarDecl *NewValue = D->getParamDecl(1);
612  QualType NewValueTy = NewValue->getType();
613 
614  assert(OldValueTy == NewValueTy);
615 
616  const ParmVarDecl *TheValue = D->getParamDecl(2);
617  QualType TheValueTy = TheValue->getType();
618  const PointerType *PT = TheValueTy->getAs<PointerType>();
619  if (!PT)
620  return nullptr;
621  QualType PointeeTy = PT->getPointeeType();
622 
623  ASTMaker M(C);
624  // Construct the comparison.
625  Expr *Comparison =
626  M.makeComparison(
627  M.makeLvalueToRvalue(M.makeDeclRefExpr(OldValue), OldValueTy),
628  M.makeLvalueToRvalue(
629  M.makeDereference(
630  M.makeLvalueToRvalue(M.makeDeclRefExpr(TheValue), TheValueTy),
631  PointeeTy),
632  PointeeTy),
633  BO_EQ);
634 
635  // Construct the body of the IfStmt.
636  Stmt *Stmts[2];
637  Stmts[0] =
638  M.makeAssignment(
639  M.makeDereference(
640  M.makeLvalueToRvalue(M.makeDeclRefExpr(TheValue), TheValueTy),
641  PointeeTy),
642  M.makeLvalueToRvalue(M.makeDeclRefExpr(NewValue), NewValueTy),
643  NewValueTy);
644 
645  Expr *BoolVal = M.makeObjCBool(true);
646  Expr *RetVal = isBoolean ? M.makeIntegralCastToBoolean(BoolVal)
647  : M.makeIntegralCast(BoolVal, ResultTy);
648  Stmts[1] = M.makeReturn(RetVal);
649  CompoundStmt *Body = M.makeCompound(Stmts);
650 
651  // Construct the else clause.
652  BoolVal = M.makeObjCBool(false);
653  RetVal = isBoolean ? M.makeIntegralCastToBoolean(BoolVal)
654  : M.makeIntegralCast(BoolVal, ResultTy);
655  Stmt *Else = M.makeReturn(RetVal);
656 
657  /// Construct the If.
658  auto *If =
660  /* Init=*/nullptr,
661  /* Var=*/nullptr, Comparison,
662  /* LPL=*/SourceLocation(),
663  /* RPL=*/SourceLocation(), Body, SourceLocation(), Else);
664 
665  return If;
666 }
667 
669  Optional<Stmt *> &Val = Bodies[D];
670  if (Val.hasValue())
671  return Val.getValue();
672 
673  Val = nullptr;
674 
675  if (D->getIdentifier() == nullptr)
676  return nullptr;
677 
678  StringRef Name = D->getName();
679  if (Name.empty())
680  return nullptr;
681 
682  FunctionFarmer FF;
683 
684  if (Name.startswith("OSAtomicCompareAndSwap") ||
685  Name.startswith("objc_atomicCompareAndSwap")) {
687  } else if (Name == "call_once" && D->getDeclContext()->isStdNamespace()) {
688  FF = create_call_once;
689  } else {
690  FF = llvm::StringSwitch<FunctionFarmer>(Name)
691  .Case("dispatch_sync", create_dispatch_sync)
692  .Case("dispatch_once", create_dispatch_once)
693  .Default(nullptr);
694  }
695 
696  if (FF) { Val = FF(C, D); }
697  else if (Injector) { Val = Injector->getBody(D); }
698  return Val.getValue();
699 }
700 
701 static const ObjCIvarDecl *findBackingIvar(const ObjCPropertyDecl *Prop) {
702  const ObjCIvarDecl *IVar = Prop->getPropertyIvarDecl();
703 
704  if (IVar)
705  return IVar;
706 
707  // When a readonly property is shadowed in a class extensions with a
708  // a readwrite property, the instance variable belongs to the shadowing
709  // property rather than the shadowed property. If there is no instance
710  // variable on a readonly property, check to see whether the property is
711  // shadowed and if so try to get the instance variable from shadowing
712  // property.
713  if (!Prop->isReadOnly())
714  return nullptr;
715 
716  auto *Container = cast<ObjCContainerDecl>(Prop->getDeclContext());
717  const ObjCInterfaceDecl *PrimaryInterface = nullptr;
718  if (auto *InterfaceDecl = dyn_cast<ObjCInterfaceDecl>(Container)) {
719  PrimaryInterface = InterfaceDecl;
720  } else if (auto *CategoryDecl = dyn_cast<ObjCCategoryDecl>(Container)) {
721  PrimaryInterface = CategoryDecl->getClassInterface();
722  } else if (auto *ImplDecl = dyn_cast<ObjCImplDecl>(Container)) {
723  PrimaryInterface = ImplDecl->getClassInterface();
724  } else {
725  return nullptr;
726  }
727 
728  // FindPropertyVisibleInPrimaryClass() looks first in class extensions, so it
729  // is guaranteed to find the shadowing property, if it exists, rather than
730  // the shadowed property.
731  auto *ShadowingProp = PrimaryInterface->FindPropertyVisibleInPrimaryClass(
732  Prop->getIdentifier(), Prop->getQueryKind());
733  if (ShadowingProp && ShadowingProp != Prop) {
734  IVar = ShadowingProp->getPropertyIvarDecl();
735  }
736 
737  return IVar;
738 }
739 
741  const ObjCMethodDecl *MD) {
742  // First, find the backing ivar.
743  const ObjCIvarDecl *IVar = nullptr;
744  const ObjCPropertyDecl *Prop = nullptr;
745 
746  // Property accessor stubs sometimes do not correspond to any property decl
747  // in the current interface (but in a superclass). They still have a
748  // corresponding property impl decl in this case.
749  if (MD->isSynthesizedAccessorStub()) {
750  const ObjCInterfaceDecl *IntD = MD->getClassInterface();
751  const ObjCImplementationDecl *ImpD = IntD->getImplementation();
752  for (const auto *PI : ImpD->property_impls()) {
753  if (const ObjCPropertyDecl *Candidate = PI->getPropertyDecl()) {
754  if (Candidate->getGetterName() == MD->getSelector()) {
755  Prop = Candidate;
756  IVar = Prop->getPropertyIvarDecl();
757  }
758  }
759  }
760  }
761 
762  if (!IVar) {
763  Prop = MD->findPropertyDecl();
764  IVar = findBackingIvar(Prop);
765  }
766 
767  if (!IVar || !Prop)
768  return nullptr;
769 
770  // Ignore weak variables, which have special behavior.
772  return nullptr;
773 
774  // Look to see if Sema has synthesized a body for us. This happens in
775  // Objective-C++ because the return value may be a C++ class type with a
776  // non-trivial copy constructor. We can only do this if we can find the
777  // @synthesize for this property, though (or if we know it's been auto-
778  // synthesized).
779  const ObjCImplementationDecl *ImplDecl =
781  if (ImplDecl) {
782  for (const auto *I : ImplDecl->property_impls()) {
783  if (I->getPropertyDecl() != Prop)
784  continue;
785 
786  if (I->getGetterCXXConstructor()) {
787  ASTMaker M(Ctx);
788  return M.makeReturn(I->getGetterCXXConstructor());
789  }
790  }
791  }
792 
793  // Sanity check that the property is the same type as the ivar, or a
794  // reference to it, and that it is either an object pointer or trivially
795  // copyable.
796  if (!Ctx.hasSameUnqualifiedType(IVar->getType(),
797  Prop->getType().getNonReferenceType()))
798  return nullptr;
799  if (!IVar->getType()->isObjCLifetimeType() &&
800  !IVar->getType().isTriviallyCopyableType(Ctx))
801  return nullptr;
802 
803  // Generate our body:
804  // return self->_ivar;
805  ASTMaker M(Ctx);
806 
807  const VarDecl *selfVar = MD->getSelfDecl();
808  if (!selfVar)
809  return nullptr;
810 
811  Expr *loadedIVar = M.makeObjCIvarRef(
812  M.makeLvalueToRvalue(M.makeDeclRefExpr(selfVar), selfVar->getType()),
813  IVar);
814 
815  if (!MD->getReturnType()->isReferenceType())
816  loadedIVar = M.makeLvalueToRvalue(loadedIVar, IVar->getType());
817 
818  return M.makeReturn(loadedIVar);
819 }
820 
822  // We currently only know how to synthesize property accessors.
823  if (!D->isPropertyAccessor())
824  return nullptr;
825 
826  D = D->getCanonicalDecl();
827 
828  // We should not try to synthesize explicitly redefined accessors.
829  // We do not know for sure how they behave.
830  if (!D->isImplicit())
831  return nullptr;
832 
833  Optional<Stmt *> &Val = Bodies[D];
834  if (Val.hasValue())
835  return Val.getValue();
836  Val = nullptr;
837 
838  // For now, we only synthesize getters.
839  // Synthesizing setters would cause false negatives in the
840  // RetainCountChecker because the method body would bind the parameter
841  // to an instance variable, causing it to escape. This would prevent
842  // warning in the following common scenario:
843  //
844  // id foo = [[NSObject alloc] init];
845  // self.foo = foo; // We should warn that foo leaks here.
846  //
847  if (D->param_size() != 0)
848  return nullptr;
849 
850  // If the property was defined in an extension, search the extensions for
851  // overrides.
852  const ObjCInterfaceDecl *OID = D->getClassInterface();
853  if (dyn_cast<ObjCInterfaceDecl>(D->getParent()) != OID)
854  for (auto *Ext : OID->known_extensions()) {
855  auto *OMD = Ext->getInstanceMethod(D->getSelector());
856  if (OMD && !OMD->isImplicit())
857  return nullptr;
858  }
859 
860  Val = createObjCPropertyGetter(C, D);
861 
862  return Val.getValue();
863 }
clang::Type::isIntegralType
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
Definition: Type.cpp:1925
clang::ObjCInterfaceDecl
Represents an ObjC class declaration.
Definition: DeclObjC.h:1151
clang::ObjCPropertyDecl::isReadOnly
bool isReadOnly() const
isReadOnly - Return true iff the property has a setter.
Definition: DeclObjC.h:838
clang::CodeInjector::getBody
virtual Stmt * getBody(const FunctionDecl *D)=0
clang::IfStmt::Create
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL, SourceLocation RPL, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
Definition: Stmt.cpp:949
clang::FunctionDecl::getNumParams
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition: Decl.cpp:3380
clang::interp::APInt
llvm::APInt APInt
Definition: Integral.h:27
clang::OK_Ordinary
@ OK_Ordinary
An ordinary object is located at an address in memory.
Definition: Specifiers.h:136
clang::FunctionDecl::getReturnType
QualType getReturnType() const
Definition: Decl.h:2537
clang::ObjCImplementationDecl
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2546
clang::UnaryOperator::Create
static UnaryOperator * Create(const ASTContext &C, Expr *input, Opcode opc, QualType type, ExprValueKind VK, ExprObjectKind OK, SourceLocation l, bool CanOverflow, FPOptionsOverride FPFeatures)
Definition: Expr.cpp:4563
CodeInjector.h
llvm::SmallVector
Definition: LLVM.h:38
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:249
clang::MemberExpr::Create
static MemberExpr * Create(const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *MemberDecl, DeclAccessPair FoundDecl, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, QualType T, ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR)
Definition: Expr.cpp:1646
clang::QualType::getNonReferenceType
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
Definition: Type.h:6620
CXXInheritance.h
clang::BinaryOperator::isLogicalOp
bool isLogicalOp() const
Definition: Expr.h:3936
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:673
clang::FunctionDecl::getParamDecl
const ParmVarDecl * getParamDecl(unsigned i) const
Definition: Decl.h:2506
AttributeLangSupport::C
@ C
Definition: SemaDeclAttr.cpp:54
clang::QualType::getCanonicalType
QualType getCanonicalType() const
Definition: Type.h:6463
clang::ParmVarDecl
Represents a parameter to a function.
Definition: Decl.h:1665
isDispatchBlock
static bool isDispatchBlock(QualType Ty)
Definition: BodyFarm.cpp:35
clang::ObjCMethodDecl::getClassInterface
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1164
llvm::Optional
Definition: LLVM.h:40
clang::UnaryOperator
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2157
clang::Type::isVoidType
bool isVoidType() const
Definition: Type.h:6955
clang::Type::isRValueReferenceType
bool isRValueReferenceType() const
Definition: Type.h:6692
clang::FunctionDecl::param_size
size_t param_size() const
Definition: Decl.h:2499
clang::DeclarationName
The name of a declaration.
Definition: DeclarationName.h:145
clang::ObjCInterfaceDecl::known_extensions
known_extensions_range known_extensions() const
Definition: DeclObjC.h:1740
clang::CXXRecordDecl::getLambdaCallOperator
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
Definition: DeclCXX.cpp:1510
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1490
clang::ObjCBoolLiteralExpr
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
Definition: ExprObjC.h:88
Decl.h
clang::Type::isReferenceType
bool isReferenceType() const
Definition: Type.h:6684
clang::IntegerLiteral
Definition: Expr.h:1488
clang::ReturnStmt::Create
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition: Stmt.cpp:1195
findBackingIvar
static const ObjCIvarDecl * findBackingIvar(const ObjCPropertyDecl *Prop)
Definition: BodyFarm.cpp:701
clang::CompoundStmt
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1399
clang::DeclAccessPair::make
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
Definition: DeclAccessPair.h:35
clang::DeclRefExpr::Create
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
Definition: Expr.cpp:435
FunctionFarmer
Stmt *(* FunctionFarmer)(ASTContext &C, const FunctionDecl *D)
Definition: BodyFarm.cpp:243
clang::ObjCInterfaceDecl::getImplementation
ObjCImplementationDecl * getImplementation() const
Definition: DeclObjC.cpp:1588
clang::BinaryOperator
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3803
OperatorKinds.h
clang::AS_public
@ AS_public
Definition: Specifiers.h:109
clang::DeclAccessPair
A POD class for pairing a NamedDecl* with an access specifier.
Definition: DeclAccessPair.h:29
clang::ParamIdx
A single parameter index whose accessors require each use to make explicit the parameter index encodi...
Definition: Attr.h:232
clang::ObjCPropertyAttribute::kind_weak
@ kind_weak
Definition: DeclObjCCommon.h:33
clang::FPOptionsOverride
Represents difference between two FPOptions values.
Definition: LangOptions.h:600
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:212
NestedNameSpecifier.h
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7161
clang::ObjCIvarDecl::getContainingInterface
const ObjCInterfaceDecl * getContainingInterface() const
Return the class interface that this ivar is logically contained in; this is either the interface whe...
Definition: DeclObjC.cpp:1829
clang::ObjCMethodDecl::getSelector
Selector getSelector() const
Definition: DeclObjC.h:330
clang::FunctionProtoType::getParamType
QualType getParamType(unsigned i) const
Definition: Type.h:4097
clang::ObjCMethodDecl::getSelfDecl
ImplicitParamDecl * getSelfDecl() const
Definition: DeclObjC.h:423
createObjCPropertyGetter
static Stmt * createObjCPropertyGetter(ASTContext &Ctx, const ObjCMethodDecl *MD)
Definition: BodyFarm.cpp:740
clang::IntegerLiteral::Create
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition: Expr.cpp:883
clang::Type::isLValueReferenceType
bool isLValueReferenceType() const
Definition: Type.h:6688
clang::ImplicitCastExpr::Create
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition: Expr.cpp:1997
clang::DeclContext::isStdNamespace
bool isStdNamespace() const
Definition: DeclBase.cpp:1126
Expr.h
ASTContext.h
clang::VarDecl
Represents a variable declaration or definition.
Definition: Decl.h:876
clang::ObjCMethodDecl::getReturnType
QualType getReturnType() const
Definition: DeclObjC.h:332
clang::Type::getPointeeType
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:625
clang::Type::getAsCXXRecordDecl
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1760
ExprObjC.h
clang::NestedNameSpecifierLoc
A C++ nested-name-specifier augmented with source location information.
Definition: NestedNameSpecifier.h:243
ExprCXX.h
Base
clang::ObjCPropertyDecl::getType
QualType getType() const
Definition: DeclObjC.h:804
clang::ObjCMethodDecl::getCanonicalDecl
ObjCMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclObjC.cpp:965
clang::BlockPointerType
Pointer to a block type.
Definition: Type.h:2720
clang::Decl::isImplicit
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:563
clang::IfStatementKind::Ordinary
@ Ordinary
clang::CXXOperatorCallExpr::Create
static CXXOperatorCallExpr * Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation OperatorLoc, FPOptionsOverride FPFeatures, ADLCallKind UsesADL=NotADL)
Definition: ExprCXX.cpp:558
clang::Type::isObjCLifetimeType
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
Definition: Type.cpp:4304
clang::VK_LValue
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:124
clang::CXXRecordDecl
Represents a C++ struct/union/class.
Definition: DeclCXX.h:255
clang::CallExpr::Create
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition: Expr.cpp:1414
clang::BinaryOperator::Create
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Definition: Expr.cpp:4506
clang::ObjCImplDecl::property_impls
propimpl_range property_impls() const
Definition: DeclObjC.h:2461
clang::VK_PRValue
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:120
clang::QualType::isTriviallyCopyableType
bool isTriviallyCopyableType(const ASTContext &Context) const
Return true if this is a trivially copyable type (C++0x [basic.types]p9)
Definition: Type.cpp:2451
clang::NamedDecl::getIdentifier
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
clang::ValueDecl
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:676
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3885
clang::DeclContext::getParent
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1860
clang::NOUR_None
@ NOUR_None
This is an odr-use.
Definition: Specifiers.h:160
clang::BlockPointerType::getPointeeType
QualType getPointeeType() const
Definition: Type.h:2732
clang::ObjCMethodDecl::isSynthesizedAccessorStub
bool isSynthesizedAccessorStub() const
Definition: DeclObjC.h:449
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:738
llvm::ArrayRef
Definition: LLVM.h:34
Value
Value
Definition: UninitializedValues.cpp:102
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
clang::ObjCPropertyDecl::getPropertyIvarDecl
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:924
clang::BinaryOperator::isComparisonOp
bool isComparisonOp() const
Definition: Expr.h:3903
clang::ObjCPropertyDecl
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:732
clang::Type::getAsRecordDecl
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition: Type.cpp:1764
clang::ObjCPropertyDecl::getQueryKind
ObjCPropertyQueryKind getQueryKind() const
Definition: DeclObjC.h:860
clang::FunctionProtoType::getNumParams
unsigned getNumParams() const
Definition: Type.h:4095
clang::BinaryOperatorKind
BinaryOperatorKind
Definition: OperationKinds.h:25
clang::ExprValueKind
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:117
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:84
BodyFarm.h
clang::Type::isBooleanType
bool isBooleanType() const
Definition: Type.h:7071
clang::ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass
ObjCPropertyDecl * FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId, ObjCPropertyQueryKind QueryKind) const
FindPropertyVisibleInPrimaryClass - Finds declaration of the property with name 'PropertyId' in the p...
Definition: DeclObjC.cpp:370
clang::ObjCMethodDecl
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
clang::PointerType
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2640
clang::ObjCMethodDecl::findPropertyDecl
const ObjCPropertyDecl * findPropertyDecl(bool CheckOverrides=true) const
Returns the property associated with this method's selector.
Definition: DeclObjC.cpp:1331
clang
Definition: CalledOnceCheck.h:17
clang::ObjCContainerDecl::getInstanceMethod
ObjCMethodDecl * getInstanceMethod(Selector Sel, bool AllowHidden=false) const
Definition: DeclObjC.h:1066
create_call_once_lambda_call
static CallExpr * create_call_once_lambda_call(ASTContext &C, ASTMaker M, const ParmVarDecl *Callback, CXXRecordDecl *CallbackDecl, ArrayRef< Expr * > CallArgs)
Definition: BodyFarm.cpp:271
clang::DeclContext::lookup
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1645
clang::DeclaratorContext::Block
@ Block
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:69
clang::ObjCIvarDecl
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1924
clang::Expr::getType
QualType getType() const
Definition: Expr.h:141
clang::FunctionType::getReturnType
QualType getReturnType() const
Definition: Type.h:3809
clang::NamedDecl::getDeclName
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:313
create_dispatch_sync
static Stmt * create_dispatch_sync(ASTContext &C, const FunctionDecl *D)
Create a fake body for dispatch_sync.
Definition: BodyFarm.cpp:560
clang::DeclContextLookupResult
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1292
clang::ImplicitCastExpr
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3618
clang::ObjCMethodDecl::isPropertyAccessor
bool isPropertyAccessor() const
Definition: DeclObjC.h:441
clang::MemberExpr
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3162
clang::CXXBasePaths
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
Definition: CXXInheritance.h:117
clang::BodyFarm::getBody
Stmt * getBody(const FunctionDecl *D)
Factory method for creating bodies for ordinary functions.
Definition: BodyFarm.cpp:668
create_call_once_funcptr_call
static CallExpr * create_call_once_funcptr_call(ASTContext &C, ASTMaker M, const ParmVarDecl *Callback, ArrayRef< Expr * > CallArgs)
Definition: BodyFarm.cpp:245
clang::PointerType::getPointeeType
QualType getPointeeType() const
Definition: Type.h:2650
clang::CXXRecordDecl::isLambda
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition: DeclCXX.h:992
clang::APValue
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
clang::ValueDecl::getType
QualType getType() const
Definition: Decl.h:687
clang::CastKind
CastKind
CastKind - The kind of operation required for a conversion.
Definition: OperationKinds.h:20
clang::Type::isIntegerType
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:6987
clang::ASTContext::hasSameUnqualifiedType
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Definition: ASTContext.h:2508
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::DeclContext::isFunctionOrMethod
bool isFunctionOrMethod() const
Definition: DeclBase.h:1912
clang::DeclarationNameInfo
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
Definition: DeclarationName.h:758
clang::ObjCPropertyDecl::getPropertyAttributes
ObjCPropertyAttribute::Kind getPropertyAttributes() const
Definition: DeclObjC.h:815
create_dispatch_once
static Stmt * create_dispatch_once(ASTContext &C, const FunctionDecl *D)
Create a fake body for dispatch_once.
Definition: BodyFarm.cpp:476
create_OSAtomicCompareAndSwap
static Stmt * create_OSAtomicCompareAndSwap(ASTContext &C, const FunctionDecl *D)
Definition: BodyFarm.cpp:586
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1217
clang::FunctionDecl
Represents a function declaration or definition.
Definition: Decl.h:1856
clang::RecordDecl
Represents a struct/union/class.
Definition: Decl.h:3859
clang::CompoundStmt::Create
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, SourceLocation LB, SourceLocation RB)
Definition: Stmt.cpp:379
clang::CallExpr
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2795
clang::ObjCIvarRefExpr
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:548
clang::ReturnStmt
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:2760
clang::ObjCMethodDecl::param_size
unsigned param_size() const
Definition: DeclObjC.h:350
create_call_once
static Stmt * create_call_once(ASTContext &C, const FunctionDecl *D)
Create a fake body for std::call_once.
Definition: BodyFarm.cpp:314
clang::Decl::getDeclContext
DeclContext * getDeclContext()
Definition: DeclBase.h:439
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276