[clang] Set dllstorage on ObjectiveC ivar offsets (PR #77385)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 8 14:18:35 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Frederik Carlier (qmfrederik)

<details>
<summary>Changes</summary>

Mark instance variable offset symbols with `dllexport`/`dllimport` if they are not hidden and the interface declaration is marked with `dllexport`/`dllimport`, when using the GNUstep 2.x ABI.

/cc @<!-- -->davidchisnall 

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGObjCGNU.cpp (+2) 
- (modified) clang/test/CodeGenObjC/dllstorage.m (+29) 


``````````diff
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..9443fecf9b7946 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1851,6 +1851,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
                     llvm::GlobalValue::HiddenVisibility :
                     llvm::GlobalValue::DefaultVisibility;
         OffsetVar->setVisibility(ivarVisibility);
+        if (ivarVisibility != llvm::GlobalValue::HiddenVisibility)
+          CGM.setGVProperties(OffsetVar, OID->getClassInterface());
         ivarBuilder.add(OffsetVar);
         // Ivar size
         ivarBuilder.addInt(Int32Ty,
diff --git a/clang/test/CodeGenObjC/dllstorage.m b/clang/test/CodeGenObjC/dllstorage.m
index 64ba21f9769ae2..0dbf1881caa9c0 100644
--- a/clang/test/CodeGenObjC/dllstorage.m
+++ b/clang/test/CodeGenObjC/dllstorage.m
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fdeclspec -fobjc-runtime=ios -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap -check-prefix CHECK-IR %s
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fdeclspec -fobjc-runtime=gnustep-2.0 -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap -check-prefix CHECK-NF %s
 // RUN: %clang_cc1 -triple i686-windows-itanium -fms-extensions -fobjc-runtime=macosx -fdeclspec -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap -check-prefix CHECK-IR %s
 // RUN: %clang_cc1 -triple i686-windows-itanium -fms-extensions -fobjc-runtime=objfw -fdeclspec -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -allow-deprecated-dag-overlap -check-prefix CHECK-FW %s
 
@@ -12,6 +13,8 @@ + (instancetype) new;
 // CHECK-IR-DAG: @"OBJC_METACLASS_$_I" = external dllimport global %struct._class_t
 // CHECK-IR-DAG: @"OBJC_CLASS_$_I" = external dllimport global %struct._class_t
 
+// CHECK-NF-DAG: @"$_OBJC_CLASS_I" = external dllimport global ptr
+
 __declspec(dllexport)
 @interface J : I
 @end
@@ -22,6 +25,9 @@ @interface J : I
 // CHECK-FW-DAG: @_OBJC_METACLASS_J = dso_local dllexport global
 // CHECK-FW-DAG: @_OBJC_CLASS_J = dso_local dllexport global
 
+// CHECK-NF-DAG: @"$_OBJC_METACLASS_J" = internal global
+// CHECK-NF-DAG: @"$_OBJC_CLASS_J" = dllexport global
+
 @implementation J {
   id _ivar;
 }
@@ -29,6 +35,8 @@ @implementation J {
 
 // CHECK-IR-DAG: @"OBJC_IVAR_$_J._ivar" = global i32
 
+// CHECK-NF-DAG: @"__objc_ivar_offset_J._ivar.\01" = hidden global i32
+
 @interface K : J
 @end
 
@@ -38,6 +46,9 @@ @interface K : J
 // CHECK-FW-DAG: @_OBJC_METACLASS_K = dso_local global
 // CHECK-FW-DAG: @_OBJC_CLASS_K = dso_local global
 
+// CHECK-NF-DAG: @"$_OBJC_METACLASS_K" = internal global
+// CHECK-NF-DAG: @"$_OBJC_CLASS_K" = global
+
 @implementation K {
   id _ivar;
 }
@@ -45,6 +56,8 @@ @implementation K {
 
 // CHECK-IR-DAG: @"OBJC_IVAR_$_K._ivar" = global i32
 
+// CHECK-NF-DAG: @"__objc_ivar_offset_K._ivar.\01" = hidden global i32
+
 __declspec(dllexport)
 @interface L : K
 @end
@@ -55,6 +68,9 @@ @interface L : K
 // CHECK-FW-DAG: @_OBJC_METACLASS_L = dso_local dllexport global
 // CHECK-FW-DAG: @_OBJC_CLASS_L = dso_local dllexport global
 
+// CHECK-NF-DAG: @"$_OBJC_METACLASS_L" = internal global
+// CHECK-NF-DAG: @"$_OBJC_CLASS_L" = dllexport global
+
 @implementation L {
   id _none;
 
@@ -78,6 +94,12 @@ @implementation L {
 // CHECK-IR-DAG: @"OBJC_IVAR_$_L._package" = global i32
 // CHECK-IR-DAG: @"OBJC_IVAR_$_L._private" = global i32
 
+// CHECK-NF-DAG: @"__objc_ivar_offset_L._none.\01" = hidden global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_L._public.\01" = dso_local dllexport global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_L._protected.\01" = dso_local dllexport global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_L._package.\01" = hidden global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_L._private.\01" = hidden global i32
+
 __declspec(dllimport)
 @interface M : I {
   @public
@@ -89,6 +111,9 @@ @interface M : I {
 
 // CHECK-IR-DAG: @"OBJC_IVAR_$_M._ivar" = external dllimport global i32
 
+// CHECK-NF-DAG: @"$_OBJC_REF_CLASS_M" = external dllimport global ptr
+// CHECK-NF-DAG: @"__objc_ivar_offset_M._ivar.\01" = external global i32
+
 __declspec(dllexport)
 __attribute__((__objc_exception__))
 @interface N : I
@@ -97,6 +122,8 @@ @interface N : I
 // CHECK-FW-DAG: @_OBJC_METACLASS_N = dso_local dllexport global
 // CHECK-FW-DAG: @_OBJC_CLASS_N = dso_local dllexport global
 
+// CHECK-NF-DAG: @"$_OBJC_CLASS_N" = dllexport global
+
 @implementation N : I
 @end
 
@@ -124,6 +151,8 @@ id f(Q *q) {
 
 // CHECK-IR-DAG: @"OBJC_IVAR_$_M._ivar" = external dllimport global i32
 
+// CHECK-NF-DAG: @"__objc_ivar_offset_M._ivar.\01" = external global i32
+
 int g(void) {
   @autoreleasepool {
     M *mi = [M new];

``````````

</details>


https://github.com/llvm/llvm-project/pull/77385


More information about the cfe-commits mailing list