[clang] Set dllimport on Objective C ivar offsets (PR #107604)
Frederik Carlier via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 6 09:14:58 PDT 2024
https://github.com/qmfrederik created https://github.com/llvm/llvm-project/pull/107604
Ensures that offsets for instance variables are marked with `dllimport` if the interface to which they belong has this attribute.
>From 83511b91e37a9191fcde289b1f302c79e8533b6f Mon Sep 17 00:00:00 2001
From: Frederik Carlier <frederik.carlier at keysight.com>
Date: Fri, 6 Sep 2024 11:54:59 +0000
Subject: [PATCH] Set dllimport on Objective C ivar offsets
This commit ensures that offsets for instance variables are marked with `dllimport` if the interface to which they belong have this attribute.
---
clang/lib/CodeGen/CGObjCGNU.cpp | 11 ++++++++---
clang/test/CodeGenObjC/dllstorage.m | 2 +-
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index adc7cdbfded880..c78a3ab9830a1c 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1698,12 +1698,17 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
}
llvm::Value *EmitIvarOffset(CodeGenFunction &CGF,
const ObjCInterfaceDecl *Interface,
- const ObjCIvarDecl *Ivar) override {
- const std::string Name = GetIVarOffsetVariableName(Ivar->getContainingInterface(), Ivar);
+ const ObjCIvarDecl *Ivar) override {
+ const ObjCInterfaceDecl *ContainingInterface = Ivar->getContainingInterface();
+ const std::string Name = GetIVarOffsetVariableName(ContainingInterface, Ivar);
llvm::GlobalVariable *IvarOffsetPointer = TheModule.getNamedGlobal(Name);
- if (!IvarOffsetPointer)
+ if (!IvarOffsetPointer) {
IvarOffsetPointer = new llvm::GlobalVariable(TheModule, IntTy, false,
llvm::GlobalValue::ExternalLinkage, nullptr, Name);
+ if (Ivar->getAccessControl() != ObjCIvarDecl::Private
+ && Ivar->getAccessControl() != ObjCIvarDecl::Package)
+ CGM.setGVProperties(IvarOffsetPointer, ContainingInterface);
+ }
CharUnits Align = CGM.getIntAlign();
llvm::Value *Offset =
CGF.Builder.CreateAlignedLoad(IntTy, IvarOffsetPointer, Align);
diff --git a/clang/test/CodeGenObjC/dllstorage.m b/clang/test/CodeGenObjC/dllstorage.m
index c94f4c9b5804d0..0801fb049f6b45 100644
--- a/clang/test/CodeGenObjC/dllstorage.m
+++ b/clang/test/CodeGenObjC/dllstorage.m
@@ -151,7 +151,7 @@ id f(Q *q) {
// CHECK-IR-DAG: @"OBJC_IVAR_$_M._ivar" = external dllimport global i32
-// CHECK-NF-DAG: @"__objc_ivar_offset_M._ivar.@" = external global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_M._ivar.@" = external dllimport global i32
int g(void) {
@autoreleasepool {
More information about the cfe-commits
mailing list