Rename GetLanguageInfo to GetLanguageSpecificData (#117012)
[llvm-project.git] / clang / lib / Analysis / ObjCNoReturn.cpp
blob9e651c29e085da395f424d4f6c12272c69a179c0
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,
21 const IdentifierInfo *II) {
22 if (!Class)
23 return false;
24 if (Class->getIdentifier() == II)
25 return true;
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<const IdentifierInfo *, 3> II;
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]);
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.
54 return S == RaiseSel;
57 if (const ObjCInterfaceDecl *ID = ME->getReceiverInterface()) {
58 if (isSubclass(ID, NSExceptionII) &&
59 llvm::is_contained(NSExceptionInstanceRaiseSelectors, S))
60 return true;
63 return false;