Skip to content

Commit 1876a29

Browse files
committed
Revert more changes that landed on top of 741978d
This should've been in 7ad6667 but wasn't. Squashes these twoc commits: Revert "[clang][cli] Let denormalizer decide how to render the option based on the option class" This reverts commit 70410a2. Revert "[clang][cli] Implement `getAllArgValues` marshalling" This reverts commit 63a2481.
1 parent bbd758a commit 1876a29

File tree

4 files changed

+47
-147
lines changed

4 files changed

+47
-147
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,8 +1839,7 @@ def fsystem_module : Flag<["-"], "fsystem-module">, Flags<[CC1Option]>,
18391839
MarshallingInfoFlag<"FrontendOpts.IsSystemModule">;
18401840
def fmodule_map_file : Joined<["-"], "fmodule-map-file=">,
18411841
Group<f_Group>, Flags<[NoXarchOption,CC1Option]>, MetaVarName<"<file>">,
1842-
HelpText<"Load this module map file">,
1843-
MarshallingInfoStringVector<"FrontendOpts.ModuleMapFiles">;
1842+
HelpText<"Load this module map file">;
18441843
def fmodule_file : Joined<["-"], "fmodule-file=">,
18451844
Group<i_Group>, Flags<[NoXarchOption,CC1Option]>, MetaVarName<"[<name>=]<file>">,
18461845
HelpText<"Specify the mapping of module name to precompiled module file, or load a module file if name is omitted.">;
@@ -4625,7 +4624,7 @@ def arcmt_action_EQ : Joined<["-"], "arcmt-action=">, Flags<[CC1Option, NoDriver
46254624
NormalizedValuesScope<"FrontendOptions">,
46264625
NormalizedValues<["ARCMT_Check", "ARCMT_Modify", "ARCMT_Migrate"]>,
46274626
MarshallingInfoString<"FrontendOpts.ARCMTAction", "ARCMT_None">,
4628-
AutoNormalizeEnum;
4627+
AutoNormalizeEnumJoined;
46294628

46304629
def opt_record_file : Separate<["-"], "opt-record-file">,
46314630
HelpText<"File name to use for YAML optimization record output">;

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 40 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ static Optional<bool> normalizeSimpleNegativeFlag(OptSpecifier Opt, unsigned,
152152
/// argument.
153153
static void denormalizeSimpleFlag(SmallVectorImpl<const char *> &Args,
154154
const char *Spelling,
155-
CompilerInvocation::StringAllocator,
156-
Option::OptionClass, unsigned, /*T*/...) {
155+
CompilerInvocation::StringAllocator, unsigned,
156+
/*T*/...) {
157157
Args.push_back(Spelling);
158158
}
159159

@@ -193,41 +193,12 @@ static auto makeBooleanOptionNormalizer(bool Value, bool OtherValue,
193193

194194
static auto makeBooleanOptionDenormalizer(bool Value) {
195195
return [Value](SmallVectorImpl<const char *> &Args, const char *Spelling,
196-
CompilerInvocation::StringAllocator, Option::OptionClass,
197-
unsigned, bool KeyPath) {
196+
CompilerInvocation::StringAllocator, unsigned, bool KeyPath) {
198197
if (KeyPath == Value)
199198
Args.push_back(Spelling);
200199
};
201200
}
202201

203-
static void denormalizeStringImpl(SmallVectorImpl<const char *> &Args,
204-
const char *Spelling,
205-
CompilerInvocation::StringAllocator SA,
206-
Option::OptionClass OptClass, unsigned,
207-
Twine Value) {
208-
switch (OptClass) {
209-
case Option::SeparateClass:
210-
case Option::JoinedOrSeparateClass:
211-
Args.push_back(Spelling);
212-
Args.push_back(SA(Value));
213-
break;
214-
case Option::JoinedClass:
215-
Args.push_back(SA(Twine(Spelling) + Value));
216-
break;
217-
default:
218-
llvm_unreachable("Cannot denormalize an option with option class "
219-
"incompatible with string denormalization.");
220-
}
221-
}
222-
223-
template <typename T>
224-
static void
225-
denormalizeString(SmallVectorImpl<const char *> &Args, const char *Spelling,
226-
CompilerInvocation::StringAllocator SA,
227-
Option::OptionClass OptClass, unsigned TableIndex, T Value) {
228-
denormalizeStringImpl(Args, Spelling, SA, OptClass, TableIndex, Twine(Value));
229-
}
230-
231202
static Optional<SimpleEnumValue>
232203
findValueTableByName(const SimpleEnumValueTable &Table, StringRef Name) {
233204
for (int I = 0, E = Table.Size; I != E; ++I)
@@ -269,13 +240,12 @@ static llvm::Optional<unsigned> normalizeSimpleEnum(OptSpecifier Opt,
269240
static void denormalizeSimpleEnumImpl(SmallVectorImpl<const char *> &Args,
270241
const char *Spelling,
271242
CompilerInvocation::StringAllocator SA,
272-
Option::OptionClass OptClass,
273243
unsigned TableIndex, unsigned Value) {
274244
assert(TableIndex < SimpleEnumValueTablesSize);
275245
const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
276246
if (auto MaybeEnumVal = findValueTableByValue(Table, Value)) {
277-
denormalizeString(Args, Spelling, SA, OptClass, TableIndex,
278-
MaybeEnumVal->Name);
247+
Args.push_back(Spelling);
248+
Args.push_back(MaybeEnumVal->Name);
279249
} else {
280250
llvm_unreachable("The simple enum value was not correctly defined in "
281251
"the tablegen option description");
@@ -286,12 +256,24 @@ template <typename T>
286256
static void denormalizeSimpleEnum(SmallVectorImpl<const char *> &Args,
287257
const char *Spelling,
288258
CompilerInvocation::StringAllocator SA,
289-
Option::OptionClass OptClass,
290259
unsigned TableIndex, T Value) {
291-
return denormalizeSimpleEnumImpl(Args, Spelling, SA, OptClass, TableIndex,
260+
return denormalizeSimpleEnumImpl(Args, Spelling, SA, TableIndex,
292261
static_cast<unsigned>(Value));
293262
}
294263

264+
static void denormalizeSimpleEnumJoined(SmallVectorImpl<const char *> &Args,
265+
const char *Spelling,
266+
CompilerInvocation::StringAllocator SA,
267+
unsigned TableIndex, unsigned Value) {
268+
assert(TableIndex < SimpleEnumValueTablesSize);
269+
const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
270+
if (auto MaybeEnumVal = findValueTableByValue(Table, Value))
271+
Args.push_back(SA(Twine(Spelling) + MaybeEnumVal->Name));
272+
else
273+
llvm_unreachable("The simple enum value was not correctly defined in "
274+
"the tablegen option description");
275+
}
276+
295277
static Optional<std::string> normalizeString(OptSpecifier Opt, int TableIndex,
296278
const ArgList &Args,
297279
DiagnosticsEngine &Diags) {
@@ -301,6 +283,25 @@ static Optional<std::string> normalizeString(OptSpecifier Opt, int TableIndex,
301283
return std::string(Arg->getValue());
302284
}
303285

286+
static void denormalizeString(SmallVectorImpl<const char *> &Args,
287+
const char *Spelling,
288+
CompilerInvocation::StringAllocator SA, unsigned,
289+
Twine Value) {
290+
Args.push_back(Spelling);
291+
Args.push_back(SA(Value));
292+
}
293+
294+
template <typename T,
295+
std::enable_if_t<!std::is_convertible<T, Twine>::value &&
296+
std::is_constructible<Twine, T>::value,
297+
bool> = false>
298+
static void denormalizeString(SmallVectorImpl<const char *> &Args,
299+
const char *Spelling,
300+
CompilerInvocation::StringAllocator SA,
301+
unsigned TableIndex, T Value) {
302+
denormalizeString(Args, Spelling, SA, TableIndex, Twine(Value));
303+
}
304+
304305
template <typename IntTy>
305306
static Optional<IntTy> normalizeStringIntegral(OptSpecifier Opt, int,
306307
const ArgList &Args,
@@ -316,23 +317,6 @@ static Optional<IntTy> normalizeStringIntegral(OptSpecifier Opt, int,
316317
return Res;
317318
}
318319

319-
static Optional<std::vector<std::string>>
320-
normalizeStringVector(OptSpecifier Opt, int, const ArgList &Args,
321-
DiagnosticsEngine &) {
322-
return Args.getAllArgValues(Opt);
323-
}
324-
325-
static void denormalizeStringVector(SmallVectorImpl<const char *> &Args,
326-
const char *Spelling,
327-
CompilerInvocation::StringAllocator SA,
328-
Option::OptionClass OptClass,
329-
unsigned TableIndex,
330-
const std::vector<std::string> &Values) {
331-
for (const std::string &Value : Values) {
332-
denormalizeString(Args, Spelling, SA, OptClass, TableIndex, Value);
333-
}
334-
}
335-
336320
static Optional<std::string> normalizeTriple(OptSpecifier Opt, int TableIndex,
337321
const ArgList &Args,
338322
DiagnosticsEngine &Diags) {
@@ -2105,6 +2089,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
21052089
Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
21062090
Opts.ASTDumpDecls = Args.hasArg(OPT_ast_dump, OPT_ast_dump_EQ);
21072091
Opts.ASTDumpAll = Args.hasArg(OPT_ast_dump_all, OPT_ast_dump_all_EQ);
2092+
Opts.ModuleMapFiles = Args.getAllArgValues(OPT_fmodule_map_file);
21082093
// Only the -fmodule-file=<file> form.
21092094
for (const auto *A : Args.filtered(OPT_fmodule_file)) {
21102095
StringRef Val = A->getValue();
@@ -4001,8 +3986,7 @@ void CompilerInvocation::generateCC1CommandLine(
40013986
(Extracted != \
40023987
static_cast<decltype(this->KEYPATH)>( \
40033988
(IMPLIED_CHECK) ? (IMPLIED_VALUE) : (DEFAULT_VALUE)))) \
4004-
DENORMALIZER(Args, SPELLING, SA, Option::KIND##Class, TABLE_INDEX, \
4005-
Extracted); \
3989+
DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, Extracted); \
40063990
}(EXTRACTOR(this->KEYPATH)); \
40073991
}
40083992

clang/unittests/Frontend/CompilerInvocationTest.cpp

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ using namespace llvm;
1818
using namespace clang;
1919

2020
using ::testing::Contains;
21-
using ::testing::HasSubstr;
2221
using ::testing::StrEq;
2322

2423
namespace {
@@ -343,109 +342,30 @@ TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateRequiredAbsent) {
343342
ASSERT_THAT(GeneratedArgs, Contains(StrEq(DefaultTriple.c_str())));
344343
}
345344

346-
TEST_F(CommandLineTest, SeparateEnumNonDefault) {
345+
TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateEnumNonDefault) {
347346
const char *Args[] = {"-mrelocation-model", "static"};
348347

349348
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
350349

351350
ASSERT_FALSE(Diags->hasErrorOccurred());
352-
ASSERT_EQ(Invocation.getCodeGenOpts().RelocationModel, Reloc::Model::Static);
353351

354352
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
355353

356354
// Non default relocation model.
357-
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-mrelocation-model")));
358355
ASSERT_THAT(GeneratedArgs, Contains(StrEq("static")));
359-
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-mrelocation-model=static"))));
360356
}
361357

362-
TEST_F(CommandLineTest, SeparateEnumDefault) {
358+
TEST_F(CommandLineTest, CanGenerateCC1COmmandLineSeparateEnumDefault) {
363359
const char *Args[] = {"-mrelocation-model", "pic"};
364360

365361
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
366362

367363
ASSERT_FALSE(Diags->hasErrorOccurred());
368-
ASSERT_EQ(Invocation.getCodeGenOpts().RelocationModel, Reloc::Model::PIC_);
369364

370365
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
371366

372367
// Default relocation model.
373-
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-mrelocation-model"))));
374368
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("pic"))));
375-
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-mrelocation-model=pic"))));
376-
}
377-
378-
TEST_F(CommandLineTest, JoinedEnumNonDefault) {
379-
const char *Args[] = {"-fobjc-dispatch-method=non-legacy"};
380-
381-
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
382-
383-
ASSERT_FALSE(Diags->hasErrorOccurred());
384-
ASSERT_EQ(Invocation.getCodeGenOpts().getObjCDispatchMethod(),
385-
CodeGenOptions::NonLegacy);
386-
387-
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
388-
389-
ASSERT_THAT(GeneratedArgs,
390-
Contains(StrEq("-fobjc-dispatch-method=non-legacy")));
391-
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fobjc-dispatch-method="))));
392-
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("non-legacy"))));
393-
}
394-
395-
TEST_F(CommandLineTest, JoinedEnumDefault) {
396-
const char *Args[] = {"-fobjc-dispatch-method=legacy"};
397-
398-
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
399-
400-
ASSERT_FALSE(Diags->hasErrorOccurred());
401-
ASSERT_EQ(Invocation.getCodeGenOpts().getObjCDispatchMethod(),
402-
CodeGenOptions::Legacy);
403-
404-
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
405-
406-
ASSERT_THAT(GeneratedArgs,
407-
Not(Contains(StrEq("-fobjc-dispatch-method=legacy"))));
408-
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fobjc-dispatch-method="))));
409-
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("legacy"))));
410-
}
411-
412-
TEST_F(CommandLineTest, StringVectorEmpty) {
413-
const char *Args[] = {""};
414-
415-
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
416-
417-
ASSERT_FALSE(Diags->hasErrorOccurred());
418-
ASSERT_TRUE(Invocation.getFrontendOpts().ModuleMapFiles.empty());
419-
420-
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
421-
ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-fmodule-map-file="))));
422-
}
423-
424-
TEST_F(CommandLineTest, StringVectorSingle) {
425-
const char *Args[] = {"-fmodule-map-file=a"};
426-
427-
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
428-
429-
ASSERT_FALSE(Diags->hasErrorOccurred());
430-
ASSERT_EQ(Invocation.getFrontendOpts().ModuleMapFiles,
431-
std::vector<std::string>({"a"}));
432-
433-
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
434-
ASSERT_EQ(count(GeneratedArgs, StringRef("-fmodule-map-file=a")), 1);
435-
}
436-
437-
TEST_F(CommandLineTest, StringVectorMultiple) {
438-
const char *Args[] = {"-fmodule-map-file=a", "-fmodule-map-file=b"};
439-
440-
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
441-
442-
ASSERT_FALSE(Diags->hasErrorOccurred());
443-
ASSERT_TRUE(Invocation.getFrontendOpts().ModuleMapFiles ==
444-
std::vector<std::string>({"a", "b"}));
445-
446-
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
447-
ASSERT_EQ(count(GeneratedArgs, StringRef("-fmodule-map-file=a")), 1);
448-
ASSERT_EQ(count(GeneratedArgs, StringRef("-fmodule-map-file=b")), 1);
449369
}
450370

451371
// Tree of boolean options that can be (directly or transitively) implied by

llvm/include/llvm/Option/OptParser.td

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,6 @@ class MarshallingInfoStringInt<code keypath, code defaultvalue="0", code type="u
167167
code Denormalizer = "denormalizeString";
168168
}
169169

170-
class MarshallingInfoStringVector<code keypath>
171-
: MarshallingInfo<keypath, "std::vector<std::string>({})"> {
172-
code Normalizer = "normalizeStringVector";
173-
code Denormalizer = "denormalizeStringVector";
174-
}
175-
176170
class MarshallingInfoFlag<code keypath, code defaultvalue = "false">
177171
: MarshallingInfo<keypath, defaultvalue> {
178172
code Normalizer = "normalizeSimpleFlag";
@@ -208,6 +202,9 @@ class AutoNormalizeEnum {
208202
code Normalizer = "normalizeSimpleEnum";
209203
code Denormalizer = "denormalizeSimpleEnum";
210204
}
205+
class AutoNormalizeEnumJoined : AutoNormalizeEnum {
206+
code Denormalizer = "denormalizeSimpleEnumJoined";
207+
}
211208
class ValueMerger<code merger> { code ValueMerger = merger; }
212209
class ValueExtractor<code extractor> { code ValueExtractor = extractor; }
213210

0 commit comments

Comments
 (0)