|
65 | 65 | #include "llvm/Support/TargetSelect.h" |
66 | 66 | #include "llvm/Support/TimeProfiler.h" |
67 | 67 | #include "llvm/Support/raw_ostream.h" |
| 68 | +#include <algorithm> |
68 | 69 | #include <cstdlib> |
69 | 70 | #include <tuple> |
70 | 71 | #include <utility> |
@@ -1700,51 +1701,59 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) { |
1700 | 1701 | bool hasZicfilpFuncSigReportDynamic = false; |
1701 | 1702 | bool hasZicfissReportDynamic = false; |
1702 | 1703 | struct ReportOptDesc { |
1703 | | - const char *const name; |
| 1704 | + const StringRef name; |
1704 | 1705 | ReportPolicy &policy; |
1705 | 1706 | bool *const seen; |
1706 | 1707 |
|
1707 | | - ReportOptDesc(const char *const name, ReportPolicy &policy, bool *seen) |
| 1708 | + ReportOptDesc(const StringRef name, ReportPolicy &policy, bool *seen) |
1708 | 1709 | : name(name), policy(policy), seen(seen) {} |
1709 | 1710 | }; |
1710 | | - const ReportOptDesc reports[] = { |
1711 | | - {"bti-report", ctx.arg.zBtiReport, nullptr}, |
1712 | | - {"cet-report", ctx.arg.zCetReport, nullptr}, |
1713 | | - {"execute-only-report", ctx.arg.zExecuteOnlyReport, nullptr}, |
1714 | | - {"gcs-report", ctx.arg.zGcsReport, nullptr}, |
1715 | | - {"gcs-report-dynamic", ctx.arg.zGcsReportDynamic, &hasGcsReportDynamic}, |
1716 | | - {"pauth-report", ctx.arg.zPauthReport, nullptr}, |
1717 | | - {"zicfilp-unlabeled-report", ctx.arg.zZicfilpUnlabeledReport, nullptr}, |
1718 | | - {"zicfilp-unlabeled-report-dynamic", |
| 1711 | + // Sort the descriptions by name according to StringRef::compare() so we can |
| 1712 | + // binary search it |
| 1713 | + ReportOptDesc reports[] = { |
| 1714 | + {{"bti-report"}, ctx.arg.zBtiReport, nullptr}, |
| 1715 | + {{"cet-report"}, ctx.arg.zCetReport, nullptr}, |
| 1716 | + {{"execute-only-report"}, ctx.arg.zExecuteOnlyReport, nullptr}, |
| 1717 | + {{"gcs-report"}, ctx.arg.zGcsReport, nullptr}, |
| 1718 | + {{"gcs-report-dynamic"}, ctx.arg.zGcsReportDynamic, &hasGcsReportDynamic}, |
| 1719 | + {{"pauth-report"}, ctx.arg.zPauthReport, nullptr}, |
| 1720 | + {{"zicfilp-func-sig-report"}, ctx.arg.zZicfilpFuncSigReport, nullptr}, |
| 1721 | + {{"zicfilp-func-sig-report-dynamic"}, |
| 1722 | + ctx.arg.zZicfilpFuncSigReportDynamic, |
| 1723 | + &hasZicfilpFuncSigReportDynamic}, |
| 1724 | + {{"zicfilp-unlabeled-report"}, ctx.arg.zZicfilpUnlabeledReport, nullptr}, |
| 1725 | + {{"zicfilp-unlabeled-report-dynamic"}, |
1719 | 1726 | ctx.arg.zZicfilpUnlabeledReportDynamic, |
1720 | 1727 | &hasZicfilpUnlabeledReportDynamic}, |
1721 | | - {"zicfilp-func-sig-report", ctx.arg.zZicfilpFuncSigReport, nullptr}, |
1722 | | - {"zicfilp-func-sig-report-dynamic", ctx.arg.zZicfilpFuncSigReportDynamic, |
1723 | | - &hasZicfilpFuncSigReportDynamic}, |
1724 | | - {"zicfiss-report", ctx.arg.zZicfissReport, nullptr}, |
1725 | | - {"zicfiss-report-dynamic", ctx.arg.zZicfissReportDynamic, |
| 1728 | + {{"zicfiss-report"}, ctx.arg.zZicfissReport, nullptr}, |
| 1729 | + {{"zicfiss-report-dynamic"}, |
| 1730 | + ctx.arg.zZicfissReportDynamic, |
1726 | 1731 | &hasZicfissReportDynamic}}; |
1727 | 1732 | for (opt::Arg *arg : args.filtered(OPT_z)) { |
1728 | 1733 | std::pair<StringRef, StringRef> option = |
1729 | 1734 | StringRef(arg->getValue()).split('='); |
1730 | | - for (const ReportOptDesc &desc : reports) { |
1731 | | - if (option.first != desc.name) |
1732 | | - continue; |
1733 | | - arg->claim(); |
1734 | | - if (option.second == "none") |
1735 | | - desc.policy = ReportPolicy::None; |
1736 | | - else if (option.second == "warning") |
1737 | | - desc.policy = ReportPolicy::Warning; |
1738 | | - else if (option.second == "error") |
1739 | | - desc.policy = ReportPolicy::Error; |
1740 | | - else { |
1741 | | - ErrAlways(ctx) << "unknown -z " << desc.name |
1742 | | - << "= value: " << option.second; |
1743 | | - continue; |
1744 | | - } |
1745 | | - if (desc.seen) |
1746 | | - *desc.seen = true; |
| 1735 | + ReportOptDesc *const desc = |
| 1736 | + std::lower_bound(std::begin(reports), std::end(reports), option.first, |
| 1737 | + [](const ReportOptDesc &d, const StringRef &s) { |
| 1738 | + return d.name < s; |
| 1739 | + }); |
| 1740 | + if (desc == std::end(reports) || desc->name != option.first) |
| 1741 | + continue; |
| 1742 | + |
| 1743 | + arg->claim(); |
| 1744 | + if (option.second == "none") |
| 1745 | + desc->policy = ReportPolicy::None; |
| 1746 | + else if (option.second == "warning") |
| 1747 | + desc->policy = ReportPolicy::Warning; |
| 1748 | + else if (option.second == "error") |
| 1749 | + desc->policy = ReportPolicy::Error; |
| 1750 | + else { |
| 1751 | + ErrAlways(ctx) << "unknown -z " << desc->name |
| 1752 | + << "= value: " << option.second; |
| 1753 | + continue; |
1747 | 1754 | } |
| 1755 | + if (desc->seen) |
| 1756 | + *desc->seen = true; |
1748 | 1757 | } |
1749 | 1758 |
|
1750 | 1759 | struct ReportDynamicOptDesc { |
|
0 commit comments