Skip to content

Commit 8fda5cb

Browse files
author
Jenkins
committed
merge main into amd-staging
Change-Id: Iede01f85dc84585670a45a48fc7e4f26ae89151c
2 parents 02b7b6e + 8df6637 commit 8fda5cb

File tree

119 files changed

+1887
-4626
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+1887
-4626
lines changed

clang/docs/Multilib.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ For a more comprehensive example see
202202
203203
# If there is no multilib available for a particular set of flags, and the
204204
# other multilibs are not adequate fallbacks, then you can define a variant
205-
# record with a FatalError key in place of the Dir key.
206-
- FatalError: this multilib collection has no hard-float ABI support
205+
# record with an Error key in place of the Dir key.
206+
- Error: this multilib collection has no hard-float ABI support
207207
Flags: [--target=thumbv7m-none-eabi, -mfloat-abi=hard]
208208
209209

clang/include/clang/Driver/Multilib.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Multilib {
5454
// Some Multilib objects don't actually represent library directories you can
5555
// select. Instead, they represent failures of multilib selection, of the
5656
// form 'Sorry, we don't have any library compatible with these constraints'.
57-
std::optional<std::string> FatalError;
57+
std::optional<std::string> Error;
5858

5959
public:
6060
/// GCCSuffix, OSSuffix & IncludeSuffix will be appended directly to the
@@ -63,7 +63,7 @@ class Multilib {
6363
Multilib(StringRef GCCSuffix = {}, StringRef OSSuffix = {},
6464
StringRef IncludeSuffix = {}, const flags_list &Flags = flags_list(),
6565
StringRef ExclusiveGroup = {},
66-
std::optional<StringRef> FatalError = std::nullopt);
66+
std::optional<StringRef> Error = std::nullopt);
6767

6868
/// Get the detected GCC installation path suffix for the multi-arch
6969
/// target variant. Always starts with a '/', unless empty
@@ -94,9 +94,9 @@ class Multilib {
9494

9595
bool operator==(const Multilib &Other) const;
9696

97-
bool isFatalError() const { return FatalError.has_value(); }
97+
bool isError() const { return Error.has_value(); }
9898

99-
const std::string &getFatalError() const { return FatalError.value(); }
99+
const std::string &getErrorMessage() const { return Error.value(); }
100100
};
101101

102102
raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5670,6 +5670,9 @@ def mthumb : Flag<["-"], "mthumb">, Group<m_Group>;
56705670
def mtune_EQ : Joined<["-"], "mtune=">, Group<m_Group>,
56715671
Visibility<[ClangOption, FlangOption]>,
56725672
HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and X86">;
5673+
def multi_lib_config : Joined<["-", "--"], "multi-lib-config=">,
5674+
HelpText<"Path to the YAML configuration file to be used for multilib selection">,
5675+
MetaVarName<"<file>">;
56735676
def multi__module : Flag<["-"], "multi_module">;
56745677
def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
56755678
def multiply__defined : Separate<["-"], "multiply_defined">;

clang/lib/Driver/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2345,7 +2345,7 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
23452345

23462346
if (C.getArgs().hasArg(options::OPT_print_multi_lib)) {
23472347
for (const Multilib &Multilib : TC.getMultilibs())
2348-
if (!Multilib.isFatalError())
2348+
if (!Multilib.isError())
23492349
llvm::outs() << Multilib << "\n";
23502350
return false;
23512351
}

clang/lib/Driver/Multilib.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ using namespace llvm::sys;
3232

3333
Multilib::Multilib(StringRef GCCSuffix, StringRef OSSuffix,
3434
StringRef IncludeSuffix, const flags_list &Flags,
35-
StringRef ExclusiveGroup,
36-
std::optional<StringRef> FatalError)
35+
StringRef ExclusiveGroup, std::optional<StringRef> Error)
3736
: GCCSuffix(GCCSuffix), OSSuffix(OSSuffix), IncludeSuffix(IncludeSuffix),
38-
Flags(Flags), ExclusiveGroup(ExclusiveGroup), FatalError(FatalError) {
37+
Flags(Flags), ExclusiveGroup(ExclusiveGroup), Error(Error) {
3938
assert(GCCSuffix.empty() ||
4039
(StringRef(GCCSuffix).front() == '/' && GCCSuffix.size() > 1));
4140
assert(OSSuffix.empty() ||
@@ -100,6 +99,7 @@ bool MultilibSet::select(const Driver &D, const Multilib::flags_list &Flags,
10099
llvm::SmallVectorImpl<Multilib> &Selected) const {
101100
llvm::StringSet<> FlagSet(expandFlags(Flags));
102101
Selected.clear();
102+
bool AnyErrors = false;
103103

104104
// Decide which multilibs we're going to select at all.
105105
llvm::DenseSet<StringRef> ExclusiveGroupsSelected;
@@ -123,13 +123,11 @@ bool MultilibSet::select(const Driver &D, const Multilib::flags_list &Flags,
123123
continue;
124124
}
125125

126-
// If this multilib is actually a placeholder containing a fatal
127-
// error message written by the multilib.yaml author, display that
128-
// error message, and return failure.
129-
if (M.isFatalError()) {
130-
D.Diag(clang::diag::err_drv_multilib_custom_error) << M.getFatalError();
131-
return false;
132-
}
126+
// If this multilib is actually a placeholder containing an error message
127+
// written by the multilib.yaml author, then set a flag that will cause a
128+
// failure return. Our caller will display the error message.
129+
if (M.isError())
130+
AnyErrors = true;
133131

134132
// Select this multilib.
135133
Selected.push_back(M);
@@ -139,7 +137,7 @@ bool MultilibSet::select(const Driver &D, const Multilib::flags_list &Flags,
139137
// round.
140138
std::reverse(Selected.begin(), Selected.end());
141139

142-
return !Selected.empty();
140+
return !AnyErrors && !Selected.empty();
143141
}
144142

145143
llvm::StringSet<>
@@ -173,7 +171,7 @@ static const VersionTuple MultilibVersionCurrent(1, 0);
173171

174172
struct MultilibSerialization {
175173
std::string Dir; // if this record successfully selects a library dir
176-
std::string FatalError; // if this record reports a fatal error message
174+
std::string Error; // if this record reports a fatal error message
177175
std::vector<std::string> Flags;
178176
std::string Group;
179177
};
@@ -217,15 +215,15 @@ struct MultilibSetSerialization {
217215
template <> struct llvm::yaml::MappingTraits<MultilibSerialization> {
218216
static void mapping(llvm::yaml::IO &io, MultilibSerialization &V) {
219217
io.mapOptional("Dir", V.Dir);
220-
io.mapOptional("FatalError", V.FatalError);
218+
io.mapOptional("Error", V.Error);
221219
io.mapRequired("Flags", V.Flags);
222220
io.mapOptional("Group", V.Group);
223221
}
224222
static std::string validate(IO &io, MultilibSerialization &V) {
225-
if (V.Dir.empty() && V.FatalError.empty())
226-
return "one of the 'Dir' and 'FatalError' keys must be specified";
227-
if (!V.Dir.empty() && !V.FatalError.empty())
228-
return "the 'Dir' and 'FatalError' keys may not both be specified";
223+
if (V.Dir.empty() && V.Error.empty())
224+
return "one of the 'Dir' and 'Error' keys must be specified";
225+
if (!V.Dir.empty() && !V.Error.empty())
226+
return "the 'Dir' and 'Error' keys may not both be specified";
229227
if (StringRef(V.Dir).starts_with("/"))
230228
return "paths must be relative but \"" + V.Dir + "\" starts with \"/\"";
231229
return std::string{};
@@ -311,8 +309,8 @@ MultilibSet::parseYaml(llvm::MemoryBufferRef Input,
311309
multilib_list Multilibs;
312310
Multilibs.reserve(MS.Multilibs.size());
313311
for (const auto &M : MS.Multilibs) {
314-
if (!M.FatalError.empty()) {
315-
Multilibs.emplace_back("", "", "", M.Flags, M.Group, M.FatalError);
312+
if (!M.Error.empty()) {
313+
Multilibs.emplace_back("", "", "", M.Flags, M.Group, M.Error);
316314
} else {
317315
std::string Dir;
318316
if (M.Dir != ".")

clang/lib/Driver/ToolChains/BareMetal.cpp

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,23 @@ static bool findRISCVMultilibs(const Driver &D,
9797
return false;
9898
}
9999

100+
static std::string computeBaseSysRoot(const Driver &D, bool IncludeTriple) {
101+
if (!D.SysRoot.empty())
102+
return D.SysRoot;
103+
104+
SmallString<128> SysRootDir(D.Dir);
105+
llvm::sys::path::append(SysRootDir, "..", "lib", "clang-runtimes");
106+
107+
if (IncludeTriple)
108+
llvm::sys::path::append(SysRootDir, D.getTargetTriple());
109+
110+
return std::string(SysRootDir);
111+
}
112+
100113
BareMetal::BareMetal(const Driver &D, const llvm::Triple &Triple,
101114
const ArgList &Args)
102-
: ToolChain(D, Triple, Args) {
115+
: ToolChain(D, Triple, Args),
116+
SysRoot(computeBaseSysRoot(D, /*IncludeTriple=*/true)) {
103117
getProgramPaths().push_back(getDriver().Dir);
104118

105119
findMultilibs(D, Triple, Args);
@@ -186,45 +200,62 @@ static void findMultilibsFromYAML(const ToolChain &TC, const Driver &D,
186200
return;
187201
D.Diag(clang::diag::warn_drv_missing_multilib) << llvm::join(Flags, " ");
188202
std::stringstream ss;
203+
204+
// If multilib selection didn't complete successfully, report a list
205+
// of all the configurations the user could have provided.
189206
for (const Multilib &Multilib : Result.Multilibs)
190-
if (!Multilib.isFatalError())
207+
if (!Multilib.isError())
191208
ss << "\n" << llvm::join(Multilib.flags(), " ");
192209
D.Diag(clang::diag::note_drv_available_multilibs) << ss.str();
210+
211+
// Now report any custom error messages requested by the YAML. We do
212+
// this after displaying the list of available multilibs, because
213+
// that list is probably large, and (in interactive use) risks
214+
// scrolling the useful error message off the top of the user's
215+
// terminal.
216+
for (const Multilib &Multilib : Result.SelectedMultilibs)
217+
if (Multilib.isError())
218+
D.Diag(clang::diag::err_drv_multilib_custom_error)
219+
<< Multilib.getErrorMessage();
220+
221+
// If there was an error, clear the SelectedMultilibs vector, in
222+
// case it contains partial data.
223+
Result.SelectedMultilibs.clear();
193224
}
194225

195226
static constexpr llvm::StringLiteral MultilibFilename = "multilib.yaml";
196227

197-
// Get the sysroot, before multilib takes effect.
198-
static std::string computeBaseSysRoot(const Driver &D,
199-
const llvm::Triple &Triple) {
200-
if (!D.SysRoot.empty())
201-
return D.SysRoot;
202-
203-
SmallString<128> SysRootDir(D.Dir);
204-
llvm::sys::path::append(SysRootDir, "..", "lib", "clang-runtimes");
205-
206-
SmallString<128> MultilibPath(SysRootDir);
207-
llvm::sys::path::append(MultilibPath, MultilibFilename);
208-
209-
// New behaviour: if multilib.yaml is found then use clang-runtimes as the
210-
// sysroot.
211-
if (D.getVFS().exists(MultilibPath))
212-
return std::string(SysRootDir);
213-
214-
// Otherwise fall back to the old behaviour of appending the target triple.
215-
llvm::sys::path::append(SysRootDir, D.getTargetTriple());
216-
return std::string(SysRootDir);
228+
static std::optional<llvm::SmallString<128>>
229+
getMultilibConfigPath(const Driver &D, const llvm::Triple &Triple,
230+
const ArgList &Args) {
231+
llvm::SmallString<128> MultilibPath;
232+
if (Arg *ConfigFileArg = Args.getLastArg(options::OPT_multi_lib_config)) {
233+
MultilibPath = ConfigFileArg->getValue();
234+
if (!D.getVFS().exists(MultilibPath)) {
235+
D.Diag(clang::diag::err_drv_no_such_file) << MultilibPath.str();
236+
return {};
237+
}
238+
} else {
239+
MultilibPath = computeBaseSysRoot(D, /*IncludeTriple=*/false);
240+
llvm::sys::path::append(MultilibPath, MultilibFilename);
241+
}
242+
return MultilibPath;
217243
}
218244

219245
void BareMetal::findMultilibs(const Driver &D, const llvm::Triple &Triple,
220246
const ArgList &Args) {
221247
DetectedMultilibs Result;
222248
// Look for a multilib.yaml before trying target-specific hardwired logic.
223249
// If it exists, always do what it specifies.
224-
llvm::SmallString<128> MultilibPath(computeBaseSysRoot(D, Triple));
225-
llvm::sys::path::append(MultilibPath, MultilibFilename);
226-
if (D.getVFS().exists(MultilibPath)) {
227-
findMultilibsFromYAML(*this, D, MultilibPath, Args, Result);
250+
std::optional<llvm::SmallString<128>> MultilibPath =
251+
getMultilibConfigPath(D, Triple, Args);
252+
if (!MultilibPath)
253+
return;
254+
if (D.getVFS().exists(*MultilibPath)) {
255+
// If multilib.yaml is found, update sysroot so it doesn't use a target
256+
// specific suffix
257+
SysRoot = computeBaseSysRoot(D, /*IncludeTriple=*/false);
258+
findMultilibsFromYAML(*this, D, *MultilibPath, Args, Result);
228259
SelectedMultilibs = Result.SelectedMultilibs;
229260
Multilibs = Result.Multilibs;
230261
} else if (isRISCVBareMetal(Triple)) {
@@ -248,9 +279,7 @@ Tool *BareMetal::buildStaticLibTool() const {
248279
return new tools::baremetal::StaticLibTool(*this);
249280
}
250281

251-
std::string BareMetal::computeSysRoot() const {
252-
return computeBaseSysRoot(getDriver(), getTriple());
253-
}
282+
std::string BareMetal::computeSysRoot() const { return SysRoot; }
254283

255284
BareMetal::OrderedMultilibs BareMetal::getOrderedMultilibs() const {
256285
// Get multilibs in reverse order because they're ordered most-specific last.

clang/lib/Driver/ToolChains/BareMetal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain {
7878
using OrderedMultilibs =
7979
llvm::iterator_range<llvm::SmallVector<Multilib>::const_reverse_iterator>;
8080
OrderedMultilibs getOrderedMultilibs() const;
81+
82+
std::string SysRoot;
8183
};
8284

8385
} // namespace toolchains

clang/lib/Sema/SemaExpr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6992,8 +6992,7 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
69926992
}
69936993

69946994
if (CXXMethodDecl *Method = dyn_cast_or_null<CXXMethodDecl>(FDecl))
6995-
if (!isa<RequiresExprBodyDecl>(CurContext) &&
6996-
Method->isImplicitObjectMemberFunction())
6995+
if (Method->isImplicitObjectMemberFunction())
69976996
return ExprError(Diag(LParenLoc, diag::err_member_call_without_object)
69986997
<< Fn->getSourceRange() << 0);
69996998

clang/lib/Sema/TreeTransform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13907,7 +13907,7 @@ bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
1390713907
}
1390813908

1390913909
AllEmptyPacks &= Decls.empty();
13910-
};
13910+
}
1391113911

1391213912
// C++ [temp.res]/8.4.2:
1391313913
// The program is ill-formed, no diagnostic required, if [...] lookup for
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
MultilibVersion: 1.0
3+
4+
Variants:
5+
6+
Mappings:
7+
8+
...

0 commit comments

Comments
 (0)