[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-10 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall closed 
https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-10 Thread Frederik Carlier via cfe-commits

qmfrederik wrote:

@davidchisnall Apologies, that was a fat-finger mistake while addressing the 
latest feedback.  CI is green now.

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-10 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From 9ede4ecbd65ee35cd2f2f81fb251debf2df189ee Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  7 ++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 35 +++-
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 87 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..56a246eb65e0a8 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,8 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+return Target.getTriple().isOSCygMing() ? EHPersonality::GNU_CPlusPlus_SEH
+: EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 9443fecf9b7946..cd1a0b6a130ff0 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -168,6 +168,8 @@ class CGObjCGNU : public CGObjCRuntime {
   /// Does the current target use SEH-based exceptions? False implies
   /// Itanium-style DWARF unwinding.
   bool usesSEHExceptions;
+  /// Does the current target uses C++-based exceptions?
+  bool usesCxxExceptions;
 
   /// Helper to check if we are targeting a specific runtime version or later.
   bool isRuntime(ObjCRuntime::Kind kind, unsigned major, unsigned minor=0) {
@@ -819,12 +821,18 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+  if (usesCxxExceptions) {
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
 EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
 // void __cxa_end_catch(void)
@@ -833,7 +841,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 ExceptionReThrowFn.init(, "_Unwind_Resume_or_Rethrow", VoidTy,
 PtrTy);
   } else if (R.getVersion() >= VersionTuple(1, 7)) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // id objc_begin_catch(void *e)
 EnterCatchFn.init(, "objc_begin_catch", IdTy, PtrTy);
 // void objc_end_catch(void)
@@ -841,7 +848,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 // void _Unwind_Resume_or_Rethrow(void*)
 ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, PtrTy);
   }
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
   SetPropertyAtomic.init(, "objc_setProperty_atomic", VoidTy, IdTy,
  SelectorTy, IdTy, PtrDiffTy);
   SetPropertyAtomicCopy.init(, "objc_setProperty_atomic_copy", VoidTy,
@@ -2126,6 +2132,9 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
   msgSendMDKind = VMContext.getMDKindID("GNUObjCMessageSend");
   usesSEHExceptions =

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-10 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From 4d41874bd13cda572105239c0a26f1667c556085 Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  7 ++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 35 +++-
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 87 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..56a246eb65e0a8 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,8 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+return Target.getTriple().isOSCygMing() ? EHPersonality::GNU_CPlusPlus_SEH
+: EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 9443fecf9b7946..ef78ec2dff43a7 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -168,6 +168,8 @@ class CGObjCGNU : public CGObjCRuntime {
   /// Does the current target use SEH-based exceptions? False implies
   /// Itanium-style DWARF unwinding.
   bool usesSEHExceptions;
+  /// Does the current target uses C++-based exceptions?
+  bool usesCxxExceptions;
 
   /// Helper to check if we are targeting a specific runtime version or later.
   bool isRuntime(ObjCRuntime::Kind kind, unsigned major, unsigned minor=0) {
@@ -819,12 +821,18 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+  if (usesCxxExceptions) {
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
 EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
 // void __cxa_end_catch(void)
@@ -833,7 +841,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 ExceptionReThrowFn.init(, "_Unwind_Resume_or_Rethrow", VoidTy,
 PtrTy);
   } else if (R.getVersion() >= VersionTuple(1, 7)) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // id objc_begin_catch(void *e)
 EnterCatchFn.init(, "objc_begin_catch", IdTy, PtrTy);
 // void objc_end_catch(void)
@@ -841,7 +848,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 // void _Unwind_Resume_or_Rethrow(void*)
 ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, PtrTy);
   }
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
   SetPropertyAtomic.init(, "objc_setProperty_atomic", VoidTy, IdTy,
  SelectorTy, IdTy, PtrDiffTy);
   SetPropertyAtomicCopy.init(, "objc_setProperty_atomic_copy", VoidTy,
@@ -2126,6 +2132,9 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
   msgSendMDKind = VMContext.getMDKindID("GNUObjCMessageSend");
   usesSEHExceptions =

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-10 Thread David Chisnall via cfe-commits

davidchisnall wrote:

It looks as if three tests are failing in CI:

  Clang :: CodeGenObjC/2007-04-03-ObjcEH.m
  Clang :: CodeGenObjC/exceptions-personality.m
  Clang :: Coverage/codegen-gnu.m


https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-10 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From d0d2e2f72965961712dd2df6fe34bd0f7e2befe8 Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  7 ++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 36 -
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 87 insertions(+), 19 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..56a246eb65e0a8 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,8 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+return Target.getTriple().isOSCygMing() ? EHPersonality::GNU_CPlusPlus_SEH
+: EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 9443fecf9b7946..3902bf3db9a8c0 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -168,6 +168,8 @@ class CGObjCGNU : public CGObjCRuntime {
   /// Does the current target use SEH-based exceptions? False implies
   /// Itanium-style DWARF unwinding.
   bool usesSEHExceptions;
+  /// Does the current target uses C++-based exceptions?
+  bool usesCxxExceptions;
 
   /// Helper to check if we are targeting a specific runtime version or later.
   bool isRuntime(ObjCRuntime::Kind kind, unsigned major, unsigned minor=0) {
@@ -819,12 +821,18 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+  if (usesCxxExceptions) {
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
 EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
 // void __cxa_end_catch(void)
@@ -833,7 +841,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 ExceptionReThrowFn.init(, "_Unwind_Resume_or_Rethrow", VoidTy,
 PtrTy);
   } else if (R.getVersion() >= VersionTuple(1, 7)) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // id objc_begin_catch(void *e)
 EnterCatchFn.init(, "objc_begin_catch", IdTy, PtrTy);
 // void objc_end_catch(void)
@@ -841,7 +848,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 // void _Unwind_Resume_or_Rethrow(void*)
 ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, PtrTy);
   }
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
   SetPropertyAtomic.init(, "objc_setProperty_atomic", VoidTy, IdTy,
  SelectorTy, IdTy, PtrDiffTy);
   SetPropertyAtomicCopy.init(, "objc_setProperty_atomic_copy", VoidTy,
@@ -2126,6 +2132,9 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
   msgSendMDKind = VMContext.getMDKindID("GNUObjCMessageSend");
   usesSEHExceptions 

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-10 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From 7048dcba9440bb38ddab6140d6a83839938dae8d Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH 1/2] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  7 ++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 36 -
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 88 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..56a246eb65e0a8 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,8 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+return Target.getTriple().isOSCygMing() ? EHPersonality::GNU_CPlusPlus_SEH
+: EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 9443fecf9b7946..9fc0986b05010e 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -168,6 +168,8 @@ class CGObjCGNU : public CGObjCRuntime {
   /// Does the current target use SEH-based exceptions? False implies
   /// Itanium-style DWARF unwinding.
   bool usesSEHExceptions;
+  /// Does the current target uses C++-based exceptions?
+  bool usesCxxExceptions;
 
   /// Helper to check if we are targeting a specific runtime version or later.
   bool isRuntime(ObjCRuntime::Kind kind, unsigned major, unsigned minor=0) {
@@ -819,12 +821,18 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+  if (usesCxxExceptions) {
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
 EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
 // void __cxa_end_catch(void)
@@ -833,7 +841,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 ExceptionReThrowFn.init(, "_Unwind_Resume_or_Rethrow", VoidTy,
 PtrTy);
   } else if (R.getVersion() >= VersionTuple(1, 7)) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // id objc_begin_catch(void *e)
 EnterCatchFn.init(, "objc_begin_catch", IdTy, PtrTy);
 // void objc_end_catch(void)
@@ -841,7 +848,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 // void _Unwind_Resume_or_Rethrow(void*)
 ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, PtrTy);
   }
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
   SetPropertyAtomic.init(, "objc_setProperty_atomic", VoidTy, IdTy,
  SelectorTy, IdTy, PtrDiffTy);
   SetPropertyAtomicCopy.init(, "objc_setProperty_atomic_copy", VoidTy,
@@ -2126,6 +2132,9 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
   msgSendMDKind = VMContext.getMDKindID("GNUObjCMessageSend");
   

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-10 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From 7048dcba9440bb38ddab6140d6a83839938dae8d Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH 1/2] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  7 ++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 36 -
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 88 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..56a246eb65e0a8 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,8 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+return Target.getTriple().isOSCygMing() ? EHPersonality::GNU_CPlusPlus_SEH
+: EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 9443fecf9b7946..9fc0986b05010e 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -168,6 +168,8 @@ class CGObjCGNU : public CGObjCRuntime {
   /// Does the current target use SEH-based exceptions? False implies
   /// Itanium-style DWARF unwinding.
   bool usesSEHExceptions;
+  /// Does the current target uses C++-based exceptions?
+  bool usesCxxExceptions;
 
   /// Helper to check if we are targeting a specific runtime version or later.
   bool isRuntime(ObjCRuntime::Kind kind, unsigned major, unsigned minor=0) {
@@ -819,12 +821,18 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+  if (usesCxxExceptions) {
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
 EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
 // void __cxa_end_catch(void)
@@ -833,7 +841,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 ExceptionReThrowFn.init(, "_Unwind_Resume_or_Rethrow", VoidTy,
 PtrTy);
   } else if (R.getVersion() >= VersionTuple(1, 7)) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // id objc_begin_catch(void *e)
 EnterCatchFn.init(, "objc_begin_catch", IdTy, PtrTy);
 // void objc_end_catch(void)
@@ -841,7 +848,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 // void _Unwind_Resume_or_Rethrow(void*)
 ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, PtrTy);
   }
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
   SetPropertyAtomic.init(, "objc_setProperty_atomic", VoidTy, IdTy,
  SelectorTy, IdTy, PtrDiffTy);
   SetPropertyAtomicCopy.init(, "objc_setProperty_atomic_copy", VoidTy,
@@ -2126,6 +2132,9 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
   msgSendMDKind = VMContext.getMDKindID("GNUObjCMessageSend");
   

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Saleem Abdulrasool via cfe-commits


@@ -2210,7 +2219,11 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if (usesCxxExceptions) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);

compnerd wrote:

I would say that a ternary to select between the exception model and identify 
the name would be better as you are just selecting the label.

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Saleem Abdulrasool via cfe-commits

https://github.com/compnerd approved this pull request.


https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Saleem Abdulrasool via cfe-commits

https://github.com/compnerd edited 
https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Frederik Carlier via cfe-commits

qmfrederik wrote:

CI looks green, let me know if there's anything else you need from me on this 
PR!

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Frederik Carlier via cfe-commits

qmfrederik wrote:

Looks like there was an intermittent issue with GitHub, which should be 
resolved now.  I've squashed and pushed.  Fingers crossed!

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From be6dccb1691b84a9b84cc78c7bb40fdf2ed53c8a Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  7 ++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 36 -
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 88 insertions(+), 18 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..56a246eb65e0a8 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,8 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+return Target.getTriple().isOSCygMing() ? EHPersonality::GNU_CPlusPlus_SEH
+: EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..9ad1ecf7e52b04 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -168,6 +168,8 @@ class CGObjCGNU : public CGObjCRuntime {
   /// Does the current target use SEH-based exceptions? False implies
   /// Itanium-style DWARF unwinding.
   bool usesSEHExceptions;
+  /// Does the current target uses C++-based exceptions?
+  bool usesCxxExceptions;
 
   /// Helper to check if we are targeting a specific runtime version or later.
   bool isRuntime(ObjCRuntime::Kind kind, unsigned major, unsigned minor=0) {
@@ -819,12 +821,18 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+  if (usesCxxExceptions) {
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
 EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
 // void __cxa_end_catch(void)
@@ -833,7 +841,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 ExceptionReThrowFn.init(, "_Unwind_Resume_or_Rethrow", VoidTy,
 PtrTy);
   } else if (R.getVersion() >= VersionTuple(1, 7)) {
-llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // id objc_begin_catch(void *e)
 EnterCatchFn.init(, "objc_begin_catch", IdTy, PtrTy);
 // void objc_end_catch(void)
@@ -841,7 +848,6 @@ class CGObjCGNUstep : public CGObjCGNU {
 // void _Unwind_Resume_or_Rethrow(void*)
 ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, PtrTy);
   }
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
   SetPropertyAtomic.init(, "objc_setProperty_atomic", VoidTy, IdTy,
  SelectorTy, IdTy, PtrDiffTy);
   SetPropertyAtomicCopy.init(, "objc_setProperty_atomic_copy", VoidTy,
@@ -2124,6 +2130,9 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
   msgSendMDKind = VMContext.getMDKindID("GNUObjCMessageSend");
   usesSEHExceptions 

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread David Chisnall via cfe-commits

davidchisnall wrote:

I'd like CI to be green.  Hopefully the failure is transient, but I don't seem 
to be able to kick off a rerun.  Maybe once others start passing, you can 
squash the two commits and force push to restart it?

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Frederik Carlier via cfe-commits

qmfrederik wrote:

@compnerd @davidchisnall I've addressed the feedback and CI is (mostly) green.  
The build failure on Windows seems unrelated:


```
# Removing c:/ws\src
# Creating "c:/ws\src"
> git clone -v -- https://github.com/llvm-premerge-tests/llvm-project.git .
Cloning into '.'...
remote: Internal Server Error
fatal: unable to access 
'https://github.com/llvm-premerge-tests/llvm-project.git/': The requested URL 
returned error: 500
```



https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From 6195e6c57b5b461dda2bffec0e5497ceb659f82c Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH 1/2] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  9 +++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 35 
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 92 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..cadd6f6ad75daa 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,10 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+if (Target.getTriple().isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else
+  return EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..2b3a5da87fb778 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -819,10 +819,19 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
 llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {
+ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  }
   // int objc_sync_enter(id);
   SyncEnterFn.init(, "objc_sync_enter", IntTy, IdTy);
   // int objc_sync_exit(id);
@@ -2387,7 +2401,9 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
   if (usesSEHExceptions)
 return CGM.getCXXABI().getAddrOfRTTIDescriptor(T);
 
-  if (!CGM.getLangOpts().CPlusPlus)
+  if (!CGM.getLangOpts().CPlusPlus &&
+  !(CGM.getTarget().getTriple().isOSCygMing() &&
+isRuntime(ObjCRuntime::GNUstep, 2)))
 return CGObjCGNU::GetEHType(T);
 
   // For Objective-C++, we want to provide the ability to catch both C++ and
@@ -3993,7 +4009,9 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction ,
 ExceptionAsObject = CGF.ObjCEHValueStack.back();
 isRethrow = true;
   }
-  if (isRethrow && usesSEHExceptions) {
+  if (isRethrow &&
+  (usesSEHExceptions || (CGM.getTarget().getTriple().isOSCygMing() &&
+ isRuntime(ObjCRuntime::GNUstep, 2 {
 // For SEH, ExceptionAsObject may be 

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From 6195e6c57b5b461dda2bffec0e5497ceb659f82c Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH 1/2] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  9 +++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 35 
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 92 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..cadd6f6ad75daa 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,10 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+if (Target.getTriple().isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else
+  return EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..2b3a5da87fb778 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -819,10 +819,19 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
 llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {
+ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  }
   // int objc_sync_enter(id);
   SyncEnterFn.init(, "objc_sync_enter", IntTy, IdTy);
   // int objc_sync_exit(id);
@@ -2387,7 +2401,9 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
   if (usesSEHExceptions)
 return CGM.getCXXABI().getAddrOfRTTIDescriptor(T);
 
-  if (!CGM.getLangOpts().CPlusPlus)
+  if (!CGM.getLangOpts().CPlusPlus &&
+  !(CGM.getTarget().getTriple().isOSCygMing() &&
+isRuntime(ObjCRuntime::GNUstep, 2)))
 return CGObjCGNU::GetEHType(T);
 
   // For Objective-C++, we want to provide the ability to catch both C++ and
@@ -3993,7 +4009,9 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction ,
 ExceptionAsObject = CGF.ObjCEHValueStack.back();
 isRethrow = true;
   }
-  if (isRethrow && usesSEHExceptions) {
+  if (isRethrow &&
+  (usesSEHExceptions || (CGM.getTarget().getTriple().isOSCygMing() &&
+ isRuntime(ObjCRuntime::GNUstep, 2 {
 // For SEH, ExceptionAsObject may be 

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Frederik Carlier via cfe-commits

qmfrederik wrote:

@compnerd Thanks for you feedback, I addressed your comments.

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From 6195e6c57b5b461dda2bffec0e5497ceb659f82c Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH 1/2] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  9 +++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 35 
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 92 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..cadd6f6ad75daa 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,10 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+if (Target.getTriple().isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else
+  return EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..2b3a5da87fb778 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -819,10 +819,19 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
 llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {
+ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  }
   // int objc_sync_enter(id);
   SyncEnterFn.init(, "objc_sync_enter", IntTy, IdTy);
   // int objc_sync_exit(id);
@@ -2387,7 +2401,9 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
   if (usesSEHExceptions)
 return CGM.getCXXABI().getAddrOfRTTIDescriptor(T);
 
-  if (!CGM.getLangOpts().CPlusPlus)
+  if (!CGM.getLangOpts().CPlusPlus &&
+  !(CGM.getTarget().getTriple().isOSCygMing() &&
+isRuntime(ObjCRuntime::GNUstep, 2)))
 return CGObjCGNU::GetEHType(T);
 
   // For Objective-C++, we want to provide the ability to catch both C++ and
@@ -3993,7 +4009,9 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction ,
 ExceptionAsObject = CGF.ObjCEHValueStack.back();
 isRethrow = true;
   }
-  if (isRethrow && usesSEHExceptions) {
+  if (isRethrow &&
+  (usesSEHExceptions || (CGM.getTarget().getTriple().isOSCygMing() &&
+ isRuntime(ObjCRuntime::GNUstep, 2 {
 // For SEH, ExceptionAsObject may be 

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Frederik Carlier via cfe-commits


@@ -3993,7 +4009,9 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction ,
 ExceptionAsObject = CGF.ObjCEHValueStack.back();
 isRethrow = true;
   }
-  if (isRethrow && usesSEHExceptions) {
+  if (isRethrow &&
+  (usesSEHExceptions || (CGM.getTarget().getTriple().isOSCygMing() &&
+ isRuntime(ObjCRuntime::GNUstep, 2 {

qmfrederik wrote:

Yes, that makes the intent clearer.  I changed this.

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Frederik Carlier via cfe-commits


@@ -819,10 +819,19 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);

qmfrederik wrote:

Good remark, thanks.  Fixed this.

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From 6195e6c57b5b461dda2bffec0e5497ceb659f82c Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH 1/2] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  9 +++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 35 
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 92 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..cadd6f6ad75daa 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,10 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+if (Target.getTriple().isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else
+  return EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..2b3a5da87fb778 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -819,10 +819,19 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
 llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {
+ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  }
   // int objc_sync_enter(id);
   SyncEnterFn.init(, "objc_sync_enter", IntTy, IdTy);
   // int objc_sync_exit(id);
@@ -2387,7 +2401,9 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
   if (usesSEHExceptions)
 return CGM.getCXXABI().getAddrOfRTTIDescriptor(T);
 
-  if (!CGM.getLangOpts().CPlusPlus)
+  if (!CGM.getLangOpts().CPlusPlus &&
+  !(CGM.getTarget().getTriple().isOSCygMing() &&
+isRuntime(ObjCRuntime::GNUstep, 2)))
 return CGObjCGNU::GetEHType(T);
 
   // For Objective-C++, we want to provide the ability to catch both C++ and
@@ -3993,7 +4009,9 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction ,
 ExceptionAsObject = CGF.ObjCEHValueStack.back();
 isRethrow = true;
   }
-  if (isRethrow && usesSEHExceptions) {
+  if (isRethrow &&
+  (usesSEHExceptions || (CGM.getTarget().getTriple().isOSCygMing() &&
+ isRuntime(ObjCRuntime::GNUstep, 2 {
 // For SEH, ExceptionAsObject may be 

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-08 Thread Saleem Abdulrasool via cfe-commits


@@ -210,7 +212,10 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+if (Target.getTriple().isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else
+  return EHPersonality::GNU_ObjCXX;

compnerd wrote:

This might be nicer as a ternary return.

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-08 Thread Saleem Abdulrasool via cfe-commits


@@ -3993,7 +4009,9 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction ,
 ExceptionAsObject = CGF.ObjCEHValueStack.back();
 isRethrow = true;
   }
-  if (isRethrow && usesSEHExceptions) {
+  if (isRethrow &&
+  (usesSEHExceptions || (CGM.getTarget().getTriple().isOSCygMing() &&
+ isRuntime(ObjCRuntime::GNUstep, 2 {

compnerd wrote:

Does it make sense to introduce a `usesCxxExceptions` variable?

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-08 Thread Saleem Abdulrasool via cfe-commits


@@ -819,10 +819,19 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);

compnerd wrote:

Why not hoist this?  It is used across multiple branches.

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-08 Thread David Chisnall via cfe-commits


@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {

davidchisnall wrote:

Ah, sorry, I didn't see the `re` bit.

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-08 Thread Frederik Carlier via cfe-commits


@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {

qmfrederik wrote:

On MinGW + objc2, `objc_exception_rethrow` is called; on other targets, 
`objc_exception_throw` is used (**re**throw vs throw).  I find it odd we were 
using `objc_exception_throw` to *re*throw an exception but decided to change it 
for MinGW+objc2 only.

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-08 Thread David Chisnall via cfe-commits

davidchisnall wrote:

The failing format CI isn’t in this PR, rebasing to (hopefully) fix it

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-08 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall updated 
https://github.com/llvm/llvm-project/pull/77255

>From 6195e6c57b5b461dda2bffec0e5497ceb659f82c Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  9 +++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 35 
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 92 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..cadd6f6ad75daa 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,10 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+if (Target.getTriple().isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else
+  return EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..2b3a5da87fb778 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -819,10 +819,19 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
 llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {
+ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  }
   // int objc_sync_enter(id);
   SyncEnterFn.init(, "objc_sync_enter", IntTy, IdTy);
   // int objc_sync_exit(id);
@@ -2387,7 +2401,9 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
   if (usesSEHExceptions)
 return CGM.getCXXABI().getAddrOfRTTIDescriptor(T);
 
-  if (!CGM.getLangOpts().CPlusPlus)
+  if (!CGM.getLangOpts().CPlusPlus &&
+  !(CGM.getTarget().getTriple().isOSCygMing() &&
+isRuntime(ObjCRuntime::GNUstep, 2)))
 return CGObjCGNU::GetEHType(T);
 
   // For Objective-C++, we want to provide the ability to catch both C++ and
@@ -3993,7 +4009,9 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction ,
 ExceptionAsObject = CGF.ObjCEHValueStack.back();
 isRethrow = true;
   }
-  if (isRethrow && usesSEHExceptions) {
+  if (isRethrow &&
+  (usesSEHExceptions || (CGM.getTarget().getTriple().isOSCygMing() &&
+ isRuntime(ObjCRuntime::GNUstep, 2 {
 // For SEH, ExceptionAsObject may be 

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-08 Thread David Chisnall via cfe-commits


@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {

davidchisnall wrote:

It looks as if both branches of the if and else here do the same thing?

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-07 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From d5dec27c1b0eb1999a86035ac458da377132ec7d Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  9 +++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 35 
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 92 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..cadd6f6ad75daa 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,10 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+if (Target.getTriple().isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else
+  return EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..2b3a5da87fb778 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -819,10 +819,19 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
 llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {
+ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  }
   // int objc_sync_enter(id);
   SyncEnterFn.init(, "objc_sync_enter", IntTy, IdTy);
   // int objc_sync_exit(id);
@@ -2387,7 +2401,9 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
   if (usesSEHExceptions)
 return CGM.getCXXABI().getAddrOfRTTIDescriptor(T);
 
-  if (!CGM.getLangOpts().CPlusPlus)
+  if (!CGM.getLangOpts().CPlusPlus &&
+  !(CGM.getTarget().getTriple().isOSCygMing() &&
+isRuntime(ObjCRuntime::GNUstep, 2)))
 return CGObjCGNU::GetEHType(T);
 
   // For Objective-C++, we want to provide the ability to catch both C++ and
@@ -3993,7 +4009,9 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction ,
 ExceptionAsObject = CGF.ObjCEHValueStack.back();
 isRethrow = true;
   }
-  if (isRethrow && usesSEHExceptions) {
+  if (isRethrow &&
+  (usesSEHExceptions || (CGM.getTarget().getTriple().isOSCygMing() &&
+ isRuntime(ObjCRuntime::GNUstep, 2 {
 // For SEH, ExceptionAsObject may be undef, 

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-07 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From 4212c79b5bb9168ae741b05b2c3388aa23e38693 Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  9 +++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 35 
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 92 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..cadd6f6ad75daa 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,10 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+if (Target.getTriple().isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else
+  return EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..2b3a5da87fb778 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -819,10 +819,19 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
 llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {
+ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  }
   // int objc_sync_enter(id);
   SyncEnterFn.init(, "objc_sync_enter", IntTy, IdTy);
   // int objc_sync_exit(id);
@@ -2387,7 +2401,9 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
   if (usesSEHExceptions)
 return CGM.getCXXABI().getAddrOfRTTIDescriptor(T);
 
-  if (!CGM.getLangOpts().CPlusPlus)
+  if (!CGM.getLangOpts().CPlusPlus &&
+  !(CGM.getTarget().getTriple().isOSCygMing() &&
+isRuntime(ObjCRuntime::GNUstep, 2)))
 return CGObjCGNU::GetEHType(T);
 
   // For Objective-C++, we want to provide the ability to catch both C++ and
@@ -3993,7 +4009,9 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction ,
 ExceptionAsObject = CGF.ObjCEHValueStack.back();
 isRethrow = true;
   }
-  if (isRethrow && usesSEHExceptions) {
+  if (isRethrow &&
+  (usesSEHExceptions || (CGM.getTarget().getTriple().isOSCygMing() &&
+ isRuntime(ObjCRuntime::GNUstep, 2 {
 // For SEH, ExceptionAsObject may be undef, 

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-07 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From d3e6d552b2502765eff8faccd20b7566a9362491 Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  9 +++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 35 
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 3 files changed, 86 insertions(+), 11 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..cadd6f6ad75daa 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,10 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+if (Target.getTriple().isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else
+  return EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..2b3a5da87fb778 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -819,10 +819,19 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
 llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {
+ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  }
   // int objc_sync_enter(id);
   SyncEnterFn.init(, "objc_sync_enter", IntTy, IdTy);
   // int objc_sync_exit(id);
@@ -2387,7 +2401,9 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
   if (usesSEHExceptions)
 return CGM.getCXXABI().getAddrOfRTTIDescriptor(T);
 
-  if (!CGM.getLangOpts().CPlusPlus)
+  if (!CGM.getLangOpts().CPlusPlus &&
+  !(CGM.getTarget().getTriple().isOSCygMing() &&
+isRuntime(ObjCRuntime::GNUstep, 2)))
 return CGObjCGNU::GetEHType(T);
 
   // For Objective-C++, we want to provide the ability to catch both C++ and
@@ -3993,7 +4009,9 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction ,
 ExceptionAsObject = CGF.ObjCEHValueStack.back();
 isRethrow = true;
   }
-  if (isRethrow && usesSEHExceptions) {
+  if (isRethrow &&
+  (usesSEHExceptions || (CGM.getTarget().getTriple().isOSCygMing() &&
+ isRuntime(ObjCRuntime::GNUstep, 2 {
 // For SEH, ExceptionAsObject may be undef, because the catch handler is
 // not passed it for catchalls and so it is not visible to the catch
 

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-07 Thread Frederik Carlier via cfe-commits


@@ -156,7 +154,11 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())

qmfrederik wrote:

OK - this broke some tests, so I'll revert that.

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-07 Thread Frederik Carlier via cfe-commits

qmfrederik wrote:

/cc @davidchisnall 

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-07 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik edited 
https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-07 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik edited 
https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-07 Thread Frederik Carlier via cfe-commits


@@ -156,7 +154,11 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())

qmfrederik wrote:

I moved the check for `isWindowsMSVCEnvironment` inside the `GNUstep` case, as 
on Windows we'll be using `MSVC_CxxFrameHandler3` when compiling with GNUstep + 
msvc; `GNU_CPlusPlus_SEH` when compiling with GNUstep + mingw and 
`GNU_ObjC_SEH` when compiling iwth GCC + mingw.

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-07 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From d04a41177e9c39799b73168d397dd87fb948caa1 Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp | 18 ---
 clang/lib/CodeGen/CGObjCGNU.cpp   | 35 
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 3 files changed, 90 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..939f7962dcc635 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -145,8 +145,6 @@ static const EHPersonality (const 
TargetInfo ,
 static const EHPersonality (const TargetInfo ,
const LangOptions ) {
   const llvm::Triple  = Target.getTriple();
-  if (T.isWindowsMSVCEnvironment())
-return EHPersonality::MSVC_CxxFrameHandler3;
 
   switch (L.ObjCRuntime.getKind()) {
   case ObjCRuntime::FragileMacOSX:
@@ -156,7 +154,11 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (T.isWindowsMSVCEnvironment())
+  return EHPersonality::MSVC_CxxFrameHandler3;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -192,9 +194,6 @@ static const EHPersonality (const 
TargetInfo ,
 /// and Objective-C exceptions are being caught.
 static const EHPersonality (const TargetInfo ,
  const LangOptions ) {
-  if (Target.getTriple().isWindowsMSVCEnvironment())
-return EHPersonality::MSVC_CxxFrameHandler3;
-
   switch (L.ObjCRuntime.getKind()) {
   // In the fragile ABI, just use C++ exception handling and hope
   // they're not doing crazy exception mixing.
@@ -210,7 +209,12 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+if (Target.getTriple().isWindowsMSVCEnvironment())
+  return EHPersonality::MSVC_CxxFrameHandler3;
+else if (Target.getTriple().isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else
+  return EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..2b3a5da87fb778 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -819,10 +819,19 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
 llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {
+ExceptionReThrowFn.init(, "objc_exception_throw", 

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-07 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik updated 
https://github.com/llvm/llvm-project/pull/77255

>From 62d7da8476b786f7950ea6bb8d6ac223fc6d0468 Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp | 18 ---
 clang/lib/CodeGen/CGObjCGNU.cpp   | 34 
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 3 files changed, 89 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..939f7962dcc635 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -145,8 +145,6 @@ static const EHPersonality (const 
TargetInfo ,
 static const EHPersonality (const TargetInfo ,
const LangOptions ) {
   const llvm::Triple  = Target.getTriple();
-  if (T.isWindowsMSVCEnvironment())
-return EHPersonality::MSVC_CxxFrameHandler3;
 
   switch (L.ObjCRuntime.getKind()) {
   case ObjCRuntime::FragileMacOSX:
@@ -156,7 +154,11 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (T.isWindowsMSVCEnvironment())
+  return EHPersonality::MSVC_CxxFrameHandler3;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -192,9 +194,6 @@ static const EHPersonality (const 
TargetInfo ,
 /// and Objective-C exceptions are being caught.
 static const EHPersonality (const TargetInfo ,
  const LangOptions ) {
-  if (Target.getTriple().isWindowsMSVCEnvironment())
-return EHPersonality::MSVC_CxxFrameHandler3;
-
   switch (L.ObjCRuntime.getKind()) {
   // In the fragile ABI, just use C++ exception handling and hope
   // they're not doing crazy exception mixing.
@@ -210,7 +209,12 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+if (Target.getTriple().isWindowsMSVCEnvironment())
+  return EHPersonality::MSVC_CxxFrameHandler3;
+else if (Target.getTriple().isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else
+  return EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..3165fabf00a2e7 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -819,10 +819,19 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
 llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
@@ -2210,7 +2219,11 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() && 
isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {
+ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, 

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-07 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 6e1ecd100d7663a91135b1cf6c4a603681b7385b 
4cbc22e9b7c53547b97c666b24f191b25ae8866f -- clang/lib/CodeGen/CGException.cpp 
clang/lib/CodeGen/CGObjCGNU.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 5ace469c92..2b3a5da87f 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -819,7 +819,8 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (CGM.getTarget().getTriple().isOSCygMing() && 
isRuntime(ObjCRuntime::GNUstep, 2)) {
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
 llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
 EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
@@ -828,9 +829,9 @@ class CGObjCGNUstep : public CGObjCGNU {
 // void objc_exception_rethrow(void*)
 ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
   } else if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
 llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
@@ -2218,7 +2219,8 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  if ((CGM.getTarget().getTriple().isOSCygMing() && 
isRuntime(ObjCRuntime::GNUstep, 2))) {
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
 ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
   } else {
 ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
@@ -2399,7 +2401,9 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
   if (usesSEHExceptions)
 return CGM.getCXXABI().getAddrOfRTTIDescriptor(T);
 
-  if (!CGM.getLangOpts().CPlusPlus && 
!(CGM.getTarget().getTriple().isOSCygMing() && isRuntime(ObjCRuntime::GNUstep, 
2)))
+  if (!CGM.getLangOpts().CPlusPlus &&
+  !(CGM.getTarget().getTriple().isOSCygMing() &&
+isRuntime(ObjCRuntime::GNUstep, 2)))
 return CGObjCGNU::GetEHType(T);
 
   // For Objective-C++, we want to provide the ability to catch both C++ and
@@ -4005,7 +4009,9 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction ,
 ExceptionAsObject = CGF.ObjCEHValueStack.back();
 isRethrow = true;
   }
-  if (isRethrow && (usesSEHExceptions || 
(CGM.getTarget().getTriple().isOSCygMing() && isRuntime(ObjCRuntime::GNUstep, 
2 {
+  if (isRethrow &&
+  (usesSEHExceptions || (CGM.getTarget().getTriple().isOSCygMing() &&
+ isRuntime(ObjCRuntime::GNUstep, 2 {
 // For SEH, ExceptionAsObject may be undef, because the catch handler is
 // not passed it for catchalls and so it is not visible to the catch
 // funclet.  The real thrown object will still be live on the stack at this
@@ -4015,8 +4021,7 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction ,
 // argument.
 llvm::CallBase *Throw = CGF.EmitRuntimeCallOrInvoke(ExceptionReThrowFn);
 Throw->setDoesNotReturn();
-  }
-  else {
+  } else {
 ExceptionAsObject = CGF.Builder.CreateBitCast(ExceptionAsObject, IdTy);
 llvm::CallBase *Throw =
 CGF.EmitRuntimeCallOrInvoke(ExceptionThrowFn, ExceptionAsObject);

``




https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-07 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Frederik Carlier (qmfrederik)


Changes

The GNUstep Objective C runtime (libobjc2) is adding support for MinGW.  This 
runtime uses C++ exceptions in that configuration.

---
Full diff: https://github.com/llvm/llvm-project/pull/77255.diff


3 Files Affected:

- (modified) clang/lib/CodeGen/CGException.cpp (+11-7) 
- (modified) clang/lib/CodeGen/CGObjCGNU.cpp (+16-4) 
- (added) clang/test/CodeGenObjC/exceptions-personality.m (+53) 


``diff
diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..939f7962dcc635 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -145,8 +145,6 @@ static const EHPersonality (const 
TargetInfo ,
 static const EHPersonality (const TargetInfo ,
const LangOptions ) {
   const llvm::Triple  = Target.getTriple();
-  if (T.isWindowsMSVCEnvironment())
-return EHPersonality::MSVC_CxxFrameHandler3;
 
   switch (L.ObjCRuntime.getKind()) {
   case ObjCRuntime::FragileMacOSX:
@@ -156,7 +154,11 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (T.isWindowsMSVCEnvironment())
+  return EHPersonality::MSVC_CxxFrameHandler3;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -192,9 +194,6 @@ static const EHPersonality (const 
TargetInfo ,
 /// and Objective-C exceptions are being caught.
 static const EHPersonality (const TargetInfo ,
  const LangOptions ) {
-  if (Target.getTriple().isWindowsMSVCEnvironment())
-return EHPersonality::MSVC_CxxFrameHandler3;
-
   switch (L.ObjCRuntime.getKind()) {
   // In the fragile ABI, just use C++ exception handling and hope
   // they're not doing crazy exception mixing.
@@ -210,7 +209,12 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+if (Target.getTriple().isWindowsMSVCEnvironment())
+  return EHPersonality::MSVC_CxxFrameHandler3;
+else if (Target.getTriple().isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else
+  return EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..5ace469c927045 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -819,7 +819,15 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
+  if (CGM.getTarget().getTriple().isOSCygMing() && 
isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
   llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
   // void objc_exception_rethrow(void)
   ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
@@ -2210,7 +2218,11 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() && 
isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {
+ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  }
   // int objc_sync_enter(id);
   SyncEnterFn.init(, "objc_sync_enter", IntTy, IdTy);
   // int objc_sync_exit(id);
@@ -2387,7 +2399,7 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
   if (usesSEHExceptions)
 return CGM.getCXXABI().getAddrOfRTTIDescriptor(T);
 
-  if (!CGM.getLangOpts().CPlusPlus)
+  if (!CGM.getLangOpts().CPlusPlus && 
!(CGM.getTarget().getTriple().isOSCygMing() && isRuntime(ObjCRuntime::GNUstep, 
2)))
 return CGObjCGNU::GetEHType(T);
 
   // For Objective-C++, we want to provide the ability to catch both C++ and
@@ 

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-07 Thread via cfe-commits

github-actions[bot] wrote:

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-07 Thread Frederik Carlier via cfe-commits

https://github.com/qmfrederik created 
https://github.com/llvm/llvm-project/pull/77255

The GNUstep Objective C runtime (libobjc2) is adding support for MinGW.  This 
runtime uses C++ exceptions in that configuration.

>From 4cbc22e9b7c53547b97c666b24f191b25ae8866f Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp | 18 ---
 clang/lib/CodeGen/CGObjCGNU.cpp   | 20 +--
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 3 files changed, 80 insertions(+), 11 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..939f7962dcc635 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -145,8 +145,6 @@ static const EHPersonality (const 
TargetInfo ,
 static const EHPersonality (const TargetInfo ,
const LangOptions ) {
   const llvm::Triple  = Target.getTriple();
-  if (T.isWindowsMSVCEnvironment())
-return EHPersonality::MSVC_CxxFrameHandler3;
 
   switch (L.ObjCRuntime.getKind()) {
   case ObjCRuntime::FragileMacOSX:
@@ -156,7 +154,11 @@ static const EHPersonality (const 
TargetInfo ,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (T.isWindowsMSVCEnvironment())
+  return EHPersonality::MSVC_CxxFrameHandler3;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -192,9 +194,6 @@ static const EHPersonality (const 
TargetInfo ,
 /// and Objective-C exceptions are being caught.
 static const EHPersonality (const TargetInfo ,
  const LangOptions ) {
-  if (Target.getTriple().isWindowsMSVCEnvironment())
-return EHPersonality::MSVC_CxxFrameHandler3;
-
   switch (L.ObjCRuntime.getKind()) {
   // In the fragile ABI, just use C++ exception handling and hope
   // they're not doing crazy exception mixing.
@@ -210,7 +209,12 @@ static const EHPersonality (const 
TargetInfo ,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+if (Target.getTriple().isWindowsMSVCEnvironment())
+  return EHPersonality::MSVC_CxxFrameHandler3;
+else if (Target.getTriple().isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else
+  return EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..5ace469c927045 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -819,7 +819,15 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
+  if (CGM.getTarget().getTriple().isOSCygMing() && 
isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
   llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
   // void objc_exception_rethrow(void)
   ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy);
@@ -2210,7 +2218,11 @@ CGObjCGNU::CGObjCGNU(CodeGenModule , unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() && 
isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {
+ExceptionReThrowFn.init(, "objc_exception_throw", VoidTy, IdTy);
+  }
   // int objc_sync_enter(id);
   SyncEnterFn.init(, "objc_sync_enter", IntTy, IdTy);
   // int objc_sync_exit(id);
@@ -2387,7 +2399,7 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
   if