We were missing this case. GCC optimizes it, apparently.
Diff Detail
Event Timeline
lib/Transforms/Utils/SimplifyLibCalls.cpp | ||
---|---|---|
1843 | The number of arguments should be an exact comparison? | |
1849 | FormatStr[0] --> ChrStr[0] ? | |
1852 | This does not behave the way that we need. | |
test/Transforms/InstCombine/printf-2.ll | ||
13 | Please add/use test cases that verify that the return value of printf is handled correctly by this transform. |
lib/Transforms/Utils/SimplifyLibCalls.cpp | ||
---|---|---|
1843 | Hmm, I don't think so. printf("%c", 'a', 0, 0, 0, 0) | |
1849 | Nice catch, will fix. | |
1852 | I was scared, because basically every function violates what you describe. // Do not do any of the following transformations if the printf return value // is used, in general the printf return value is not compatible with either // putchar() or puts(). if (!CI->use_empty()) return nullptr; So, while in the future we *might* relax this, I think the transformation as is it's safe for now. | |
test/Transforms/InstCombine/printf-2.ll | ||
13 | Already covered (see comment above) |
lib/Transforms/Utils/SimplifyLibCalls.cpp | ||
---|---|---|
1843 | Ok - clang does warn in that case ( warning: data argument not used by format string [-Wformat-extra-args] ), but the extra args are not removed by the front-end, so this looks fine. | |
1852 | Ah, I didn't look far enough ahead to see that guard. | |
test/Transforms/InstCombine/printf-2.ll | ||
13 | Ok - there is an existing negative test to check that the transform doesn't fire when the return value is used in llvm/test/Transforms/InstCombine/printf-1.ll. |
lib/Transforms/Utils/SimplifyLibCalls.cpp | ||
---|---|---|
1852 | Good idea, maybe in the next commit I can do a global sweep? |
Good idea, maybe in the next commit I can do a global sweep?
That would be fine with me. But if you do it that way, please do add a 'FIXME' comment in this patch just in case it doesn't happen immediately.
The number of arguments should be an exact comparison?
CI->getNumArgOperands() == 2