Index: include/llvm/Support/CommandLine.h =================================================================== --- include/llvm/Support/CommandLine.h +++ include/llvm/Support/CommandLine.h @@ -64,12 +64,15 @@ void ParseEnvironmentOptions(const char *progName, const char *envvar, const char *Overview = ""); +// Function pointer type for printing version information. +typedef void (*VersionPrinterTy)(raw_ostream &); + ///===---------------------------------------------------------------------===// /// SetVersionPrinter - Override the default (LLVM specific) version printer /// used to print out the version when --version is given /// on the command line. This allows other systems using the /// CommandLine utilities to print their own version string. -void SetVersionPrinter(void (*func)()); +void SetVersionPrinter(VersionPrinterTy func); ///===---------------------------------------------------------------------===// /// AddExtraVersionPrinter - Add an extra printer to use in addition to the @@ -78,7 +81,7 @@ /// which will be called after the basic LLVM version /// printing is complete. Each can then add additional /// information specific to the tool. -void AddExtraVersionPrinter(void (*func)()); +void AddExtraVersionPrinter(VersionPrinterTy func); // PrintOptionValues - Print option values. // With -print-options print the difference between option values and defaults. Index: include/llvm/Support/TargetRegistry.h =================================================================== --- include/llvm/Support/TargetRegistry.h +++ include/llvm/Support/TargetRegistry.h @@ -598,7 +598,7 @@ /// printRegisteredTargetsForVersion - Print the registered targets /// appropriately for inclusion in a tool's version output. - static void printRegisteredTargetsForVersion(); + static void printRegisteredTargetsForVersion(raw_ostream &OS); /// @name Registry Access /// @{ Index: lib/Support/CommandLine.cpp =================================================================== --- lib/Support/CommandLine.cpp +++ lib/Support/CommandLine.cpp @@ -2042,9 +2042,9 @@ Opts[i].second->printOptionValue(MaxArgLen, PrintAllOptions); } -static void (*OverrideVersionPrinter)() = nullptr; +static VersionPrinterTy OverrideVersionPrinter = nullptr; -static std::vector *ExtraVersionPrinters = nullptr; +static std::vector *ExtraVersionPrinters = nullptr; namespace { class VersionPrinter { @@ -2084,7 +2084,7 @@ return; if (OverrideVersionPrinter != nullptr) { - (*OverrideVersionPrinter)(); + (*OverrideVersionPrinter)(outs()); exit(0); } print(); @@ -2093,10 +2093,8 @@ // information. if (ExtraVersionPrinters != nullptr) { outs() << '\n'; - for (std::vector::iterator I = ExtraVersionPrinters->begin(), - E = ExtraVersionPrinters->end(); - I != E; ++I) - (*I)(); + for (auto I : *ExtraVersionPrinters) + I(outs()); } exit(0); @@ -2134,11 +2132,11 @@ /// Utility function for printing version number. void cl::PrintVersionMessage() { VersionPrinterInstance.print(); } -void cl::SetVersionPrinter(void (*func)()) { OverrideVersionPrinter = func; } +void cl::SetVersionPrinter(VersionPrinterTy func) { OverrideVersionPrinter = func; } -void cl::AddExtraVersionPrinter(void (*func)()) { +void cl::AddExtraVersionPrinter(VersionPrinterTy func) { if (!ExtraVersionPrinters) - ExtraVersionPrinters = new std::vector; + ExtraVersionPrinters = new std::vector; ExtraVersionPrinters->push_back(func); } Index: lib/Support/TargetRegistry.cpp =================================================================== --- lib/Support/TargetRegistry.cpp +++ lib/Support/TargetRegistry.cpp @@ -114,7 +114,7 @@ return LHS->first.compare(RHS->first); } -void TargetRegistry::printRegisteredTargetsForVersion() { +void TargetRegistry::printRegisteredTargetsForVersion(raw_ostream &OS) { std::vector > Targets; size_t Width = 0; for (const auto &T : TargetRegistry::targets()) { @@ -123,7 +123,6 @@ } array_pod_sort(Targets.begin(), Targets.end(), TargetArraySortFn); - raw_ostream &OS = outs(); OS << " Registered Targets:\n"; for (unsigned i = 0, e = Targets.size(); i != e; ++i) { OS << " " << Targets[i].first;