Ted Kremenek | a43df95 | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 1 | //== BodyFarm.cpp - Factory for conjuring up fake bodies ----------*- C++ -*-// |
| 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 | // BodyFarm is a factory for creating faux implementations for functions/methods |
| 11 | // for analysis purposes. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Ted Kremenek | a43df95 | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 15 | #include "BodyFarm.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
| 17 | #include "clang/AST/Decl.h" |
| 18 | #include "clang/AST/Expr.h" |
| 19 | #include "clang/AST/ExprObjC.h" |
| 20 | #include "llvm/ADT/StringSwitch.h" |
Ted Kremenek | a43df95 | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace clang; |
| 23 | |
Ted Kremenek | 0a4c098 | 2012-09-21 17:54:32 +0000 | [diff] [blame] | 24 | //===----------------------------------------------------------------------===// |
| 25 | // Helper creation functions for constructing faux ASTs. |
| 26 | //===----------------------------------------------------------------------===// |
Ted Kremenek | a43df95 | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 27 | |
Ted Kremenek | cc85d21 | 2012-09-21 00:52:24 +0000 | [diff] [blame] | 28 | static bool isDispatchBlock(QualType Ty) { |
| 29 | // Is it a block pointer? |
| 30 | const BlockPointerType *BPT = Ty->getAs<BlockPointerType>(); |
| 31 | if (!BPT) |
| 32 | return false; |
| 33 | |
| 34 | // Check if the block pointer type takes no arguments and |
| 35 | // returns void. |
| 36 | const FunctionProtoType *FT = |
| 37 | BPT->getPointeeType()->getAs<FunctionProtoType>(); |
| 38 | if (!FT || !FT->getResultType()->isVoidType() || |
| 39 | FT->getNumArgs() != 0) |
| 40 | return false; |
| 41 | |
| 42 | return true; |
| 43 | } |
| 44 | |
Ted Kremenek | 016c33d | 2012-09-21 17:54:35 +0000 | [diff] [blame] | 45 | namespace { |
| 46 | class ASTMaker { |
| 47 | public: |
| 48 | ASTMaker(ASTContext &C) : C(C) {} |
| 49 | |
Ted Kremenek | b80e5bb | 2012-09-21 18:33:54 +0000 | [diff] [blame] | 50 | /// Create a new BinaryOperator representing a simple assignment. |
| 51 | BinaryOperator *makeAssignment(const Expr *LHS, const Expr *RHS, QualType Ty); |
| 52 | |
Ted Kremenek | 48fa136 | 2012-10-11 20:58:18 +0000 | [diff] [blame] | 53 | /// Create a new BinaryOperator representing a comparison. |
| 54 | BinaryOperator *makeComparison(const Expr *LHS, const Expr *RHS, |
| 55 | BinaryOperator::Opcode Op); |
| 56 | |
| 57 | /// Create a new compound stmt using the provided statements. |
| 58 | CompoundStmt *makeCompound(ArrayRef<Stmt*>); |
| 59 | |
Ted Kremenek | a6d62a1 | 2012-09-21 18:13:23 +0000 | [diff] [blame] | 60 | /// Create a new DeclRefExpr for the referenced variable. |
Ted Kremenek | 016c33d | 2012-09-21 17:54:35 +0000 | [diff] [blame] | 61 | DeclRefExpr *makeDeclRefExpr(const VarDecl *D); |
| 62 | |
Ted Kremenek | 0b5c5e4 | 2012-09-21 18:33:52 +0000 | [diff] [blame] | 63 | /// Create a new UnaryOperator representing a dereference. |
| 64 | UnaryOperator *makeDereference(const Expr *Arg, QualType Ty); |
| 65 | |
Ted Kremenek | a6d62a1 | 2012-09-21 18:13:23 +0000 | [diff] [blame] | 66 | /// Create an implicit cast for an integer conversion. |
Ted Kremenek | 5dbd990 | 2012-10-12 00:18:19 +0000 | [diff] [blame] | 67 | Expr *makeIntegralCast(const Expr *Arg, QualType Ty); |
Ted Kremenek | a6d62a1 | 2012-09-21 18:13:23 +0000 | [diff] [blame] | 68 | |
Ted Kremenek | 48fa136 | 2012-10-11 20:58:18 +0000 | [diff] [blame] | 69 | /// Create an implicit cast to a builtin boolean type. |
| 70 | ImplicitCastExpr *makeIntegralCastToBoolean(const Expr *Arg); |
| 71 | |
Ted Kremenek | 9ba05cd | 2012-09-21 18:13:27 +0000 | [diff] [blame] | 72 | // Create an implicit cast for lvalue-to-rvaluate conversions. |
| 73 | ImplicitCastExpr *makeLvalueToRvalue(const Expr *Arg, QualType Ty); |
| 74 | |
Ted Kremenek | 48fa136 | 2012-10-11 20:58:18 +0000 | [diff] [blame] | 75 | /// Create an Objective-C bool literal. |
| 76 | ObjCBoolLiteralExpr *makeObjCBool(bool Val); |
| 77 | |
| 78 | /// Create a Return statement. |
| 79 | ReturnStmt *makeReturn(const Expr *RetVal); |
| 80 | |
Ted Kremenek | 016c33d | 2012-09-21 17:54:35 +0000 | [diff] [blame] | 81 | private: |
| 82 | ASTContext &C; |
| 83 | }; |
| 84 | } |
| 85 | |
Ted Kremenek | b80e5bb | 2012-09-21 18:33:54 +0000 | [diff] [blame] | 86 | BinaryOperator *ASTMaker::makeAssignment(const Expr *LHS, const Expr *RHS, |
| 87 | QualType Ty) { |
| 88 | return new (C) BinaryOperator(const_cast<Expr*>(LHS), const_cast<Expr*>(RHS), |
| 89 | BO_Assign, Ty, VK_RValue, |
Lang Hames | be9af12 | 2012-10-02 04:45:10 +0000 | [diff] [blame] | 90 | OK_Ordinary, SourceLocation(), false); |
Ted Kremenek | b80e5bb | 2012-09-21 18:33:54 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Ted Kremenek | 48fa136 | 2012-10-11 20:58:18 +0000 | [diff] [blame] | 93 | BinaryOperator *ASTMaker::makeComparison(const Expr *LHS, const Expr *RHS, |
| 94 | BinaryOperator::Opcode Op) { |
| 95 | assert(BinaryOperator::isLogicalOp(Op) || |
| 96 | BinaryOperator::isComparisonOp(Op)); |
| 97 | return new (C) BinaryOperator(const_cast<Expr*>(LHS), |
| 98 | const_cast<Expr*>(RHS), |
| 99 | Op, |
| 100 | C.getLogicalOperationType(), |
| 101 | VK_RValue, |
| 102 | OK_Ordinary, SourceLocation(), false); |
| 103 | } |
| 104 | |
| 105 | CompoundStmt *ASTMaker::makeCompound(ArrayRef<Stmt *> Stmts) { |
Nico Weber | d36aa35 | 2012-12-29 20:03:39 +0000 | [diff] [blame] | 106 | return new (C) CompoundStmt(C, Stmts, SourceLocation(), SourceLocation()); |
Ted Kremenek | 48fa136 | 2012-10-11 20:58:18 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Ted Kremenek | 016c33d | 2012-09-21 17:54:35 +0000 | [diff] [blame] | 109 | DeclRefExpr *ASTMaker::makeDeclRefExpr(const VarDecl *D) { |
| 110 | DeclRefExpr *DR = |
| 111 | DeclRefExpr::Create(/* Ctx = */ C, |
| 112 | /* QualifierLoc = */ NestedNameSpecifierLoc(), |
| 113 | /* TemplateKWLoc = */ SourceLocation(), |
| 114 | /* D = */ const_cast<VarDecl*>(D), |
| 115 | /* isEnclosingLocal = */ false, |
| 116 | /* NameLoc = */ SourceLocation(), |
| 117 | /* T = */ D->getType(), |
| 118 | /* VK = */ VK_LValue); |
| 119 | return DR; |
| 120 | } |
| 121 | |
Ted Kremenek | 0b5c5e4 | 2012-09-21 18:33:52 +0000 | [diff] [blame] | 122 | UnaryOperator *ASTMaker::makeDereference(const Expr *Arg, QualType Ty) { |
| 123 | return new (C) UnaryOperator(const_cast<Expr*>(Arg), UO_Deref, Ty, |
| 124 | VK_LValue, OK_Ordinary, SourceLocation()); |
| 125 | } |
| 126 | |
Ted Kremenek | 9ba05cd | 2012-09-21 18:13:27 +0000 | [diff] [blame] | 127 | ImplicitCastExpr *ASTMaker::makeLvalueToRvalue(const Expr *Arg, QualType Ty) { |
| 128 | return ImplicitCastExpr::Create(C, Ty, CK_LValueToRValue, |
| 129 | const_cast<Expr*>(Arg), 0, VK_RValue); |
| 130 | } |
| 131 | |
Ted Kremenek | 5dbd990 | 2012-10-12 00:18:19 +0000 | [diff] [blame] | 132 | Expr *ASTMaker::makeIntegralCast(const Expr *Arg, QualType Ty) { |
| 133 | if (Arg->getType() == Ty) |
| 134 | return const_cast<Expr*>(Arg); |
| 135 | |
Ted Kremenek | a6d62a1 | 2012-09-21 18:13:23 +0000 | [diff] [blame] | 136 | return ImplicitCastExpr::Create(C, Ty, CK_IntegralCast, |
| 137 | const_cast<Expr*>(Arg), 0, VK_RValue); |
| 138 | } |
| 139 | |
Ted Kremenek | 48fa136 | 2012-10-11 20:58:18 +0000 | [diff] [blame] | 140 | ImplicitCastExpr *ASTMaker::makeIntegralCastToBoolean(const Expr *Arg) { |
| 141 | return ImplicitCastExpr::Create(C, C.BoolTy, CK_IntegralToBoolean, |
| 142 | const_cast<Expr*>(Arg), 0, VK_RValue); |
| 143 | } |
| 144 | |
| 145 | ObjCBoolLiteralExpr *ASTMaker::makeObjCBool(bool Val) { |
| 146 | QualType Ty = C.getBOOLDecl() ? C.getBOOLType() : C.ObjCBuiltinBoolTy; |
| 147 | return new (C) ObjCBoolLiteralExpr(Val, Ty, SourceLocation()); |
| 148 | } |
| 149 | |
| 150 | ReturnStmt *ASTMaker::makeReturn(const Expr *RetVal) { |
| 151 | return new (C) ReturnStmt(SourceLocation(), const_cast<Expr*>(RetVal), 0); |
| 152 | } |
| 153 | |
Ted Kremenek | 0a4c098 | 2012-09-21 17:54:32 +0000 | [diff] [blame] | 154 | //===----------------------------------------------------------------------===// |
| 155 | // Creation functions for faux ASTs. |
| 156 | //===----------------------------------------------------------------------===// |
| 157 | |
| 158 | typedef Stmt *(*FunctionFarmer)(ASTContext &C, const FunctionDecl *D); |
| 159 | |
Ted Kremenek | cc85d21 | 2012-09-21 00:52:24 +0000 | [diff] [blame] | 160 | /// Create a fake body for dispatch_once. |
| 161 | static Stmt *create_dispatch_once(ASTContext &C, const FunctionDecl *D) { |
| 162 | // Check if we have at least two parameters. |
| 163 | if (D->param_size() != 2) |
| 164 | return 0; |
| 165 | |
| 166 | // Check if the first parameter is a pointer to integer type. |
| 167 | const ParmVarDecl *Predicate = D->getParamDecl(0); |
| 168 | QualType PredicateQPtrTy = Predicate->getType(); |
| 169 | const PointerType *PredicatePtrTy = PredicateQPtrTy->getAs<PointerType>(); |
| 170 | if (!PredicatePtrTy) |
| 171 | return 0; |
| 172 | QualType PredicateTy = PredicatePtrTy->getPointeeType(); |
| 173 | if (!PredicateTy->isIntegerType()) |
| 174 | return 0; |
| 175 | |
| 176 | // Check if the second parameter is the proper block type. |
| 177 | const ParmVarDecl *Block = D->getParamDecl(1); |
| 178 | QualType Ty = Block->getType(); |
| 179 | if (!isDispatchBlock(Ty)) |
| 180 | return 0; |
| 181 | |
| 182 | // Everything checks out. Create a fakse body that checks the predicate, |
| 183 | // sets it, and calls the block. Basically, an AST dump of: |
| 184 | // |
| 185 | // void dispatch_once(dispatch_once_t *predicate, dispatch_block_t block) { |
| 186 | // if (!*predicate) { |
| 187 | // *predicate = 1; |
| 188 | // block(); |
| 189 | // } |
| 190 | // } |
| 191 | |
Ted Kremenek | 016c33d | 2012-09-21 17:54:35 +0000 | [diff] [blame] | 192 | ASTMaker M(C); |
| 193 | |
Ted Kremenek | cc85d21 | 2012-09-21 00:52:24 +0000 | [diff] [blame] | 194 | // (1) Create the call. |
Ted Kremenek | 016c33d | 2012-09-21 17:54:35 +0000 | [diff] [blame] | 195 | DeclRefExpr *DR = M.makeDeclRefExpr(Block); |
Ted Kremenek | 9ba05cd | 2012-09-21 18:13:27 +0000 | [diff] [blame] | 196 | ImplicitCastExpr *ICE = M.makeLvalueToRvalue(DR, Ty); |
Ted Kremenek | cc85d21 | 2012-09-21 00:52:24 +0000 | [diff] [blame] | 197 | CallExpr *CE = new (C) CallExpr(C, ICE, ArrayRef<Expr*>(), C.VoidTy, |
| 198 | VK_RValue, SourceLocation()); |
| 199 | |
| 200 | // (2) Create the assignment to the predicate. |
| 201 | IntegerLiteral *IL = |
| 202 | IntegerLiteral::Create(C, llvm::APInt(C.getTypeSize(C.IntTy), (uint64_t) 1), |
| 203 | C.IntTy, SourceLocation()); |
Ted Kremenek | fcf8eba | 2012-09-21 18:33:56 +0000 | [diff] [blame] | 204 | BinaryOperator *B = |
| 205 | M.makeAssignment( |
| 206 | M.makeDereference( |
| 207 | M.makeLvalueToRvalue( |
| 208 | M.makeDeclRefExpr(Predicate), PredicateQPtrTy), |
| 209 | PredicateTy), |
| 210 | M.makeIntegralCast(IL, PredicateTy), |
| 211 | PredicateTy); |
| 212 | |
Ted Kremenek | cc85d21 | 2012-09-21 00:52:24 +0000 | [diff] [blame] | 213 | // (3) Create the compound statement. |
| 214 | Stmt *Stmts[2]; |
| 215 | Stmts[0] = B; |
Ted Kremenek | 48fa136 | 2012-10-11 20:58:18 +0000 | [diff] [blame] | 216 | Stmts[1] = CE; |
| 217 | CompoundStmt *CS = M.makeCompound(ArrayRef<Stmt*>(Stmts, 2)); |
Ted Kremenek | cc85d21 | 2012-09-21 00:52:24 +0000 | [diff] [blame] | 218 | |
| 219 | // (4) Create the 'if' condition. |
Ted Kremenek | fcf8eba | 2012-09-21 18:33:56 +0000 | [diff] [blame] | 220 | ImplicitCastExpr *LValToRval = |
| 221 | M.makeLvalueToRvalue( |
| 222 | M.makeDereference( |
| 223 | M.makeLvalueToRvalue( |
| 224 | M.makeDeclRefExpr(Predicate), |
| 225 | PredicateQPtrTy), |
| 226 | PredicateTy), |
| 227 | PredicateTy); |
| 228 | |
| 229 | UnaryOperator *UO = new (C) UnaryOperator(LValToRval, UO_LNot, C.IntTy, |
| 230 | VK_RValue, OK_Ordinary, |
| 231 | SourceLocation()); |
Ted Kremenek | cc85d21 | 2012-09-21 00:52:24 +0000 | [diff] [blame] | 232 | |
| 233 | // (5) Create the 'if' statement. |
| 234 | IfStmt *If = new (C) IfStmt(C, SourceLocation(), 0, UO, CS); |
| 235 | return If; |
| 236 | } |
| 237 | |
Ted Kremenek | a43df95 | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 238 | /// Create a fake body for dispatch_sync. |
| 239 | static Stmt *create_dispatch_sync(ASTContext &C, const FunctionDecl *D) { |
| 240 | // Check if we have at least two parameters. |
| 241 | if (D->param_size() != 2) |
| 242 | return 0; |
| 243 | |
| 244 | // Check if the second parameter is a block. |
| 245 | const ParmVarDecl *PV = D->getParamDecl(1); |
| 246 | QualType Ty = PV->getType(); |
Ted Kremenek | cc85d21 | 2012-09-21 00:52:24 +0000 | [diff] [blame] | 247 | if (!isDispatchBlock(Ty)) |
Ted Kremenek | a43df95 | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 248 | return 0; |
Ted Kremenek | 016c33d | 2012-09-21 17:54:35 +0000 | [diff] [blame] | 249 | |
Ted Kremenek | a43df95 | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 250 | // Everything checks out. Create a fake body that just calls the block. |
| 251 | // This is basically just an AST dump of: |
| 252 | // |
| 253 | // void dispatch_sync(dispatch_queue_t queue, void (^block)(void)) { |
| 254 | // block(); |
| 255 | // } |
Ted Kremenek | 016c33d | 2012-09-21 17:54:35 +0000 | [diff] [blame] | 256 | // |
| 257 | ASTMaker M(C); |
| 258 | DeclRefExpr *DR = M.makeDeclRefExpr(PV); |
Ted Kremenek | 0b5c5e4 | 2012-09-21 18:33:52 +0000 | [diff] [blame] | 259 | ImplicitCastExpr *ICE = M.makeLvalueToRvalue(DR, Ty); |
Ted Kremenek | a43df95 | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 260 | CallExpr *CE = new (C) CallExpr(C, ICE, ArrayRef<Expr*>(), C.VoidTy, |
| 261 | VK_RValue, SourceLocation()); |
| 262 | return CE; |
| 263 | } |
| 264 | |
Ted Kremenek | 48fa136 | 2012-10-11 20:58:18 +0000 | [diff] [blame] | 265 | static Stmt *create_OSAtomicCompareAndSwap(ASTContext &C, const FunctionDecl *D) |
| 266 | { |
| 267 | // There are exactly 3 arguments. |
| 268 | if (D->param_size() != 3) |
| 269 | return 0; |
| 270 | |
| 271 | // Body for: |
| 272 | // if (oldValue == *theValue) { |
| 273 | // *theValue = newValue; |
| 274 | // return YES; |
| 275 | // } |
| 276 | // else return NO; |
| 277 | |
Ted Kremenek | 5dbd990 | 2012-10-12 00:18:19 +0000 | [diff] [blame] | 278 | QualType ResultTy = D->getResultType(); |
| 279 | bool isBoolean = ResultTy->isBooleanType(); |
| 280 | if (!isBoolean && !ResultTy->isIntegralType(C)) |
| 281 | return 0; |
| 282 | |
Ted Kremenek | 48fa136 | 2012-10-11 20:58:18 +0000 | [diff] [blame] | 283 | const ParmVarDecl *OldValue = D->getParamDecl(0); |
| 284 | QualType OldValueTy = OldValue->getType(); |
| 285 | |
| 286 | const ParmVarDecl *NewValue = D->getParamDecl(1); |
| 287 | QualType NewValueTy = NewValue->getType(); |
| 288 | |
| 289 | assert(OldValueTy == NewValueTy); |
| 290 | |
| 291 | const ParmVarDecl *TheValue = D->getParamDecl(2); |
| 292 | QualType TheValueTy = TheValue->getType(); |
| 293 | const PointerType *PT = TheValueTy->getAs<PointerType>(); |
| 294 | if (!PT) |
| 295 | return 0; |
| 296 | QualType PointeeTy = PT->getPointeeType(); |
| 297 | |
| 298 | ASTMaker M(C); |
| 299 | // Construct the comparison. |
| 300 | Expr *Comparison = |
| 301 | M.makeComparison( |
| 302 | M.makeLvalueToRvalue(M.makeDeclRefExpr(OldValue), OldValueTy), |
| 303 | M.makeLvalueToRvalue( |
| 304 | M.makeDereference( |
| 305 | M.makeLvalueToRvalue(M.makeDeclRefExpr(TheValue), TheValueTy), |
| 306 | PointeeTy), |
| 307 | PointeeTy), |
| 308 | BO_EQ); |
| 309 | |
| 310 | // Construct the body of the IfStmt. |
| 311 | Stmt *Stmts[2]; |
| 312 | Stmts[0] = |
| 313 | M.makeAssignment( |
| 314 | M.makeDereference( |
| 315 | M.makeLvalueToRvalue(M.makeDeclRefExpr(TheValue), TheValueTy), |
| 316 | PointeeTy), |
| 317 | M.makeLvalueToRvalue(M.makeDeclRefExpr(NewValue), NewValueTy), |
| 318 | NewValueTy); |
Ted Kremenek | 5dbd990 | 2012-10-12 00:18:19 +0000 | [diff] [blame] | 319 | |
| 320 | Expr *BoolVal = M.makeObjCBool(true); |
| 321 | Expr *RetVal = isBoolean ? M.makeIntegralCastToBoolean(BoolVal) |
| 322 | : M.makeIntegralCast(BoolVal, ResultTy); |
| 323 | Stmts[1] = M.makeReturn(RetVal); |
Ted Kremenek | 48fa136 | 2012-10-11 20:58:18 +0000 | [diff] [blame] | 324 | CompoundStmt *Body = M.makeCompound(ArrayRef<Stmt*>(Stmts, 2)); |
| 325 | |
| 326 | // Construct the else clause. |
Ted Kremenek | 5dbd990 | 2012-10-12 00:18:19 +0000 | [diff] [blame] | 327 | BoolVal = M.makeObjCBool(false); |
| 328 | RetVal = isBoolean ? M.makeIntegralCastToBoolean(BoolVal) |
| 329 | : M.makeIntegralCast(BoolVal, ResultTy); |
| 330 | Stmt *Else = M.makeReturn(RetVal); |
Ted Kremenek | 48fa136 | 2012-10-11 20:58:18 +0000 | [diff] [blame] | 331 | |
| 332 | /// Construct the If. |
| 333 | Stmt *If = |
| 334 | new (C) IfStmt(C, SourceLocation(), 0, Comparison, Body, |
| 335 | SourceLocation(), Else); |
| 336 | |
| 337 | return If; |
| 338 | } |
| 339 | |
Ted Kremenek | a43df95 | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 340 | Stmt *BodyFarm::getBody(const FunctionDecl *D) { |
| 341 | D = D->getCanonicalDecl(); |
| 342 | |
| 343 | llvm::Optional<Stmt *> &Val = Bodies[D]; |
| 344 | if (Val.hasValue()) |
| 345 | return Val.getValue(); |
| 346 | |
| 347 | Val = 0; |
| 348 | |
| 349 | if (D->getIdentifier() == 0) |
| 350 | return 0; |
| 351 | |
| 352 | StringRef Name = D->getName(); |
| 353 | if (Name.empty()) |
| 354 | return 0; |
Ted Kremenek | 48fa136 | 2012-10-11 20:58:18 +0000 | [diff] [blame] | 355 | |
| 356 | FunctionFarmer FF; |
| 357 | |
| 358 | if (Name.startswith("OSAtomicCompareAndSwap") || |
| 359 | Name.startswith("objc_atomicCompareAndSwap")) { |
| 360 | FF = create_OSAtomicCompareAndSwap; |
| 361 | } |
| 362 | else { |
| 363 | FF = llvm::StringSwitch<FunctionFarmer>(Name) |
| 364 | .Case("dispatch_sync", create_dispatch_sync) |
| 365 | .Case("dispatch_once", create_dispatch_once) |
| 366 | .Default(NULL); |
Ted Kremenek | a43df95 | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Ted Kremenek | 48fa136 | 2012-10-11 20:58:18 +0000 | [diff] [blame] | 369 | if (FF) { Val = FF(C, D); } |
Ted Kremenek | a43df95 | 2012-09-21 00:09:11 +0000 | [diff] [blame] | 370 | return Val.getValue(); |
| 371 | } |
| 372 | |