Index: lib/CodeGen/CodeGenModule.cpp =================================================================== --- lib/CodeGen/CodeGenModule.cpp +++ lib/CodeGen/CodeGenModule.cpp @@ -4093,15 +4093,20 @@ llvm::Constant *Zero = llvm::Constant::getNullValue(Int32Ty); llvm::Constant *Zeros[] = { Zero, Zero }; - + // If we don't already have it, get __CFConstantStringClassReference. if (!CFConstantStringClassRef) { llvm::Type *Ty = getTypes().ConvertType(getContext().IntTy); Ty = llvm::ArrayType::get(Ty, 0); - llvm::GlobalValue *GV = cast( - CreateRuntimeVariable(Ty, "__CFConstantStringClassReference")); - + llvm::Constant *CGV = + CreateRuntimeVariable(Ty, "__CFConstantStringClassReference"); + llvm::GlobalValue *GV = dyn_cast(CGV); + if (getTriple().isOSBinFormatCOFF()) { + // Instead of using a cast<>, just assert if it's null, this is + // consistent with old behavior for this target as it would fail + // on the cast<> instead. + assert(GV && "isa isn't a GlobalValue"); IdentifierInfo &II = getContext().Idents.get(GV->getName()); TranslationUnitDecl *TUDecl = getContext().getTranslationUnitDecl(); DeclContext *DC = TranslationUnitDecl::castToDeclContext(TUDecl); @@ -4119,11 +4124,12 @@ GV->setLinkage(llvm::GlobalValue::ExternalLinkage); } } - setDSOLocal(GV); + if (GV) + setDSOLocal(GV); // Decay array -> ptr CFConstantStringClassRef = - llvm::ConstantExpr::getGetElementPtr(Ty, GV, Zeros); + llvm::ConstantExpr::getGetElementPtr(Ty, CGV, Zeros); } QualType CFTy = getContext().getCFConstantStringType();