Skip to content

Commit 78a8c8a

Browse files
committed
Addressing comments #1
1 parent e194bda commit 78a8c8a

File tree

2 files changed

+23
-29
lines changed

2 files changed

+23
-29
lines changed

clang/include/clang/Driver/Multilib.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,19 @@ class Multilib {
102102
raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
103103

104104
namespace custom_flag {
105-
struct CustomFlagDeclaration;
106-
using CustomFlagDeclarationPtr = std::shared_ptr<CustomFlagDeclaration>;
105+
struct Declaration;
106+
using DeclarationPtr = std::shared_ptr<Declaration>;
107107

108-
struct CustomFlagValueDetail {
108+
struct ValueDetail {
109109
std::string Name;
110110
std::optional<SmallVector<std::string>> ExtraBuildArgs;
111-
CustomFlagDeclarationPtr Decl;
111+
DeclarationPtr Decl;
112112
};
113113

114-
struct CustomFlagDeclaration {
114+
struct Declaration {
115115
std::string Name;
116-
SmallVector<CustomFlagValueDetail> ValueList;
117-
size_t DefaultValueIdx = ~0UL;
116+
SmallVector<ValueDetail> ValueList;
117+
std::optional<size_t> DefaultValueIdx;
118118
};
119119

120120
static constexpr StringRef Prefix = "-fmultilib-flag=";
@@ -140,15 +140,15 @@ class MultilibSet {
140140
private:
141141
multilib_list Multilibs;
142142
SmallVector<FlagMatcher> FlagMatchers;
143-
SmallVector<custom_flag::CustomFlagDeclarationPtr> CustomFlagDecls;
143+
SmallVector<custom_flag::DeclarationPtr> CustomFlagDecls;
144144
IncludeDirsFunc IncludeCallback;
145145
IncludeDirsFunc FilePathsCallback;
146146

147147
public:
148148
MultilibSet() = default;
149-
MultilibSet(
150-
multilib_list &&Multilibs, SmallVector<FlagMatcher> &&FlagMatchers = {},
151-
SmallVector<custom_flag::CustomFlagDeclarationPtr> &&CustomFlagDecls = {})
149+
MultilibSet(multilib_list &&Multilibs,
150+
SmallVector<FlagMatcher> &&FlagMatchers = {},
151+
SmallVector<custom_flag::DeclarationPtr> &&CustomFlagDecls = {})
152152
: Multilibs(std::move(Multilibs)), FlagMatchers(std::move(FlagMatchers)),
153153
CustomFlagDecls(std::move(CustomFlagDecls)) {}
154154

clang/lib/Driver/Multilib.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,16 @@ struct MultilibSetSerialization {
208208
SmallVector<MultilibGroupSerialization> Groups;
209209
SmallVector<MultilibSerialization> Multilibs;
210210
SmallVector<MultilibSet::FlagMatcher> FlagMatchers;
211-
SmallVector<custom_flag::CustomFlagDeclarationPtr> CustomFlagDeclarations;
211+
SmallVector<custom_flag::DeclarationPtr> CustomFlagDeclarations;
212212
};
213213

214214
} // end anonymous namespace
215215

216216
LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSerialization)
217217
LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibGroupSerialization)
218218
LLVM_YAML_IS_SEQUENCE_VECTOR(MultilibSet::FlagMatcher)
219-
LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::CustomFlagValueDetail)
220-
LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::CustomFlagDeclarationPtr)
219+
LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::ValueDetail)
220+
LLVM_YAML_IS_SEQUENCE_VECTOR(custom_flag::DeclarationPtr)
221221

222222
template <> struct llvm::yaml::MappingTraits<MultilibSerialization> {
223223
static void mapping(llvm::yaml::IO &io, MultilibSerialization &V) {
@@ -267,14 +267,14 @@ template <> struct llvm::yaml::MappingTraits<MultilibSet::FlagMatcher> {
267267
};
268268

269269
template <>
270-
struct llvm::yaml::MappingContextTraits<custom_flag::CustomFlagValueDetail,
270+
struct llvm::yaml::MappingContextTraits<custom_flag::ValueDetail,
271271
llvm::SmallSet<std::string, 32>> {
272-
static void mapping(llvm::yaml::IO &io, custom_flag::CustomFlagValueDetail &V,
272+
static void mapping(llvm::yaml::IO &io, custom_flag::ValueDetail &V,
273273
llvm::SmallSet<std::string, 32> &) {
274274
io.mapRequired("Name", V.Name);
275275
io.mapOptional("ExtraBuildArgs", V.ExtraBuildArgs);
276276
}
277-
static std::string validate(IO &io, custom_flag::CustomFlagValueDetail &V,
277+
static std::string validate(IO &io, custom_flag::ValueDetail &V,
278278
llvm::SmallSet<std::string, 32> &NameSet) {
279279
if (V.Name.empty())
280280
return "custom flag value requires a name";
@@ -285,13 +285,12 @@ struct llvm::yaml::MappingContextTraits<custom_flag::CustomFlagValueDetail,
285285
};
286286

287287
template <>
288-
struct llvm::yaml::MappingContextTraits<custom_flag::CustomFlagDeclarationPtr,
288+
struct llvm::yaml::MappingContextTraits<custom_flag::DeclarationPtr,
289289
llvm::SmallSet<std::string, 32>> {
290-
static void mapping(llvm::yaml::IO &io,
291-
custom_flag::CustomFlagDeclarationPtr &V,
290+
static void mapping(llvm::yaml::IO &io, custom_flag::DeclarationPtr &V,
292291
llvm::SmallSet<std::string, 32> &NameSet) {
293292
assert(!V);
294-
V = std::make_shared<custom_flag::CustomFlagDeclaration>();
293+
V = std::make_shared<custom_flag::Declaration>();
295294
io.mapRequired("Name", V->Name);
296295
io.mapRequired("Values", V->ValueList, NameSet);
297296
std::string DefaultValueName;
@@ -300,24 +299,19 @@ struct llvm::yaml::MappingContextTraits<custom_flag::CustomFlagDeclarationPtr,
300299
for (auto [Idx, Value] : llvm::enumerate(V->ValueList)) {
301300
Value.Decl = V;
302301
if (Value.Name == DefaultValueName) {
303-
assert(V->DefaultValueIdx == ~0UL);
302+
assert(!V->DefaultValueIdx);
304303
V->DefaultValueIdx = Idx;
305304
}
306305
}
307306
}
308-
static std::string validate(IO &io, custom_flag::CustomFlagDeclarationPtr &V,
307+
static std::string validate(IO &io, custom_flag::DeclarationPtr &V,
309308
llvm::SmallSet<std::string, 32> &) {
310309
if (V->Name.empty())
311310
return "custom flag requires a name";
312311
if (V->ValueList.empty())
313312
return "custom flag must have at least one value";
314-
if (V->DefaultValueIdx >= V->ValueList.size())
313+
if (!V->DefaultValueIdx)
315314
return "custom flag must have a default value";
316-
if (llvm::any_of(V->ValueList, [&V](const auto &Value) {
317-
return !Value.Decl || Value.Decl != V;
318-
}))
319-
return "custom flag value missing reference to its custom flag "
320-
"declaration";
321315
return {};
322316
}
323317
};

0 commit comments

Comments
 (0)