CallEvent.h revision f540c54701e3eeb34cb619a3a4eb18f1ac70ef2d
1//===- CallEvent.h - Wrapper for all function and method calls ----*- 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/// \file This file defines CallEvent and its subclasses, which represent path- 11/// sensitive instances of different kinds of function and method calls 12/// (C, C++, and Objective-C). 13// 14//===----------------------------------------------------------------------===// 15 16#ifndef LLVM_CLANG_STATICANALYZER_PATHSENSITIVE_CALL 17#define LLVM_CLANG_STATICANALYZER_PATHSENSITIVE_CALL 18 19#include "clang/Basic/SourceManager.h" 20#include "clang/AST/DeclCXX.h" 21#include "clang/AST/ExprCXX.h" 22#include "clang/AST/ExprObjC.h" 23#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h" 24#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h" 25#include "llvm/ADT/PointerIntPair.h" 26 27namespace clang { 28class ProgramPoint; 29class ProgramPointTag; 30 31namespace ento { 32 33enum CallEventKind { 34 CE_Function, 35 CE_CXXMember, 36 CE_CXXMemberOperator, 37 CE_BEG_CXX_INSTANCE_CALLS = CE_CXXMember, 38 CE_END_CXX_INSTANCE_CALLS = CE_CXXMemberOperator, 39 CE_Block, 40 CE_BEG_SIMPLE_CALLS = CE_Function, 41 CE_END_SIMPLE_CALLS = CE_Block, 42 CE_CXXConstructor, 43 CE_CXXDestructor, 44 CE_CXXAllocator, 45 CE_BEG_FUNCTION_CALLS = CE_Function, 46 CE_END_FUNCTION_CALLS = CE_CXXAllocator, 47 CE_ObjCMessage 48}; 49 50 51/// \brief Represents an abstract call to a function or method along a 52/// particular path. 53class CallEvent { 54public: 55 typedef CallEventKind Kind; 56 57private: 58 // PointerIntPair doesn't respect IntrusiveRefCntPtr, so we have to manually 59 // retain and release the state. 60 llvm::PointerIntPair<const ProgramState *, 2> State; 61 llvm::PointerIntPair<const LocationContext *, 2> LCtx; 62 llvm::PointerUnion<const Expr *, const Decl *> Origin; 63 64protected: 65 // This is user data for subclasses. 66 const void *Data; 67 SourceLocation Location; 68 69 CallEvent(const Expr *E, ProgramStateRef state, const LocationContext *lctx, 70 Kind k) 71 : State(state.getPtr(), (k & 0x3)), 72 LCtx(lctx, ((k >> 2) & 0x3)), 73 Origin(E) { 74 IntrusiveRefCntPtrInfo<const ProgramState>::retain(getState()); 75 assert(k == getKind() && "More kinds than bits in the PointerIntPairs."); 76 } 77 78 CallEvent(const Decl *D, ProgramStateRef state, const LocationContext *lctx, 79 Kind k) 80 : State(state.getPtr(), (k & 0x3)), 81 LCtx(lctx, ((k >> 2) & 0x3)), 82 Origin(D) { 83 IntrusiveRefCntPtrInfo<const ProgramState>::retain(getState()); 84 assert(k == getKind() && "More kinds than bits in the PointerIntPairs."); 85 } 86 87 const ProgramState *getState() const { 88 return State.getPointer(); 89 } 90 91 const LocationContext *getLocationContext() const { 92 return LCtx.getPointer(); 93 } 94 95 ~CallEvent() { 96 IntrusiveRefCntPtrInfo<const ProgramState>::release(getState()); 97 } 98 99 100 /// \brief Get the value of arbitrary expressions at this point in the path. 101 SVal getSVal(const Stmt *S) const { 102 return getState()->getSVal(S, getLocationContext()); 103 } 104 105 typedef SmallVectorImpl<const MemRegion *> RegionList; 106 107 /// \brief Used to specify non-argument regions that will be invalidated as a 108 /// result of this call. 109 void getExtraInvalidatedRegions(RegionList &Regions) const; 110 111 QualType getDeclaredResultType() const; 112 113public: 114 /// \brief Returns the kind of call this is. 115 Kind getKind() const { 116 return static_cast<Kind>((State.getInt()) | (LCtx.getInt() << 2)); 117 } 118 119 /// \brief Returns the declaration of the function or method that will be 120 /// called. May be null. 121 const Decl *getDecl() const; 122 123 /// \brief Returns the definition of the function or method that will be 124 /// called. Returns NULL if the definition cannot be found; ex: due to 125 /// dynamic dispatch in ObjC methods. 126 const Decl *getRuntimeDefinition() const; 127 128 /// \brief Returns the expression whose value will be the result of this call. 129 /// May be null. 130 const Expr *getOriginExpr() const { 131 return Origin.dyn_cast<const Expr *>(); 132 } 133 134 /// \brief Returns the number of arguments (explicit and implicit). 135 /// 136 /// Note that this may be greater than the number of parameters in the 137 /// callee's declaration, and that it may include arguments not written in 138 /// the source. 139 unsigned getNumArgs() const; 140 141 /// \brief Returns true if the callee is known to be from a system header. 142 bool isInSystemHeader() const { 143 const Decl *D = getDecl(); 144 if (!D) 145 return false; 146 147 SourceLocation Loc = D->getLocation(); 148 if (Loc.isValid()) { 149 const SourceManager &SM = 150 getState()->getStateManager().getContext().getSourceManager(); 151 return SM.isInSystemHeader(D->getLocation()); 152 } 153 154 // Special case for implicitly-declared global operator new/delete. 155 // These should be considered system functions. 156 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) 157 return FD->isOverloadedOperator() && FD->isImplicit() && FD->isGlobal(); 158 159 return false; 160 } 161 162 /// \brief Returns a source range for the entire call, suitable for 163 /// outputting in diagnostics. 164 SourceRange getSourceRange() const; 165 166 /// \brief Returns the value of a given argument at the time of the call. 167 SVal getArgSVal(unsigned Index) const; 168 169 /// \brief Returns the expression associated with a given argument. 170 /// May be null if this expression does not appear in the source. 171 const Expr *getArgExpr(unsigned Index) const; 172 173 /// \brief Returns the source range for errors associated with this argument. 174 /// May be invalid if the argument is not written in the source. 175 // FIXME: Is it better to return an invalid range or the range of the origin 176 // expression? 177 SourceRange getArgSourceRange(unsigned Index) const; 178 179 /// \brief Returns the result type, adjusted for references. 180 QualType getResultType() const; 181 182 /// \brief Returns the value of the implicit 'this' object, or UndefinedVal if 183 /// this is not a C++ member function call. 184 SVal getCXXThisVal() const; 185 186 /// \brief Returns true if any of the arguments appear to represent callbacks. 187 bool hasNonZeroCallbackArg() const; 188 189 /// \brief Returns true if any of the arguments are known to escape to long- 190 /// term storage, even if this method will not modify them. 191 // NOTE: The exact semantics of this are still being defined! 192 // We don't really want a list of hardcoded exceptions in the long run, 193 // but we don't want duplicated lists of known APIs in the short term either. 194 bool argumentsMayEscape() const; 195 196 /// \brief Returns an appropriate ProgramPoint for this call. 197 ProgramPoint getProgramPoint(bool IsPreVisit = false, 198 const ProgramPointTag *Tag = 0) const; 199 200 /// \brief Returns a new state with all argument regions invalidated. 201 /// 202 /// This accepts an alternate state in case some processing has already 203 /// occurred. 204 ProgramStateRef invalidateRegions(unsigned BlockCount, 205 ProgramStateRef Orig = 0) const; 206 207 /// \brief Returns true if this is a statement that can be considered for 208 /// inlining. 209 static bool mayBeInlined(const Stmt *S); 210 211 // Iterator access to formal parameters and their types. 212private: 213 typedef std::const_mem_fun_t<QualType, ParmVarDecl> get_type_fun; 214 215public: 216 typedef const ParmVarDecl * const *param_iterator; 217 218 /// Returns an iterator over the call's formal parameters. 219 /// 220 /// If UseDefinitionParams is set, this will return the parameter decls 221 /// used in the callee's definition (suitable for inlining). Most of the 222 /// time it is better to use the decl found by name lookup, which likely 223 /// carries more annotations. 224 /// 225 /// Remember that the number of formal parameters may not match the number 226 /// of arguments for all calls. However, the first parameter will always 227 /// correspond with the argument value returned by \c getArgSVal(0). 228 /// 229 /// If the call has no accessible declaration (or definition, if 230 /// \p UseDefinitionParams is set), \c param_begin() will be equal to 231 /// \c param_end(). 232 param_iterator param_begin(bool UseDefinitionParams = false) const; 233 /// \sa param_begin() 234 param_iterator param_end(bool UseDefinitionParams = false) const; 235 236 typedef llvm::mapped_iterator<param_iterator, get_type_fun> 237 param_type_iterator; 238 239 /// Returns an iterator over the types of the call's formal parameters. 240 /// 241 /// This uses the callee decl found by default name lookup rather than the 242 /// definition because it represents a public interface, and probably has 243 /// more annotations. 244 param_type_iterator param_type_begin() const { 245 return llvm::map_iterator(param_begin(), 246 get_type_fun(&ParmVarDecl::getType)); 247 } 248 /// \sa param_type_begin() 249 param_type_iterator param_type_end() const { 250 return llvm::map_iterator(param_end(), get_type_fun(&ParmVarDecl::getType)); 251 } 252 253 // For debugging purposes only 254 void dump(raw_ostream &Out) const; 255 LLVM_ATTRIBUTE_USED void dump() const { dump(llvm::errs()); } 256 257 static bool classof(const CallEvent *) { return true; } 258}; 259 260 261/// \brief Represents a call to any sort of function that might have a 262/// FunctionDecl. 263class AnyFunctionCall : public CallEvent { 264 friend class CallEvent; 265 266protected: 267 AnyFunctionCall(const Expr *E, ProgramStateRef St, 268 const LocationContext *LCtx, Kind K) 269 : CallEvent(E, St, LCtx, K) {} 270 AnyFunctionCall(const Decl *D, ProgramStateRef St, 271 const LocationContext *LCtx, Kind K) 272 : CallEvent(D, St, LCtx, K) {} 273 274 // Most function calls have no extra invalidated regions. 275 void getExtraInvalidatedRegions(RegionList &Regions) const {} 276 277 QualType getDeclaredResultType() const; 278 279public: 280 // This function is overridden by subclasses, but they must return 281 // a FunctionDecl. 282 const FunctionDecl *getDecl() const { 283 return cast_or_null<FunctionDecl>(CallEvent::getDecl()); 284 } 285 286 const Decl *getRuntimeDefinition() const { 287 const FunctionDecl *FD = getDecl(); 288 // Note that hasBody() will fill FD with the definition FunctionDecl. 289 if (FD && FD->hasBody(FD)) 290 return FD; 291 return 0; 292 } 293 294 bool argumentsMayEscape() const; 295 296 SVal getArgSVal(unsigned Index) const; 297 SourceRange getArgSourceRange(unsigned Index) const; 298 299 param_iterator param_begin(bool UseDefinitionParams = false) const; 300 param_iterator param_end(bool UseDefinitionParams = false) const; 301 302 static bool classof(const CallEvent *CA) { 303 return CA->getKind() >= CE_BEG_FUNCTION_CALLS && 304 CA->getKind() <= CE_END_FUNCTION_CALLS; 305 } 306}; 307 308/// \brief Represents a call to a written as a CallExpr. 309class SimpleCall : public AnyFunctionCall { 310protected: 311 SimpleCall(const CallExpr *CE, ProgramStateRef St, 312 const LocationContext *LCtx, Kind K) 313 : AnyFunctionCall(CE, St, LCtx, K) { 314 } 315 316public: 317 const CallExpr *getOriginExpr() const { 318 return cast<CallExpr>(AnyFunctionCall::getOriginExpr()); 319 } 320 321 const FunctionDecl *getDecl() const; 322 323 unsigned getNumArgs() const { return getOriginExpr()->getNumArgs(); } 324 SourceRange getSourceRange() const { 325 return getOriginExpr()->getSourceRange(); 326 } 327 328 const Expr *getArgExpr(unsigned Index) const { 329 return getOriginExpr()->getArg(Index); 330 } 331 332 static bool classof(const CallEvent *CA) { 333 return CA->getKind() >= CE_BEG_SIMPLE_CALLS && 334 CA->getKind() <= CE_END_SIMPLE_CALLS; 335 } 336}; 337 338/// \brief Represents a C function or static C++ member function call. 339/// 340/// Example: \c fun() 341class FunctionCall : public SimpleCall { 342public: 343 FunctionCall(const CallExpr *CE, ProgramStateRef St, 344 const LocationContext *LCtx) 345 : SimpleCall(CE, St, LCtx, CE_Function) {} 346 347 SVal getCXXThisVal() const { return UndefinedVal(); } 348 349 static bool classof(const CallEvent *CA) { 350 return CA->getKind() == CE_Function; 351 } 352}; 353 354/// \brief Represents a non-static C++ member function call, no matter how 355/// it is written. 356class CXXInstanceCall : public SimpleCall { 357 friend class CallEvent; 358 359protected: 360 void getExtraInvalidatedRegions(RegionList &Regions) const; 361 362 CXXInstanceCall(const CallExpr *CE, ProgramStateRef St, 363 const LocationContext *LCtx, Kind K) 364 : SimpleCall(CE, St, LCtx, K) {} 365 366public: 367 const Decl *getRuntimeDefinition() const; 368 369 static bool classof(const CallEvent *CA) { 370 return CA->getKind() >= CE_BEG_CXX_INSTANCE_CALLS && 371 CA->getKind() <= CE_END_CXX_INSTANCE_CALLS; 372 } 373}; 374 375/// \brief Represents a non-static C++ member function call. 376/// 377/// Example: \c obj.fun() 378class CXXMemberCall : public CXXInstanceCall { 379public: 380 CXXMemberCall(const CXXMemberCallExpr *CE, ProgramStateRef St, 381 const LocationContext *LCtx) 382 : CXXInstanceCall(CE, St, LCtx, CE_CXXMember) {} 383 384 const CXXMemberCallExpr *getOriginExpr() const { 385 return cast<CXXMemberCallExpr>(SimpleCall::getOriginExpr()); 386 } 387 388 SVal getCXXThisVal() const; 389 390 static bool classof(const CallEvent *CA) { 391 return CA->getKind() == CE_CXXMember; 392 } 393}; 394 395/// \brief Represents a C++ overloaded operator call where the operator is 396/// implemented as a non-static member function. 397/// 398/// Example: <tt>iter + 1</tt> 399class CXXMemberOperatorCall : public CXXInstanceCall { 400public: 401 CXXMemberOperatorCall(const CXXOperatorCallExpr *CE, ProgramStateRef St, 402 const LocationContext *LCtx) 403 : CXXInstanceCall(CE, St, LCtx, CE_CXXMemberOperator) {} 404 405 const CXXOperatorCallExpr *getOriginExpr() const { 406 return cast<CXXOperatorCallExpr>(SimpleCall::getOriginExpr()); 407 } 408 409 unsigned getNumArgs() const { return getOriginExpr()->getNumArgs() - 1; } 410 const Expr *getArgExpr(unsigned Index) const { 411 return getOriginExpr()->getArg(Index + 1); 412 } 413 414 SVal getCXXThisVal() const; 415 416 static bool classof(const CallEvent *CA) { 417 return CA->getKind() == CE_CXXMemberOperator; 418 } 419}; 420 421/// \brief Represents a call to a block. 422/// 423/// Example: <tt>^{ /* ... */ }()</tt> 424class BlockCall : public SimpleCall { 425 friend class CallEvent; 426 427protected: 428 void getExtraInvalidatedRegions(RegionList &Regions) const; 429 430 QualType getDeclaredResultType() const; 431 432public: 433 BlockCall(const CallExpr *CE, ProgramStateRef St, 434 const LocationContext *LCtx) 435 : SimpleCall(CE, St, LCtx, CE_Block) {} 436 437 /// \brief Returns the region associated with this instance of the block. 438 /// 439 /// This may be NULL if the block's origin is unknown. 440 const BlockDataRegion *getBlockRegion() const; 441 442 /// \brief Gets the declaration of the block. 443 /// 444 /// This is not an override of getDecl() because AnyFunctionCall has already 445 /// assumed that it's a FunctionDecl. 446 const BlockDecl *getBlockDecl() const { 447 const BlockDataRegion *BR = getBlockRegion(); 448 if (!BR) 449 return 0; 450 return BR->getDecl(); 451 } 452 453 const Decl *getRuntimeDefinition() const { 454 return getBlockDecl(); 455 } 456 457 param_iterator param_begin(bool UseDefinitionParams = false) const; 458 param_iterator param_end(bool UseDefinitionParams = false) const; 459 460 SVal getCXXThisVal() const { return UndefinedVal(); } 461 462 static bool classof(const CallEvent *CA) { 463 return CA->getKind() == CE_Block; 464 } 465}; 466 467/// \brief Represents a call to a C++ constructor. 468/// 469/// Example: \c T(1) 470class CXXConstructorCall : public AnyFunctionCall { 471 friend class CallEvent; 472 473protected: 474 void getExtraInvalidatedRegions(RegionList &Regions) const; 475 476public: 477 /// Represents a constructor call to a new or unknown region. 478 CXXConstructorCall(const CXXConstructExpr *CE, ProgramStateRef St, 479 const LocationContext *LCtx) 480 : AnyFunctionCall(CE, St, LCtx, CE_CXXConstructor) { 481 Data = 0; 482 } 483 484 /// Represents a constructor call on an existing object region. 485 CXXConstructorCall(const CXXConstructExpr *CE, const MemRegion *target, 486 ProgramStateRef St, const LocationContext *LCtx) 487 : AnyFunctionCall(CE, St, LCtx, CE_CXXConstructor) { 488 Data = target; 489 } 490 491 const CXXConstructExpr *getOriginExpr() const { 492 return cast<CXXConstructExpr>(AnyFunctionCall::getOriginExpr()); 493 } 494 495 SourceRange getSourceRange() const { 496 return getOriginExpr()->getSourceRange(); 497 } 498 499 const CXXConstructorDecl *getDecl() const { 500 return getOriginExpr()->getConstructor(); 501 } 502 503 unsigned getNumArgs() const { return getOriginExpr()->getNumArgs(); } 504 505 const Expr *getArgExpr(unsigned Index) const { 506 return getOriginExpr()->getArg(Index); 507 } 508 509 SVal getCXXThisVal() const; 510 511 static bool classof(const CallEvent *CA) { 512 return CA->getKind() == CE_CXXConstructor; 513 } 514}; 515 516/// \brief Represents an implicit call to a C++ destructor. 517/// 518/// This can occur at the end of a scope (for automatic objects), at the end 519/// of a full-expression (for temporaries), or as part of a delete. 520class CXXDestructorCall : public AnyFunctionCall { 521 friend class CallEvent; 522 523protected: 524 void getExtraInvalidatedRegions(RegionList &Regions) const; 525 526public: 527 /// Creates an implicit destructor. 528 /// 529 /// \param DD The destructor that will be called. 530 /// \param Trigger The statement whose completion causes this destructor call. 531 /// \param Target The object region to be destructed. 532 /// \param St The path-sensitive state at this point in the program. 533 /// \param LCtx The location context at this point in the program. 534 CXXDestructorCall(const CXXDestructorDecl *DD, const Stmt *Trigger, 535 const MemRegion *Target, ProgramStateRef St, 536 const LocationContext *LCtx) 537 : AnyFunctionCall(DD, St, LCtx, CE_CXXDestructor) { 538 Data = Target; 539 Location = Trigger->getLocEnd(); 540 } 541 542 SourceRange getSourceRange() const { return Location; } 543 unsigned getNumArgs() const { return 0; } 544 545 SVal getCXXThisVal() const; 546 const Decl *getRuntimeDefinition() const; 547 548 static bool classof(const CallEvent *CA) { 549 return CA->getKind() == CE_CXXDestructor; 550 } 551}; 552 553/// \brief Represents the memory allocation call in a C++ new-expression. 554/// 555/// This is a call to "operator new". 556class CXXAllocatorCall : public AnyFunctionCall { 557public: 558 CXXAllocatorCall(const CXXNewExpr *E, ProgramStateRef St, 559 const LocationContext *LCtx) 560 : AnyFunctionCall(E, St, LCtx, CE_CXXAllocator) {} 561 562 const CXXNewExpr *getOriginExpr() const { 563 return cast<CXXNewExpr>(AnyFunctionCall::getOriginExpr()); 564 } 565 566 // FIXME: This isn't exactly the range of the allocator... 567 SourceRange getSourceRange() const { 568 return getOriginExpr()->getSourceRange(); 569 } 570 571 const FunctionDecl *getDecl() const { 572 return getOriginExpr()->getOperatorNew(); 573 } 574 575 unsigned getNumArgs() const { 576 return getOriginExpr()->getNumPlacementArgs() + 1; 577 } 578 579 const Expr *getArgExpr(unsigned Index) const { 580 // The first argument of an allocator call is the size of the allocation. 581 if (Index == 0) 582 return 0; 583 return getOriginExpr()->getPlacementArg(Index - 1); 584 } 585 586 SVal getCXXThisVal() const { return UndefinedVal(); } 587 588 static bool classof(const CallEvent *CE) { 589 return CE->getKind() == CE_CXXAllocator; 590 } 591}; 592 593/// \brief Represents the ways an Objective-C message send can occur. 594// 595// Note to maintainers: OCM_Message should always be last, since it does not 596// need to fit in the Data field's low bits. 597enum ObjCMessageKind { 598 OCM_PropertyAccess, 599 OCM_Subscript, 600 OCM_Message 601}; 602 603/// \brief Represents any expression that calls an Objective-C method. 604/// 605/// This includes all of the kinds listed in ObjCMessageKind. 606class ObjCMethodCall : public CallEvent { 607 friend class CallEvent; 608 609 const PseudoObjectExpr *getContainingPseudoObjectExpr() const; 610 611protected: 612 void getExtraInvalidatedRegions(RegionList &Regions) const; 613 614 QualType getDeclaredResultType() const; 615 ObjCMethodDecl *LookupClassMethodDefinition(Selector Sel, 616 ObjCInterfaceDecl *ClassDecl) const; 617 618public: 619 ObjCMethodCall(const ObjCMessageExpr *Msg, ProgramStateRef St, 620 const LocationContext *LCtx) 621 : CallEvent(Msg, St, LCtx, CE_ObjCMessage) { 622 Data = 0; 623 } 624 625 const ObjCMessageExpr *getOriginExpr() const { 626 return cast<ObjCMessageExpr>(CallEvent::getOriginExpr()); 627 } 628 const ObjCMethodDecl *getDecl() const { 629 return getOriginExpr()->getMethodDecl(); 630 } 631 unsigned getNumArgs() const { 632 return getOriginExpr()->getNumArgs(); 633 } 634 const Expr *getArgExpr(unsigned Index) const { 635 return getOriginExpr()->getArg(Index); 636 } 637 638 bool isInstanceMessage() const { 639 return getOriginExpr()->isInstanceMessage(); 640 } 641 ObjCMethodFamily getMethodFamily() const { 642 return getOriginExpr()->getMethodFamily(); 643 } 644 Selector getSelector() const { 645 return getOriginExpr()->getSelector(); 646 } 647 648 SourceRange getSourceRange() const; 649 650 /// \brief Returns the value of the receiver at the time of this call. 651 SVal getReceiverSVal() const; 652 653 /// \brief Get the interface for the receiver. 654 /// 655 /// This works whether this is an instance message or a class message. 656 /// However, it currently just uses the static type of the receiver. 657 const ObjCInterfaceDecl *getReceiverInterface() const { 658 return getOriginExpr()->getReceiverInterface(); 659 } 660 661 ObjCMessageKind getMessageKind() const; 662 663 bool isSetter() const { 664 switch (getMessageKind()) { 665 case OCM_Message: 666 llvm_unreachable("This is not a pseudo-object access!"); 667 case OCM_PropertyAccess: 668 return getNumArgs() > 0; 669 case OCM_Subscript: 670 return getNumArgs() > 1; 671 } 672 llvm_unreachable("Unknown message kind"); 673 } 674 675 // TODO: We might want to only compute this once (or change the API for 676 // getting the parameters). Currently, this gets called 3 times during 677 // inlining. 678 const Decl *getRuntimeDefinition() const { 679 680 const ObjCMessageExpr *E = getOriginExpr(); 681 if (E->isInstanceMessage()) { 682 return 0; 683 } else { 684 // This is a calss method. 685 // If we have type info for the receiver class, we are calling via 686 // class name. 687 if (ObjCInterfaceDecl *IDecl = E->getReceiverInterface()) { 688 return LookupClassMethodDefinition(E->getSelector(), IDecl); 689 } 690 } 691 692 return 0; 693 } 694 695 SVal getCXXThisVal() const { return UndefinedVal(); } 696 697 bool argumentsMayEscape() const { 698 return hasNonZeroCallbackArg(); 699 } 700 701 SVal getArgSVal(unsigned Index) const { return getSVal(getArgExpr(Index)); } 702 SourceRange getArgSourceRange(unsigned Index) const { 703 return getArgExpr(Index)->getSourceRange(); 704 } 705 706 param_iterator param_begin(bool UseDefinitionParams = false) const; 707 param_iterator param_end(bool UseDefinitionParams = false) const; 708 709 static bool classof(const CallEvent *CA) { 710 return CA->getKind() == CE_ObjCMessage; 711 } 712}; 713 714 715// FIXME: Use a .def or .td file for this. 716#define DISPATCH(fn) \ 717 switch (getKind()) { \ 718 case CE_Function: \ 719 return cast<FunctionCall>(this)->fn(); \ 720 case CE_CXXMember: \ 721 return cast<CXXMemberCall>(this)->fn(); \ 722 case CE_CXXMemberOperator: \ 723 return cast<CXXMemberOperatorCall>(this)->fn(); \ 724 case CE_Block: \ 725 return cast<BlockCall>(this)->fn(); \ 726 case CE_CXXConstructor: \ 727 return cast<CXXConstructorCall>(this)->fn(); \ 728 case CE_CXXDestructor: \ 729 return cast<CXXDestructorCall>(this)->fn(); \ 730 case CE_CXXAllocator: \ 731 return cast<CXXAllocatorCall>(this)->fn(); \ 732 case CE_ObjCMessage: \ 733 return cast<ObjCMethodCall>(this)->fn(); \ 734 } \ 735 llvm_unreachable("unknown CallEvent kind"); 736 737#define DISPATCH_ARG(fn, arg) \ 738 switch (getKind()) { \ 739 case CE_Function: \ 740 return cast<FunctionCall>(this)->fn(arg); \ 741 case CE_CXXMember: \ 742 return cast<CXXMemberCall>(this)->fn(arg); \ 743 case CE_CXXMemberOperator: \ 744 return cast<CXXMemberOperatorCall>(this)->fn(arg); \ 745 case CE_Block: \ 746 return cast<BlockCall>(this)->fn(arg); \ 747 case CE_CXXConstructor: \ 748 return cast<CXXConstructorCall>(this)->fn(arg); \ 749 case CE_CXXDestructor: \ 750 return cast<CXXDestructorCall>(this)->fn(arg); \ 751 case CE_CXXAllocator: \ 752 return cast<CXXAllocatorCall>(this)->fn(arg); \ 753 case CE_ObjCMessage: \ 754 return cast<ObjCMethodCall>(this)->fn(arg); \ 755 } \ 756 llvm_unreachable("unknown CallEvent kind"); 757 758inline void CallEvent::getExtraInvalidatedRegions(RegionList &Regions) const { 759 DISPATCH_ARG(getExtraInvalidatedRegions, Regions); 760} 761 762inline QualType CallEvent::getDeclaredResultType() const { 763 DISPATCH(getDeclaredResultType); 764} 765 766inline const Decl *CallEvent::getDecl() const { 767 if (const Decl *D = Origin.dyn_cast<const Decl *>()) 768 return D; 769 DISPATCH(getDecl); 770} 771 772inline const Decl *CallEvent::getRuntimeDefinition() const { 773 DISPATCH(getRuntimeDefinition); 774} 775 776inline unsigned CallEvent::getNumArgs() const { 777 DISPATCH(getNumArgs); 778} 779 780inline SourceRange CallEvent::getSourceRange() const { 781 DISPATCH(getSourceRange); 782} 783 784inline SVal CallEvent::getArgSVal(unsigned Index) const { 785 DISPATCH_ARG(getArgSVal, Index); 786} 787 788inline const Expr *CallEvent::getArgExpr(unsigned Index) const { 789 DISPATCH_ARG(getArgExpr, Index); 790} 791 792inline SourceRange CallEvent::getArgSourceRange(unsigned Index) const { 793 DISPATCH_ARG(getArgSourceRange, Index); 794} 795 796inline SVal CallEvent::getCXXThisVal() const { 797 DISPATCH(getCXXThisVal); 798} 799 800 801inline bool CallEvent::argumentsMayEscape() const { 802 DISPATCH(argumentsMayEscape); 803} 804 805inline CallEvent::param_iterator 806CallEvent::param_begin(bool UseDefinitionParams) const { 807 DISPATCH_ARG(param_begin, UseDefinitionParams); 808} 809 810inline CallEvent::param_iterator 811CallEvent::param_end(bool UseDefinitionParams) const { 812 DISPATCH_ARG(param_end, UseDefinitionParams); 813} 814 815#undef DISPATCH 816#undef DISPATCH_ARG 817 818} // end namespace ento 819} // end namespace clang 820 821#endif 822