[PATCH] Windows support for ObjC DLLIMPORT

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 4 13:41:46 PDT 2016

In addition to the Sema tests, this change needs tests in CodeGenObjC to
show where the attribute is applied in the IR.

--- a/lib/CodeGen/CGBlocks.cpp
+++ b/lib/CodeGen/CGBlocks.cpp
@@ -2334,5 +2334,9 @@ llvm::Constant
*CodeGenModule::getNSConcreteStackBlock() {
   configureBlocksRuntimeObject(*this, NSConcreteStackBlock);
+  if (getContext().getLangOpts().MSVCCompat) {
+    auto *GV =
+    GV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
+  }
   return NSConcreteStackBlock;

I have a feeling that you want to configure all of these blocks runtime
references to be dllimport, so maybe move this
into configureBlocksRuntimeObject and do it before the early return.

You probably also want to conditionalize these imports on
Triple::isOSBinFormatCOFF() instead of MSVCCompat. Any Windows blocks
runtime will want to import these.

 llvm::Value *CGObjCGNU::EmitNSAutoreleasePoolClassRef(CodeGenFunction
&CGF) {
-  return GetClassNamed(CGF, "NSAutoreleasePool", false);
+  return GetClassNamed(CGF, "NSAutoreleasePool", false,

Again, probably isOSBinFormatCOFF. I suppose you don't want to use
dllimport if the obj-c runtime is statically linked, so you might want to
wrap this all up in a predicate like CGObjCGNU::isRuntimeDLLImport. Also,
wrap to 80cols with clang-format.

+++ b/test/SemaObjC/dllimport.m

This file should have Unix line endings.

On Mon, Apr 4, 2016 at 12:34 PM, Wes Witt via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Please accept this diff as a change to support dllimport of objective c
> interfaces on windows. I’ve included a new test and changes to an existing
> test as well. All clang tests pass on Linux & Windows. This change is
> required for Microsoft’s use of the clang compiler in support of objective
> c on windows.
> Thanks,
> Wes Witt
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160404/1c8e08b6/attachment.html>

More information about the cfe-commits mailing list