Index: lib/Transforms/Utils/SimplifyLibCalls.cpp =================================================================== --- lib/Transforms/Utils/SimplifyLibCalls.cpp +++ lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -1834,9 +1834,9 @@ // printf("x") -> putchar('x'), even for '%'. if (FormatStr.size() == 1) { Value *Res = emitPutChar(B.getInt32(FormatStr[0]), B, TLI); - if (CI->use_empty() || !Res) - return Res; - return B.CreateIntCast(Res, CI->getType(), true); + assert(CI->use_empty() && + "printf return value used should inhibit optimizations"); + return Res; } // printf("%s", "a") --> putchar('a') @@ -1847,14 +1847,9 @@ if (ChrStr.size() != 1) return nullptr; Value *Res = emitPutChar(B.getInt32(ChrStr[0]), B, TLI); - - // FIXME: Here we check that the return value is not used - // but ealier we prevent transformations in case it is. - // This should probably be an assert. - if (CI->use_empty() || !Res) - return Res; - - return B.CreateIntCast(Res, CI->getType(), true); + assert(CI->use_empty() && + "printf return value used should inhibit optimizations"); + return Res; } // printf("foo\n") --> puts("foo") @@ -1865,9 +1860,9 @@ FormatStr = FormatStr.drop_back(); Value *GV = B.CreateGlobalString(FormatStr, "str"); Value *NewCI = emitPutS(GV, B, TLI); - return (CI->use_empty() || !NewCI) - ? NewCI - : ConstantInt::get(CI->getType(), FormatStr.size() + 1); + assert(CI->use_empty() && + "printf return value used should inhibit optimizations"); + return NewCI; } // Optimize specific format strings. @@ -1875,16 +1870,18 @@ if (FormatStr == "%c" && CI->getNumArgOperands() > 1 && CI->getArgOperand(1)->getType()->isIntegerTy()) { Value *Res = emitPutChar(CI->getArgOperand(1), B, TLI); - - if (CI->use_empty() || !Res) - return Res; - return B.CreateIntCast(Res, CI->getType(), true); + assert(CI->use_empty() && + "printf return value used should inhibit optimizations"); + return Res; } // printf("%s\n", str) --> puts(str) if (FormatStr == "%s\n" && CI->getNumArgOperands() > 1 && CI->getArgOperand(1)->getType()->isPointerTy()) { - return emitPutS(CI->getArgOperand(1), B, TLI); + Value *Res = emitPutS(CI->getArgOperand(1), B, TLI); + assert(CI->use_empty() && + "printf return value used should inhibit optimizations"); + return Res; } return nullptr; }