Skip to content

Commit

Permalink
build wide strings with ConstantDataArray, just because we can.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149928 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
lattner committed Feb 6, 2012
1 parent 812234b commit d79ed43
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2072,20 +2072,26 @@ CodeGenModule::GetConstantArrayFromStringLiteral(const StringLiteral *E) {
cast<llvm::ArrayType>(getTypes().ConvertType(E->getType()));
llvm::Type *ElemTy = AType->getElementType();
unsigned NumElements = AType->getNumElements();
std::vector<llvm::Constant*> Elts;
Elts.reserve(NumElements);

for(unsigned i=0;i<E->getLength();++i) {
unsigned value = E->getCodeUnit(i);
llvm::Constant *C = llvm::ConstantInt::get(ElemTy,value,false);
Elts.push_back(C);
}
for(unsigned i=E->getLength();i<NumElements;++i) {
llvm::Constant *C = llvm::ConstantInt::get(ElemTy,0,false);
Elts.push_back(C);

// Wide strings have either 2-byte or 4-byte elements.
if (ElemTy->getPrimitiveSizeInBits() == 16) {
SmallVector<uint16_t, 32> Elements;
Elements.reserve(NumElements);

for(unsigned i = 0, e = E->getLength(); i != e; ++i)
Elements.push_back(E->getCodeUnit(i));
Elements.resize(NumElements);
return llvm::ConstantDataArray::get(VMContext, Elements);
}

return llvm::ConstantArray::get(AType, Elts);
assert(ElemTy->getPrimitiveSizeInBits() == 32);
SmallVector<uint32_t, 32> Elements;
Elements.reserve(NumElements);

for(unsigned i = 0, e = E->getLength(); i != e; ++i)
Elements.push_back(E->getCodeUnit(i));
Elements.resize(NumElements);
return llvm::ConstantDataArray::get(VMContext, Elements);
}

/// GetAddrOfConstantStringFromLiteral - Return a pointer to a
Expand Down

0 comments on commit d79ed43

Please sign in to comment.