Skip to content

Commit 0b43f11

Browse files
author
git apple-llvm automerger
committed
Merge commit '76058c090714' from llvm.org/main into next
2 parents 4db63c8 + 76058c0 commit 0b43f11

File tree

9 files changed

+63
-99
lines changed

9 files changed

+63
-99
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ CODEGENOPT(XCOFFReadOnlyPointers, 1, 0, Benign) ///< Set for -mxcoff-roptr.
5656
CODEGENOPT(AllTocData, 1, 0, Benign) ///< AIX -mtocdata
5757
ENUM_CODEGENOPT(FramePointer, FramePointerKind, 2, FramePointerKind::None, Benign) /// frame-pointer: all,non-leaf,reserved,none
5858

59+
ENUM_CODEGENOPT(ExceptionHandling, ExceptionHandlingKind, 3, ExceptionHandlingKind::None, NotCompatible)
60+
5961
CODEGENOPT(ClearASTBeforeBackend , 1, 0, Benign) ///< Free the AST before running backend code generation. Only works with -disable-free.
6062
CODEGENOPT(DisableFree , 1, 0, Benign) ///< Don't free memory.
6163
CODEGENOPT(DiscardValueNames , 1, 0, Benign) ///< Discard Value Names from the IR (LLVMContext flag)

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
177177
llvm_unreachable("invalid FramePointerKind");
178178
}
179179

180+
/// Possible exception handling behavior.
181+
enum class ExceptionHandlingKind { None, SjLj, WinEH, DwarfCFI, Wasm };
182+
180183
enum class SwiftAsyncFramePointerKind {
181184
Auto, // Choose Swift async extended frame info based on deployment target.
182185
Always, // Unconditionally emit Swift async extended frame info.
@@ -555,6 +558,22 @@ class CodeGenOptions : public CodeGenOptionsBase {
555558
return NoBuiltinFuncs;
556559
}
557560

561+
bool hasSjLjExceptions() const {
562+
return getExceptionHandling() == ExceptionHandlingKind::SjLj;
563+
}
564+
565+
bool hasSEHExceptions() const {
566+
return getExceptionHandling() == ExceptionHandlingKind::WinEH;
567+
}
568+
569+
bool hasDWARFExceptions() const {
570+
return getExceptionHandling() == ExceptionHandlingKind::DwarfCFI;
571+
}
572+
573+
bool hasWasmExceptions() const {
574+
return getExceptionHandling() == ExceptionHandlingKind::Wasm;
575+
}
576+
558577
/// Check if Clang profile instrumenation is on.
559578
bool hasProfileClangInstr() const {
560579
return getProfileInstr() ==

clang/include/clang/Basic/LangOptions.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ LANGOPT(Exceptions , 1, 0, NotCompatible, "exception handling")
9898
LANGOPT(ObjCExceptions , 1, 0, NotCompatible, "Objective-C exceptions")
9999
LANGOPT(CXXExceptions , 1, 0, NotCompatible, "C++ exceptions")
100100
LANGOPT(EHAsynch , 1, 0, NotCompatible, "C/C++ EH Asynch exceptions")
101-
ENUM_LANGOPT(ExceptionHandling, ExceptionHandlingKind, 3,
102-
ExceptionHandlingKind::None, NotCompatible, "exception handling")
103101
LANGOPT(IgnoreExceptions , 1, 0, NotCompatible, "ignore exceptions")
104102
LANGOPT(ExternCNoUnwind , 1, 0, NotCompatible, "Assume extern C functions don't unwind")
105103
LANGOPT(AssumeNothrowExceptionDtor , 1, 0, NotCompatible, "Assume exception object's destructor is nothrow")

clang/include/clang/Basic/LangOptions.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,6 @@ class LangOptionsBase {
339339

340340
enum ExcessPrecisionKind { FPP_Standard, FPP_Fast, FPP_None };
341341

342-
/// Possible exception handling behavior.
343-
enum class ExceptionHandlingKind { None, SjLj, WinEH, DwarfCFI, Wasm };
344-
345342
enum class LaxVectorConversionKind {
346343
/// Permit no implicit vector bitcasts.
347344
None,
@@ -823,22 +820,6 @@ class LangOptions : public LangOptionsBase {
823820
return getSignReturnAddressScope() == SignReturnAddressScopeKind::All;
824821
}
825822

826-
bool hasSjLjExceptions() const {
827-
return getExceptionHandling() == ExceptionHandlingKind::SjLj;
828-
}
829-
830-
bool hasSEHExceptions() const {
831-
return getExceptionHandling() == ExceptionHandlingKind::WinEH;
832-
}
833-
834-
bool hasDWARFExceptions() const {
835-
return getExceptionHandling() == ExceptionHandlingKind::DwarfCFI;
836-
}
837-
838-
bool hasWasmExceptions() const {
839-
return getExceptionHandling() == ExceptionHandlingKind::Wasm;
840-
}
841-
842823
bool isSYCL() const { return SYCLIsDevice || SYCLIsHost; }
843824

844825
bool hasDefaultVisibilityExportMapping() const {

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,10 +2278,10 @@ def fwasm_exceptions : Flag<["-"], "fwasm-exceptions">, Group<f_Group>,
22782278
HelpText<"Use WebAssembly style exceptions">;
22792279
def exception_model : Separate<["-"], "exception-model">,
22802280
Visibility<[CC1Option]>, HelpText<"The exception model">,
2281-
Values<"dwarf,sjlj,seh,wasm">,
2282-
NormalizedValuesScope<"LangOptions::ExceptionHandlingKind">,
2283-
NormalizedValues<["DwarfCFI", "SjLj", "WinEH", "Wasm"]>,
2284-
MarshallingInfoEnum<LangOpts<"ExceptionHandling">, "None">;
2281+
Values<"dwarf,sjlj,seh,wasm,none">,
2282+
NormalizedValuesScope<"CodeGenOptions::ExceptionHandlingKind">,
2283+
NormalizedValues<["DwarfCFI", "SjLj", "WinEH", "Wasm", "None"]>,
2284+
MarshallingInfoEnum<CodeGenOpts<"ExceptionHandling">, "None">;
22852285
def exception_model_EQ : Joined<["-"], "exception-model=">,
22862286
Visibility<[CC1Option]>, Alias<exception_model>;
22872287
def fignore_exceptions : Flag<["-"], "fignore-exceptions">, Group<f_Group>,

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,13 @@ static bool initTargetOptions(const CompilerInstance &CI,
417417
// Set EABI version.
418418
Options.EABIVersion = TargetOpts.EABIVersion;
419419

420-
if (LangOpts.hasSjLjExceptions())
420+
if (CodeGenOpts.hasSjLjExceptions())
421421
Options.ExceptionModel = llvm::ExceptionHandling::SjLj;
422-
if (LangOpts.hasSEHExceptions())
422+
if (CodeGenOpts.hasSEHExceptions())
423423
Options.ExceptionModel = llvm::ExceptionHandling::WinEH;
424-
if (LangOpts.hasDWARFExceptions())
424+
if (CodeGenOpts.hasDWARFExceptions())
425425
Options.ExceptionModel = llvm::ExceptionHandling::DwarfCFI;
426-
if (LangOpts.hasWasmExceptions())
426+
if (CodeGenOpts.hasWasmExceptions())
427427
Options.ExceptionModel = llvm::ExceptionHandling::Wasm;
428428

429429
Options.NoInfsFPMath = LangOpts.NoHonorInfs;

clang/lib/CodeGen/CGException.cpp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -131,28 +131,29 @@ const EHPersonality EHPersonality::ZOS_CPlusPlus = {"__zos_cxx_personality_v2",
131131
nullptr};
132132

133133
static const EHPersonality &getCPersonality(const TargetInfo &Target,
134-
const LangOptions &L) {
134+
const CodeGenOptions &CGOpts) {
135135
const llvm::Triple &T = Target.getTriple();
136136
if (T.isWindowsMSVCEnvironment())
137137
return EHPersonality::MSVC_CxxFrameHandler3;
138-
if (L.hasSjLjExceptions())
138+
if (CGOpts.hasSjLjExceptions())
139139
return EHPersonality::GNU_C_SJLJ;
140-
if (L.hasDWARFExceptions())
140+
if (CGOpts.hasDWARFExceptions())
141141
return EHPersonality::GNU_C;
142-
if (L.hasSEHExceptions())
142+
if (CGOpts.hasSEHExceptions())
143143
return EHPersonality::GNU_C_SEH;
144144
return EHPersonality::GNU_C;
145145
}
146146

147147
static const EHPersonality &getObjCPersonality(const TargetInfo &Target,
148+
const CodeGenOptions &CGOpts,
148149
const LangOptions &L) {
149150
const llvm::Triple &T = Target.getTriple();
150151
if (T.isWindowsMSVCEnvironment())
151152
return EHPersonality::MSVC_CxxFrameHandler3;
152153

153154
switch (L.ObjCRuntime.getKind()) {
154155
case ObjCRuntime::FragileMacOSX:
155-
return getCPersonality(Target, L);
156+
return getCPersonality(Target, CGOpts);
156157
case ObjCRuntime::MacOSX:
157158
case ObjCRuntime::iOS:
158159
case ObjCRuntime::WatchOS:
@@ -165,29 +166,29 @@ static const EHPersonality &getObjCPersonality(const TargetInfo &Target,
165166
[[fallthrough]];
166167
case ObjCRuntime::GCC:
167168
case ObjCRuntime::ObjFW:
168-
if (L.hasSjLjExceptions())
169+
if (CGOpts.hasSjLjExceptions())
169170
return EHPersonality::GNU_ObjC_SJLJ;
170-
if (L.hasSEHExceptions())
171+
if (CGOpts.hasSEHExceptions())
171172
return EHPersonality::GNU_ObjC_SEH;
172173
return EHPersonality::GNU_ObjC;
173174
}
174175
llvm_unreachable("bad runtime kind");
175176
}
176177

177178
static const EHPersonality &getCXXPersonality(const TargetInfo &Target,
178-
const LangOptions &L) {
179+
const CodeGenOptions &CGOpts) {
179180
const llvm::Triple &T = Target.getTriple();
180181
if (T.isWindowsMSVCEnvironment())
181182
return EHPersonality::MSVC_CxxFrameHandler3;
182183
if (T.isOSAIX())
183184
return EHPersonality::XL_CPlusPlus;
184-
if (L.hasSjLjExceptions())
185+
if (CGOpts.hasSjLjExceptions())
185186
return EHPersonality::GNU_CPlusPlus_SJLJ;
186-
if (L.hasDWARFExceptions())
187+
if (CGOpts.hasDWARFExceptions())
187188
return EHPersonality::GNU_CPlusPlus;
188-
if (L.hasSEHExceptions())
189+
if (CGOpts.hasSEHExceptions())
189190
return EHPersonality::GNU_CPlusPlus_SEH;
190-
if (L.hasWasmExceptions())
191+
if (CGOpts.hasWasmExceptions())
191192
return EHPersonality::GNU_Wasm_CPlusPlus;
192193
if (T.isOSzOS())
193194
return EHPersonality::ZOS_CPlusPlus;
@@ -197,6 +198,7 @@ static const EHPersonality &getCXXPersonality(const TargetInfo &Target,
197198
/// Determines the personality function to use when both C++
198199
/// and Objective-C exceptions are being caught.
199200
static const EHPersonality &getObjCXXPersonality(const TargetInfo &Target,
201+
const CodeGenOptions &CGOpts,
200202
const LangOptions &L) {
201203
if (Target.getTriple().isWindowsMSVCEnvironment())
202204
return EHPersonality::MSVC_CxxFrameHandler3;
@@ -205,15 +207,15 @@ static const EHPersonality &getObjCXXPersonality(const TargetInfo &Target,
205207
// In the fragile ABI, just use C++ exception handling and hope
206208
// they're not doing crazy exception mixing.
207209
case ObjCRuntime::FragileMacOSX:
208-
return getCXXPersonality(Target, L);
210+
return getCXXPersonality(Target, CGOpts);
209211

210212
// The ObjC personality defers to the C++ personality for non-ObjC
211213
// handlers. Unlike the C++ case, we use the same personality
212214
// function on targets using (backend-driven) SJLJ EH.
213215
case ObjCRuntime::MacOSX:
214216
case ObjCRuntime::iOS:
215217
case ObjCRuntime::WatchOS:
216-
return getObjCPersonality(Target, L);
218+
return getObjCPersonality(Target, CGOpts, L);
217219

218220
case ObjCRuntime::GNUstep:
219221
return Target.getTriple().isOSCygMing() ? EHPersonality::GNU_CPlusPlus_SEH
@@ -223,7 +225,7 @@ static const EHPersonality &getObjCXXPersonality(const TargetInfo &Target,
223225
// mixed EH. Use the ObjC personality just to avoid returning null.
224226
case ObjCRuntime::GCC:
225227
case ObjCRuntime::ObjFW:
226-
return getObjCPersonality(Target, L);
228+
return getObjCPersonality(Target, CGOpts, L);
227229
}
228230
llvm_unreachable("bad runtime kind");
229231
}
@@ -237,6 +239,7 @@ static const EHPersonality &getSEHPersonalityMSVC(const llvm::Triple &T) {
237239
const EHPersonality &EHPersonality::get(CodeGenModule &CGM,
238240
const FunctionDecl *FD) {
239241
const llvm::Triple &T = CGM.getTarget().getTriple();
242+
const CodeGenOptions &CGOpts = CGM.getCodeGenOpts();
240243
const LangOptions &L = CGM.getLangOpts();
241244
const TargetInfo &Target = CGM.getTarget();
242245

@@ -245,10 +248,10 @@ const EHPersonality &EHPersonality::get(CodeGenModule &CGM,
245248
return getSEHPersonalityMSVC(T);
246249

247250
if (L.ObjC)
248-
return L.CPlusPlus ? getObjCXXPersonality(Target, L)
249-
: getObjCPersonality(Target, L);
250-
return L.CPlusPlus ? getCXXPersonality(Target, L)
251-
: getCPersonality(Target, L);
251+
return L.CPlusPlus ? getObjCXXPersonality(Target, CGOpts, L)
252+
: getObjCPersonality(Target, CGOpts, L);
253+
return L.CPlusPlus ? getCXXPersonality(Target, CGOpts)
254+
: getCPersonality(Target, CGOpts);
252255
}
253256

254257
const EHPersonality &EHPersonality::get(CodeGenFunction &CGF) {
@@ -344,7 +347,7 @@ void CodeGenModule::SimplifyPersonality() {
344347
return;
345348

346349
const EHPersonality &ObjCXX = EHPersonality::get(*this, /*FD=*/nullptr);
347-
const EHPersonality &CXX = getCXXPersonality(getTarget(), LangOpts);
350+
const EHPersonality &CXX = getCXXPersonality(getTarget(), CodeGenOpts);
348351
if (&ObjCXX == &CXX)
349352
return;
350353

@@ -500,7 +503,7 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
500503
// In Wasm EH we currently treat 'throw()' in the same way as 'noexcept'. In
501504
// case of throw with types, we ignore it and print a warning for now.
502505
// TODO Correctly handle exception specification in Wasm EH
503-
if (CGM.getLangOpts().hasWasmExceptions()) {
506+
if (CGM.getCodeGenOpts().hasWasmExceptions()) {
504507
if (EST == EST_DynamicNone)
505508
EHStack.pushTerminate();
506509
else
@@ -515,8 +518,8 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
515518
// throw with types.
516519
// TODO Correctly handle exception specification in Emscripten EH
517520
if (getTarget().getCXXABI() == TargetCXXABI::WebAssembly &&
518-
CGM.getLangOpts().getExceptionHandling() ==
519-
LangOptions::ExceptionHandlingKind::None &&
521+
CGM.getCodeGenOpts().getExceptionHandling() ==
522+
CodeGenOptions::ExceptionHandlingKind::None &&
520523
EST == EST_Dynamic)
521524
CGM.getDiags().Report(D->getLocation(),
522525
diag::warn_wasm_dynamic_exception_spec_ignored)
@@ -604,7 +607,7 @@ void CodeGenFunction::EmitEndEHSpec(const Decl *D) {
604607
// In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
605608
// case of throw with types, we ignore it and print a warning for now.
606609
// TODO Correctly handle exception specification in wasm
607-
if (CGM.getLangOpts().hasWasmExceptions()) {
610+
if (CGM.getCodeGenOpts().hasWasmExceptions()) {
608611
if (EST == EST_DynamicNone)
609612
EHStack.popTerminate();
610613
return;

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -633,11 +633,11 @@ static bool FixupInvocation(CompilerInvocation &Invocation,
633633
CodeGenOpts.CodeModel = TargetOpts.CodeModel;
634634
CodeGenOpts.LargeDataThreshold = TargetOpts.LargeDataThreshold;
635635

636-
if (LangOpts.getExceptionHandling() !=
637-
LangOptions::ExceptionHandlingKind::None &&
636+
if (CodeGenOpts.getExceptionHandling() !=
637+
CodeGenOptions::ExceptionHandlingKind::None &&
638638
T.isWindowsMSVCEnvironment())
639639
Diags.Report(diag::err_fe_invalid_exception_model)
640-
<< static_cast<unsigned>(LangOpts.getExceptionHandling()) << T.str();
640+
<< static_cast<unsigned>(CodeGenOpts.getExceptionHandling()) << T.str();
641641

642642
if (LangOpts.AppleKext && !LangOpts.CPlusPlus)
643643
Diags.Report(diag::warn_c_kext);
@@ -4014,23 +4014,6 @@ static StringRef GetInputKindName(InputKind IK) {
40144014
llvm_unreachable("unknown input language");
40154015
}
40164016

4017-
static StringRef getExceptionHandlingName(unsigned EHK) {
4018-
switch (static_cast<LangOptions::ExceptionHandlingKind>(EHK)) {
4019-
case LangOptions::ExceptionHandlingKind::None:
4020-
return "none";
4021-
case LangOptions::ExceptionHandlingKind::DwarfCFI:
4022-
return "dwarf";
4023-
case LangOptions::ExceptionHandlingKind::SjLj:
4024-
return "sjlj";
4025-
case LangOptions::ExceptionHandlingKind::WinEH:
4026-
return "seh";
4027-
case LangOptions::ExceptionHandlingKind::Wasm:
4028-
return "wasm";
4029-
}
4030-
4031-
llvm_unreachable("covered switch");
4032-
}
4033-
40344017
void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts,
40354018
ArgumentConsumer Consumer,
40364019
const llvm::Triple &T,
@@ -4046,10 +4029,6 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts,
40464029
GenerateArg(Consumer, OPT_pic_is_pie);
40474030
for (StringRef Sanitizer : serializeSanitizerKinds(Opts.Sanitize))
40484031
GenerateArg(Consumer, OPT_fsanitize_EQ, Sanitizer);
4049-
if (Opts.ExceptionHandling) {
4050-
GenerateArg(Consumer, OPT_exception_model,
4051-
getExceptionHandlingName(Opts.ExceptionHandling));
4052-
}
40534032

40544033
return;
40554034
}
@@ -4422,24 +4401,6 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
44224401
parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
44234402
Diags, Opts.Sanitize);
44244403

4425-
if (const Arg *A = Args.getLastArg(options::OPT_exception_model)) {
4426-
std::optional<LangOptions::ExceptionHandlingKind> EMValue =
4427-
llvm::StringSwitch<std::optional<LangOptions::ExceptionHandlingKind>>(
4428-
A->getValue())
4429-
.Case("dwarf", LangOptions::ExceptionHandlingKind::DwarfCFI)
4430-
.Case("sjlj", LangOptions::ExceptionHandlingKind::SjLj)
4431-
.Case("seh", LangOptions::ExceptionHandlingKind::WinEH)
4432-
.Case("wasm", LangOptions::ExceptionHandlingKind::Wasm)
4433-
.Case("none", LangOptions::ExceptionHandlingKind::None)
4434-
.Default(std::nullopt);
4435-
if (EMValue) {
4436-
Opts.ExceptionHandling = static_cast<unsigned>(*EMValue);
4437-
} else {
4438-
Diags.Report(diag::err_drv_invalid_value)
4439-
<< A->getAsString(Args) << A->getValue();
4440-
}
4441-
}
4442-
44434404
return Diags.getNumErrors() == NumErrorsBefore;
44444405
}
44454406

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,14 +1032,14 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
10321032
if (LangOpts.GNUCVersion && LangOpts.RTTI)
10331033
Builder.defineMacro("__GXX_RTTI");
10341034

1035-
if (LangOpts.hasSjLjExceptions())
1035+
if (CGOpts.hasSjLjExceptions())
10361036
Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");
1037-
else if (LangOpts.hasSEHExceptions())
1037+
else if (CGOpts.hasSEHExceptions())
10381038
Builder.defineMacro("__SEH__");
1039-
else if (LangOpts.hasDWARFExceptions() &&
1039+
else if (CGOpts.hasDWARFExceptions() &&
10401040
(TI.getTriple().isThumb() || TI.getTriple().isARM()))
10411041
Builder.defineMacro("__ARM_DWARF_EH__");
1042-
else if (LangOpts.hasWasmExceptions() && TI.getTriple().isWasm())
1042+
else if (CGOpts.hasWasmExceptions() && TI.getTriple().isWasm())
10431043
Builder.defineMacro("__WASM_EXCEPTIONS__");
10441044

10451045
if (LangOpts.Deprecated)

0 commit comments

Comments
 (0)