diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-06-25 16:45:54 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-06-25 16:45:54 +0000 |
commit | 36d4c0750081523561daf167eabfe0066e78522f (patch) | |
tree | 0b9eafe6bc9fcfc9307ef454ed4c91e224fc7acd /llvm/tools/llvm2cpp/CppWriter.cpp | |
parent | a866514528d482b3b0e4118b45a675d9dfca6d93 (diff) | |
download | bcm5719-llvm-36d4c0750081523561daf167eabfe0066e78522f.tar.gz bcm5719-llvm-36d4c0750081523561daf167eabfe0066e78522f.zip |
Fix PR1525:
Use a better determinator for identifying constant array initializers that
are or are not zero terminated and generate code appropriately.
llvm-svn: 37720
Diffstat (limited to 'llvm/tools/llvm2cpp/CppWriter.cpp')
-rw-r--r-- | llvm/tools/llvm2cpp/CppWriter.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/llvm/tools/llvm2cpp/CppWriter.cpp b/llvm/tools/llvm2cpp/CppWriter.cpp index 8e30c7990d1..7063b10cbe8 100644 --- a/llvm/tools/llvm2cpp/CppWriter.cpp +++ b/llvm/tools/llvm2cpp/CppWriter.cpp @@ -720,12 +720,18 @@ void CppWriter::printConstant(const Constant *CV) { } else if (const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) { if (CA->isString() && CA->getType()->getElementType() == Type::Int8Ty) { Out << "Constant* " << constName << " = ConstantArray::get(\""; - printEscapedString(CA->getAsString()); + std::string tmp = CA->getAsString(); + bool nullTerminate = false; + if (tmp[tmp.length()-1] == 0) { + tmp.erase(tmp.length()-1); + nullTerminate = true; + } + printEscapedString(tmp); // Determine if we want null termination or not. - if (CA->getType()->getNumElements() <= CA->getAsString().length()) - Out << "\", false";// No null terminator - else + if (nullTerminate) Out << "\", true"; // Indicate that the null terminator should be added. + else + Out << "\", false";// No null terminator Out << ");"; } else { Out << "std::vector<Constant*> " << constName << "_elems;"; |