diff options
author | Petr Hosek <phosek@chromium.org> | 2019-04-27 00:25:11 +0000 |
---|---|---|
committer | Petr Hosek <phosek@chromium.org> | 2019-04-27 00:25:11 +0000 |
commit | 0f9f021d05ac0697b1baf4f79916e8c97208d58d (patch) | |
tree | 1ca265e52eeda53228c16cb3e38c7d005410cbf2 /clang/lib/Driver/Multilib.cpp | |
parent | 4f331cb1f31ed122ffdc66208b7911c5e8bfb587 (diff) | |
download | bcm5719-llvm-0f9f021d05ac0697b1baf4f79916e8c97208d58d.tar.gz bcm5719-llvm-0f9f021d05ac0697b1baf4f79916e8c97208d58d.zip |
[Driver] Support priority for multilibs
When more than one multilib flag matches, try to select the best
possible match based on priority. When two different multilibs with
the same same priority match, we still throw an error matching the
existing behavior.
Differential Revision: https://reviews.llvm.org/D60990
llvm-svn: 359359
Diffstat (limited to 'clang/lib/Driver/Multilib.cpp')
-rw-r--r-- | clang/lib/Driver/Multilib.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/clang/lib/Driver/Multilib.cpp b/clang/lib/Driver/Multilib.cpp index 29c633e39b1..303047e05f7 100644 --- a/clang/lib/Driver/Multilib.cpp +++ b/clang/lib/Driver/Multilib.cpp @@ -51,8 +51,9 @@ static void normalizePathSegment(std::string &Segment) { } Multilib::Multilib(StringRef GCCSuffix, StringRef OSSuffix, - StringRef IncludeSuffix) - : GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix) { + StringRef IncludeSuffix, int Priority) + : GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix), + Priority(Priority) { normalizePathSegment(this->GCCSuffix); normalizePathSegment(this->OSSuffix); normalizePathSegment(this->IncludeSuffix); @@ -265,8 +266,19 @@ bool MultilibSet::select(const Multilib::flags_list &Flags, Multilib &M) const { return true; } - // TODO: pick the "best" multlib when more than one is suitable - assert(false); + // Sort multilibs by priority and select the one with the highest priority. + llvm::sort(Filtered.begin(), Filtered.end(), + [](const Multilib &a, const Multilib &b) -> bool { + return a.priority() > b.priority(); + }); + + if (Filtered[0].priority() > Filtered[1].priority()) { + M = Filtered[0]; + return true; + } + + // TODO: We should consider returning llvm::Error rather than aborting. + assert(false && "More than one multilib with the same priority"); return false; } |