[DFAJumpThreading] Remove incoming StartBlock from all phis when unfolding select...
[llvm-project.git] / clang / lib / Analysis / ObjCNoReturn.cpp
blob9d7c365c3b9924d77dbaeb26adba6ddb67e7026d
1 //= ObjCNoReturn.cpp - Handling of Cocoa APIs known not to return --*- 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 // This file implements special handling of recognizing ObjC API hooks that
10 // do not return but aren't marked as such in API headers.
12 //===----------------------------------------------------------------------===//
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/ExprObjC.h"
16 #include "clang/Analysis/DomainSpecific/ObjCNoReturn.h"
18 using namespace clang;
20 static bool isSubclass(const ObjCInterfaceDecl *Class, IdentifierInfo *II) {
21 if (!Class)
22 return false;
23 if (Class->getIdentifier() == II)
24 return true;
25 return isSubclass(Class->getSuperClass(), II);
28 ObjCNoReturn::ObjCNoReturn(ASTContext &C)
29 : RaiseSel(GetNullarySelector("raise", C)),
30 NSExceptionII(&C.Idents.get("NSException"))
32 // Generate selectors.
33 SmallVector<IdentifierInfo*, 3> II;
35 // raise:format:
36 II.push_back(&C.Idents.get("raise"));
37 II.push_back(&C.Idents.get("format"));
38 NSExceptionInstanceRaiseSelectors[0] =
39 C.Selectors.getSelector(II.size(), &II[0]);
41 // raise:format:arguments:
42 II.push_back(&C.Idents.get("arguments"));
43 NSExceptionInstanceRaiseSelectors[1] =
44 C.Selectors.getSelector(II.size(), &II[0]);
48 bool ObjCNoReturn::isImplicitNoReturn(const ObjCMessageExpr *ME) {
49 Selector S = ME->getSelector();
51 if (ME->isInstanceMessage()) {
52 // Check for the "raise" message.
53 return S == RaiseSel;
56 if (const ObjCInterfaceDecl *ID = ME->getReceiverInterface()) {
57 if (isSubclass(ID, NSExceptionII) &&
58 llvm::is_contained(NSExceptionInstanceRaiseSelectors, S))
59 return true;
62 return false;