From eaf2bb89eb2aad3b80673de30febe52df43c10ec Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 24 Feb 2009 22:18:39 +0000 Subject: first wave of fixes for @encode sema support. This is part of PR3648. The big difference here is that (like string literal) @encode has array type, not pointer type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65391 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'lib/CodeGen/CodeGenModule.cpp') diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index ccba324aa0..95490df46b 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -1098,6 +1098,21 @@ CodeGenModule::GetAddrOfConstantStringFromLiteral(const StringLiteral *S) { return GetAddrOfConstantString(GetStringForStringLiteral(S)); } +/// GetAddrOfConstantStringFromObjCEncode - Return a pointer to a constant +/// array for the given ObjCEncodeExpr node. +llvm::Constant * +CodeGenModule::GetAddrOfConstantStringFromObjCEncode(const ObjCEncodeExpr *E) { + std::string Str; + getContext().getObjCEncodingForType(E->getEncodedType(), Str); + + llvm::Constant *C = llvm::ConstantArray::get(Str); + C = new llvm::GlobalVariable(C->getType(), true, + llvm::GlobalValue::InternalLinkage, + C, ".str", &getModule()); + return C; +} + + /// GenerateWritableString -- Creates storage for a string literal. static llvm::Constant *GenerateStringLiteral(const std::string &str, bool constant, @@ -1107,13 +1122,10 @@ static llvm::Constant *GenerateStringLiteral(const std::string &str, llvm::Constant *C = llvm::ConstantArray::get(str, false); // Create a global variable for this string - C = new llvm::GlobalVariable(C->getType(), constant, - llvm::GlobalValue::InternalLinkage, - C, - GlobalName ? GlobalName : ".str", - &CGM.getModule()); - - return C; + return new llvm::GlobalVariable(C->getType(), constant, + llvm::GlobalValue::InternalLinkage, + C, GlobalName ? GlobalName : ".str", + &CGM.getModule()); } /// GetAddrOfConstantString - Returns a pointer to a character array @@ -1134,7 +1146,7 @@ llvm::Constant *CodeGenModule::GetAddrOfConstantString(const std::string &str, ConstantStringMap.GetOrCreateValue(&str[0], &str[str.length()]); if (Entry.getValue()) - return Entry.getValue(); + return Entry.getValue(); // Create a global variable for this. llvm::Constant *C = GenerateStringLiteral(str, true, *this, GlobalName); -- cgit v1.2.3-18-g5258