1 //= ObjCNoReturn.cpp - Handling of Cocoa APIs known not to return --*- C++ -*---
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
13 //===----------------------------------------------------------------------===//
15 #include "clang/AST/ASTContext.h"
16 #include "clang/AST/ExprObjC.h"
17 #include "clang/Analysis/DomainSpecific/ObjCNoReturn.h"
19 using namespace clang;
21 static bool isSubclass(const ObjCInterfaceDecl *Class, IdentifierInfo *II) {
24 if (Class->getIdentifier() == II)
26 return isSubclass(Class->getSuperClass(), II);
29 ObjCNoReturn::ObjCNoReturn(ASTContext &C)
30 : RaiseSel(GetNullarySelector("raise", C)),
31 NSExceptionII(&C.Idents.get("NSException"))
33 // Generate selectors.
34 SmallVector<IdentifierInfo*, 3> II;
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]);
42 // raise:format:arguments:
43 II.push_back(&C.Idents.get("arguments"));
44 NSExceptionInstanceRaiseSelectors[1] =
45 C.Selectors.getSelector(II.size(), &II[0]);
49 bool ObjCNoReturn::isImplicitNoReturn(const ObjCMessageExpr *ME) {
50 Selector S = ME->getSelector();
52 if (ME->isInstanceMessage()) {
53 // Check for the "raise" message.
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])