Index: lib/CodeGen/CGBlocks.cpp =================================================================== --- lib/CodeGen/CGBlocks.cpp +++ lib/CodeGen/CGBlocks.cpp @@ -2586,11 +2586,11 @@ } } - if (!CGM.getLangOpts().BlocksRuntimeOptional) - return; - - if (GV->isDeclaration() && GV->hasExternalLinkage()) + if (CGM.getLangOpts().BlocksRuntimeOptional && GV->isDeclaration() && + GV->hasExternalLinkage()) GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); + + CGM.setDSOLocal(GV); } llvm::Constant *CodeGenModule::getBlockObjectDispose() { Index: test/CodeGen/blocks-windows.c =================================================================== --- test/CodeGen/blocks-windows.c +++ test/CodeGen/blocks-windows.c @@ -67,7 +67,7 @@ return _Block_copy(^{ ++i; return i; }); } -// CHECK-BLOCKS-IN-BLOCKS-DECL: @_NSConcreteStackBlock = external dllexport global i8* +// CHECK-BLOCKS-IN-BLOCKS-DECL: @_NSConcreteStackBlock = external dso_local dllexport global i8* // CHECK-BLOCKS-IN-BLOCKS-DEFN: @_NSConcreteStackBlock = common dso_local dllexport global [5 x i32] // CHECK-BLOCKS-NOT-IN-BLOCKS: @_NSConcreteStackBlock = external dllimport global i8* // CHECK-BLOCKS-NOT-IN-BLOCKS-EXTERN: @_NSConcreteStackBlock = external dllimport global i8*