ConstantInt::get only works for arguments < 128.
authorChris Lattner <sabre@nondot.org>
Mon, 1 Aug 2005 16:52:50 +0000 (16:52 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 1 Aug 2005 16:52:50 +0000 (16:52 +0000)
SimplifyLibCalls probably has to be audited to make sure it does not make
this mistake elsewhere.  Also, if this code knows that the type will be
unsigned, obviously one arm of this is dead.

Reid, can you take a look into this further?

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

lib/Transforms/IPO/SimplifyLibCalls.cpp

index 754143bea7f58c78cee533d0aa9deee2f38f3802..99675b3cb359193e1c0127551ccbc4c8cbe53fc2 100644 (file)
@@ -962,8 +962,12 @@ struct StrLenOptimization : public LibCallOptimization
       return false;
 
     // strlen("xyz") -> 3 (for example)
-    ci->replaceAllUsesWith(
-        ConstantInt::get(SLC.getTargetData()->getIntPtrType(),len));
+    const Type *Ty = SLC.getTargetData()->getIntPtrType();
+    if (Ty->isSigned())
+      ci->replaceAllUsesWith(ConstantSInt::get(Ty, len));
+    else
+      ci->replaceAllUsesWith(ConstantUInt::get(Ty, len));
+     
     ci->eraseFromParent();
     return true;
   }