diff options
author | Chris Lattner <sabre@nondot.org> | 2009-02-24 22:18:39 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-02-24 22:18:39 +0000 |
commit | d7e7b8e4115d34c42b3ba479ff7615a7efbf25fc (patch) | |
tree | fe3641cd6aca04382717ef836335d30d4cb8f98c /clang/lib/CodeGen/CGExprConstant.cpp | |
parent | 9b15effcd1f3a9ea9dec0ba4a4447015196a85b3 (diff) | |
download | bcm5719-llvm-d7e7b8e4115d34c42b3ba479ff7615a7efbf25fc.tar.gz bcm5719-llvm-d7e7b8e4115d34c42b3ba479ff7615a7efbf25fc.zip |
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.
llvm-svn: 65391
Diffstat (limited to 'clang/lib/CodeGen/CGExprConstant.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGExprConstant.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 1141c0da8aa..487b274f1c7 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -76,7 +76,10 @@ public: cast<llvm::ArrayType>(ConvertType(ILE->getType())); unsigned NumInitElements = ILE->getNumInits(); // FIXME: Check for wide strings - if (NumInitElements > 0 && isa<StringLiteral>(ILE->getInit(0)) && + // FIXME: Check for NumInitElements exactly equal to 1?? + if (NumInitElements > 0 && + (isa<StringLiteral>(ILE->getInit(0)) || + isa<ObjCEncodeExpr>(ILE->getInit(0))) && ILE->getType()->getArrayElementTypeNoTypeQual()->isCharType()) return Visit(ILE->getInit(0)); const llvm::Type *ElemTy = AType->getElementType(); @@ -346,12 +349,26 @@ public: llvm::Constant *VisitStringLiteral(StringLiteral *E) { assert(!E->getType()->isPointerType() && "Strings are always arrays"); - // Otherwise this must be a string initializing an array in a static - // initializer. Don't emit it as the address of the string, emit the string - // data itself as an inline array. + // This must be a string initializing an array in a static initializer. + // Don't emit it as the address of the string, emit the string data itself + // as an inline array. return llvm::ConstantArray::get(CGM.GetStringForStringLiteral(E), false); } + llvm::Constant *VisitObjCEncodeExpr(ObjCEncodeExpr *E) { + // This must be an @encode initializing an array in a static initializer. + // Don't emit it as the address of the string, emit the string data itself + // as an inline array. + std::string Str; + CGM.getContext().getObjCEncodingForType(E->getEncodedType(), Str); + const ConstantArrayType *CAT = cast<ConstantArrayType>(E->getType()); + + // Resize the string to the right size, adding zeros at the end, or + // truncating as needed. + Str.resize(CAT->getSize().getZExtValue(), '\0'); + return llvm::ConstantArray::get(Str, false); + } + llvm::Constant *VisitUnaryExtension(const UnaryOperator *E) { return Visit(E->getSubExpr()); } @@ -398,6 +415,8 @@ public: } case Expr::StringLiteralClass: return CGM.GetAddrOfConstantStringFromLiteral(cast<StringLiteral>(E)); + case Expr::ObjCEncodeExprClass: + return CGM.GetAddrOfConstantStringFromObjCEncode(cast<ObjCEncodeExpr>(E)); case Expr::ObjCStringLiteralClass: { ObjCStringLiteral* SL = cast<ObjCStringLiteral>(E); std::string S(SL->getString()->getStrData(), |