fix some sema problems with wide strings and hook up basic codegen for them.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65582 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 95490df..75a8302 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -1069,11 +1069,6 @@
 /// GetStringForStringLiteral - Return the appropriate bytes for a
 /// string literal, properly padded to match the literal type.
 std::string CodeGenModule::GetStringForStringLiteral(const StringLiteral *E) {
-  if (E->isWide()) {
-    ErrorUnsupported(E, "wide string");
-    return "FIXME";
-  }
-
   const char *StrData = E->getStrData();
   unsigned Len = E->getByteLength();
 
@@ -1081,10 +1076,13 @@
     getContext().getAsConstantArrayType(E->getType());
   assert(CAT && "String isn't pointer or array!");
   
-  // Resize the string to the right size
-  // FIXME: What about wchar_t strings?
+  // Resize the string to the right size.
   std::string Str(StrData, StrData+Len);
   uint64_t RealLen = CAT->getSize().getZExtValue();
+  
+  if (E->isWide())
+    RealLen *= getContext().Target.getWCharWidth()/8;
+  
   Str.resize(RealLen, '\0');
   
   return Str;
diff --git a/lib/Lex/LiteralSupport.cpp b/lib/Lex/LiteralSupport.cpp
index 9815f9b..c20383f 100644
--- a/lib/Lex/LiteralSupport.cpp
+++ b/lib/Lex/LiteralSupport.cpp
@@ -672,8 +672,7 @@
     // Remember if we see any wide strings.
     AnyWide |= StringToks[i].is(tok::wide_string_literal);
   }
-  
-  
+
   // Include space for the null terminator.
   ++SizeBound;
   
@@ -779,13 +778,6 @@
     }
   }
   
-  // Add zero terminator.
-  *ResultPtr = 0;
-  if (AnyWide) {
-    for (unsigned i = 1, e = wchar_tByteWidth; i != e; ++i)
-    *ResultPtr++ = 0;
-  }
-    
   if (Pascal) {
     ResultBuf[0] = ResultPtr-&ResultBuf[0]-1;
 
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index eec27ce..01be6b2 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -400,7 +400,7 @@
   // the nul terminator character as well as the string length for pascal
   // strings.
   StrTy = Context.getConstantArrayType(StrTy,
-                                   llvm::APInt(32, Literal.GetStringLength()+1),
+                                 llvm::APInt(32, Literal.GetNumStringChars()+1),
                                        ArrayType::Normal, 0);
   
   // Pass &StringTokLocs[0], StringTokLocs.size() to factory!