Basic fix for PR#591; don't convert an fprintf() to an fwrite() if there
authorJohn Criswell <criswell@uiuc.edu>
Wed, 29 Jun 2005 15:03:18 +0000 (15:03 +0000)
committerJohn Criswell <criswell@uiuc.edu>
Wed, 29 Jun 2005 15:03:18 +0000 (15:03 +0000)
is a mismatch in their character type pointers (i.e. fprintf() prints an
array of ubytes while fwrite() takes an array of sbytes).
We can probably do better than this (such as casting the ubyte to an
sbyte).

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

lib/Transforms/IPO/SimplifyLibCalls.cpp

index a2ca69214763875091ecdb72ba7f7913ff2001ce..fb4df738184de426411772023434b5187aa2bab6 100644 (file)
@@ -1305,6 +1305,15 @@ public:
       Function* fwrite_func = SLC.get_fwrite(FILEptr_type);
       if (!fwrite_func)
         return false;
+
+      // Make sure that the fprintf() and fwrite() functions both take the
+      // same type of char pointer.
+      if (ci->getOperand(2)->getType() !=
+          fwrite_func->getFunctionType()->getParamType(0))
+      {
+        return false;
+      }
+
       std::vector<Value*> args;
       args.push_back(ci->getOperand(2));
       args.push_back(ConstantUInt::get(SLC.getIntPtrType(),len));