[clang] [ObjC] Fix jmp_buf sizing for ObjC exceptions (PR #85481)

2024-03-29 Thread via cfe-commits

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


[clang] [ObjC] Fix jmp_buf sizing for ObjC exceptions (PR #85481)

2024-03-28 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

As far as I can tell, the code in question only actually runs for 32-bit x86 
targets (it's tied to the old ABI, which was replaced on newer targets).  So 
there's no point to modifying it.

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


[clang] [ObjC] Fix jmp_buf sizing for ObjC exceptions (PR #85481)

2024-03-17 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/85481

>From 26f0da257911cfe8998f6daf84a61557acc9d0bd Mon Sep 17 00:00:00 2001
From: Rose 
Date: Fri, 15 Mar 2024 18:45:48 -0400
Subject: [PATCH] [ObjC] Fix jmp_buf sizing for ObjC exceptions

The size of 18 only works for x86, but does not work for the other 
architectures. This works for Darwin and was retrieved via reading the setjmp.h 
header. It would be nice if we could do the equivalent of sizeof() that would 
obtain the size as though it were being run on the target, not the host, but 
this is the best I could do for now.
---
 clang/lib/CodeGen/CGObjCMac.cpp | 33 +++--
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index e815e097e1fb48..0f43c19ca8fb07 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -587,9 +587,9 @@ class ObjCTypesHelper : public ObjCCommonTypesHelper {
   /// SetJmpFn - LLVM _setjmp function.
   llvm::FunctionCallee getSetJmpFn() {
 // This is specifically the prototype for x86.
-llvm::Type *params[] = { CGM.Int32Ty->getPointerTo() };
+llvm::Type *params[] = {IntTy->getPointerTo()};
 return CGM.CreateRuntimeFunction(
-llvm::FunctionType::get(CGM.Int32Ty, params, false), "_setjmp",
+llvm::FunctionType::get(IntTy, params, false), "_setjmp",
 llvm::AttributeList::get(CGM.getLLVMContext(),
  llvm::AttributeList::FunctionIndex,
  llvm::Attribute::NonLazyBind));
@@ -5946,16 +5946,37 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule 
)
   ModuleTy = llvm::StructType::create("struct._objc_module", LongTy, LongTy,
   Int8PtrTy, SymtabPtrTy);
 
-  // FIXME: This is the size of the setjmp buffer and should be target
-  // specific. 18 is what's used on 32-bit X86.
-  uint64_t SetJmpBufferSize = 18;
+  // FIXME: Not a perfect solution, but one that better fits the other
+  // architectures Values are derived from setjmp.h on Darwin
+  uint64_t SetJmpBufferSize = 0;
+  switch (CGM.getTarget().getTriple().getArch()) {
+  case llvm::Triple::arm:
+if (CGM.getTarget().getTriple().getSubArch() !=
+llvm::Triple::ARMSubArch_v7k) {
+  SetJmpBufferSize = (10 + 16 + 2);
+  break;
+}
+[[fallthrough]];
+  case llvm::Triple::aarch64:
+SetJmpBufferSize = ((14 + 8 + 2) * 2);
+break;
+  case llvm::Triple::x86_64:
+SetJmpBufferSize = ((9 * 2) + 3 + 16);
+break;
+  case llvm::Triple::x86:
+  default:
+// 18 is what's used on 32-bit X86 and on all architectures on prior
+// versions of clang.
+SetJmpBufferSize = 18;
+break;
+  }
 
   // Exceptions
   llvm::Type *StackPtrTy = llvm::ArrayType::get(CGM.Int8PtrTy, 4);
 
   ExceptionDataTy = llvm::StructType::create(
   "struct._objc_exception_data",
-  llvm::ArrayType::get(CGM.Int32Ty, SetJmpBufferSize), StackPtrTy);
+  llvm::ArrayType::get(CGM.IntTy, SetJmpBufferSize), StackPtrTy);
 }
 
 
ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModule
 )

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ObjC] Fix jmp_buf sizing for ObjC exceptions (PR #85481)

2024-03-15 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/85481

>From 65f867c70dc3e2c4adf78628c7db8103506c2101 Mon Sep 17 00:00:00 2001
From: Rose 
Date: Fri, 15 Mar 2024 18:45:48 -0400
Subject: [PATCH] [ObjC] Fix jmp_buf sizing for ObjC exceptions

The size of 18 only works for x86, but does not work for the other 
architectures. This works for Darwin and was retrieved via reading the setjmp.h 
header. It would be nice if we could do the equivalent of sizeof() that would 
obtain the size as though it were being run on the target, not the host, but 
this is the best I could do for now.
---
 clang/lib/CodeGen/CGObjCMac.cpp | 33 +++--
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index e815e097e1fb48..0f43c19ca8fb07 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -587,9 +587,9 @@ class ObjCTypesHelper : public ObjCCommonTypesHelper {
   /// SetJmpFn - LLVM _setjmp function.
   llvm::FunctionCallee getSetJmpFn() {
 // This is specifically the prototype for x86.
-llvm::Type *params[] = { CGM.Int32Ty->getPointerTo() };
+llvm::Type *params[] = {IntTy->getPointerTo()};
 return CGM.CreateRuntimeFunction(
-llvm::FunctionType::get(CGM.Int32Ty, params, false), "_setjmp",
+llvm::FunctionType::get(IntTy, params, false), "_setjmp",
 llvm::AttributeList::get(CGM.getLLVMContext(),
  llvm::AttributeList::FunctionIndex,
  llvm::Attribute::NonLazyBind));
@@ -5946,16 +5946,37 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule 
)
   ModuleTy = llvm::StructType::create("struct._objc_module", LongTy, LongTy,
   Int8PtrTy, SymtabPtrTy);
 
-  // FIXME: This is the size of the setjmp buffer and should be target
-  // specific. 18 is what's used on 32-bit X86.
-  uint64_t SetJmpBufferSize = 18;
+  // FIXME: Not a perfect solution, but one that better fits the other
+  // architectures Values are derived from setjmp.h on Darwin
+  uint64_t SetJmpBufferSize = 0;
+  switch (CGM.getTarget().getTriple().getArch()) {
+  case llvm::Triple::arm:
+if (CGM.getTarget().getTriple().getSubArch() !=
+llvm::Triple::ARMSubArch_v7k) {
+  SetJmpBufferSize = (10 + 16 + 2);
+  break;
+}
+[[fallthrough]];
+  case llvm::Triple::aarch64:
+SetJmpBufferSize = ((14 + 8 + 2) * 2);
+break;
+  case llvm::Triple::x86_64:
+SetJmpBufferSize = ((9 * 2) + 3 + 16);
+break;
+  case llvm::Triple::x86:
+  default:
+// 18 is what's used on 32-bit X86 and on all architectures on prior
+// versions of clang.
+SetJmpBufferSize = 18;
+break;
+  }
 
   // Exceptions
   llvm::Type *StackPtrTy = llvm::ArrayType::get(CGM.Int8PtrTy, 4);
 
   ExceptionDataTy = llvm::StructType::create(
   "struct._objc_exception_data",
-  llvm::ArrayType::get(CGM.Int32Ty, SetJmpBufferSize), StackPtrTy);
+  llvm::ArrayType::get(CGM.IntTy, SetJmpBufferSize), StackPtrTy);
 }
 
 
ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModule
 )

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ObjC] Fix jmp_buf sizing for ObjC exceptions (PR #85481)

2024-03-15 Thread via cfe-commits

https://github.com/AtariDreams updated 
https://github.com/llvm/llvm-project/pull/85481

>From c85838773496d54c41fd10c13e461f0f7c03ac40 Mon Sep 17 00:00:00 2001
From: Rose 
Date: Fri, 15 Mar 2024 18:45:48 -0400
Subject: [PATCH] [ObjC] Fix jmp_buf sizing for ObjC exceptions

The size of 18 only works for x86, but does not work for the other 
architectures. This works for Darwin and was retrieved via reading the setjmp.h 
header. It would be nice if we could do the equivalent of sizeof() that would 
obtain the size as though it were being run on the target, not the host, but 
this is the best I could do for now.
---
 clang/lib/CodeGen/CGObjCMac.cpp | 33 +++--
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index e815e097e1fb48..05dc7b15495304 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -587,9 +587,9 @@ class ObjCTypesHelper : public ObjCCommonTypesHelper {
   /// SetJmpFn - LLVM _setjmp function.
   llvm::FunctionCallee getSetJmpFn() {
 // This is specifically the prototype for x86.
-llvm::Type *params[] = { CGM.Int32Ty->getPointerTo() };
+llvm::Type *params[] = {CGM.IntTy->getPointerTo()};
 return CGM.CreateRuntimeFunction(
-llvm::FunctionType::get(CGM.Int32Ty, params, false), "_setjmp",
+llvm::FunctionType::get(CGM.IntTy, params, false), "_setjmp",
 llvm::AttributeList::get(CGM.getLLVMContext(),
  llvm::AttributeList::FunctionIndex,
  llvm::Attribute::NonLazyBind));
@@ -5946,16 +5946,37 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule 
)
   ModuleTy = llvm::StructType::create("struct._objc_module", LongTy, LongTy,
   Int8PtrTy, SymtabPtrTy);
 
-  // FIXME: This is the size of the setjmp buffer and should be target
-  // specific. 18 is what's used on 32-bit X86.
-  uint64_t SetJmpBufferSize = 18;
+  // FIXME: Not a perfect solution, but one that better fits the other
+  // architectures Values are derived from setjmp.h on Darwin
+  uint64_t SetJmpBufferSize = 0;
+  switch (CGM.getTarget().getTriple().getArch()) {
+  case llvm::Triple::arm:
+if (CGM.getTarget().getTriple().getSubArch() !=
+llvm::Triple::ARMSubArch_v7k) {
+  SetJmpBufferSize = (10 + 16 + 2);
+  break;
+}
+[[fallthrough]];
+  case llvm::Triple::aarch64:
+SetJmpBufferSize = ((14 + 8 + 2) * 2);
+break;
+  case llvm::Triple::x86_64:
+SetJmpBufferSize = ((9 * 2) + 3 + 16);
+break;
+  case llvm::Triple::x86:
+  default:
+// 18 is what's used on 32-bit X86 and on all architectures on prior
+// versions of clang.
+SetJmpBufferSize = 18;
+break;
+  }
 
   // Exceptions
   llvm::Type *StackPtrTy = llvm::ArrayType::get(CGM.Int8PtrTy, 4);
 
   ExceptionDataTy = llvm::StructType::create(
   "struct._objc_exception_data",
-  llvm::ArrayType::get(CGM.Int32Ty, SetJmpBufferSize), StackPtrTy);
+  llvm::ArrayType::get(CGM.IntTy, SetJmpBufferSize), StackPtrTy);
 }
 
 
ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModule
 )

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ObjC] Fix jmp_buf sizing for ObjC exceptions (PR #85481)

2024-03-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: AtariDreams (AtariDreams)


Changes

The size of 18 only works for x86, but does not work for the other 
architectures. This works for Darwin and was retrieved via reading the setjmp.h 
header. It would be nice if we could do the equivalent of sizeof() that would 
obtain the size as though it were being run on the target, not the host, but 
this is the best I could do for now.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGObjCMac.cpp (+27-6) 


``diff
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index e815e097e1fb48..340e99ab5b94c4 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -587,9 +587,9 @@ class ObjCTypesHelper : public ObjCCommonTypesHelper {
   /// SetJmpFn - LLVM _setjmp function.
   llvm::FunctionCallee getSetJmpFn() {
 // This is specifically the prototype for x86.
-llvm::Type *params[] = { CGM.Int32Ty->getPointerTo() };
+llvm::Type *params[] = {CGM.IntTy->getPointerTo()};
 return CGM.CreateRuntimeFunction(
-llvm::FunctionType::get(CGM.Int32Ty, params, false), "_setjmp",
+llvm::FunctionType::get(CGM.IntTy, params, false), "_setjmp",
 llvm::AttributeList::get(CGM.getLLVMContext(),
  llvm::AttributeList::FunctionIndex,
  llvm::Attribute::NonLazyBind));
@@ -5946,16 +5946,37 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule 
)
   ModuleTy = llvm::StructType::create("struct._objc_module", LongTy, LongTy,
   Int8PtrTy, SymtabPtrTy);
 
-  // FIXME: This is the size of the setjmp buffer and should be target
-  // specific. 18 is what's used on 32-bit X86.
-  uint64_t SetJmpBufferSize = 18;
+  // FIXME: Not a perfect solution, but one that better fits the other
+  // architectures Values are derived from setjmp.h on Darwin
+  uint64_t SetJmpBufferSize = 0;
+  switch (CGM.getTarget().getTriple().getArch()) {
+  case llvm::Triple::arm:
+if (CGM.getTarget().getTriple().getSubArch() !=
+llvm::Triple::ARMSubArch_v7k) {
+  SetJmpBufferSize = (10 + 16 + 2);
+  break;
+}
+[[fallthrough]];
+  case llvm::Triple::aarch64:
+SetJmpBufferSize = ((14 + 8 + 2) * 2);
+break;
+  case llvm::Triple::x86_64:
+SetJmpBufferSize = ((9 * 2) + 3 + 16); // Obtained from macOS's setjmp.h
+break;
+  case llvm::Triple::x86:
+  default:
+// 18 is what's used on 32-bit X86 and on all architectures on prior
+// versions of clang.
+SetJmpBufferSize = 18;
+break;
+  }
 
   // Exceptions
   llvm::Type *StackPtrTy = llvm::ArrayType::get(CGM.Int8PtrTy, 4);
 
   ExceptionDataTy = llvm::StructType::create(
   "struct._objc_exception_data",
-  llvm::ArrayType::get(CGM.Int32Ty, SetJmpBufferSize), StackPtrTy);
+  llvm::ArrayType::get(CGM.IntTy, SetJmpBufferSize), StackPtrTy);
 }
 
 
ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModule
 )

``




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


[clang] [ObjC] Fix jmp_buf sizing for ObjC exceptions (PR #85481)

2024-03-15 Thread via cfe-commits

https://github.com/AtariDreams created 
https://github.com/llvm/llvm-project/pull/85481

The size of 18 only works for x86, but does not work for the other 
architectures. This works for Darwin and was retrieved via reading the setjmp.h 
header. It would be nice if we could do the equivalent of sizeof() that would 
obtain the size as though it were being run on the target, not the host, but 
this is the best I could do for now.

>From 0e5f8c332649c2dd6e9eacb6d058aafebf5141d9 Mon Sep 17 00:00:00 2001
From: Rose 
Date: Fri, 15 Mar 2024 18:45:48 -0400
Subject: [PATCH] [ObjC] Fix jmp_buf sizing for ObjC exceptions

The size of 18 only works for x86, but does not work for the other 
architectures. This works for Darwin and was retrieved via reading the setjmp.h 
header. It would be nice if we could do the equivalent of sizeof() that would 
obtain the size as though it were being run on the target, not the host, but 
this is the best I could do for now.
---
 clang/lib/CodeGen/CGObjCMac.cpp | 33 +++--
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index e815e097e1fb48..340e99ab5b94c4 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -587,9 +587,9 @@ class ObjCTypesHelper : public ObjCCommonTypesHelper {
   /// SetJmpFn - LLVM _setjmp function.
   llvm::FunctionCallee getSetJmpFn() {
 // This is specifically the prototype for x86.
-llvm::Type *params[] = { CGM.Int32Ty->getPointerTo() };
+llvm::Type *params[] = {CGM.IntTy->getPointerTo()};
 return CGM.CreateRuntimeFunction(
-llvm::FunctionType::get(CGM.Int32Ty, params, false), "_setjmp",
+llvm::FunctionType::get(CGM.IntTy, params, false), "_setjmp",
 llvm::AttributeList::get(CGM.getLLVMContext(),
  llvm::AttributeList::FunctionIndex,
  llvm::Attribute::NonLazyBind));
@@ -5946,16 +5946,37 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule 
)
   ModuleTy = llvm::StructType::create("struct._objc_module", LongTy, LongTy,
   Int8PtrTy, SymtabPtrTy);
 
-  // FIXME: This is the size of the setjmp buffer and should be target
-  // specific. 18 is what's used on 32-bit X86.
-  uint64_t SetJmpBufferSize = 18;
+  // FIXME: Not a perfect solution, but one that better fits the other
+  // architectures Values are derived from setjmp.h on Darwin
+  uint64_t SetJmpBufferSize = 0;
+  switch (CGM.getTarget().getTriple().getArch()) {
+  case llvm::Triple::arm:
+if (CGM.getTarget().getTriple().getSubArch() !=
+llvm::Triple::ARMSubArch_v7k) {
+  SetJmpBufferSize = (10 + 16 + 2);
+  break;
+}
+[[fallthrough]];
+  case llvm::Triple::aarch64:
+SetJmpBufferSize = ((14 + 8 + 2) * 2);
+break;
+  case llvm::Triple::x86_64:
+SetJmpBufferSize = ((9 * 2) + 3 + 16); // Obtained from macOS's setjmp.h
+break;
+  case llvm::Triple::x86:
+  default:
+// 18 is what's used on 32-bit X86 and on all architectures on prior
+// versions of clang.
+SetJmpBufferSize = 18;
+break;
+  }
 
   // Exceptions
   llvm::Type *StackPtrTy = llvm::ArrayType::get(CGM.Int8PtrTy, 4);
 
   ExceptionDataTy = llvm::StructType::create(
   "struct._objc_exception_data",
-  llvm::ArrayType::get(CGM.Int32Ty, SetJmpBufferSize), StackPtrTy);
+  llvm::ArrayType::get(CGM.IntTy, SetJmpBufferSize), StackPtrTy);
 }
 
 
ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModule
 )

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits