[llvm-commits] CVS: llvm/tools/llvm2cpp/CppWriter.cpp

Reid Spencer reid at x10sys.com
Mon Jun 25 09:46:17 PDT 2007



Changes in directory llvm/tools/llvm2cpp:

CppWriter.cpp updated: 1.52 -> 1.53
---
Log message:

Fix PR1525: http://llvm.org/PR1525 :
Use a better determinator for identifying constant array initializers that
are or are not zero terminated and generate code appropriately.


---
Diffs of the changes:  (+10 -4)

 CppWriter.cpp |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)


Index: llvm/tools/llvm2cpp/CppWriter.cpp
diff -u llvm/tools/llvm2cpp/CppWriter.cpp:1.52 llvm/tools/llvm2cpp/CppWriter.cpp:1.53
--- llvm/tools/llvm2cpp/CppWriter.cpp:1.52	Sat Jun 16 15:48:27 2007
+++ llvm/tools/llvm2cpp/CppWriter.cpp	Mon Jun 25 11:45:54 2007
@@ -720,12 +720,18 @@
   } 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;";






More information about the llvm-commits mailing list