<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Feb 4, 2012, at 10:03 PM, Chad Rosier wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Chris,<div>This commit is causing our llvm-gcc build bot to fail at stage 1.</div></div></blockquote><div><br></div>Yep, llvm-gcc is dead.</div><div><br></div><div>-Chris</div><div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><span class="Apple-style-span" style="color: rgb(255, 0, 0); font-family: 'Courier New', courier, monotype; white-space: pre; "><br></span></div><div><span class="Apple-style-span" style="color: rgb(255, 0, 0); font-family: 'Courier New', courier, monotype; white-space: pre; ">../../llvm-gcc.src/gcc/llvm-backend.cpp: In function 'void readLLVMValues()':</span></div><div><span class="Apple-style-span" style="font-family: Times; "><pre style="font-family: 'Courier New', courier, monotype; "><span class="stderr" style="font-family: 'Courier New', courier, monotype; color: red; ">../../llvm-gcc.src/gcc/llvm-backend.cpp:282: error: 'class llvm::ConstantArray' has no member named 'getAsString'
../../llvm-gcc.src/gcc/llvm-backend.cpp: In function 'llvm::Constant* ConvertMetadataStringToGV(const char*)':
../../llvm-gcc.src/gcc/llvm-backend.cpp:1302: error: no matching function for call to 'llvm::ConstantArray::get(llvm::LLVMContext&, std::string)'
/Users/buildslave/zorg/buildbot/smooshlab/slave-0.8/build.llvm-gcc-i386-darwin9-RA/llvm.src/include/llvm/Constants.h:353: note: candidates are: static llvm::Constant* llvm::ConstantArray::get(llvm::ArrayType*, llvm::ArrayRef<llvm::Constant*>)</span></pre></span></div><div> Chad</div><div><br><div><div>On Feb 4, 2012, at 6:29 PM, Chris Lattner wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Author: lattner<br>Date: Sat Feb  4 20:29:43 2012<br>New Revision: 149800<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=149800&view=rev">http://llvm.org/viewvc/llvm-project?rev=149800&view=rev</a><br>Log:<br>reapply the patches reverted in r149470 that reenable ConstantDataArray,<br>but with a critical fix to the SelectionDAG code that optimizes copies<br>from strings into immediate stores: the previous code was stopping reading<br>string data at the first nul.  Address this by adding a new argument to<br>llvm::getConstantStringInfo, preserving the behavior before the patch.<br><br><br>Modified:<br>    llvm/trunk/include/llvm/Analysis/ValueTracking.h<br>    llvm/trunk/include/llvm/Constants.h<br>    llvm/trunk/lib/Analysis/ConstantFolding.cpp<br>    llvm/trunk/lib/Analysis/ValueTracking.cpp<br>    llvm/trunk/lib/AsmParser/LLParser.cpp<br>    llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp<br>    llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp<br>    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp<br>    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp<br>    llvm/trunk/lib/Target/CBackend/CBackend.cpp<br>    llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp<br>    llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp<br>    llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp<br>    llvm/trunk/lib/VMCore/AsmWriter.cpp<br>    llvm/trunk/lib/VMCore/Constants.cpp<br>    llvm/trunk/lib/VMCore/Core.cpp<br>    llvm/trunk/lib/VMCore/IRBuilder.cpp<br>    llvm/trunk/tools/bugpoint/Miscompilation.cpp<br>    llvm/trunk/tools/lto/LTOModule.cpp<br><br>Modified: llvm/trunk/include/llvm/Analysis/ValueTracking.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ValueTracking.h?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ValueTracking.h?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/include/llvm/Analysis/ValueTracking.h (original)<br>+++ llvm/trunk/include/llvm/Analysis/ValueTracking.h Sat Feb  4 20:29:43 2012<br>@@ -17,14 +17,13 @@<br><br> #include "llvm/ADT/ArrayRef.h"<br> #include "llvm/Support/DataTypes.h"<br>-#include <string><br><br> namespace llvm {<br>-  template <typename T> class SmallVectorImpl;<br>   class Value;<br>   class Instruction;<br>   class APInt;<br>   class TargetData;<br>+  class StringRef;<br><br>   /// ComputeMaskedBits - Determine which of the bits specified in Mask are<br>   /// known to be either zero or one and return them in the KnownZero/KnownOne<br>@@ -125,16 +124,15 @@<br>     return GetPointerBaseWithConstantOffset(const_cast<Value*>(Ptr), Offset,TD);<br>   }<br><br>-  /// GetConstantStringInfo - This function computes the length of a<br>+  /// getConstantStringInfo - This function computes the length of a<br>   /// null-terminated C string pointed to by V.  If successful, it returns true<br>-  /// and returns the string in Str.  If unsuccessful, it returns false.  If<br>-  /// StopAtNul is set to true (the default), the returned string is truncated<br>-  /// by a nul character in the global.  If StopAtNul is false, the nul<br>-  /// character is included in the result string.<br>-  bool GetConstantStringInfo(const Value *V, std::string &Str,<br>-                             uint64_t Offset = 0,<br>-                             bool StopAtNul = true);<br>-                        <br>+  /// and returns the string in Str.  If unsuccessful, it returns false.  This<br>+  /// does not include the trailing nul character by default.  If TrimAtNul is<br>+  /// set to false, then this returns any trailing nul characters as well as any<br>+  /// other characters that come after it.<br>+  bool getConstantStringInfo(const Value *V, StringRef &Str,<br>+                             uint64_t Offset = 0, bool TrimAtNul = true);<br>+<br>   /// GetStringLength - If we can compute the length of the string pointed to by<br>   /// the specified pointer, return 'len+1'.  If we can't, return 0.<br>   uint64_t GetStringLength(Value *V);<br><br>Modified: llvm/trunk/include/llvm/Constants.h<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constants.h?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constants.h?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/include/llvm/Constants.h (original)<br>+++ llvm/trunk/include/llvm/Constants.h Sat Feb  4 20:29:43 2012<br>@@ -352,17 +352,6 @@<br>   // ConstantArray accessors<br>   static Constant *get(ArrayType *T, ArrayRef<Constant*> V);<br><br>-  /// This method constructs a ConstantArray and initializes it with a text<br>-  /// string. The default behavior (AddNull==true) causes a null terminator to<br>-  /// be placed at the end of the array. This effectively increases the length<br>-  /// of the array by one (you've been warned).  However, in some situations <br>-  /// this is not desired so if AddNull==false then the string is copied without<br>-  /// null termination.<br>-  <br>-  // FIXME Remove this.<br>-  static Constant *get(LLVMContext &Context, StringRef Initializer,<br>-                       bool AddNull = true);<br>-  <br>   /// Transparently provide more efficient getOperand methods.<br>   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);<br><br>@@ -373,31 +362,6 @@<br>     return reinterpret_cast<ArrayType*>(Value::getType());<br>   }<br><br>-  // FIXME: String methods will eventually be removed.<br>-  <br>-  <br>-  /// isString - This method returns true if the array is an array of i8 and<br>-  /// the elements of the array are all ConstantInt's.<br>-  bool isString() const;<br>-<br>-  /// isCString - This method returns true if the array is a string (see<br>-  /// @verbatim<br>-  /// isString) and it ends in a null byte \0 and does not contains any other<br>-  /// @endverbatim<br>-  /// null bytes except its terminator.<br>-  bool isCString() const;<br>-<br>-  /// getAsString - If this array is isString(), then this method converts the<br>-  /// array to an std::string and returns it.  Otherwise, it asserts out.<br>-  ///<br>-  std::string getAsString() const;<br>-<br>-  /// getAsCString - If this array is isCString(), then this method converts the<br>-  /// array (without the trailing null byte) to an std::string and returns it.<br>-  /// Otherwise, it asserts out.<br>-  ///<br>-  std::string getAsCString() const;<br>-<br>   virtual void destroyConstant();<br>   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);<br><br><br>Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)<br>+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Sat Feb  4 20:29:43 2012<br>@@ -476,9 +476,9 @@<br><br>   // Instead of loading constant c string, use corresponding integer value<br>   // directly if string length is small enough.<br>-  std::string Str;<br>-  if (TD && GetConstantStringInfo(CE, Str) && !Str.empty()) {<br>-    unsigned StrLen = Str.length();<br>+  StringRef Str;<br>+  if (TD && getConstantStringInfo(CE, Str) && !Str.empty()) {<br>+    unsigned StrLen = Str.size();<br>     Type *Ty = cast<PointerType>(CE->getType())->getElementType();<br>     unsigned NumBits = Ty->getPrimitiveSizeInBits();<br>     // Replace load with immediate integer if the result is an integer or fp<br><br>Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)<br>+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Sat Feb  4 20:29:43 2012<br>@@ -1369,25 +1369,21 @@<br>     }<br>   }<br><br>-  // A ConstantArray is splatable if all its members are equal and also<br>-  // splatable.<br>-  if (ConstantArray *CA = dyn_cast<ConstantArray>(V)) {<br>-    if (CA->getNumOperands() == 0)<br>-      return 0;<br>-    <br>-    Value *Val = isBytewiseValue(CA->getOperand(0));<br>+  // A ConstantDataArray/Vector is splatable if all its members are equal and<br>+  // also splatable.<br>+  if (ConstantDataSequential *CA = dyn_cast<ConstantDataSequential>(V)) {<br>+    Value *Elt = CA->getElementAsConstant(0);<br>+    Value *Val = isBytewiseValue(Elt);<br>     if (!Val)<br>       return 0;<br><br>-    for (unsigned I = 1, E = CA->getNumOperands(); I != E; ++I)<br>-      if (CA->getOperand(I-1) != CA->getOperand(I))<br>+    for (unsigned I = 1, E = CA->getNumElements(); I != E; ++I)<br>+      if (CA->getElementAsConstant(I) != Elt)<br>         return 0;<br><br>     return Val;<br>   }<br><br>-  // FIXME: Vector types (e.g., <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>).<br>-  <br>   // Conceptually, we could handle things like:<br>   //   %a = zext i8 %X to i16<br>   //   %b = shl i16 %a, 8<br>@@ -1607,33 +1603,19 @@<br> }<br><br><br>-/// GetConstantStringInfo - This function computes the length of a<br>+/// getConstantStringInfo - This function computes the length of a<br> /// null-terminated C string pointed to by V.  If successful, it returns true<br> /// and returns the string in Str.  If unsuccessful, it returns false.<br>-bool llvm::GetConstantStringInfo(const Value *V, std::string &Str,<br>-                                 uint64_t Offset, bool StopAtNul) {<br>-  // If V is NULL then return false;<br>-  if (V == NULL) return false;<br>-<br>-  // Look through bitcast instructions.<br>-  if (const BitCastInst *BCI = dyn_cast<BitCastInst>(V))<br>-    return GetConstantStringInfo(BCI->getOperand(0), Str, Offset, StopAtNul);<br>-  <br>-  // If the value is not a GEP instruction nor a constant expression with a<br>-  // GEP instruction, then return false because ConstantArray can't occur<br>-  // any other way.<br>-  const User *GEP = 0;<br>-  if (const GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(V)) {<br>-    GEP = GEPI;<br>-  } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {<br>-    if (CE->getOpcode() == Instruction::BitCast)<br>-      return GetConstantStringInfo(CE->getOperand(0), Str, Offset, StopAtNul);<br>-    if (CE->getOpcode() != Instruction::GetElementPtr)<br>-      return false;<br>-    GEP = CE;<br>-  }<br>-  <br>-  if (GEP) {<br>+bool llvm::getConstantStringInfo(const Value *V, StringRef &Str,<br>+                                 uint64_t Offset, bool TrimAtNul) {<br>+  assert(V);<br>+<br>+  // Look through bitcast instructions and geps.<br>+  V = V->stripPointerCasts();<br>+  <br>+  // If the value is a GEP instructionor  constant expression, treat it as an<br>+  // offset.<br>+  if (const GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {<br>     // Make sure the GEP has exactly three arguments.<br>     if (GEP->getNumOperands() != 3)<br>       return false;<br>@@ -1658,51 +1640,48 @@<br>       StartIdx = CI->getZExtValue();<br>     else<br>       return false;<br>-    return GetConstantStringInfo(GEP->getOperand(0), Str, StartIdx+Offset,<br>-                                 StopAtNul);<br>+    return getConstantStringInfo(GEP->getOperand(0), Str, StartIdx+Offset);<br>   }<br><br>   // The GEP instruction, constant or instruction, must reference a global<br>   // variable that is a constant and is initialized. The referenced constant<br>   // initializer is the array that we'll use for optimization.<br>-  const GlobalVariable* GV = dyn_cast<GlobalVariable>(V);<br>+  const GlobalVariable *GV = dyn_cast<GlobalVariable>(V);<br>   if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer())<br>     return false;<br>-  const Constant *GlobalInit = GV->getInitializer();<br>-  <br>+<br>   // Handle the all-zeros case<br>-  if (GlobalInit->isNullValue()) {<br>+  if (GV->getInitializer()->isNullValue()) {<br>     // This is a degenerate case. The initializer is constant zero so the<br>     // length of the string must be zero.<br>-    Str.clear();<br>+    Str = "";<br>     return true;<br>   }<br><br>   // Must be a Constant Array<br>-  const ConstantArray *Array = dyn_cast<ConstantArray>(GlobalInit);<br>-  if (Array == 0 || !Array->getType()->getElementType()->isIntegerTy(8))<br>+  const ConstantDataArray *Array =<br>+    dyn_cast<ConstantDataArray>(GV->getInitializer());<br>+  if (Array == 0 || !Array->isString())<br>     return false;<br><br>   // Get the number of elements in the array<br>-  uint64_t NumElts = Array->getType()->getNumElements();<br>-  <br>+  uint64_t NumElts = Array->getType()->getArrayNumElements();<br>+<br>+  // Start out with the entire array in the StringRef.<br>+  Str = Array->getAsString();<br>+<br>   if (Offset > NumElts)<br>     return false;<br><br>-  // Traverse the constant array from 'Offset' which is the place the GEP refers<br>-  // to in the array.<br>-  Str.reserve(NumElts-Offset);<br>-  for (unsigned i = Offset; i != NumElts; ++i) {<br>-    const Constant *Elt = Array->getOperand(i);<br>-    const ConstantInt *CI = dyn_cast<ConstantInt>(Elt);<br>-    if (!CI) // This array isn't suitable, non-int initializer.<br>-      return false;<br>-    if (StopAtNul && CI->isZero())<br>-      return true; // we found end of string, success!<br>-    Str += (char)CI->getZExtValue();<br>-  }<br>+  // Skip over 'offset' bytes.<br>+  Str = Str.substr(Offset);<br><br>-  // The array isn't null terminated, but maybe this is a memcpy, not a strcpy.<br>+  if (TrimAtNul) {<br>+    // Trim off the \0 and anything after it.  If the array is not nul<br>+    // terminated, we just return the whole end of string.  The client may know<br>+    // some other way that the string is length-bound.<br>+    Str = Str.substr(0, Str.find('\0'));<br>+  }<br>   return true;<br> }<br><br>@@ -1714,8 +1693,7 @@<br> /// the specified pointer, return 'len+1'.  If we can't, return 0.<br> static uint64_t GetStringLengthH(Value *V, SmallPtrSet<PHINode*, 32> &PHIs) {<br>   // Look through noop bitcast instructions.<br>-  if (BitCastInst *BCI = dyn_cast<BitCastInst>(V))<br>-    return GetStringLengthH(BCI->getOperand(0), PHIs);<br>+  V = V->stripPointerCasts();<br><br>   // If this is a PHI node, there are two cases: either we have already seen it<br>   // or we haven't.<br>@@ -1751,83 +1729,13 @@<br>     if (Len1 != Len2) return 0;<br>     return Len1;<br>   }<br>-<br>-  // As a special-case, "@string = constant i8 0" is also a string with zero<br>-  // length, not wrapped in a bitcast or GEP.<br>-  if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {<br>-    if (GV->isConstant() && GV->hasDefinitiveInitializer())<br>-      if (GV->getInitializer()->isNullValue()) return 1;<br>-    return 0;<br>-  }<br>-<br>-  // If the value is not a GEP instruction nor a constant expression with a<br>-  // GEP instruction, then return unknown.<br>-  User *GEP = 0;<br>-  if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(V)) {<br>-    GEP = GEPI;<br>-  } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {<br>-    if (CE->getOpcode() != Instruction::GetElementPtr)<br>-      return 0;<br>-    GEP = CE;<br>-  } else {<br>-    return 0;<br>-  }<br>-<br>-  // Make sure the GEP has exactly three arguments.<br>-  if (GEP->getNumOperands() != 3)<br>-    return 0;<br>-<br>-  // Check to make sure that the first operand of the GEP is an integer and<br>-  // has value 0 so that we are sure we're indexing into the initializer.<br>-  if (ConstantInt *Idx = dyn_cast<ConstantInt>(GEP->getOperand(1))) {<br>-    if (!Idx->isZero())<br>-      return 0;<br>-  } else<br>-    return 0;<br>-<br>-  // If the second index isn't a ConstantInt, then this is a variable index<br>-  // into the array.  If this occurs, we can't say anything meaningful about<br>-  // the string.<br>-  uint64_t StartIdx = 0;<br>-  if (ConstantInt *CI = dyn_cast<ConstantInt>(GEP->getOperand(2)))<br>-    StartIdx = CI->getZExtValue();<br>-  else<br>-    return 0;<br>-<br>-  // The GEP instruction, constant or instruction, must reference a global<br>-  // variable that is a constant and is initialized. The referenced constant<br>-  // initializer is the array that we'll use for optimization.<br>-  GlobalVariable* GV = dyn_cast<GlobalVariable>(GEP->getOperand(0));<br>-  if (!GV || !GV->isConstant() || !GV->hasInitializer() ||<br>-      GV->mayBeOverridden())<br>+  <br>+  // Otherwise, see if we can read the string.<br>+  StringRef StrData;<br>+  if (!getConstantStringInfo(V, StrData))<br>     return 0;<br>-  Constant *GlobalInit = GV->getInitializer();<br>-<br>-  // Handle the ConstantAggregateZero case, which is a degenerate case. The<br>-  // initializer is constant zero so the length of the string must be zero.<br>-  if (isa<ConstantAggregateZero>(GlobalInit))<br>-    return 1;  // Len = 0 offset by 1.<br>-<br>-  // Must be a Constant Array<br>-  ConstantArray *Array = dyn_cast<ConstantArray>(GlobalInit);<br>-  if (!Array || !Array->getType()->getElementType()->isIntegerTy(8))<br>-    return false;<br>-<br>-  // Get the number of elements in the array<br>-  uint64_t NumElts = Array->getType()->getNumElements();<br>-<br>-  // Traverse the constant array from StartIdx (derived above) which is<br>-  // the place the GEP refers to in the array.<br>-  for (unsigned i = StartIdx; i != NumElts; ++i) {<br>-    Constant *Elt = Array->getOperand(i);<br>-    ConstantInt *CI = dyn_cast<ConstantInt>(Elt);<br>-    if (!CI) // This array isn't suitable, non-int initializer.<br>-      return 0;<br>-    if (CI->isZero())<br>-      return i-StartIdx+1; // We found end of string, success!<br>-  }<br><br>-  return 0; // The array isn't null terminated, conservatively return 'unknown'.<br>+  return StrData.size()+1;<br> }<br><br> /// GetStringLength - If we can compute the length of the string pointed to by<br><br>Modified: llvm/trunk/lib/AsmParser/LLParser.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)<br>+++ llvm/trunk/lib/AsmParser/LLParser.cpp Sat Feb  4 20:29:43 2012<br>@@ -2018,7 +2018,8 @@<br>   }<br>   case lltok::kw_c:  // c "foo"<br>     Lex.Lex();<br>-    ID.ConstantVal = ConstantArray::get(Context, Lex.getStrVal(), false);<br>+    ID.ConstantVal = ConstantDataArray::getString(Context, Lex.getStrVal(),<br>+                                                  false);<br>     if (ParseToken(lltok::StringConstant, "expected string")) return true;<br>     ID.Kind = ValID::t_Constant;<br>     return false;<br><br>Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)<br>+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Sat Feb  4 20:29:43 2012<br>@@ -845,32 +845,6 @@<br>       } else {<br>         assert (0 && "Unknown FP type!");<br>       }<br>-    } else if (isa<ConstantArray>(C) && cast<ConstantArray>(C)->isString()) {<br>-      const ConstantArray *CA = cast<ConstantArray>(C);<br>-      // Emit constant strings specially.<br>-      unsigned NumOps = CA->getNumOperands();<br>-      // If this is a null-terminated string, use the denser CSTRING encoding.<br>-      if (CA->getOperand(NumOps-1)->isNullValue()) {<br>-        Code = bitc::CST_CODE_CSTRING;<br>-        --NumOps;  // Don't encode the null, which isn't allowed by char6.<br>-      } else {<br>-        Code = bitc::CST_CODE_STRING;<br>-        AbbrevToUse = String8Abbrev;<br>-      }<br>-      bool isCStr7 = Code == bitc::CST_CODE_CSTRING;<br>-      bool isCStrChar6 = Code == bitc::CST_CODE_CSTRING;<br>-      for (unsigned i = 0; i != NumOps; ++i) {<br>-        unsigned char V = cast<ConstantInt>(CA->getOperand(i))->getZExtValue();<br>-        Record.push_back(V);<br>-        isCStr7 &= (V & 128) == 0;<br>-        if (isCStrChar6)<br>-          isCStrChar6 = BitCodeAbbrevOp::isChar6(V);<br>-      }<br>-<br>-      if (isCStrChar6)<br>-        AbbrevToUse = CString6Abbrev;<br>-      else if (isCStr7)<br>-        AbbrevToUse = CString7Abbrev;<br>     } else if (isa<ConstantDataSequential>(C) &&<br>                cast<ConstantDataSequential>(C)->isString()) {<br>       const ConstantDataSequential *Str = cast<ConstantDataSequential>(C);<br><br>Modified: llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp (original)<br>+++ llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp Sat Feb  4 20:29:43 2012<br>@@ -321,10 +321,6 @@<br>   if (const Constant *C = dyn_cast<Constant>(V)) {<br>     if (isa<GlobalValue>(C)) {<br>       // Initializers for globals are handled explicitly elsewhere.<br>-    } else if (isa<ConstantArray>(C) && cast<ConstantArray>(C)->isString()) {<br>-      // Do not enumerate the initializers for an array of simple characters.<br>-      // The initializers just pollute the value table, and we emit the strings<br>-      // specially.<br>     } else if (C->getNumOperands()) {<br>       // If a constant has operands, enumerate them.  This makes sure that if a<br>       // constant has uses (for example an array of const ints), that they are<br><br>Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)<br>+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Sat Feb  4 20:29:43 2012<br>@@ -1684,31 +1684,18 @@<br><br> static void EmitGlobalConstantArray(const ConstantArray *CA, unsigned AddrSpace,<br>                                     AsmPrinter &AP) {<br>-  if (AddrSpace != 0 || !CA->isString()) {<br>-    // Not a string.  Print the values in successive locations.<br>-<br>-    // See if we can aggregate some values.  Make sure it can be<br>-    // represented as a series of bytes of the constant value.<br>-    int Value = isRepeatedByteSequence(CA, AP.TM);<br>-<br>-    if (Value != -1) {<br>-      uint64_t Bytes = AP.TM.getTargetData()->getTypeAllocSize(CA->getType());<br>-      AP.OutStreamer.EmitFill(Bytes, Value, AddrSpace);<br>-    }<br>-    else {<br>-      for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i)<br>-        EmitGlobalConstantImpl(CA->getOperand(i), AddrSpace, AP);<br>-    }<br>-    return;<br>+  // See if we can aggregate some values.  Make sure it can be<br>+  // represented as a series of bytes of the constant value.<br>+  int Value = isRepeatedByteSequence(CA, AP.TM);<br>+<br>+  if (Value != -1) {<br>+    uint64_t Bytes = AP.TM.getTargetData()->getTypeAllocSize(CA->getType());<br>+    AP.OutStreamer.EmitFill(Bytes, Value, AddrSpace);<br>+  }<br>+  else {<br>+    for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i)<br>+      EmitGlobalConstantImpl(CA->getOperand(i), AddrSpace, AP);<br>   }<br>-<br>-  // Otherwise, it can be emitted as .ascii.<br>-  SmallVector<char, 128> TmpVec;<br>-  TmpVec.reserve(CA->getNumOperands());<br>-  for (unsigned i = 0, e = CA->getNumOperands(); i != e; ++i)<br>-    TmpVec.push_back(cast<ConstantInt>(CA->getOperand(i))->getZExtValue());<br>-<br>-  AP.OutStreamer.EmitBytes(StringRef(TmpVec.data(), TmpVec.size()), AddrSpace);<br> }<br><br> static void EmitGlobalConstantVector(const ConstantVector *CV,<br><br>Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)<br>+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Sat Feb  4 20:29:43 2012<br>@@ -3298,8 +3298,7 @@<br> /// used when a memcpy is turned into a memset when the source is a constant<br> /// string ptr.<br> static SDValue getMemsetStringVal(EVT VT, DebugLoc dl, SelectionDAG &DAG,<br>-                                  const TargetLowering &TLI,<br>-                                  std::string &Str, unsigned Offset) {<br>+                                  const TargetLowering &TLI, StringRef Str) {<br>   // Handle vector with all elements zero.<br>   if (Str.empty()) {<br>     if (VT.isInteger())<br>@@ -3317,15 +3316,18 @@<br>   }<br><br>   assert(!VT.isVector() && "Can't handle vector type here!");<br>-  unsigned NumBits = VT.getSizeInBits();<br>-  unsigned MSB = NumBits / 8;<br>+  unsigned NumVTBytes = VT.getSizeInBits() / 8;<br>+  unsigned NumBytes = std::min(NumVTBytes, unsigned(Str.size()));<br>+<br>   uint64_t Val = 0;<br>-  if (TLI.isLittleEndian())<br>-    Offset = Offset + MSB - 1;<br>-  for (unsigned i = 0; i != MSB; ++i) {<br>-    Val = (Val << 8) | (unsigned char)Str[Offset];<br>-    Offset += TLI.isLittleEndian() ? -1 : 1;<br>+  if (TLI.isLittleEndian()) {<br>+    for (unsigned i = 0; i != NumBytes; ++i)<br>+      Val |= (uint64_t)(unsigned char)Str[i] << i*8;<br>+  } else {<br>+    for (unsigned i = 0; i != NumBytes; ++i)<br>+      Val |= (uint64_t)(unsigned char)Str[i] << (NumVTBytes-i-1)*8;<br>   }<br>+<br>   return DAG.getConstant(Val, VT);<br> }<br><br>@@ -3340,7 +3342,7 @@<br><br> /// isMemSrcFromString - Returns true if memcpy source is a string constant.<br> ///<br>-static bool isMemSrcFromString(SDValue Src, std::string &Str) {<br>+static bool isMemSrcFromString(SDValue Src, StringRef &Str) {<br>   unsigned SrcDelta = 0;<br>   GlobalAddressSDNode *G = NULL;<br>   if (Src.getOpcode() == ISD::GlobalAddress)<br>@@ -3354,11 +3356,7 @@<br>   if (!G)<br>     return false;<br><br>-  const GlobalVariable *GV = dyn_cast<GlobalVariable>(G->getGlobal());<br>-  if (GV && GetConstantStringInfo(GV, Str, SrcDelta, false))<br>-    return true;<br>-<br>-  return false;<br>+  return getConstantStringInfo(G->getGlobal(), Str, SrcDelta, false);<br> }<br><br> /// FindOptimalMemOpLowering - Determines the optimial series memory ops<br>@@ -3461,7 +3459,7 @@<br>   unsigned SrcAlign = DAG.InferPtrAlignment(Src);<br>   if (Align > SrcAlign)<br>     SrcAlign = Align;<br>-  std::string Str;<br>+  StringRef Str;<br>   bool CopyFromStr = isMemSrcFromString(Src, Str);<br>   bool isZeroStr = CopyFromStr && Str.empty();<br>   unsigned Limit = AlwaysInline ? ~0U : TLI.getMaxStoresPerMemcpy(OptSize);<br>@@ -3498,7 +3496,7 @@<br>       // We only handle zero vectors here.<br>       // FIXME: Handle other cases where store of vector immediate is done in<br>       // a single instruction.<br>-      Value = getMemsetStringVal(VT, dl, DAG, TLI, Str, SrcOff);<br>+      Value = getMemsetStringVal(VT, dl, DAG, TLI, Str.substr(SrcOff));<br>       Store = DAG.getStore(Chain, dl, Value,<br>                            getMemBasePlusOffset(Dst, DstOff, DAG),<br>                            DstPtrInfo.getWithOffset(DstOff), isVol,<br><br>Modified: llvm/trunk/lib/Target/CBackend/CBackend.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CBackend/CBackend.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CBackend/CBackend.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Target/CBackend/CBackend.cpp (original)<br>+++ llvm/trunk/lib/Target/CBackend/CBackend.cpp Sat Feb  4 20:29:43 2012<br>@@ -558,73 +558,21 @@<br> }<br><br> void CWriter::printConstantArray(ConstantArray *CPA, bool Static) {<br>-  // As a special case, print the array as a string if it is an array of<br>-  // ubytes or an array of sbytes with positive values.<br>-  //<br>-  if (CPA->isCString()) {<br>-    Out << '\"';<br>-    // Keep track of whether the last number was a hexadecimal escape.<br>-    bool LastWasHex = false;<br>-<br>-    // Do not include the last character, which we know is null<br>-    for (unsigned i = 0, e = CPA->getNumOperands()-1; i != e; ++i) {<br>-      unsigned char C = cast<ConstantInt>(CPA->getOperand(i))->getZExtValue();<br>-<br>-      // Print it out literally if it is a printable character.  The only thing<br>-      // to be careful about is when the last letter output was a hex escape<br>-      // code, in which case we have to be careful not to print out hex digits<br>-      // explicitly (the C compiler thinks it is a continuation of the previous<br>-      // character, sheesh...)<br>-      //<br>-      if (isprint(C) && (!LastWasHex || !isxdigit(C))) {<br>-        LastWasHex = false;<br>-        if (C == '"' || C == '\\')<br>-          Out << "\\" << (char)C;<br>-        else<br>-          Out << (char)C;<br>-      } else {<br>-        LastWasHex = false;<br>-        switch (C) {<br>-        case '\n': Out << "<a href="smb://n">\\n</a>"; break;<br>-        case '\t': Out << "<a href="smb://t">\\t</a>"; break;<br>-        case '\r': Out << "<a href="smb://r">\\r</a>"; break;<br>-        case '\v': Out << "<a href="smb://v">\\v</a>"; break;<br>-        case '\a': Out << "<a href="smb://a">\\a</a>"; break;<br>-        case '\"': Out << "\\\""; break;<br>-        case '\'': Out << "\\\'"; break;<br>-        default:<br>-          Out << "<a href="smb://x">\\x</a>";<br>-          Out << (char)(( C/16  < 10) ? ( C/16 +'0') : ( C/16 -10+'A'));<br>-          Out << (char)(((C&15) < 10) ? ((C&15)+'0') : ((C&15)-10+'A'));<br>-          LastWasHex = true;<br>-          break;<br>-        }<br>-      }<br>-    }<br>-    Out << '\"';<br>-  } else {<br>-    Out << '{';<br>-    if (CPA->getNumOperands()) {<br>-      Out << ' ';<br>-      printConstant(cast<Constant>(CPA->getOperand(0)), Static);<br>-      for (unsigned i = 1, e = CPA->getNumOperands(); i != e; ++i) {<br>-        Out << ", ";<br>-        printConstant(cast<Constant>(CPA->getOperand(i)), Static);<br>-      }<br>-    }<br>-    Out << " }";<br>+  Out << "{ ";<br>+  printConstant(cast<Constant>(CPA->getOperand(0)), Static);<br>+  for (unsigned i = 1, e = CPA->getNumOperands(); i != e; ++i) {<br>+    Out << ", ";<br>+    printConstant(cast<Constant>(CPA->getOperand(i)), Static);<br>   }<br>+  Out << " }";<br> }<br><br> void CWriter::printConstantVector(ConstantVector *CP, bool Static) {<br>-  Out << '{';<br>-  if (CP->getNumOperands()) {<br>-    Out << ' ';<br>-    printConstant(cast<Constant>(CP->getOperand(0)), Static);<br>-    for (unsigned i = 1, e = CP->getNumOperands(); i != e; ++i) {<br>-      Out << ", ";<br>-      printConstant(cast<Constant>(CP->getOperand(i)), Static);<br>-    }<br>+  Out << "{ ";<br>+  printConstant(cast<Constant>(CP->getOperand(0)), Static);<br>+  for (unsigned i = 1, e = CP->getNumOperands(); i != e; ++i) {<br>+    Out << ", ";<br>+    printConstant(cast<Constant>(CP->getOperand(i)), Static);<br>   }<br>   Out << " }";<br> }<br><br>Modified: llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp (original)<br>+++ llvm/trunk/lib/Target/CppBackend/CPPBackend.cpp Sat Feb  4 20:29:43 2012<br>@@ -698,36 +698,17 @@<br>     printCFP(CFP);<br>     Out << ";";<br>   } else if (const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {<br>-    if (CA->isString()) {<br>-      Out << "Constant* " << constName <<<br>-             " = ConstantArray::get(mod->getContext(), \"";<br>-      std::string tmp = CA->getAsString();<br>-      bool nullTerminate = false;<br>-      if (tmp[tmp.length()-1] == 0) {<br>-        tmp.erase(tmp.length()-1);<br>-        nullTerminate = true;<br>-      }<br>-      printEscapedString(tmp);<br>-      // Determine if we want null termination or not.<br>-      if (nullTerminate)<br>-        Out << "\", true"; // Indicate that the null terminator should be<br>-                           // added.<br>-      else<br>-        Out << "\", false";// No null terminator<br>-      Out << ");";<br>-    } else {<br>-      Out << "std::vector<Constant*> " << constName << "_elems;";<br>+    Out << "std::vector<Constant*> " << constName << "_elems;";<br>+    nl(Out);<br>+    unsigned N = CA->getNumOperands();<br>+    for (unsigned i = 0; i < N; ++i) {<br>+      printConstant(CA->getOperand(i)); // recurse to print operands<br>+      Out << constName << "_elems.push_back("<br>+          << getCppName(CA->getOperand(i)) << ");";<br>       nl(Out);<br>-      unsigned N = CA->getNumOperands();<br>-      for (unsigned i = 0; i < N; ++i) {<br>-        printConstant(CA->getOperand(i)); // recurse to print operands<br>-        Out << constName << "_elems.push_back("<br>-            << getCppName(CA->getOperand(i)) << ");";<br>-        nl(Out);<br>-      }<br>-      Out << "Constant* " << constName << " = ConstantArray::get("<br>-          << typeName << ", " << constName << "_elems);";<br>     }<br>+    Out << "Constant* " << constName << " = ConstantArray::get("<br>+        << typeName << ", " << constName << "_elems);";<br>   } else if (const ConstantStruct *CS = dyn_cast<ConstantStruct>(CV)) {<br>     Out << "std::vector<Constant*> " << constName << "_fields;";<br>     nl(Out);<br>@@ -740,14 +721,14 @@<br>     }<br>     Out << "Constant* " << constName << " = ConstantStruct::get("<br>         << typeName << ", " << constName << "_fields);";<br>-  } else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {<br>+  } else if (const ConstantVector *CV = dyn_cast<ConstantVector>(CV)) {<br>     Out << "std::vector<Constant*> " << constName << "_elems;";<br>     nl(Out);<br>-    unsigned N = CP->getNumOperands();<br>+    unsigned N = CV->getNumOperands();<br>     for (unsigned i = 0; i < N; ++i) {<br>-      printConstant(CP->getOperand(i));<br>+      printConstant(CV->getOperand(i));<br>       Out << constName << "_elems.push_back("<br>-          << getCppName(CP->getOperand(i)) << ");";<br>+          << getCppName(CV->getOperand(i)) << ");";<br>       nl(Out);<br>     }<br>     Out << "Constant* " << constName << " = ConstantVector::get("<br>@@ -760,7 +741,7 @@<br>     if (CDS->isString()) {<br>       Out << "Constant *" << constName <<<br>       " = ConstantDataArray::getString(mod->getContext(), \"";<br>-      StringRef Str = CA->getAsString();<br>+      StringRef Str = CDS->getAsString();<br>       bool nullTerminate = false;<br>       if (Str.back() == 0) {<br>         Str = Str.drop_back();<br><br>Modified: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp (original)<br>+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Sat Feb  4 20:29:43 2012<br>@@ -213,7 +213,7 @@<br><br> // Create a constant for Str so that we can pass it to the run-time lib.<br> static GlobalVariable *createPrivateGlobalForString(Module &M, StringRef Str) {<br>-  Constant *StrConst = ConstantArray::get(M.getContext(), Str);<br>+  Constant *StrConst = ConstantDataArray::getString(M.getContext(), Str);<br>   return new GlobalVariable(M, StrConst->getType(), true,<br>                             GlobalValue::PrivateLinkage, StrConst, "");<br> }<br><br>Modified: llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp (original)<br>+++ llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp Sat Feb  4 20:29:43 2012<br>@@ -256,19 +256,18 @@<br>                         ConstantInt::get(TD->getIntPtrType(*Context), Len),<br>                         B, TD);<br>     }<br>-<br>+    <br>     // Otherwise, the character is a constant, see if the first argument is<br>     // a string literal.  If so, we can constant fold.<br>-    std::string Str;<br>-    if (!GetConstantStringInfo(SrcStr, Str))<br>+    StringRef Str;<br>+    if (!getConstantStringInfo(SrcStr, Str))<br>       return 0;<br><br>-    // strchr can find the nul character.<br>-    Str += '\0';<br>-<br>-    // Compute the offset.<br>-    size_t I = Str.find(CharC->getSExtValue());<br>-    if (I == std::string::npos) // Didn't find the char.  strchr returns null.<br>+    // Compute the offset, make sure to handle the case when we're searching for<br>+    // zero (a weird way to spell strlen).<br>+    size_t I = CharC->getSExtValue() == 0 ?<br>+        Str.size() : Str.find(CharC->getSExtValue());<br>+    if (I == StringRef::npos) // Didn't find the char.  strchr returns null.<br>       return Constant::getNullValue(CI->getType());<br><br>     // strchr(s+n,c)  -> gep(s+n+i,c)<br>@@ -296,20 +295,18 @@<br>     if (!CharC)<br>       return 0;<br><br>-    std::string Str;<br>-    if (!GetConstantStringInfo(SrcStr, Str)) {<br>+    StringRef Str;<br>+    if (!getConstantStringInfo(SrcStr, Str)) {<br>       // strrchr(s, 0) -> strchr(s, 0)<br>       if (TD && CharC->isZero())<br>         return EmitStrChr(SrcStr, '\0', B, TD);<br>       return 0;<br>     }<br><br>-    // strrchr can find the nul character.<br>-    Str += '\0';<br>-<br>     // Compute the offset.<br>-    size_t I = Str.rfind(CharC->getSExtValue());<br>-    if (I == std::string::npos) // Didn't find the char. Return null.<br>+    size_t I = CharC->getSExtValue() == 0 ?<br>+        Str.size() : Str.rfind(CharC->getSExtValue());<br>+    if (I == StringRef::npos) // Didn't find the char. Return null.<br>       return Constant::getNullValue(CI->getType());<br><br>     // strrchr(s+n,c) -> gep(s+n+i,c)<br>@@ -334,14 +331,13 @@<br>     if (Str1P == Str2P)      // strcmp(x,x)  -> 0<br>       return ConstantInt::get(CI->getType(), 0);<br><br>-    std::string Str1, Str2;<br>-    bool HasStr1 = GetConstantStringInfo(Str1P, Str1);<br>-    bool HasStr2 = GetConstantStringInfo(Str2P, Str2);<br>+    StringRef Str1, Str2;<br>+    bool HasStr1 = getConstantStringInfo(Str1P, Str1);<br>+    bool HasStr2 = getConstantStringInfo(Str2P, Str2);<br><br>     // strcmp(x, y)  -> cnst  (if both x and y are constant strings)<br>     if (HasStr1 && HasStr2)<br>-      return ConstantInt::get(CI->getType(),<br>-                              StringRef(Str1).compare(Str2));<br>+      return ConstantInt::get(CI->getType(), Str1.compare(Str2));<br><br>     if (HasStr1 && Str1.empty()) // strcmp("", x) -> -*x<br>       return B.CreateNeg(B.CreateZExt(B.CreateLoad(Str2P, "strcmpload"),<br>@@ -397,14 +393,14 @@<br>     if (TD && Length == 1) // strncmp(x,y,1) -> memcmp(x,y,1)<br>       return EmitMemCmp(Str1P, Str2P, CI->getArgOperand(2), B, TD);<br><br>-    std::string Str1, Str2;<br>-    bool HasStr1 = GetConstantStringInfo(Str1P, Str1);<br>-    bool HasStr2 = GetConstantStringInfo(Str2P, Str2);<br>+    StringRef Str1, Str2;<br>+    bool HasStr1 = getConstantStringInfo(Str1P, Str1);<br>+    bool HasStr2 = getConstantStringInfo(Str2P, Str2);<br><br>     // strncmp(x, y)  -> cnst  (if both x and y are constant strings)<br>     if (HasStr1 && HasStr2) {<br>-      StringRef SubStr1 = StringRef(Str1).substr(0, Length);<br>-      StringRef SubStr2 = StringRef(Str2).substr(0, Length);<br>+      StringRef SubStr1 = Str1.substr(0, Length);<br>+      StringRef SubStr2 = Str2.substr(0, Length);<br>       return ConstantInt::get(CI->getType(), SubStr1.compare(SubStr2));<br>     }<br><br>@@ -549,9 +545,9 @@<br>         FT->getReturnType() != FT->getParamType(0))<br>       return 0;<br><br>-    std::string S1, S2;<br>-    bool HasS1 = GetConstantStringInfo(CI->getArgOperand(0), S1);<br>-    bool HasS2 = GetConstantStringInfo(CI->getArgOperand(1), S2);<br>+    StringRef S1, S2;<br>+    bool HasS1 = getConstantStringInfo(CI->getArgOperand(0), S1);<br>+    bool HasS2 = getConstantStringInfo(CI->getArgOperand(1), S2);<br><br>     // strpbrk(s, "") -> NULL<br>     // strpbrk("", s) -> NULL<br>@@ -609,9 +605,9 @@<br>         !FT->getReturnType()->isIntegerTy())<br>       return 0;<br><br>-    std::string S1, S2;<br>-    bool HasS1 = GetConstantStringInfo(CI->getArgOperand(0), S1);<br>-    bool HasS2 = GetConstantStringInfo(CI->getArgOperand(1), S2);<br>+    StringRef S1, S2;<br>+    bool HasS1 = getConstantStringInfo(CI->getArgOperand(0), S1);<br>+    bool HasS2 = getConstantStringInfo(CI->getArgOperand(1), S2);<br><br>     // strspn(s, "") -> 0<br>     // strspn("", s) -> 0<br>@@ -619,8 +615,11 @@<br>       return Constant::getNullValue(CI->getType());<br><br>     // Constant folding.<br>-    if (HasS1 && HasS2)<br>-      return ConstantInt::get(CI->getType(), strspn(S1.c_str(), S2.c_str()));<br>+    if (HasS1 && HasS2) {<br>+      size_t Pos = S1.find_first_not_of(S2);<br>+      if (Pos == StringRef::npos) Pos = S1.size();<br>+      return ConstantInt::get(CI->getType(), Pos);<br>+    }<br><br>     return 0;<br>   }<br>@@ -638,17 +637,20 @@<br>         !FT->getReturnType()->isIntegerTy())<br>       return 0;<br><br>-    std::string S1, S2;<br>-    bool HasS1 = GetConstantStringInfo(CI->getArgOperand(0), S1);<br>-    bool HasS2 = GetConstantStringInfo(CI->getArgOperand(1), S2);<br>+    StringRef S1, S2;<br>+    bool HasS1 = getConstantStringInfo(CI->getArgOperand(0), S1);<br>+    bool HasS2 = getConstantStringInfo(CI->getArgOperand(1), S2);<br><br>     // strcspn("", s) -> 0<br>     if (HasS1 && S1.empty())<br>       return Constant::getNullValue(CI->getType());<br><br>     // Constant folding.<br>-    if (HasS1 && HasS2)<br>-      return ConstantInt::get(CI->getType(), strcspn(S1.c_str(), S2.c_str()));<br>+    if (HasS1 && HasS2) {<br>+      size_t Pos = S1.find_first_of(S2);<br>+      if (Pos == StringRef::npos) Pos = S1.size();<br>+      return ConstantInt::get(CI->getType(), Pos);<br>+    }<br><br>     // strcspn(s, "") -> strlen(s)<br>     if (TD && HasS2 && S2.empty())<br>@@ -692,9 +694,9 @@<br>     }<br><br>     // See if either input string is a constant string.<br>-    std::string SearchStr, ToFindStr;<br>-    bool HasStr1 = GetConstantStringInfo(CI->getArgOperand(0), SearchStr);<br>-    bool HasStr2 = GetConstantStringInfo(CI->getArgOperand(1), ToFindStr);<br>+    StringRef SearchStr, ToFindStr;<br>+    bool HasStr1 = getConstantStringInfo(CI->getArgOperand(0), SearchStr);<br>+    bool HasStr2 = getConstantStringInfo(CI->getArgOperand(1), ToFindStr);<br><br>     // fold strstr(x, "") -> x.<br>     if (HasStr2 && ToFindStr.empty())<br>@@ -704,7 +706,7 @@<br>     if (HasStr1 && HasStr2) {<br>       std::string::size_type Offset = SearchStr.find(ToFindStr);<br><br>-      if (Offset == std::string::npos) // strstr("foo", "bar") -> null<br>+      if (Offset == StringRef::npos) // strstr("foo", "bar") -> null<br>         return Constant::getNullValue(CI->getType());<br><br>       // strstr("abcd", "bc") -> gep((char*)"abcd", 1)<br>@@ -756,11 +758,11 @@<br>     }<br><br>     // Constant folding: memcmp(x, y, l) -> cnst (all arguments are constant)<br>-    std::string LHSStr, RHSStr;<br>-    if (GetConstantStringInfo(LHS, LHSStr) &&<br>-        GetConstantStringInfo(RHS, RHSStr)) {<br>+    StringRef LHSStr, RHSStr;<br>+    if (getConstantStringInfo(LHS, LHSStr) &&<br>+        getConstantStringInfo(RHS, RHSStr)) {<br>       // Make sure we're not reading out-of-bounds memory.<br>-      if (Len > LHSStr.length() || Len > RHSStr.length())<br>+      if (Len > LHSStr.size() || Len > RHSStr.size())<br>         return 0;<br>       uint64_t Ret = memcmp(LHSStr.data(), RHSStr.data(), Len);<br>       return ConstantInt::get(CI->getType(), Ret);<br>@@ -1116,8 +1118,8 @@<br>   Value *OptimizeFixedFormatString(Function *Callee, CallInst *CI,<br>                                    IRBuilder<> &B) {<br>     // Check for a fixed format string.<br>-    std::string FormatStr;<br>-    if (!GetConstantStringInfo(CI->getArgOperand(0), FormatStr))<br>+    StringRef FormatStr;<br>+    if (!getConstantStringInfo(CI->getArgOperand(0), FormatStr))<br>       return 0;<br><br>     // Empty format string -> noop.<br>@@ -1143,7 +1145,7 @@<br>         FormatStr.find('%') == std::string::npos) {  // no format characters.<br>       // Create a string literal with no \n on it.  We expect the constant merge<br>       // pass to be run after this pass, to merge duplicate strings.<br>-      FormatStr.erase(FormatStr.end()-1);<br>+      FormatStr = FormatStr.drop_back();<br>       Value *GV = B.CreateGlobalString(FormatStr, "str");<br>       EmitPutS(GV, B, TD);<br>       return CI->use_empty() ? (Value*)CI :<br>@@ -1203,8 +1205,8 @@<br>   Value *OptimizeFixedFormatString(Function *Callee, CallInst *CI,<br>                                    IRBuilder<> &B) {<br>     // Check for a fixed format string.<br>-    std::string FormatStr;<br>-    if (!GetConstantStringInfo(CI->getArgOperand(1), FormatStr))<br>+    StringRef FormatStr;<br>+    if (!getConstantStringInfo(CI->getArgOperand(1), FormatStr))<br>       return 0;<br><br>     // If we just have a format string (nothing else crazy) transform it.<br>@@ -1358,8 +1360,8 @@<br>   Value *OptimizeFixedFormatString(Function *Callee, CallInst *CI,<br>                                    IRBuilder<> &B) {<br>     // All the optimizations depend on the format string.<br>-    std::string FormatStr;<br>-    if (!GetConstantStringInfo(CI->getArgOperand(1), FormatStr))<br>+    StringRef FormatStr;<br>+    if (!getConstantStringInfo(CI->getArgOperand(1), FormatStr))<br>       return 0;<br><br>     // fprintf(F, "foo") --> fwrite("foo", 3, 1, F)<br>@@ -1442,8 +1444,8 @@<br>       return 0;<br><br>     // Check for a constant string.<br>-    std::string Str;<br>-    if (!GetConstantStringInfo(CI->getArgOperand(0), Str))<br>+    StringRef Str;<br>+    if (!getConstantStringInfo(CI->getArgOperand(0), Str))<br>       return 0;<br><br>     if (Str.empty() && CI->use_empty()) {<br>@@ -2413,6 +2415,8 @@<br> //   * stpcpy(str, "literal") -><br> //           llvm.memcpy(str,"literal",strlen("literal")+1,1)<br> //<br>+// strchr:<br>+//   * strchr(p, 0) -> strlen(p)<br> // tan, tanf, tanl:<br> //   * tan(atan(x)) -> x<br> //<br><br>Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/VMCore/AsmWriter.cpp (original)<br>+++ llvm/trunk/lib/VMCore/AsmWriter.cpp Sat Feb  4 20:29:43 2012<br>@@ -827,30 +827,21 @@<br>   }<br><br>   if (const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {<br>-    // As a special case, print the array as a string if it is an array of<br>-    // i8 with ConstantInt values.<br>-    //<br>     Type *ETy = CA->getType()->getElementType();<br>-    if (CA->isString()) {<br>-      Out << "c\"";<br>-      PrintEscapedString(CA->getAsString(), Out);<br>-      Out << '"';<br>-    } else {                // Cannot output in string format...<br>-      Out << '[';<br>+    Out << '[';<br>+    TypePrinter.print(ETy, Out);<br>+    Out << ' ';<br>+    WriteAsOperandInternal(Out, CA->getOperand(0),<br>+                           &TypePrinter, Machine,<br>+                           Context);<br>+    for (unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {<br>+      Out << ", ";<br>       TypePrinter.print(ETy, Out);<br>       Out << ' ';<br>-      WriteAsOperandInternal(Out, CA->getOperand(0),<br>-                             &TypePrinter, Machine,<br>+      WriteAsOperandInternal(Out, CA->getOperand(i), &TypePrinter, Machine,<br>                              Context);<br>-      for (unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {<br>-        Out << ", ";<br>-        TypePrinter.print(ETy, Out);<br>-        Out << ' ';<br>-        WriteAsOperandInternal(Out, CA->getOperand(i), &TypePrinter, Machine,<br>-                               Context);<br>-      }<br>-      Out << ']';<br>     }<br>+    Out << ']';<br>     return;<br>   }<br><br><br>Modified: llvm/trunk/lib/VMCore/Constants.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/VMCore/Constants.cpp (original)<br>+++ llvm/trunk/lib/VMCore/Constants.cpp Sat Feb  4 20:29:43 2012<br>@@ -176,7 +176,7 @@<br>     return UV->getElementValue(Elt);<br><br>   if (const ConstantDataSequential *CDS =dyn_cast<ConstantDataSequential>(this))<br>-    return CDS->getElementAsConstant(Elt);<br>+    return Elt < CDS->getNumElements() ? CDS->getElementAsConstant(Elt) : 0;<br>   return 0;<br> }<br><br>@@ -666,6 +666,13 @@<br> //                            ConstantXXX Classes<br> //===----------------------------------------------------------------------===//<br><br>+template <typename ItTy, typename EltTy><br>+static bool rangeOnlyContains(ItTy Start, ItTy End, EltTy Elt) {<br>+  for (; Start != End; ++Start)<br>+    if (*Start != Elt)<br>+      return false;<br>+  return true;<br>+}<br><br> ConstantArray::ConstantArray(ArrayType *T, ArrayRef<Constant *> V)<br>   : Constant(T, ConstantArrayVal,<br>@@ -680,54 +687,97 @@<br> }<br><br> Constant *ConstantArray::get(ArrayType *Ty, ArrayRef<Constant*> V) {<br>+  // Empty arrays are canonicalized to ConstantAggregateZero.<br>+  if (V.empty())<br>+    return ConstantAggregateZero::get(Ty);<br>+<br>   for (unsigned i = 0, e = V.size(); i != e; ++i) {<br>     assert(V[i]->getType() == Ty->getElementType() &&<br>            "Wrong type in array element initializer");<br>   }<br>   LLVMContextImpl *pImpl = Ty->getContext().pImpl;<br>-  // If this is an all-zero array, return a ConstantAggregateZero object<br>-  bool isAllZero = true;<br>-  bool isUndef = false;<br>-  if (!V.empty()) {<br>-    Constant *C = V[0];<br>-    isAllZero = C->isNullValue();<br>-    isUndef = isa<UndefValue>(C);<br>-<br>-    if (isAllZero || isUndef)<br>-      for (unsigned i = 1, e = V.size(); i != e; ++i)<br>-        if (V[i] != C) {<br>-          isAllZero = false;<br>-          isUndef = false;<br>-          break;<br>-        }<br>-  }<br>+  <br>+  // If this is an all-zero array, return a ConstantAggregateZero object.  If<br>+  // all undef, return an UndefValue, if "all simple", then return a<br>+  // ConstantDataArray.<br>+  Constant *C = V[0];<br>+  if (isa<UndefValue>(C) && rangeOnlyContains(V.begin(), V.end(), C))<br>+    return UndefValue::get(Ty);<br><br>-  if (isAllZero)<br>+  if (C->isNullValue() && rangeOnlyContains(V.begin(), V.end(), C))<br>     return ConstantAggregateZero::get(Ty);<br>-  if (isUndef)<br>-    return UndefValue::get(Ty);<br>-  return pImpl->ArrayConstants.getOrCreate(Ty, V);<br>-}<br><br>-/// ConstantArray::get(const string&) - Return an array that is initialized to<br>-/// contain the specified string.  If length is zero then a null terminator is <br>-/// added to the specified string so that it may be used in a natural way. <br>-/// Otherwise, the length parameter specifies how much of the string to use <br>-/// and it won't be null terminated.<br>-///<br>-Constant *ConstantArray::get(LLVMContext &Context, StringRef Str,<br>-                             bool AddNull) {<br>-  SmallVector<Constant*, 8> ElementVals;<br>-  ElementVals.reserve(Str.size() + size_t(AddNull));<br>-  for (unsigned i = 0; i < Str.size(); ++i)<br>-    ElementVals.push_back(ConstantInt::get(Type::getInt8Ty(Context), Str[i]));<br>-<br>-  // Add a null terminator to the string...<br>-  if (AddNull)<br>-    ElementVals.push_back(ConstantInt::get(Type::getInt8Ty(Context), 0));<br>+  // Check to see if all of the elements are ConstantFP or ConstantInt and if<br>+  // the element type is compatible with ConstantDataVector.  If so, use it.<br>+  if (ConstantDataSequential::isElementTypeCompatible(C->getType())) {<br>+    // We speculatively build the elements here even if it turns out that there<br>+    // is a constantexpr or something else weird in the array, since it is so<br>+    // uncommon for that to happen.<br>+    if (ConstantInt *CI = dyn_cast<ConstantInt>(C)) {<br>+      if (CI->getType()->isIntegerTy(8)) {<br>+        SmallVector<uint8_t, 16> Elts;<br>+        for (unsigned i = 0, e = V.size(); i != e; ++i)<br>+          if (ConstantInt *CI = dyn_cast<ConstantInt>(V[i]))<br>+            Elts.push_back(CI->getZExtValue());<br>+          else<br>+            break;<br>+        if (Elts.size() == V.size())<br>+          return ConstantDataArray::get(C->getContext(), Elts);<br>+      } else if (CI->getType()->isIntegerTy(16)) {<br>+        SmallVector<uint16_t, 16> Elts;<br>+        for (unsigned i = 0, e = V.size(); i != e; ++i)<br>+          if (ConstantInt *CI = dyn_cast<ConstantInt>(V[i]))<br>+            Elts.push_back(CI->getZExtValue());<br>+          else<br>+            break;<br>+        if (Elts.size() == V.size())<br>+          return ConstantDataArray::get(C->getContext(), Elts);<br>+      } else if (CI->getType()->isIntegerTy(32)) {<br>+        SmallVector<uint32_t, 16> Elts;<br>+        for (unsigned i = 0, e = V.size(); i != e; ++i)<br>+          if (ConstantInt *CI = dyn_cast<ConstantInt>(V[i]))<br>+            Elts.push_back(CI->getZExtValue());<br>+          else<br>+            break;<br>+        if (Elts.size() == V.size())<br>+          return ConstantDataArray::get(C->getContext(), Elts);<br>+      } else if (CI->getType()->isIntegerTy(64)) {<br>+        SmallVector<uint64_t, 16> Elts;<br>+        for (unsigned i = 0, e = V.size(); i != e; ++i)<br>+          if (ConstantInt *CI = dyn_cast<ConstantInt>(V[i]))<br>+            Elts.push_back(CI->getZExtValue());<br>+          else<br>+            break;<br>+        if (Elts.size() == V.size())<br>+          return ConstantDataArray::get(C->getContext(), Elts);<br>+      }<br>+    }<br>+    <br>+    if (ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {<br>+      if (CFP->getType()->isFloatTy()) {<br>+        SmallVector<float, 16> Elts;<br>+        for (unsigned i = 0, e = V.size(); i != e; ++i)<br>+          if (ConstantFP *CFP = dyn_cast<ConstantFP>(V[i]))<br>+            Elts.push_back(CFP->getValueAPF().convertToFloat());<br>+          else<br>+            break;<br>+        if (Elts.size() == V.size())<br>+          return ConstantDataArray::get(C->getContext(), Elts);<br>+      } else if (CFP->getType()->isDoubleTy()) {<br>+        SmallVector<double, 16> Elts;<br>+        for (unsigned i = 0, e = V.size(); i != e; ++i)<br>+          if (ConstantFP *CFP = dyn_cast<ConstantFP>(V[i]))<br>+            Elts.push_back(CFP->getValueAPF().convertToDouble());<br>+          else<br>+            break;<br>+        if (Elts.size() == V.size())<br>+          return ConstantDataArray::get(C->getContext(), Elts);<br>+      }<br>+    }<br>+  }<br><br>-  ArrayType *ATy = ArrayType::get(Type::getInt8Ty(Context), ElementVals.size());<br>-  return get(ATy, ElementVals);<br>+  // Otherwise, we really do want to create a ConstantArray.<br>+  return pImpl->ArrayConstants.getOrCreate(Ty, V);<br> }<br><br> /// getTypeForElements - Return an anonymous struct type to use for a constant<br>@@ -839,8 +889,7 @@<br><br>   // Check to see if all of the elements are ConstantFP or ConstantInt and if<br>   // the element type is compatible with ConstantDataVector.  If so, use it.<br>-  if (ConstantDataSequential::isElementTypeCompatible(C->getType()) &&<br>-      (isa<ConstantFP>(C) || isa<ConstantInt>(C))) {<br>+  if (ConstantDataSequential::isElementTypeCompatible(C->getType())) {<br>     // We speculatively build the elements here even if it turns out that there<br>     // is a constantexpr or something else weird in the array, since it is so<br>     // uncommon for that to happen.<br>@@ -1146,69 +1195,6 @@<br>   destroyConstantImpl();<br> }<br><br>-/// isString - This method returns true if the array is an array of i8, and <br>-/// if the elements of the array are all ConstantInt's.<br>-bool ConstantArray::isString() const {<br>-  // Check the element type for i8...<br>-  if (!getType()->getElementType()->isIntegerTy(8))<br>-    return false;<br>-  // Check the elements to make sure they are all integers, not constant<br>-  // expressions.<br>-  for (unsigned i = 0, e = getNumOperands(); i != e; ++i)<br>-    if (!isa<ConstantInt>(getOperand(i)))<br>-      return false;<br>-  return true;<br>-}<br>-<br>-/// isCString - This method returns true if the array is a string (see<br>-/// isString) and it ends in a null byte <a href="smb://0">\\0</a> and does not contains any other<br>-/// null bytes except its terminator.<br>-bool ConstantArray::isCString() const {<br>-  // Check the element type for i8...<br>-  if (!getType()->getElementType()->isIntegerTy(8))<br>-    return false;<br>-<br>-  // Last element must be a null.<br>-  if (!getOperand(getNumOperands()-1)->isNullValue())<br>-    return false;<br>-  // Other elements must be non-null integers.<br>-  for (unsigned i = 0, e = getNumOperands()-1; i != e; ++i) {<br>-    if (!isa<ConstantInt>(getOperand(i)))<br>-      return false;<br>-    if (getOperand(i)->isNullValue())<br>-      return false;<br>-  }<br>-  return true;<br>-}<br>-<br>-<br>-/// convertToString - Helper function for getAsString() and getAsCString().<br>-static std::string convertToString(const User *U, unsigned len) {<br>-  std::string Result;<br>-  Result.reserve(len);<br>-  for (unsigned i = 0; i != len; ++i)<br>-    Result.push_back((char)cast<ConstantInt>(U->getOperand(i))->getZExtValue());<br>-  return Result;<br>-}<br>-<br>-/// getAsString - If this array is isString(), then this method converts the<br>-/// array to an std::string and returns it.  Otherwise, it asserts out.<br>-///<br>-std::string ConstantArray::getAsString() const {<br>-  assert(isString() && "Not a string!");<br>-  return convertToString(this, getNumOperands());<br>-}<br>-<br>-<br>-/// getAsCString - If this array is isCString(), then this method converts the<br>-/// array (without the trailing null byte) to an std::string and returns it.<br>-/// Otherwise, it asserts out.<br>-///<br>-std::string ConstantArray::getAsCString() const {<br>-  assert(isCString() && "Not a string!");<br>-  return convertToString(this, getNumOperands() - 1);<br>-}<br>-<br><br> //---- ConstantStruct::get() implementation...<br> //<br><br>Modified: llvm/trunk/lib/VMCore/Core.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/VMCore/Core.cpp (original)<br>+++ llvm/trunk/lib/VMCore/Core.cpp Sat Feb  4 20:29:43 2012<br>@@ -634,8 +634,8 @@<br>                                       LLVMBool DontNullTerminate) {<br>   /* Inverted the sense of AddNull because ', 0)' is a<br>      better mnemonic for null termination than ', 1)'. */<br>-  return wrap(ConstantArray::get(*unwrap(C), StringRef(Str, Length),<br>-                                 DontNullTerminate == 0));<br>+  return wrap(ConstantDataArray::getString(*unwrap(C), StringRef(Str, Length),<br>+                                           DontNullTerminate == 0));<br> }<br> LLVMValueRef LLVMConstStructInContext(LLVMContextRef C, <br>                                       LLVMValueRef *ConstantVals,<br><br>Modified: llvm/trunk/lib/VMCore/IRBuilder.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/IRBuilder.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/IRBuilder.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/lib/VMCore/IRBuilder.cpp (original)<br>+++ llvm/trunk/lib/VMCore/IRBuilder.cpp Sat Feb  4 20:29:43 2012<br>@@ -24,7 +24,7 @@<br> /// specified.  If Name is specified, it is the name of the global variable<br> /// created.<br> Value *IRBuilderBase::CreateGlobalString(StringRef Str, const Twine &Name) {<br>-  Constant *StrConstant = ConstantArray::get(Context, Str, true);<br>+  Constant *StrConstant = ConstantDataArray::getString(Context, Str);<br>   Module &M = *BB->getParent()->getParent();<br>   GlobalVariable *GV = new GlobalVariable(M, StrConstant->getType(),<br>                                           true, GlobalValue::PrivateLinkage,<br><br>Modified: llvm/trunk/tools/bugpoint/Miscompilation.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/Miscompilation.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/Miscompilation.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/tools/bugpoint/Miscompilation.cpp (original)<br>+++ llvm/trunk/tools/bugpoint/Miscompilation.cpp Sat Feb  4 20:29:43 2012<br>@@ -820,7 +820,8 @@<br>       // Don't forward functions which are external in the test module too.<br>       if (TestFn && !TestFn->isDeclaration()) {<br>         // 1. Add a string constant with its name to the global file<br>-        Constant *InitArray = ConstantArray::get(F->getContext(), F->getName());<br>+        Constant *InitArray =<br>+          ConstantDataArray::getString(F->getContext(), F->getName());<br>         GlobalVariable *funcName =<br>           new GlobalVariable(*Safe, InitArray->getType(), true /*isConstant*/,<br>                              GlobalValue::InternalLinkage, InitArray,<br><br>Modified: llvm/trunk/tools/lto/LTOModule.cpp<br>URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOModule.cpp?rev=149800&r1=149799&r2=149800&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOModule.cpp?rev=149800&r1=149799&r2=149800&view=diff</a><br>==============================================================================<br>--- llvm/trunk/tools/lto/LTOModule.cpp (original)<br>+++ llvm/trunk/tools/lto/LTOModule.cpp Sat Feb  4 20:29:43 2012<br>@@ -190,9 +190,9 @@<br>     Constant *op = ce->getOperand(0);<br>     if (GlobalVariable *gvn = dyn_cast<GlobalVariable>(op)) {<br>       Constant *cn = gvn->getInitializer();<br>-      if (ConstantArray *ca = dyn_cast<ConstantArray>(cn)) {<br>+      if (ConstantDataArray *ca = dyn_cast<ConstantDataArray>(cn)) {<br>         if (ca->isCString()) {<br>-          name = ".objc_class_name_" + ca->getAsCString();<br>+          name = ".objc_class_name_" + ca->getAsCString().str();<br>           return true;<br>         }<br>       }<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br></div></blockquote></div><br></div></div></blockquote></div><br></body></html>