[llvm-branch-commits] [clang] 1876a29 - Revert more changes that landed on top of 741978d727

Nico Weber via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Dec 23 11:24:41 PST 2020


Author: Nico Weber
Date: 2020-12-23T14:20:21-05:00
New Revision: 1876a2914fe0bedf50f7be6a305f5bf35493e496

URL: https://github.com/llvm/llvm-project/commit/1876a2914fe0bedf50f7be6a305f5bf35493e496
DIFF: https://github.com/llvm/llvm-project/commit/1876a2914fe0bedf50f7be6a305f5bf35493e496.diff

LOG: Revert more changes that landed on top of 741978d727

This should've been in 7ad666798f12456d9 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 70410a264949101ced3ce3458f37dd4cc2f5af85.

Revert "[clang][cli] Implement `getAllArgValues` marshalling"
This reverts commit 63a24816f561a5d8e28ca7054892bd8602618be4.

Added: 
    

Modified: 
    clang/include/clang/Driver/Options.td
    clang/lib/Frontend/CompilerInvocation.cpp
    clang/unittests/Frontend/CompilerInvocationTest.cpp
    llvm/include/llvm/Option/OptParser.td

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 7f63a5577262..af209eb9089d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1839,8 +1839,7 @@ def fsystem_module : Flag<["-"], "fsystem-module">, Flags<[CC1Option]>,
   MarshallingInfoFlag<"FrontendOpts.IsSystemModule">;
 def fmodule_map_file : Joined<["-"], "fmodule-map-file=">,
   Group<f_Group>, Flags<[NoXarchOption,CC1Option]>, MetaVarName<"<file>">,
-  HelpText<"Load this module map file">,
-  MarshallingInfoStringVector<"FrontendOpts.ModuleMapFiles">;
+  HelpText<"Load this module map file">;
 def fmodule_file : Joined<["-"], "fmodule-file=">,
   Group<i_Group>, Flags<[NoXarchOption,CC1Option]>, MetaVarName<"[<name>=]<file>">,
   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
   NormalizedValuesScope<"FrontendOptions">,
   NormalizedValues<["ARCMT_Check", "ARCMT_Modify", "ARCMT_Migrate"]>,
   MarshallingInfoString<"FrontendOpts.ARCMTAction", "ARCMT_None">,
-  AutoNormalizeEnum;
+  AutoNormalizeEnumJoined;
 
 def opt_record_file : Separate<["-"], "opt-record-file">,
   HelpText<"File name to use for YAML optimization record output">;

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index a7a5a73eebdd..06d8d2e27c9b 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -152,8 +152,8 @@ static Optional<bool> normalizeSimpleNegativeFlag(OptSpecifier Opt, unsigned,
 /// argument.
 static void denormalizeSimpleFlag(SmallVectorImpl<const char *> &Args,
                                   const char *Spelling,
-                                  CompilerInvocation::StringAllocator,
-                                  Option::OptionClass, unsigned, /*T*/...) {
+                                  CompilerInvocation::StringAllocator, unsigned,
+                                  /*T*/...) {
   Args.push_back(Spelling);
 }
 
@@ -193,41 +193,12 @@ static auto makeBooleanOptionNormalizer(bool Value, bool OtherValue,
 
 static auto makeBooleanOptionDenormalizer(bool Value) {
   return [Value](SmallVectorImpl<const char *> &Args, const char *Spelling,
-                 CompilerInvocation::StringAllocator, Option::OptionClass,
-                 unsigned, bool KeyPath) {
+                 CompilerInvocation::StringAllocator, unsigned, bool KeyPath) {
     if (KeyPath == Value)
       Args.push_back(Spelling);
   };
 }
 
-static void denormalizeStringImpl(SmallVectorImpl<const char *> &Args,
-                                  const char *Spelling,
-                                  CompilerInvocation::StringAllocator SA,
-                                  Option::OptionClass OptClass, unsigned,
-                                  Twine Value) {
-  switch (OptClass) {
-  case Option::SeparateClass:
-  case Option::JoinedOrSeparateClass:
-    Args.push_back(Spelling);
-    Args.push_back(SA(Value));
-    break;
-  case Option::JoinedClass:
-    Args.push_back(SA(Twine(Spelling) + Value));
-    break;
-  default:
-    llvm_unreachable("Cannot denormalize an option with option class "
-                     "incompatible with string denormalization.");
-  }
-}
-
-template <typename T>
-static void
-denormalizeString(SmallVectorImpl<const char *> &Args, const char *Spelling,
-                  CompilerInvocation::StringAllocator SA,
-                  Option::OptionClass OptClass, unsigned TableIndex, T Value) {
-  denormalizeStringImpl(Args, Spelling, SA, OptClass, TableIndex, Twine(Value));
-}
-
 static Optional<SimpleEnumValue>
 findValueTableByName(const SimpleEnumValueTable &Table, StringRef Name) {
   for (int I = 0, E = Table.Size; I != E; ++I)
@@ -269,13 +240,12 @@ static llvm::Optional<unsigned> normalizeSimpleEnum(OptSpecifier Opt,
 static void denormalizeSimpleEnumImpl(SmallVectorImpl<const char *> &Args,
                                       const char *Spelling,
                                       CompilerInvocation::StringAllocator SA,
-                                      Option::OptionClass OptClass,
                                       unsigned TableIndex, unsigned Value) {
   assert(TableIndex < SimpleEnumValueTablesSize);
   const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
   if (auto MaybeEnumVal = findValueTableByValue(Table, Value)) {
-    denormalizeString(Args, Spelling, SA, OptClass, TableIndex,
-                      MaybeEnumVal->Name);
+    Args.push_back(Spelling);
+    Args.push_back(MaybeEnumVal->Name);
   } else {
     llvm_unreachable("The simple enum value was not correctly defined in "
                      "the tablegen option description");
@@ -286,12 +256,24 @@ template <typename T>
 static void denormalizeSimpleEnum(SmallVectorImpl<const char *> &Args,
                                   const char *Spelling,
                                   CompilerInvocation::StringAllocator SA,
-                                  Option::OptionClass OptClass,
                                   unsigned TableIndex, T Value) {
-  return denormalizeSimpleEnumImpl(Args, Spelling, SA, OptClass, TableIndex,
+  return denormalizeSimpleEnumImpl(Args, Spelling, SA, TableIndex,
                                    static_cast<unsigned>(Value));
 }
 
+static void denormalizeSimpleEnumJoined(SmallVectorImpl<const char *> &Args,
+                                        const char *Spelling,
+                                        CompilerInvocation::StringAllocator SA,
+                                        unsigned TableIndex, unsigned Value) {
+  assert(TableIndex < SimpleEnumValueTablesSize);
+  const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
+  if (auto MaybeEnumVal = findValueTableByValue(Table, Value))
+    Args.push_back(SA(Twine(Spelling) + MaybeEnumVal->Name));
+  else
+    llvm_unreachable("The simple enum value was not correctly defined in "
+                     "the tablegen option description");
+}
+
 static Optional<std::string> normalizeString(OptSpecifier Opt, int TableIndex,
                                              const ArgList &Args,
                                              DiagnosticsEngine &Diags) {
@@ -301,6 +283,25 @@ static Optional<std::string> normalizeString(OptSpecifier Opt, int TableIndex,
   return std::string(Arg->getValue());
 }
 
+static void denormalizeString(SmallVectorImpl<const char *> &Args,
+                              const char *Spelling,
+                              CompilerInvocation::StringAllocator SA, unsigned,
+                              Twine Value) {
+  Args.push_back(Spelling);
+  Args.push_back(SA(Value));
+}
+
+template <typename T,
+          std::enable_if_t<!std::is_convertible<T, Twine>::value &&
+                               std::is_constructible<Twine, T>::value,
+                           bool> = false>
+static void denormalizeString(SmallVectorImpl<const char *> &Args,
+                              const char *Spelling,
+                              CompilerInvocation::StringAllocator SA,
+                              unsigned TableIndex, T Value) {
+  denormalizeString(Args, Spelling, SA, TableIndex, Twine(Value));
+}
+
 template <typename IntTy>
 static Optional<IntTy> normalizeStringIntegral(OptSpecifier Opt, int,
                                                const ArgList &Args,
@@ -316,23 +317,6 @@ static Optional<IntTy> normalizeStringIntegral(OptSpecifier Opt, int,
   return Res;
 }
 
-static Optional<std::vector<std::string>>
-normalizeStringVector(OptSpecifier Opt, int, const ArgList &Args,
-                      DiagnosticsEngine &) {
-  return Args.getAllArgValues(Opt);
-}
-
-static void denormalizeStringVector(SmallVectorImpl<const char *> &Args,
-                                    const char *Spelling,
-                                    CompilerInvocation::StringAllocator SA,
-                                    Option::OptionClass OptClass,
-                                    unsigned TableIndex,
-                                    const std::vector<std::string> &Values) {
-  for (const std::string &Value : Values) {
-    denormalizeString(Args, Spelling, SA, OptClass, TableIndex, Value);
-  }
-}
-
 static Optional<std::string> normalizeTriple(OptSpecifier Opt, int TableIndex,
                                              const ArgList &Args,
                                              DiagnosticsEngine &Diags) {
@@ -2105,6 +2089,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
   Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
   Opts.ASTDumpDecls = Args.hasArg(OPT_ast_dump, OPT_ast_dump_EQ);
   Opts.ASTDumpAll = Args.hasArg(OPT_ast_dump_all, OPT_ast_dump_all_EQ);
+  Opts.ModuleMapFiles = Args.getAllArgValues(OPT_fmodule_map_file);
   // Only the -fmodule-file=<file> form.
   for (const auto *A : Args.filtered(OPT_fmodule_file)) {
     StringRef Val = A->getValue();
@@ -4001,8 +3986,7 @@ void CompilerInvocation::generateCC1CommandLine(
           (Extracted !=                                                        \
            static_cast<decltype(this->KEYPATH)>(                               \
                (IMPLIED_CHECK) ? (IMPLIED_VALUE) : (DEFAULT_VALUE))))          \
-        DENORMALIZER(Args, SPELLING, SA, Option::KIND##Class, TABLE_INDEX,     \
-                     Extracted);                                               \
+        DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, Extracted);              \
     }(EXTRACTOR(this->KEYPATH));                                               \
   }
 

diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 5738f7079171..51b7ba8c147f 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -18,7 +18,6 @@ using namespace llvm;
 using namespace clang;
 
 using ::testing::Contains;
-using ::testing::HasSubstr;
 using ::testing::StrEq;
 
 namespace {
@@ -343,109 +342,30 @@ TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateRequiredAbsent) {
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(DefaultTriple.c_str())));
 }
 
-TEST_F(CommandLineTest, SeparateEnumNonDefault) {
+TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateEnumNonDefault) {
   const char *Args[] = {"-mrelocation-model", "static"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
   ASSERT_FALSE(Diags->hasErrorOccurred());
-  ASSERT_EQ(Invocation.getCodeGenOpts().RelocationModel, Reloc::Model::Static);
 
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   // Non default relocation model.
-  ASSERT_THAT(GeneratedArgs, Contains(StrEq("-mrelocation-model")));
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("static")));
-  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-mrelocation-model=static"))));
 }
 
-TEST_F(CommandLineTest, SeparateEnumDefault) {
+TEST_F(CommandLineTest, CanGenerateCC1COmmandLineSeparateEnumDefault) {
   const char *Args[] = {"-mrelocation-model", "pic"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
   ASSERT_FALSE(Diags->hasErrorOccurred());
-  ASSERT_EQ(Invocation.getCodeGenOpts().RelocationModel, Reloc::Model::PIC_);
 
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   // Default relocation model.
-  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-mrelocation-model"))));
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("pic"))));
-  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-mrelocation-model=pic"))));
-}
-
-TEST_F(CommandLineTest, JoinedEnumNonDefault) {
-  const char *Args[] = {"-fobjc-dispatch-method=non-legacy"};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-
-  ASSERT_FALSE(Diags->hasErrorOccurred());
-  ASSERT_EQ(Invocation.getCodeGenOpts().getObjCDispatchMethod(),
-            CodeGenOptions::NonLegacy);
-
-  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
-
-  ASSERT_THAT(GeneratedArgs,
-              Contains(StrEq("-fobjc-dispatch-method=non-legacy")));
-  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fobjc-dispatch-method="))));
-  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("non-legacy"))));
-}
-
-TEST_F(CommandLineTest, JoinedEnumDefault) {
-  const char *Args[] = {"-fobjc-dispatch-method=legacy"};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-
-  ASSERT_FALSE(Diags->hasErrorOccurred());
-  ASSERT_EQ(Invocation.getCodeGenOpts().getObjCDispatchMethod(),
-            CodeGenOptions::Legacy);
-
-  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
-
-  ASSERT_THAT(GeneratedArgs,
-              Not(Contains(StrEq("-fobjc-dispatch-method=legacy"))));
-  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fobjc-dispatch-method="))));
-  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("legacy"))));
-}
-
-TEST_F(CommandLineTest, StringVectorEmpty) {
-  const char *Args[] = {""};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-
-  ASSERT_FALSE(Diags->hasErrorOccurred());
-  ASSERT_TRUE(Invocation.getFrontendOpts().ModuleMapFiles.empty());
-
-  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
-  ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-fmodule-map-file="))));
-}
-
-TEST_F(CommandLineTest, StringVectorSingle) {
-  const char *Args[] = {"-fmodule-map-file=a"};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-
-  ASSERT_FALSE(Diags->hasErrorOccurred());
-  ASSERT_EQ(Invocation.getFrontendOpts().ModuleMapFiles,
-            std::vector<std::string>({"a"}));
-
-  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
-  ASSERT_EQ(count(GeneratedArgs, StringRef("-fmodule-map-file=a")), 1);
-}
-
-TEST_F(CommandLineTest, StringVectorMultiple) {
-  const char *Args[] = {"-fmodule-map-file=a", "-fmodule-map-file=b"};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-
-  ASSERT_FALSE(Diags->hasErrorOccurred());
-  ASSERT_TRUE(Invocation.getFrontendOpts().ModuleMapFiles ==
-              std::vector<std::string>({"a", "b"}));
-
-  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
-  ASSERT_EQ(count(GeneratedArgs, StringRef("-fmodule-map-file=a")), 1);
-  ASSERT_EQ(count(GeneratedArgs, StringRef("-fmodule-map-file=b")), 1);
 }
 
 // Tree of boolean options that can be (directly or transitively) implied by

diff  --git a/llvm/include/llvm/Option/OptParser.td b/llvm/include/llvm/Option/OptParser.td
index 943fce82d988..e96e54131569 100644
--- a/llvm/include/llvm/Option/OptParser.td
+++ b/llvm/include/llvm/Option/OptParser.td
@@ -167,12 +167,6 @@ class MarshallingInfoStringInt<code keypath, code defaultvalue="0", code type="u
   code Denormalizer = "denormalizeString";
 }
 
-class MarshallingInfoStringVector<code keypath>
-  : MarshallingInfo<keypath, "std::vector<std::string>({})"> {
-  code Normalizer = "normalizeStringVector";
-  code Denormalizer = "denormalizeStringVector";
-}
-
 class MarshallingInfoFlag<code keypath, code defaultvalue = "false">
   : MarshallingInfo<keypath, defaultvalue> {
   code Normalizer = "normalizeSimpleFlag";
@@ -208,6 +202,9 @@ class AutoNormalizeEnum {
   code Normalizer = "normalizeSimpleEnum";
   code Denormalizer = "denormalizeSimpleEnum";
 }
+class AutoNormalizeEnumJoined : AutoNormalizeEnum {
+  code Denormalizer = "denormalizeSimpleEnumJoined";
+}
 class ValueMerger<code merger> { code ValueMerger = merger; }
 class ValueExtractor<code extractor> { code ValueExtractor = extractor; }
 


        


More information about the llvm-branch-commits mailing list