diff options
author | David Chisnall <csdavec@swan.ac.uk> | 2010-01-27 12:49:23 +0000 |
---|---|---|
committer | David Chisnall <csdavec@swan.ac.uk> | 2010-01-27 12:49:23 +0000 |
commit | 358e751a7b8d235c3f0a9ceabaf56fe1a6f03ba7 (patch) | |
tree | 116dc86d23b88822de71f8f825694566af9798c8 /clang | |
parent | 4fe7a3bc084f91f4e860a33111ebf25373785437 (diff) | |
download | bcm5719-llvm-358e751a7b8d235c3f0a9ceabaf56fe1a6f03ba7.tar.gz bcm5719-llvm-358e751a7b8d235c3f0a9ceabaf56fe1a6f03ba7.zip |
Unique ObjC strings (GNU Runtime); fix for PR6142. Note: Doing this in the runtime-specific code is a bit ugly. It would be a good idea to hoist all of the string / protocol uniqueing code up into CGObjCRuntime or CodeGenModule and only handle emitting the original versions in the runtime-specific code.
llvm-svn: 94676
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/CodeGen/CGObjCGNU.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index 77be9fb5823..3a0ac994d8c 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -65,6 +65,7 @@ private: std::vector<llvm::Constant*> Classes; std::vector<llvm::Constant*> Categories; std::vector<llvm::Constant*> ConstantStrings; + llvm::StringMap<llvm::Constant*> ObjCStrings; llvm::Function *LoadFunction; llvm::StringMap<llvm::Constant*> ExistingProtocols; typedef std::pair<std::string, std::string> TypedSelector; @@ -357,8 +358,14 @@ llvm::Constant *CGObjCGNU::MakeGlobal(const llvm::ArrayType *Ty, /// Generate an NSConstantString object. llvm::Constant *CGObjCGNU::GenerateConstantString(const StringLiteral *SL) { + std::string Str(SL->getStrData(), SL->getByteLength()); + // Look for an existing one + llvm::StringMap<llvm::Constant*>::iterator old = ObjCStrings.find(Str); + if (old != ObjCStrings.end()) + return old->getValue(); + std::vector<llvm::Constant*> Ivars; Ivars.push_back(NULLPtr); Ivars.push_back(MakeConstantString(Str)); @@ -366,8 +373,9 @@ llvm::Constant *CGObjCGNU::GenerateConstantString(const StringLiteral *SL) { llvm::Constant *ObjCStr = MakeGlobal( llvm::StructType::get(VMContext, PtrToInt8Ty, PtrToInt8Ty, IntTy, NULL), Ivars, ".objc_str"); - ConstantStrings.push_back( - llvm::ConstantExpr::getBitCast(ObjCStr, PtrToInt8Ty)); + ObjCStr = llvm::ConstantExpr::getBitCast(ObjCStr, PtrToInt8Ty); + ObjCStrings[Str] = ObjCStr; + ConstantStrings.push_back(ObjCStr); return ObjCStr; } |