[cfe-commits] r65582 - in /cfe/trunk: 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

Chris Lattner sabre at nondot.org
Thu Feb 26 15:01:52 PST 2009


Author: lattner
Date: Thu Feb 26 17:01:51 2009
New Revision: 65582

URL: http://llvm.org/viewvc/llvm-project?rev=65582&view=rev
Log:
fix some sema problems with wide strings and hook up basic codegen for them.

Removed:
    cfe/trunk/test/CodeGen/unsupported.c
Modified:
    cfe/trunk/include/clang/Lex/LiteralSupport.h
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/Lex/LiteralSupport.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/CodeGen/string-literal.c

Modified: cfe/trunk/include/clang/Lex/LiteralSupport.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/LiteralSupport.h?rev=65582&r1=65581&r2=65582&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/LiteralSupport.h (original)
+++ cfe/trunk/include/clang/Lex/LiteralSupport.h Thu Feb 26 17:01:51 2009
@@ -155,8 +155,13 @@
   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.

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=65582&r1=65581&r2=65582&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Feb 26 17:01:51 2009
@@ -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;

Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=65582&r1=65581&r2=65582&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Thu Feb 26 17:01:51 2009
@@ -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;
 

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=65582&r1=65581&r2=65582&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Feb 26 17:01:51 2009
@@ -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!

Modified: cfe/trunk/test/CodeGen/string-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/string-literal.c?rev=65582&r1=65581&r2=65582&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/string-literal.c (original)
+++ cfe/trunk/test/CodeGen/string-literal.c Thu Feb 26 17:01:51 2009
@@ -2,4 +2,6 @@
 
 int main() {
   char a[10] = "abc";
+
+  void *foo = L"AB";
 }

Removed: cfe/trunk/test/CodeGen/unsupported.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/unsupported.c?rev=65581&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/unsupported.c (original)
+++ cfe/trunk/test/CodeGen/unsupported.c (removed)
@@ -1,3 +0,0 @@
-// RUN: clang -verify -emit-llvm -o - %s 
-
-void *x = L"foo"; // expected-error {{cannot compile this wide string yet}}





More information about the cfe-commits mailing list