clang 24.0.0git
EHPersonality.cpp
Go to the documentation of this file.
1//===--- EHPersonality.cpp - Shared EH personality descriptions -----------===//
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
10#include "clang/AST/Decl.h"
14
15namespace clang::CodeGenUtils {
16
17const EHPersonality EHPersonality::GNU_C = {"__gcc_personality_v0", nullptr};
18const EHPersonality EHPersonality::GNU_C_SJLJ = {"__gcc_personality_sj0",
19 nullptr};
20const EHPersonality EHPersonality::GNU_C_SEH = {"__gcc_personality_seh0",
21 nullptr};
22const EHPersonality EHPersonality::NeXT_ObjC = {"__objc_personality_v0",
23 nullptr};
24const EHPersonality EHPersonality::GNU_CPlusPlus = {"__gxx_personality_v0",
25 nullptr};
27 "__gxx_personality_sj0", nullptr};
29 "__gxx_personality_seh0", nullptr};
30const EHPersonality EHPersonality::GNU_ObjC = {"__gnu_objc_personality_v0",
31 "objc_exception_throw"};
33 "__gnu_objc_personality_sj0", "objc_exception_throw"};
35 "__gnu_objc_personality_seh0", "objc_exception_throw"};
37 "__gnustep_objcxx_personality_v0", nullptr};
39 "__gnustep_objc_personality_v0", nullptr};
40const EHPersonality EHPersonality::MSVC_except_handler = {"_except_handler3",
41 nullptr};
43 "__C_specific_handler", nullptr};
45 "__CxxFrameHandler3", nullptr};
47 "__gxx_wasm_personality_v0", nullptr};
48const EHPersonality EHPersonality::XL_CPlusPlus = {"__xlcxx_personality_v1",
49 nullptr};
50const EHPersonality EHPersonality::ZOS_CPlusPlus = {"__zos_cxx_personality_v2",
51 nullptr};
52
54 const CodeGenOptions &CGOpts) {
55 const llvm::Triple &T = Target.getTriple();
56 if (T.isWindowsMSVCEnvironment())
58 if (CGOpts.hasSjLjExceptions())
60 if (CGOpts.hasDWARFExceptions())
62 if (CGOpts.hasSEHExceptions())
65}
66
68 const CodeGenOptions &CGOpts,
69 const LangOptions &L) {
70 const llvm::Triple &T = Target.getTriple();
71 if (T.isWindowsMSVCEnvironment())
73 if (T.isWasm())
75
76 switch (L.ObjCRuntime.getKind()) {
78 return getCPersonality(Target, CGOpts);
84 if (T.isOSCygMing())
86 if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
88 [[fallthrough]];
91 if (CGOpts.hasSjLjExceptions())
93 if (CGOpts.hasSEHExceptions())
96 }
97 llvm_unreachable("bad runtime kind");
98}
99
101 const CodeGenOptions &CGOpts) {
102 const llvm::Triple &T = Target.getTriple();
103 if (T.isWindowsMSVCEnvironment())
105 if (T.isOSAIX())
107 if (CGOpts.hasSjLjExceptions())
109 if (CGOpts.hasDWARFExceptions())
111 if (CGOpts.hasSEHExceptions())
113 if (CGOpts.hasWasmExceptions())
115 if (T.isOSzOS())
118}
119
120/// Determines the personality function to use when both C++
121/// and Objective-C exceptions are being caught.
123 const CodeGenOptions &CGOpts,
124 const LangOptions &L) {
125 auto Triple = Target.getTriple();
126 if (Triple.isWindowsMSVCEnvironment())
128 if (Triple.isWasm())
130
131 switch (L.ObjCRuntime.getKind()) {
132 // In the fragile ABI, just use C++ exception handling and hope
133 // they're not doing crazy exception mixing.
135 return getCXXEHPersonality(Target, CGOpts);
136
137 // The ObjC personality defers to the C++ personality for non-ObjC
138 // handlers. Unlike the C++ case, we use the same personality
139 // function on targets using (backend-driven) SJLJ EH.
141 case ObjCRuntime::iOS:
143 return getObjCPersonality(Target, CGOpts, L);
144
146 if (Triple.isOSCygMing())
149
150 // The GCC runtime's personality function inherently doesn't support
151 // mixed EH. Use the ObjC personality just to avoid returning null.
152 case ObjCRuntime::GCC:
154 return getObjCPersonality(Target, CGOpts, L);
155 }
156 llvm_unreachable("bad runtime kind");
157}
158
159static const EHPersonality &getSEHPersonalityMSVC(const llvm::Triple &T) {
160 if (T.getArch() == llvm::Triple::x86)
163}
164
166 const LangOptions &LangOpts,
167 const CodeGenOptions &CGOpts,
168 const FunctionDecl *FD) {
169 // Functions using SEH get an SEH personality.
170 if (FD && FD->usesSEHTry())
171 return getSEHPersonalityMSVC(Target.getTriple());
172
173 if (LangOpts.ObjC)
174 return LangOpts.CPlusPlus ? getObjCXXPersonality(Target, CGOpts, LangOpts)
175 : getObjCPersonality(Target, CGOpts, LangOpts);
176 return LangOpts.CPlusPlus ? getCXXEHPersonality(Target, CGOpts)
177 : getCPersonality(Target, CGOpts);
178}
179
180} // namespace clang::CodeGenUtils
Defines the clang::LangOptions interface.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
bool hasDWARFExceptions() const
bool hasWasmExceptions() const
bool hasSjLjExceptions() const
bool hasSEHExceptions() const
Represents a function declaration or definition.
Definition Decl.h:2059
bool usesSEHTry() const
Indicates the function uses __try.
Definition Decl.h:2645
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
clang::ObjCRuntime ObjCRuntime
Kind getKind() const
Definition ObjCRuntime.h:77
const VersionTuple & getVersion() const
Definition ObjCRuntime.h:78
@ MacOSX
'macosx' is the Apple-provided NeXT-derived runtime on Mac OS X platforms that use the non-fragile AB...
Definition ObjCRuntime.h:35
@ FragileMacOSX
'macosx-fragile' is the Apple-provided NeXT-derived runtime on Mac OS X platforms that use the fragil...
Definition ObjCRuntime.h:40
@ GNUstep
'gnustep' is the modern non-fragile GNUstep runtime.
Definition ObjCRuntime.h:56
@ ObjFW
'objfw' is the Objective-C runtime included in ObjFW
Definition ObjCRuntime.h:59
@ iOS
'ios' is the Apple-provided NeXT-derived runtime on iOS or the iOS simulator; it is always non-fragil...
Definition ObjCRuntime.h:45
@ GCC
'gcc' is the Objective-C runtime shipped with GCC, implementing a fragile Objective-C ABI
Definition ObjCRuntime.h:53
@ WatchOS
'watchos' is a variant of iOS for Apple's watchOS.
Definition ObjCRuntime.h:49
Exposes information about the current target.
Definition TargetInfo.h:228
Defines the clang::TargetInfo interface.
const EHPersonality & getEHPersonality(const TargetInfo &Target, const LangOptions &LangOpts, const CodeGenOptions &CGOpts, const FunctionDecl *FD)
Selects the personality function to use for FD, or for the translation unit as a whole when FD is nul...
static const EHPersonality & getObjCXXPersonality(const TargetInfo &Target, const CodeGenOptions &CGOpts, const LangOptions &L)
Determines the personality function to use when both C++ and Objective-C exceptions are being caught.
static const EHPersonality & getObjCPersonality(const TargetInfo &Target, const CodeGenOptions &CGOpts, const LangOptions &L)
static const EHPersonality & getSEHPersonalityMSVC(const llvm::Triple &T)
const EHPersonality & getCXXEHPersonality(const TargetInfo &Target, const CodeGenOptions &CGOpts)
Selects the personality function that plain C++ would use.
static const EHPersonality & getCPersonality(const TargetInfo &Target, const CodeGenOptions &CGOpts)
const FunctionProtoType * T
The exceptions personality for a function.
static const EHPersonality GNU_CPlusPlus_SEH
static const EHPersonality MSVC_CxxFrameHandler3
static const EHPersonality NeXT_ObjC
static const EHPersonality GNU_ObjCXX
static const EHPersonality GNU_Wasm_CPlusPlus
static const EHPersonality MSVC_C_specific_handler
static const EHPersonality GNU_CPlusPlus_SJLJ
static const EHPersonality GNUstep_ObjC
static const EHPersonality GNU_C
static const EHPersonality GNU_CPlusPlus
static const EHPersonality GNU_ObjC_SJLJ
static const EHPersonality GNU_ObjC
static const EHPersonality ZOS_CPlusPlus
static const EHPersonality GNU_C_SJLJ
static const EHPersonality GNU_C_SEH
static const EHPersonality GNU_ObjC_SEH
static const EHPersonality XL_CPlusPlus
static const EHPersonality MSVC_except_handler