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 | c38adbb846c5844445624e692629da6861142211 (patch) | |
tree | 0cb6cd16131302040208fa09e54d079ca1b0af8d /tools/llvm2cpp | |
parent | 7f32156bb9c017b71971c52fac892fa7b9b06dd2 (diff) | |
download | external_llvm-c38adbb846c5844445624e692629da6861142211.zip external_llvm-c38adbb846c5844445624e692629da6861142211.tar.gz external_llvm-c38adbb846c5844445624e692629da6861142211.tar.bz2 |
Fix PR1525:
Use a better determinator for identifying constant array initializers that
are or are not zero terminated and generate code appropriately.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37720 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm2cpp')
-rw-r--r-- | tools/llvm2cpp/CppWriter.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/tools/llvm2cpp/CppWriter.cpp b/tools/llvm2cpp/CppWriter.cpp index 8e30c79..7063b10 100644 --- a/tools/llvm2cpp/CppWriter.cpp +++ b/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;"; |