[llvm-commits] [llvm-gcc-4.2] r75822 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Dale Johannesen dalej at apple.com
Wed Jul 15 13:26:26 PDT 2009


Author: johannes
Date: Wed Jul 15 15:26:26 2009
New Revision: 75822

URL: http://llvm.org/viewvc/llvm-project?rev=75822&view=rev
Log:
Code for truncating/padding string constants was
comparing size in bytes with size in elements.
OK for normal strings, not for wchar_t.


Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=75822&r1=75821&r2=75822&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Wed Jul 15 15:26:26 2009
@@ -7047,25 +7047,27 @@
     assert(0 && "Unknown character type!");
   }
   
+  unsigned LenInElts = Len /
+          TREE_INT_CST_LOW(TYPE_SIZE_UNIT(TREE_TYPE(TREE_TYPE(exp))));
   unsigned ConstantSize = StrTy->getNumElements();
   
-  if (Len != ConstantSize) {
-    // If this is a variable sized array type, set the length to Len.
+  if (LenInElts != ConstantSize) {
+    // If this is a variable sized array type, set the length to LenInElts.
     if (ConstantSize == 0) {
       tree Domain = TYPE_DOMAIN(TREE_TYPE(exp));
       if (!Domain || !TYPE_MAX_VALUE(Domain)) {
-        ConstantSize = Len;
-        StrTy = Context.getArrayType(ElTy, Len);
+        ConstantSize = LenInElts;
+        StrTy = Context.getArrayType(ElTy, LenInElts);
       }
     }
     
-    if (ConstantSize < Len) {
+    if (ConstantSize < LenInElts) {
       // Only some chars are being used, truncate the string: char X[2] = "foo";
       Elts.resize(ConstantSize);
     } else {
       // Fill the end of the string with nulls.
       Constant *C = Context.getNullValue(ElTy);
-      for (; Len != ConstantSize; ++Len)
+      for (; LenInElts != ConstantSize; ++LenInElts)
         Elts.push_back(C);
     }
   }





More information about the llvm-commits mailing list