rework this logic to not depend on the last argument to GetConstantStringInfo,
authorChris Lattner <sabre@nondot.org>
Tue, 31 Jan 2012 04:39:22 +0000 (04:39 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 31 Jan 2012 04:39:22 +0000 (04:39 +0000)
which is going away.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149348 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/SelectionDAG.cpp

index 18de13dc0a959521848f3bbb30aec259f8875fab..6b6f7bf10d7e2c1704b38df47a1a1a6e1ae39f89 100644 (file)
@@ -3323,7 +3323,10 @@ static SDValue getMemsetStringVal(EVT VT, DebugLoc dl, SelectionDAG &DAG,
   if (TLI.isLittleEndian())
     Offset = Offset + MSB - 1;
   for (unsigned i = 0; i != MSB; ++i) {
-    Val = (Val << 8) | (unsigned char)Str[Offset];
+    Val = (Val << 8);
+    
+    if (Offset < Str.size())
+      Val |= (unsigned char)Str[Offset];
     Offset += TLI.isLittleEndian() ? -1 : 1;
   }
   return DAG.getConstant(Val, VT);
@@ -3354,9 +3357,12 @@ static bool isMemSrcFromString(SDValue Src, std::string &Str) {
   if (!G)
     return false;
 
-  const GlobalVariable *GV = dyn_cast<GlobalVariable>(G->getGlobal());
-  if (GV && GetConstantStringInfo(GV, Str, SrcDelta, false))
-    return true;
+  if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(G->getGlobal()))
+    if (GetConstantStringInfo(GV, Str, SrcDelta)) {
+      // The nul can also be read.
+      Str.push_back(0);
+      return true;
+    }
 
   return false;
 }