Skip to content

Commit ce8c59e

Browse files
committed
Reapply multiple "[clang][cli]" patches
This reverts 7ad6667 and 1876a29 that reverted: 741978d [clang][cli] Port CodeGen option flags to new option parsing system 383778e [clang][cli] Port LangOpts option flags to new option parsing system aec2991 [clang][cli] Port LangOpts simple string based options to new option parsing system 95d3cc6 [clang][cli] Port CodeGenOpts simple string flags to new option parsing system 27b7d64 [clang][cli] Streamline MarshallingInfoFlag description 70410a2 [clang][cli] Let denormalizer decide how to render the option based on the option class 63a2481 [clang][cli] Implement `getAllArgValues` marshalling Commit 741978d accidentally changed the `Group` attribute of `g[no_]column_info` options from `g_flags_Group` to `g_Group`, which changed the debug info options passed to cc1 by the driver. Similar change was also present in 383778e, which accidentally added `Group<f_Group>` to `f[no_]const_strings` and `f[no_]signed_wchar`. This patch corrects all three accidental changes by replacing `Bool{G,F}Option` with `BoolCC1Option`.
1 parent 643e3c9 commit ce8c59e

File tree

8 files changed

+1033
-1342
lines changed

8 files changed

+1033
-1342
lines changed

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ namespace clang {
3030
/// Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure
3131
/// that this large collection of bitfields is a trivial class type.
3232
class CodeGenOptionsBase {
33+
friend class CompilerInvocation;
34+
3335
public:
3436
#define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits;
3537
#define ENUM_CODEGENOPT(Name, Type, Bits, Default)

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ def err_drv_invalid_thread_model_for_target : Error<
8686
"invalid thread model '%0' in '%1' for this target">;
8787
def err_drv_invalid_linker_name : Error<
8888
"invalid linker name in argument '%0'">;
89-
def err_drv_invalid_pgo_instrumentor : Error<
90-
"invalid PGO instrumentor in argument '%0'">;
9189
def err_drv_invalid_rtlib_name : Error<
9290
"invalid runtime library name in argument '%0'">;
9391
def err_drv_unsupported_rtlib_for_platform : Error<

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ def err_fe_action_not_available : Error<
108108
"action %0 not compiled in">;
109109
def err_fe_invalid_alignment : Error<
110110
"invalid value '%1' in '%0'; alignment must be a power of 2">;
111-
def err_fe_invalid_wchar_type
112-
: Error<"invalid wchar_t type '%0'; must be one of 'char', 'short', 'int'">;
113111
def err_fe_invalid_exception_model
114112
: Error<"invalid exception model '%select{none|dwarf|sjlj|arm|seh|wasm|aix}0' for target '%1'">;
115113
def warn_fe_concepts_ts_flag : Warning<

clang/include/clang/Driver/Options.td

Lines changed: 839 additions & 525 deletions
Large diffs are not rendered by default.

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 97 additions & 804 deletions
Large diffs are not rendered by default.

clang/test/Profile/c-generate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88
// PROF-INSTR-NONE-NOT: __llvm_prf
99
//
10-
// PROF-INSTR-GARBAGE: invalid PGO instrumentor in argument '-fprofile-instrument=garbage'
10+
// PROF-INSTR-GARBAGE: invalid value 'garbage' in '-fprofile-instrument=garbage'
1111

1212
int main(void) {
1313
return 0;

clang/unittests/Frontend/CompilerInvocationTest.cpp

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

2020
using ::testing::Contains;
21+
using ::testing::HasSubstr;
2122
using ::testing::StrEq;
2223

2324
namespace {
@@ -342,30 +343,109 @@ TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateRequiredAbsent) {
342343
ASSERT_THAT(GeneratedArgs, Contains(StrEq(DefaultTriple.c_str())));
343344
}
344345

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

348349
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
349350

350351
ASSERT_FALSE(Diags->hasErrorOccurred());
352+
ASSERT_EQ(Invocation.getCodeGenOpts().RelocationModel, Reloc::Model::Static);
351353

352354
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
353355

354356
// Non default relocation model.
357+
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-mrelocation-model")));
355358
ASSERT_THAT(GeneratedArgs, Contains(StrEq("static")));
359+
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-mrelocation-model=static"))));
356360
}
357361

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

361365
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
362366

363367
ASSERT_FALSE(Diags->hasErrorOccurred());
368+
ASSERT_EQ(Invocation.getCodeGenOpts().RelocationModel, Reloc::Model::PIC_);
364369

365370
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
366371

367372
// Default relocation model.
373+
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-mrelocation-model"))));
368374
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);
369449
}
370450

371451
// Wide integer option.

llvm/include/llvm/Option/OptParser.td

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,24 @@ 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+
170176
class MarshallingInfoFlag<code keypath, code defaultvalue = "false">
171177
: MarshallingInfo<keypath, defaultvalue> {
172178
code Normalizer = "normalizeSimpleFlag";
173179
code Denormalizer = "denormalizeSimpleFlag";
174180
}
175181

182+
class MarshallingInfoNegativeFlag<code keypath, code defaultvalue = "true">
183+
: MarshallingInfo<keypath, defaultvalue> {
184+
code Normalizer = "normalizeSimpleNegativeFlag";
185+
code Denormalizer = "denormalizeSimpleFlag";
186+
}
187+
176188
class MarshallingInfoBitfieldFlag<code keypath, code value>
177189
: MarshallingInfoFlag<keypath, "0u"> {
178190
code Normalizer = "makeFlagToValueNormalizer("#value#")";
@@ -190,9 +202,6 @@ class MarshallingInfoBooleanFlag<code keypath, code defaultvalue, code value, co
190202

191203
// Mixins for additional marshalling attributes.
192204

193-
class IsNegative {
194-
code Normalizer = "normalizeSimpleNegativeFlag";
195-
}
196205
class AlwaysEmit { bit ShouldAlwaysEmit = true; }
197206
class Normalizer<code normalizer> { code Normalizer = normalizer; }
198207
class Denormalizer<code denormalizer> { code Denormalizer = denormalizer; }
@@ -202,9 +211,6 @@ class AutoNormalizeEnum {
202211
code Normalizer = "normalizeSimpleEnum";
203212
code Denormalizer = "denormalizeSimpleEnum";
204213
}
205-
class AutoNormalizeEnumJoined : AutoNormalizeEnum {
206-
code Denormalizer = "denormalizeSimpleEnumJoined";
207-
}
208214
class ValueMerger<code merger> { code ValueMerger = merger; }
209215
class ValueExtractor<code extractor> { code ValueExtractor = extractor; }
210216

0 commit comments

Comments
 (0)