If the return value of printf() is used, we don't do any transformation in SimplifyLibCalls.
Yet, in each transformation we check again if Ci->use_empty(). I think this check is redundant, because it's always true. This also allows to strip some code. IT passes the testsuite, but given I wasn't entirely sure of what are the effects, I put an assert() instead.
Details
Diff Detail
Event Timeline
lib/Transforms/Utils/SimplifyLibCalls.cpp | ||
---|---|---|
1828–1832 | IMO, the asserts are unnecessary since the check for empty is right here and has a nice explanatory comment too. If others like the added safety of the asserts, I don't object. There is a proposal to refactor this whole file, so maybe asserts will be handy. But instead of repeating the assert 5x, add a one-line helper function or lambda? |
lib/Transforms/Utils/SimplifyLibCalls.cpp | ||
---|---|---|
1828–1832 | My vote is to remove the asserts alltogheter. David? |
My vote is to remove the assertions; if you do that, then LGTM.
Up to you if you'd like to wait for David to review.
lib/Transforms/Utils/SimplifyLibCalls.cpp | ||
---|---|---|
1837 | What about the !Res case? If the target has printf, but not putchar, for some reason? Or do we simply not care about those (which I think is valid :) )? |
I assume that might be a problem.
This change is NFC because the first expression always evaluate to true so we never care about the !Res case even prior to this change. In case we hit a case you describe I'll be more than happy to fix but I think the possibility of an environment defining printf() and not putchar() is very remote anyway.
I think we're already safe here. On failure (eg, putchar is not available), emitPutChar() returns nullptr, so optimizePrintFString() will also return nullptr to signal to its caller that the transform didn't work.
IMO, the asserts are unnecessary since the check for empty is right here and has a nice explanatory comment too.
If others like the added safety of the asserts, I don't object. There is a proposal to refactor this whole file, so maybe asserts will be handy.
But instead of repeating the assert 5x, add a one-line helper function or lambda?