clang 8.0.0

ObjCNoReturn.cpp
Go to the documentation of this file.
1 //= ObjCNoReturn.cpp - Handling of Cocoa APIs known not to return --*- 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 // This file implements special handling of recognizing ObjC API hooks that
11 // do not return but aren't marked as such in API headers.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/ExprObjC.h"
17 #include "clang/Analysis/DomainSpecific/ObjCNoReturn.h"
18
19 using namespace clang;
20
21 static bool isSubclass(const ObjCInterfaceDecl *Class, IdentifierInfo *II) {
22 if (!Class)
23 return false;
24 if (Class->getIdentifier() == II)
25 return true;
26 return isSubclass(Class->getSuperClass(), II);
27 }
28
29 ObjCNoReturn::ObjCNoReturn(ASTContext &C)
30 : RaiseSel(GetNullarySelector("raise", C)),
31 NSExceptionII(&C.Idents.get("NSException"))
32 {
33 // Generate selectors.
34 SmallVector<IdentifierInfo*, 3> II;
35
36 // raise:format:
37 II.push_back(&C.Idents.get("raise"));
38 II.push_back(&C.Idents.get("format"));
39 NSExceptionInstanceRaiseSelectors[0] =
40 C.Selectors.getSelector(II.size(), &II[0]);
41
42 // raise:format:arguments:
43 II.push_back(&C.Idents.get("arguments"));
44 NSExceptionInstanceRaiseSelectors[1] =
45 C.Selectors.getSelector(II.size(), &II[0]);
46 }
47
48
49 bool ObjCNoReturn::isImplicitNoReturn(const ObjCMessageExpr *ME) {
50 Selector S = ME->getSelector();
51
52 if (ME->isInstanceMessage()) {
53 // Check for the "raise" message.
54 return S == RaiseSel;
55 }
56
57 if (const ObjCInterfaceDecl *ID = ME->getReceiverInterface()) {
58 if (isSubclass(ID, NSExceptionII)) {
59 for (unsigned i = 0; i < NUM_RAISE_SELECTORS; ++i) {
60 if (S == NSExceptionInstanceRaiseSelectors[i])
61 return true;
62 }
63 }
64 }
65
66 return false;
67 }
clang::Builtin::ID
ID
Definition: Builtins.h:49
ASTContext.h
Defines the clang::ASTContext interface.
clang::Selector
Smart pointer class that efficiently represents Objective-C method names.
Definition: IdentifierTable.h:673
clang::ObjCMessageExpr::getSelector
Selector getSelector() const
Definition: ExprObjC.cpp:312
isSubclass
static bool isSubclass(const ObjCInterfaceDecl *Class, IdentifierInfo *II)
Definition: ObjCNoReturn.cpp:21
clang::ObjCMessageExpr::getReceiverInterface
ObjCInterfaceDecl * getReceiverInterface() const
Retrieve the Objective-C interface to which this message is being directed, if known.
Definition: ExprObjC.cpp:333
clang::NamedDecl::getIdentifier
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:58
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:155
clang::ASTContext::Idents
IdentifierTable & Idents
Definition: ASTContext.h:566
clang::GetNullarySelector
Selector GetNullarySelector(StringRef name, ASTContext &Ctx)
Utility function for constructing a nullary selector.
Definition: ASTContext.h:2953
ExprObjC.h
clang::ObjCInterfaceDecl
Represents an ObjC class declaration.
Definition: DeclObjC.h:1172
clang::ObjCInterfaceDecl::getSuperClass
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:338
clang::ObjCMessageExpr
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:904
clang::ASTContext::Selectors
SelectorTable & Selectors
Definition: ASTContext.h:567
clang::IdentifierTable::get
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Definition: IdentifierTable.h:519
llvm::SmallVector
Definition: LLVM.h:36
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
ObjCNoReturn.h
clang::ObjCNoReturn::isImplicitNoReturn
bool isImplicitNoReturn(const ObjCMessageExpr *ME)
Return true if the given message expression is known to never return.
Definition: ObjCNoReturn.cpp:49
clang::ObjCNoReturn::ObjCNoReturn
ObjCNoReturn(ASTContext &C)
Definition: ObjCNoReturn.cpp:29
clang::SelectorTable::getSelector
Selector getSelector(unsigned NumArgs, IdentifierInfo **IIV)
Can create any sort of selector.
Definition: IdentifierTable.cpp:635
clang::ObjCMessageExpr::isInstanceMessage
bool isInstanceMessage() const
Determine whether this is an instance message to either a computed object or to super.
Definition: ExprObjC.h:1195