Skip to content

Commit 0d61980

Browse files
lucagretschermarcelmaltry
authored andcommitted
[Shell] Fix #215: Adapt CLI print opts for Clang17
Using LLVM Clang17 on macOS, the I/O manipulation operations `std::left` and `std::right` produce a UBSan error. Therefore, refactor the code to print the shell help and to list all available components by manually insert padding to achieve the same alignment as before. Once this issue is fixed, this commit can be reverted.
1 parent cd25ab3 commit 0d61980

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/shell.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <fstream>
77
#include <functional>
88
#include <iomanip>
9-
#include <ios>
109
#include <iostream>
1110
#include <mutable/catalog/CostModel.hpp>
1211
#include <mutable/mutable.hpp>
@@ -437,7 +436,7 @@ Immanuel Haffner\
437436
std::size_t max_len = 0;
438437
for (auto &layout : layouts) max_len = std::max(max_len, strlen(layout.first));
439438
for (auto &layout : layouts) {
440-
std::cout << "\n " << std::setw(max_len) << std::left << layout.first;
439+
std::cout << "\n " << layout.first << std::setw(max_len - strlen(layout.first)) << "";
441440
if (layout.second.description())
442441
std::cout << " - " << layout.second.description();
443442
}
@@ -450,7 +449,7 @@ Immanuel Haffner\
450449
std::size_t max_len = 0;
451450
for (auto &ce : cardinality_estimators) max_len = std::max(max_len, strlen(ce.first));
452451
for (auto &ce : cardinality_estimators) {
453-
std::cout << "\n " << std::setw(max_len) << std::left << ce.first;
452+
std::cout << "\n " << ce.first << std::setw(max_len - strlen(ce.first)) << "";;
454453
if (ce.second.description())
455454
std::cout << " - " << ce.second.description();
456455
}
@@ -463,7 +462,7 @@ Immanuel Haffner\
463462
std::size_t max_len = 0;
464463
for (auto &pe : plan_enumerators) max_len = std::max(max_len, strlen(pe.first));
465464
for (auto &pe : plan_enumerators) {
466-
std::cout << "\n " << std::setw(max_len) << std::left << pe.first;
465+
std::cout << "\n " << pe.first << std::setw(max_len - strlen(pe.first)) << "";;
467466
if (pe.second.description())
468467
std::cout << " - " << pe.second.description();
469468
}
@@ -476,7 +475,7 @@ Immanuel Haffner\
476475
range backends(C.backends_cbegin(), C.backends_cend());
477476
for (auto &backend : backends) max_len = std::max(max_len, strlen(backend.first));
478477
for (auto &backend : backends) {
479-
std::cout << "\n " << std::setw(max_len) << std::left << backend.first;
478+
std::cout << "\n " << backend.first << std::setw(max_len - strlen(backend.first)) << "";;
480479
if (backend.second.description())
481480
std::cout << " - " << backend.second.description();
482481
}
@@ -487,11 +486,11 @@ Immanuel Haffner\
487486
std::cout << "List of available cost functions:";
488487
std::size_t max_len = 0;
489488
range cost_functions(C.cost_functions_cbegin(), C.cost_functions_cend());
490-
for (auto &cost_function : cost_functions) max_len = std::max(max_len, strlen(cost_function.first));
491-
for (auto &cost_function : cost_functions) {
492-
std::cout << "\n " << std::setw(max_len) << std::left << cost_function.first;
493-
if (cost_function.second.description())
494-
std::cout << " - " << cost_function.second.description();
489+
for (auto &cf : cost_functions) max_len = std::max(max_len, strlen(cf.first));
490+
for (auto &cf : cost_functions) {
491+
std::cout << "\n " << cf.first << std::setw(max_len - strlen(cf.first)) << "";;
492+
if (cf.second.description())
493+
std::cout << " - " << cf.second.description();
495494
}
496495
std::cout << "\n (Use --train-cost-models to train a cost function on your specific hardware)";
497496
std::cout << std::endl;
@@ -503,7 +502,7 @@ Immanuel Haffner\
503502
range schedulers(C.schedulers_cbegin(), C.schedulers_cend());
504503
for (auto &scheduler : schedulers) max_len = std::max(max_len, strlen(scheduler.first));
505504
for (auto &scheduler : schedulers) {
506-
std::cout << "\n " << std::setw(max_len) << std::left << scheduler.first;
505+
std::cout << "\n " << scheduler.first << std::setw(max_len - strlen(scheduler.first)) << "";;
507506
if (scheduler.second.description())
508507
std::cout << " - " << scheduler.second.description();
509508
}
@@ -516,7 +515,7 @@ Immanuel Haffner\
516515
range table_factories(C.table_properties_cbegin(), C.table_properties_cend());
517516
for (auto &table_factory : table_factories) max_len = std::max(max_len, strlen(table_factory.first));
518517
for (auto &table_factory : table_factories) {
519-
std::cout << "\n " << std::setw(max_len) << std::left << table_factory.first;
518+
std::cout << "\n " << table_factory.first << std::setw(max_len - strlen(table_factory.first)) << "";;
520519
if (table_factory.second.description())
521520
std::cout << " - " << table_factory.second.description();
522521
}

src/util/ArgParser.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,10 @@ M_LCOV_EXCL_START
158158
void ArgParser::print_args(std::ostream &out) const
159159
{
160160
auto print = [this, &out](const char *Short, const char *Long, const char *Descr) {
161-
using std::setw, std::left, std::right;
162161
out << " "
163-
<< left << setw(short_len_) << Short << right
162+
<< Short << std::setw(short_len_ - strlen(Short)) << ""
164163
<< " "
165-
<< left << setw(long_len_) << Long << right
164+
<< Long << std::setw(long_len_ - strlen(Long)) << ""
166165
<< " - "
167166
<< Descr
168167
<< '\n';

0 commit comments

Comments
 (0)