[PATCH] D100724: [SimplifyLibCalls] Transform printf("%s", str"\n") --> puts(str).
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 21 04:57:42 PDT 2021
spatel added inline comments.
================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:2379
+ // Try to emit putchar or puts.
if (FormatStr == "%s" && CI->getNumArgOperands() > 1) {
+ StringRef OperandStr;
----------------
Why is this checking for `args > 1` instead of exactly `args == 2`?
================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:2382
+ if (!getConstantStringInfo(CI->getOperand(1), OperandStr) ||
+ OperandStr.empty())
return nullptr;
----------------
What does it mean if the operand string is empty?
printf("%s", "");
It can be another patch, but please leave a "TODO" comment. Looks like gcc removes the call entirely.
================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:2388
+ // printf("%s", str"\n") --> puts(str)
+ else if (OperandStr.back() == '\n') {
+ OperandStr = OperandStr.drop_back();
----------------
Style: remove `else` ( https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return )
================
Comment at: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:2397
// printf("foo\n") --> puts("foo")
- if (FormatStr[FormatStr.size() - 1] == '\n' &&
+ if (FormatStr.back() == '\n' &&
FormatStr.find('%') == StringRef::npos) { // No format characters.
----------------
That diff is independent of this patch, so could be an NFC preliminary cleanup.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100724/new/
https://reviews.llvm.org/D100724
More information about the llvm-commits
mailing list