]> granicus.if.org Git - clang/commitdiff
fix some sema problems with wide strings and hook up basic codegen for them.
authorChris Lattner <sabre@nondot.org>
Thu, 26 Feb 2009 23:01:51 +0000 (23:01 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 26 Feb 2009 23:01:51 +0000 (23:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65582 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/LiteralSupport.h
lib/CodeGen/CodeGenModule.cpp
lib/Lex/LiteralSupport.cpp
lib/Sema/SemaExpr.cpp
test/CodeGen/string-literal.c
test/CodeGen/unsupported.c [deleted file]

index 82a1f14ad871e6b70a9fb5a337e46c138aa166bf..13da783312fd08a5fd036d43c9debcdde2aa5b5c 100644 (file)
@@ -155,8 +155,13 @@ public:
   bool Pascal;
   
   const char *GetString() { return &ResultBuf[0]; }
-  unsigned GetStringLength() { return ResultPtr-&ResultBuf[0]; }
-  
+  unsigned GetStringLength() const { return ResultPtr-&ResultBuf[0]; }
+
+  unsigned GetNumStringChars() const {
+    if (AnyWide)
+      return GetStringLength() / wchar_tByteWidth;
+    return GetStringLength();
+  }  
   /// getOffsetOfStringByte - This function returns the offset of the
   /// specified byte of the string data represented by Token.  This handles
   /// advancing over escape sequences in the string.
index 95490df46ba98e58afb657c045cdcdc1ab15fd15..75a8302792aec76dfc5f45d0505f4bc83687784e 100644 (file)
@@ -1069,11 +1069,6 @@ GetAddrOfConstantCFString(const std::string &str) {
 /// 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 @@ std::string CodeGenModule::GetStringForStringLiteral(const StringLiteral *E) {
     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;
index 9815f9b91e7b9015f620250c77c2453ba3fe04ba..c20383f0313312cc1a490ca711b4519cd44cc557 100644 (file)
@@ -672,8 +672,7 @@ StringLiteralParser(const Token *StringToks, unsigned NumStringToks,
     // 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 @@ StringLiteralParser(const Token *StringToks, unsigned NumStringToks,
     }
   }
   
-  // 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;
 
index eec27cee837cf5b05447a6a5b132eb8192ac786c..01be6b2474c945c849bf18db4110c07aeeab12ce 100644 (file)
@@ -400,7 +400,7 @@ Sema::ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks) {
   // 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!
index 104477ee12ea2b8d7db6535b5c28c72e745d5dc5..ea28f1a7cbc795563506014305da37c285276e4d 100644 (file)
@@ -2,4 +2,6 @@
 
 int main() {
   char a[10] = "abc";
+
+  void *foo = L"AB";
 }
diff --git a/test/CodeGen/unsupported.c b/test/CodeGen/unsupported.c
deleted file mode 100644 (file)
index c11f1d1..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-// RUN: clang -verify -emit-llvm -o - %s 
-
-void *x = L"foo"; // expected-error {{cannot compile this wide string yet}}