From 4501130297ceaccbf5e2b0c3e65de198006edd96 Mon Sep 17 00:00:00 2001 From: Alastair Houghton Date: Fri, 16 Feb 2024 11:40:17 +0000 Subject: [PATCH] Revert "[Runtime][IRGen] Trap C++ exceptions on *throw*, not catch." This reverts commits 76f2389fd91c3f1292e5992c88dec7970a0ef3cd, 25e9ca02b0862206e8454eb68e7e4f3fadc87051, 25e7f90af05382565e89610f62ad3f4b5a6afa63, and 143a473aa41215811f800f6656e459781de33dee. --- include/swift/AST/FeatureAvailability.def | 1 - include/swift/Runtime/Exception.h | 42 --------------- include/swift/Runtime/RuntimeFunctions.def | 18 ------- lib/IRGen/GenCall.cpp | 13 +---- stdlib/public/runtime/CMakeLists.txt | 1 - stdlib/public/runtime/Exception.cpp | 51 ------------------- ...objc-trap-on-exception-irgen-itanium.swift | 19 +------ .../trap-on-exception-irgen-itanium.swift | 13 ++--- test/abi/macOS/arm64/stdlib.swift | 1 - test/abi/macOS/x86_64/stdlib.swift | 1 - 10 files changed, 7 insertions(+), 153 deletions(-) delete mode 100644 include/swift/Runtime/Exception.h delete mode 100644 stdlib/public/runtime/Exception.cpp diff --git a/include/swift/AST/FeatureAvailability.def b/include/swift/AST/FeatureAvailability.def index cf5c351449168..9e818395db0f4 100644 --- a/include/swift/AST/FeatureAvailability.def +++ b/include/swift/AST/FeatureAvailability.def @@ -59,7 +59,6 @@ FEATURE(SignedDescriptor, (5, 9)) FEATURE(ObjCSymbolicReferences, (5, 11)) FEATURE(TypedThrows, (5, 11)) FEATURE(StaticReadOnlyArrays, (5, 11)) -FEATURE(SwiftExceptionPersonality, (5, 11)) FEATURE(TaskExecutor, FUTURE) FEATURE(Differentiation, FUTURE) diff --git a/include/swift/Runtime/Exception.h b/include/swift/Runtime/Exception.h deleted file mode 100644 index 52688beefe6ed..0000000000000 --- a/include/swift/Runtime/Exception.h +++ /dev/null @@ -1,42 +0,0 @@ -//===--- Exception.h - Exception support ------------------------*- C++ -*-===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// -// -// Swift doesn't support exception handlers, but might call code that uses -// exceptions, and when they leak out into Swift code, we want to trap them. -// -// To that end, we have our own exception personality routine, which we use -// to trap exceptions and terminate. -// -//===----------------------------------------------------------------------===// - -#ifndef SWIFT_RUNTIME_EXCEPTION_H -#define SWIFT_RUNTIME_EXCEPTION_H - -#include "swift/Runtime/Config.h" - -#if defined(__ELF__) || defined(__APPLE__) -#include - -namespace swift { - -SWIFT_RUNTIME_STDLIB_API _Unwind_Reason_Code -swift_exceptionPersonality(int version, - _Unwind_Action actions, - uint64_t exceptionClass, - struct _Unwind_Exception *exceptionObject, - struct _Unwind_Context *context); - -} // end namespace swift - -#endif // defined(__ELF__) || defined(__APPLE__) - -#endif // SWIFT_RUNTIME_EXCEPTION_H diff --git a/include/swift/Runtime/RuntimeFunctions.def b/include/swift/Runtime/RuntimeFunctions.def index f3f62f5f7750b..bcd5552c775bc 100644 --- a/include/swift/Runtime/RuntimeFunctions.def +++ b/include/swift/Runtime/RuntimeFunctions.def @@ -2807,24 +2807,6 @@ FUNCTION(InitRawStructMetadata, EFFECT(MetaData), UNKNOWN_MEMEFFECTS) -// _Unwind_Reason_Code _swift_exceptionPersonality(int version, -// _Unwind_Action actions, -// uint64 exceptionClass, -// struct _Unwind_Exception *exceptionObject, -// struct _Unwind_Context *context); -FUNCTION(ExceptionPersonality, - _swift_exceptionPersonality, - C_CC, AlwaysAvailable, - RETURNS(Int32Ty), - ARGS(Int32Ty, - Int32Ty, - Int64Ty, - Int8PtrTy, - Int8PtrTy), - ATTRS(NoUnwind), - EFFECT(NoEffect), - UNKNOWN_MEMEFFECTS) - #undef RETURNS #undef ARGS #undef ATTRS diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp index 7f7ab2f3bb043..3737081959255 100644 --- a/lib/IRGen/GenCall.cpp +++ b/lib/IRGen/GenCall.cpp @@ -4994,18 +4994,7 @@ void IRGenFunction::emitEpilogue() { // The function should have an unwind table when catching exceptions. CurFn->addFnAttr(llvm::Attribute::getWithUWTableKind( *IGM.LLVMContext, llvm::UWTableKind::Default)); - - llvm::Constant *personality; - - if (IGM.isSwiftExceptionPersonalityFeatureAvailable()) { - // The function should use our personality routine - auto swiftPersonality = IGM.getExceptionPersonalityFunctionPointer(); - personality = swiftPersonality.getDirectPointer(); - } else { - personality = IGM.getForeignExceptionHandlingPersonalityFunc(); - } - - CurFn->setPersonalityFn(personality); + CurFn->setPersonalityFn(IGM.getForeignExceptionHandlingPersonalityFunc()); } for (auto *bb : ExceptionUnwindBlocks) CurFn->insert(CurFn->end(), bb); diff --git a/stdlib/public/runtime/CMakeLists.txt b/stdlib/public/runtime/CMakeLists.txt index 2bca14bbc2f32..282574fdbb643 100644 --- a/stdlib/public/runtime/CMakeLists.txt +++ b/stdlib/public/runtime/CMakeLists.txt @@ -47,7 +47,6 @@ set(swift_runtime_sources ErrorObjectNative.cpp Errors.cpp ErrorDefaultImpls.cpp - Exception.cpp Exclusivity.cpp ExistentialContainer.cpp Float16Support.cpp diff --git a/stdlib/public/runtime/Exception.cpp b/stdlib/public/runtime/Exception.cpp deleted file mode 100644 index dde64196a7c80..0000000000000 --- a/stdlib/public/runtime/Exception.cpp +++ /dev/null @@ -1,51 +0,0 @@ -//===--- Exception.cpp - Exception support --------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// -// -// Swift doesn't support exception handlers, but might call code that uses -// exceptions, and when they leak out into Swift code, we want to trap them. -// -// To that end, we have our own exception personality routine, which we use -// to trap exceptions and terminate. -// -//===----------------------------------------------------------------------===// - -#if defined(__ELF__) || defined(__APPLE__) - -#include - -#include - -#include - -#include "swift/Runtime/Exception.h" - -using namespace swift; - -extern "C" void __cxa_begin_catch(void *); - -SWIFT_RUNTIME_STDLIB_API _Unwind_Reason_Code -_swift_exceptionPersonality(int version, - _Unwind_Action actions, - uint64_t exceptionClass, - struct _Unwind_Exception *exceptionObject, - struct _Unwind_Context *context) -{ - // Handle exceptions by catching them and calling std::terminate(). - // This, in turn, will trigger the unhandled exception routine in the - // C++ runtime. - __cxa_begin_catch(exceptionObject); - std::terminate(); - - return _URC_FATAL_PHASE1_ERROR; -} - -#endif /* defined(__ELF__) || defined(__APPLE__) */ diff --git a/test/Interop/Cxx/exceptions/objc-trap-on-exception-irgen-itanium.swift b/test/Interop/Cxx/exceptions/objc-trap-on-exception-irgen-itanium.swift index 3a11c49755e52..aeb4021df78ae 100644 --- a/test/Interop/Cxx/exceptions/objc-trap-on-exception-irgen-itanium.swift +++ b/test/Interop/Cxx/exceptions/objc-trap-on-exception-irgen-itanium.swift @@ -1,8 +1,7 @@ // RUN: %empty-directory(%t) // RUN: split-file %s %t -// RUN: %target-swift-emit-ir -target %target-future-triple -min-runtime-version 5.11 %t/test.swift -I %t/Inputs -enable-experimental-cxx-interop | %FileCheck %s -// RUN: %target-swift-emit-ir -target %target-triple -min-runtime-version 5.9 %t/test.swift -I %t/Inputs -enable-experimental-cxx-interop | %FileCheck %s --check-prefix=GXX +// RUN: %target-swift-emit-ir %t/test.swift -I %t/Inputs -enable-experimental-cxx-interop | %FileCheck %s // REQUIRES: objc_interop // UNSUPPORTED: OS=windows-msvc @@ -33,7 +32,7 @@ func testObjCMethodCall() { testObjCMethodCall() -// CHECK: define {{.*}} @"$s4test0A14ObjCMethodCallyyF"() #[[#UWATTR:]] personality ptr @_swift_exceptionPersonality +// CHECK: define {{.*}} @"$s4test0A14ObjCMethodCallyyF"() #[[#UWATTR:]] personality // CHECK: invoke void {{.*}}@objc_msgSend // CHECK-NEXT: to label %[[CONT1:.*]] unwind label %[[UNWIND1:.*]] // CHECK-EMPTY: @@ -46,17 +45,3 @@ testObjCMethodCall() // CHECK-NEXT: call void @llvm.trap() // CHECK-NEXT: unreachable // CHECK-NEXT: } - -// GXX: define {{.*}} @"$s4test0A14ObjCMethodCallyyF"() #[[#UWATTR:]] personality ptr @__gxx_personality_v0 -// GXX: invoke void {{.*}}@objc_msgSend -// GXX-NEXT: to label %[[CONT1:.*]] unwind label %[[UNWIND1:.*]] -// GXX-EMPTY: -// GXX-NEXT: [[CONT1]]: -// GXX: ret -// GXX-EMPTY: -// GXX-NEXT: [[UNWIND1]]: -// GXX-NEXT: landingpad { ptr, i32 } -// GXX-NEXT: catch ptr null -// GXX-NEXT: call void @llvm.trap() -// GXX-NEXT: unreachable -// GXX-NEXT: } diff --git a/test/Interop/Cxx/exceptions/trap-on-exception-irgen-itanium.swift b/test/Interop/Cxx/exceptions/trap-on-exception-irgen-itanium.swift index 6ff5d7c916341..1bade29c952f6 100644 --- a/test/Interop/Cxx/exceptions/trap-on-exception-irgen-itanium.swift +++ b/test/Interop/Cxx/exceptions/trap-on-exception-irgen-itanium.swift @@ -1,10 +1,8 @@ // RUN: %empty-directory(%t) // RUN: split-file %s %t -// RUN: %target-swift-emit-ir -target %target-future-triple -min-runtime-version 5.11 %t/test.swift -I %t/Inputs -enable-experimental-cxx-interop | %FileCheck %s -// RUN: %target-swift-emit-ir -target %target-future-triple -min-runtime-version 5.11 %t/test.swift -I %t/Inputs -enable-experimental-cxx-interop -g | %FileCheck --check-prefix=DEBUG %s -// RUN: %target-swift-emit-ir -target %target-triple -min-runtime-version 5.9 %t/test.swift -I %t/Inputs -enable-experimental-cxx-interop | %FileCheck --check-prefix=GXX %s -// RUN: %target-swift-emit-ir -target %target-triple -min-runtime-version 5.9 %t/test.swift -I %t/Inputs -enable-experimental-cxx-interop -g | %FileCheck --check-prefix=GXX %s +// RUN: %target-swift-emit-ir %t/test.swift -I %t/Inputs -enable-experimental-cxx-interop | %FileCheck %s +// RUN: %target-swift-emit-ir %t/test.swift -I %t/Inputs -enable-experimental-cxx-interop -g | %FileCheck --check-prefix=DEBUG %s // UNSUPPORTED: OS=windows-msvc @@ -311,7 +309,7 @@ public func test() { // CHECK-NEXT: ret i32 // CHECK-NEXT: } -// CHECK: define {{.*}} @"$s4test0A17FreeFunctionCallss5Int32VyF"() #[[#SWIFTUWMETA:]] personality ptr @_swift_exceptionPersonality +// CHECK: define {{.*}} @"$s4test0A17FreeFunctionCallss5Int32VyF"() #[[#SWIFTUWMETA:]] personality ptr @__gxx_personality_v0 // CHECK: invoke i32 @_Z18freeFunctionThrowsi(i32 0) // CHECK-NEXT: to label %[[CONT1:.*]] unwind label %[[UNWIND1:.*]] // CHECK-EMPTY: @@ -337,7 +335,7 @@ public func test() { // CHECK-NEXT: unreachable // CHECK-NEXT: } -// CHECK: i32 @_swift_exceptionPersonality(i32, i32, i64, ptr, ptr) +// CHECK: i32 @__gxx_personality_v0(...) // CHECK: define {{.*}} @"$s4test0A11MethodCallss5Int32VyF"() #[[#SWIFTUWMETA]] personality // CHECK: call swiftcc i32 @"$s4test8makeCInts5Int32VyF"() @@ -504,6 +502,3 @@ public func test() { // DEBUG: ![[#DEBUGLOC_TRAP1]] = !DILocation(line: 0, scope: ![[#TRAPSCOPE:]], inlinedAt: ![[#DEBUGLOC_FREEFUNCTIONTHROWS1]]) // DEBUG: ![[#TRAPSCOPE]] = distinct !DISubprogram(name: "Swift runtime failure: unhandled C++{{ / Objective-C | }}exception" // DEBUG: ![[#DEBUGLOC_TRAP2]] = !DILocation(line: 0, scope: ![[#TRAPSCOPE]], inlinedAt: ![[#DEBUGLOC_FREEFUNCTIONTHROWS2]]) - -// GXX: __gxx_personality_v0 -// GXX-NOT: _swift_exceptionPersonality diff --git a/test/abi/macOS/arm64/stdlib.swift b/test/abi/macOS/arm64/stdlib.swift index 367e357389a91..80c894de3f9a1 100644 --- a/test/abi/macOS/arm64/stdlib.swift +++ b/test/abi/macOS/arm64/stdlib.swift @@ -254,6 +254,5 @@ Added: __swift_pod_destroy Added: __swift_pod_direct_initializeBufferWithCopyOfBuffer Added: __swift_pod_indirect_initializeBufferWithCopyOfBuffer Added: __swift_validatePrespecializedMetadata -Added: __swift_exceptionPersonality Added: _swift_willThrowTypedImpl Added: __swift_enableSwizzlingOfAllocationAndRefCountingFunctions_forInstrumentsOnly diff --git a/test/abi/macOS/x86_64/stdlib.swift b/test/abi/macOS/x86_64/stdlib.swift index daba0b14ef004..82c192b795239 100644 --- a/test/abi/macOS/x86_64/stdlib.swift +++ b/test/abi/macOS/x86_64/stdlib.swift @@ -254,6 +254,5 @@ Added: __swift_pod_destroy Added: __swift_pod_direct_initializeBufferWithCopyOfBuffer Added: __swift_pod_indirect_initializeBufferWithCopyOfBuffer Added: __swift_validatePrespecializedMetadata -Added: __swift_exceptionPersonality Added: _swift_willThrowTypedImpl Added: __swift_enableSwizzlingOfAllocationAndRefCountingFunctions_forInstrumentsOnly