clang  19.0.0git
ObjCNoReturn.cpp
Go to the documentation of this file.
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.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/ExprObjC.h"
17 
18 using namespace clang;
19 
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);
27 }
28 
30  : RaiseSel(GetNullarySelector("raise", C)),
31  NSExceptionII(&C.Idents.get("NSException"))
32 {
33  // Generate selectors.
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 
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  llvm::is_contained(NSExceptionInstanceRaiseSelectors, S))
60  return true;
61  }
62 
63  return false;
64 }
Defines the clang::ASTContext interface.
static char ID
Definition: Arena.cpp:183
static bool isSubclass(const ObjCInterfaceDecl *Class, const IdentifierInfo *II)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:185
One of these records is kept for each identifier that is lexed.
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:945
Selector getSelector() const
Definition: ExprObjC.cpp:293
bool isInstanceMessage() const
Determine whether this is an instance message to either a computed object or to super.
Definition: ExprObjC.h:1248
ObjCInterfaceDecl * getReceiverInterface() const
Retrieve the Objective-C interface to which this message is being directed, if known.
Definition: ExprObjC.cpp:314
bool isImplicitNoReturn(const ObjCMessageExpr *ME)
Return true if the given message expression is known to never return.
ObjCNoReturn(ASTContext &C)
Smart pointer class that efficiently represents Objective-C method names.
The JSON file list parser is used to communicate input to InstallAPI.
Selector GetNullarySelector(StringRef name, ASTContext &Ctx)
Utility function for constructing a nullary selector.
Definition: ASTContext.h:3439
@ Class
The "class" keyword introduces the elaborated-type-specifier.