Skip to content

Commit

Permalink
Set dllimport on Objective C ivar offsets
Browse files Browse the repository at this point in the history
This commit ensures that offsets for instance variables are marked with `dllimport` if the interface to which they belong have this attribute.
  • Loading branch information
qmfrederik committed Sep 6, 2024
1 parent 62fec3d commit 83511b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions clang/lib/CodeGen/CGObjCGNU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGenObjC/dllstorage.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 83511b9

Please sign in to comment.