Skip to content

llvm-tli-checker: Avoid a temporary string while printing #142538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: users/arsenm/llvm-tli-checker/print-custom-name
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions llvm/tools/llvm-tli-checker/llvm-tli-checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,12 @@ static void reportArchiveChildIssue(const object::Archive::Child &C, int Index,
}

// Return Name, and if Name is mangled, append "aka" and the demangled name.
static std::string getPrintableName(StringRef Name) {
std::string OutputName = "'";
OutputName += Name;
OutputName += "'";
static void printPrintableName(raw_ostream &OS, StringRef Name) {
OS << '\'' << Name << '\'';

std::string DemangledName(demangle(Name));
if (Name != DemangledName) {
OutputName += " aka ";
OutputName += DemangledName;
}
return OutputName;
if (Name != DemangledName)
OS << " aka " << DemangledName;
}

static void reportNumberOfEntries(const TargetLibraryInfo &TLI,
Expand Down Expand Up @@ -138,10 +134,10 @@ static void dumpTLIEntries(const TargetLibraryInfo &TLI) {
StringRef Name = TLI.getName(LF);
// If there is a custom name, print it.
// TODO: Should we include the standard name in the printed line?
outs() << getPrintableName(Name);
printPrintableName(outs(), Name);
} else {
// If it's not available, refer to it by the standard name.
outs() << getPrintableName(TargetLibraryInfo::getStandardName(LF));
printPrintableName(outs(), TargetLibraryInfo::getStandardName(LF));
}

outs() << '\n';
Expand Down Expand Up @@ -345,7 +341,9 @@ int main(int argc, char *argv[]) {
constexpr char YesNo[2][4] = {"no ", "yes"};
constexpr char Indicator[4][3] = {"!!", ">>", "<<", "=="};
outs() << Indicator[Which] << " TLI " << YesNo[TLIHas] << " SDK "
<< YesNo[SDKHas] << ": " << getPrintableName(TLIName) << '\n';
<< YesNo[SDKHas] << ": ";
printPrintableName(outs(), TLIName);
outs() << '\n';
}
}

Expand Down
Loading