<div><div dir="auto">LGTM</div></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 22, 2019 at 8:34 PM Petr Hosek via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">phosek created this revision.<br>
phosek added reviewers: jroelofs, bkramer.<br>
Herald added subscribers: cfe-commits, mgrang.<br>
Herald added a project: clang.<br>
<br>
When more than one multilib flag matches, try to select the best<br>
possible match based on priority. When two different multilibs with<br>
the same same priority match, we still throw an error matching the<br>
existing behavior.<br>
<br>
<br>
Repository:<br>
rC Clang<br>
<br>
<a href="https://reviews.llvm.org/D60990" rel="noreferrer" target="_blank">https://reviews.llvm.org/D60990</a><br>
<br>
Files:<br>
clang/include/clang/Driver/Multilib.h<br>
clang/lib/Driver/Multilib.cpp<br>
<br>
<br>
Index: clang/lib/Driver/Multilib.cpp<br>
===================================================================<br>
--- clang/lib/Driver/Multilib.cpp<br>
+++ clang/lib/Driver/Multilib.cpp<br>
@@ -19,6 +19,7 @@<br>
#include "llvm/Support/raw_ostream.h"<br>
#include <algorithm><br>
#include <cassert><br>
+#include <map><br>
#include <string><br>
<br>
using namespace clang;<br>
@@ -51,8 +52,9 @@<br>
}<br>
<br>
Multilib::Multilib(StringRef GCCSuffix, StringRef OSSuffix,<br>
- StringRef IncludeSuffix)<br>
- : GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix) {<br>
+ StringRef IncludeSuffix, int Priority)<br>
+ : GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix),<br>
+ Priority(Priority) {<br>
normalizePathSegment(this->GCCSuffix);<br>
normalizePathSegment(this->OSSuffix);<br>
normalizePathSegment(this->IncludeSuffix);<br>
@@ -265,8 +267,19 @@<br>
return true;<br>
}<br>
<br>
- // TODO: pick the "best" multlib when more than one is suitable<br>
- assert(false);<br>
+ // Sort multilibs by priority and select the one with the highest priority.<br>
+ std::sort(Filtered.begin(), Filtered.end(),<br>
+ [](const Multilib &a, const Multilib &b) -> bool {<br>
+ return a.priority() > b.priority();<br>
+ });<br>
+<br>
+ if (Filtered[0].priority() <= Filtered[1].priority()) {<br>
+ M = Filtered[0];<br>
+ return true;<br>
+ }<br>
+<br>
+ // TODO: We should consider returning llvm::Error rather than aborting.<br>
+ assert(false && "More than one multilib with the same priority");<br>
return false;<br>
}<br>
<br>
Index: clang/include/clang/Driver/Multilib.h<br>
===================================================================<br>
--- clang/include/clang/Driver/Multilib.h<br>
+++ clang/include/clang/Driver/Multilib.h<br>
@@ -34,10 +34,11 @@<br>
std::string OSSuffix;<br>
std::string IncludeSuffix;<br>
flags_list Flags;<br>
+ int Priority;<br>
<br>
public:<br>
Multilib(StringRef GCCSuffix = {}, StringRef OSSuffix = {},<br>
- StringRef IncludeSuffix = {});<br>
+ StringRef IncludeSuffix = {}, int Priority = 0);<br>
<br>
/// Get the detected GCC installation path suffix for the multi-arch<br>
/// target variant. Always starts with a '/', unless empty<br>
@@ -77,6 +78,9 @@<br>
const flags_list &flags() const { return Flags; }<br>
flags_list &flags() { return Flags; }<br>
<br>
+ /// Returns the multilib priority.<br>
+ int priority() const { return Priority; }<br>
+<br>
/// Add a flag to the flags list<br>
/// \p Flag must be a flag accepted by the driver with its leading '-' removed,<br>
/// and replaced with either:<br>
<br>
<br>
</blockquote></div></div>