Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set dllstorage on ObjectiveC ivar offsets #77385

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/CGObjCGNU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 29 additions & 0 deletions clang/test/CodeGenObjC/dllstorage.m
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -22,13 +25,18 @@ @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;
}
@end

// 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

Expand All @@ -38,13 +46,18 @@ @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;
}
@end

// 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
Expand All @@ -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;

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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];
Expand Down