From fcbf0e691cc9ae899dc900f9634e18a20b2b141c Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 25 Oct 2017 03:58:15 +0000 Subject: [PATCH] CodeGen: fix a case of incorrect checks for ivars Ensure that we check the ivar containing decl for the DLL storage attribute rather than the ivar itself as the dll storage is associated to the interface decl not the ivar decl. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316545 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGObjCMac.cpp | 12 ++++++++---- test/CodeGenObjC/dllstorage.m | 10 ++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 98435fefbd..85901a6d65 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -6615,10 +6615,14 @@ CGObjCNonFragileABIMac::ObjCIvarOffsetVariable(const ObjCInterfaceDecl *ID, Ivar->getAccessControl() == ObjCIvarDecl::Private || Ivar->getAccessControl() == ObjCIvarDecl::Package; - if (ID->hasAttr() && !IsPrivateOrPackage) - IvarOffsetGV->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); - else if (ID->hasAttr()) - IvarOffsetGV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); + const ObjCInterfaceDecl *ContainingID = Ivar->getContainingInterface(); + + if (ContainingID->hasAttr()) + IvarOffsetGV + ->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); + else if (ContainingID->hasAttr() && !IsPrivateOrPackage) + IvarOffsetGV + ->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); } } return IvarOffsetGV; diff --git a/test/CodeGenObjC/dllstorage.m b/test/CodeGenObjC/dllstorage.m index 4bdbd50915..a2665eefad 100644 --- a/test/CodeGenObjC/dllstorage.m +++ b/test/CodeGenObjC/dllstorage.m @@ -1,3 +1,4 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fdeclspec -fobjc-runtime=ios -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -check-prefix CHECK-IR %s // RUN: %clang_cc1 -triple i686-windows-itanium -fms-extensions -fobjc-runtime=macosx -fdeclspec -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -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 -check-prefix CHECK-FW %s @@ -114,6 +115,15 @@ __attribute__((__objc_exception__)) // CHECK-IR-DAG: @"OBJC_EHTYPE_$_P" = external global %struct._objc_typeinfo +@interface Q : M +@end + +id f(Q *q) { + return q->_ivar; +} + +// CHECK-IR-DAG: @"OBJC_IVAR_$_M._ivar" = external dllimport global i32 + int g() { @autoreleasepool { M *mi = [M new]; -- 2.40.0