diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2011-05-17 22:21:16 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2011-05-17 22:21:16 +0000 |
commit | 7bd3d1c49b8a9df31b07695b9e53cb300430ef60 (patch) | |
tree | d0cb69bea6e67a67ff41c2520f6d219ff1ac30aa /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 4298df6d8667b0358d4921d4fe3c08e7efc8698b (diff) | |
download | bcm5719-llvm-7bd3d1c49b8a9df31b07695b9e53cb300430ef60.tar.gz bcm5719-llvm-7bd3d1c49b8a9df31b07695b9e53cb300430ef60.zip |
Patch to fix IR-gen crash generating structure ABI which implements
user specified string class via -fconstant-string-class option.
pr9914.
llvm-svn: 131496
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 84fa4af669e..7f2e3f593ef 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1768,24 +1768,31 @@ CodeGenModule::GetAddrOfConstantString(const StringLiteral *Literal) { if (!ConstantStringClassRef) { std::string StringClass(getLangOptions().ObjCConstantStringClass); const llvm::Type *Ty = getTypes().ConvertType(getContext().IntTy); - Ty = llvm::ArrayType::get(Ty, 0); llvm::Constant *GV; - if (StringClass.empty()) - GV = CreateRuntimeVariable(Ty, - Features.ObjCNonFragileABI ? - "OBJC_CLASS_$_NSConstantString" : - "_NSConstantStringClassReference"); - else { + if (Features.ObjCNonFragileABI) { std::string str; - if (Features.ObjCNonFragileABI) + if (StringClass.empty()) + str = "OBJC_CLASS_$_NSConstantString"; + else { str = "OBJC_CLASS_$_" + StringClass; - else - str = "_" + StringClass + "ClassReference"; - GV = CreateRuntimeVariable(Ty, str); + } + GV = getObjCRuntime().GetClassGlobal(str); + // Make sure the result is of the correct type. + const llvm::Type *PTy = llvm::PointerType::getUnqual(Ty); + ConstantStringClassRef = + llvm::ConstantExpr::getBitCast(GV, PTy); + } else { + Ty = llvm::ArrayType::get(Ty, 0); + if (StringClass.empty()) + GV = CreateRuntimeVariable(Ty, "_NSConstantStringClassReference"); + else { + std::string str = "_" + StringClass + "ClassReference"; + GV = CreateRuntimeVariable(Ty, str); + } + // Decay array -> ptr + ConstantStringClassRef = + llvm::ConstantExpr::getGetElementPtr(GV, Zeros, 2); } - // Decay array -> ptr - ConstantStringClassRef = - llvm::ConstantExpr::getGetElementPtr(GV, Zeros, 2); } QualType NSTy = getContext().getNSConstantStringType(); |