[llvm-branch-commits] [clang] [Serialization] No transitive identifier change (PR #92085)

2024-05-24 Thread Jan Svoboda via llvm-branch-commits


@@ -124,7 +124,7 @@ struct HeaderFileInfo {
   /// This ID number will be non-zero when there is a controlling
   /// macro whose IdentifierInfo may not yet have been loaded from
   /// external storage.
-  unsigned ControllingMacroID = 0;
+  uint64_t ControllingMacroID = 0;

jansvoboda11 wrote:

This increases the size of `HeaderFileInfo` from 32 to 40 bytes. Can we squash 
this member with `ControllingMacro` into some kind of tagged pointer & 
`uint64_t` union to save space?

https://github.com/llvm/llvm-project/pull/92085
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [Serialization] No transitive identifier change (PR #92085)

2024-05-24 Thread Jan Svoboda via llvm-branch-commits


@@ -918,7 +918,7 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, 
unsigned) {
   SelectorTable &SelTable = Reader.getContext().Selectors;
   unsigned N = endian::readNext(d);
   const IdentifierInfo *FirstII = Reader.getLocalIdentifier(
-  F, endian::readNext(d));
+  F, endian::readNext(d));

jansvoboda11 wrote:

I think having some kind of `static_assert` that `IdentifierID` is an integral 
type would be helpful. Maybe that'd be useful even within `endian::readNext()`?

https://github.com/llvm/llvm-project/pull/92085
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [Serialization] No transitive identifier change (PR #92085)

2024-05-24 Thread Jan Svoboda via llvm-branch-commits


@@ -3896,7 +3903,7 @@ void ASTWriter::WriteIdentifierTable(Preprocessor &PP,
 
   // Write out identifiers if either the ID is local or the identifier has
   // changed since it was loaded.
-  if (ID >= FirstIdentID || !Chain || !II->isFromAST() ||
+  if (isLocalIdentifierID(ID) || !Chain || !II->isFromAST() ||

jansvoboda11 wrote:

This diff makes it seem that `ID >= FirstIdentID` is equivalent to 
`isLocalIdentifierID(ID)`, which I don't think is the case. Can you explain 
what's going on here?

https://github.com/llvm/llvm-project/pull/92085
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 46ec025 - [clang][cli] NFC: Move prefix to the front of BoolOption

2021-01-25 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-25T09:15:33+01:00
New Revision: 46ec0254a97dcf35a0f9f023ea7632e7ee72a1ee

URL: 
https://github.com/llvm/llvm-project/commit/46ec0254a97dcf35a0f9f023ea7632e7ee72a1ee
DIFF: 
https://github.com/llvm/llvm-project/commit/46ec0254a97dcf35a0f9f023ea7632e7ee72a1ee.diff

LOG: [clang][cli] NFC: Move prefix to the front of BoolOption

The prefix used to be the last (optional) argument to BoolOption. This decision 
was made with the expectation that only few command line options would need to 
pass it explicitly instead of using Bool{F,G}Option. It turns out that a 
considerable number of options don't conform to Bool{F,G}Option and need to 
provide the prefix anyways. This sometimes requires to explicitly pass 
`BothFlags<[]>`.

This patch makes prefix the first parameter, so it now directly precedes the 
spelling base string. Now 8 options dropped `BothFlags<[]>` and only two 
options (`pthread` and `emit_llvm_uselists`) need to pass an empty prefix.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D95221

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7685d343ab96..2747ee27cb8d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -375,10 +375,10 @@ class BoolOptionFlag,
-  string prefix = ""> {
+  FlagDefSuffix flags_suffix = FlagDefSuffix<[], "">> {
   defvar flag1 = FlagDefExpanded.Result,
  prefix, NAME, spelling_base>;
 
@@ -436,29 +436,28 @@ class BothFlags option_flags = [], 
string help = ""> {
 /// Creates two command line flags that control the same boolean keypath.
 ///
 /// Example:
-///   defm my_boolean_option : BoolOption<"my-boolean-option",
+///   defm my_boolean_option : BoolOption<"f", "my-boolean-option",
 /// CodeGenOpts<"MyBooleanOption">, DefaultsToFalse,
 /// ChangedBy,
 /// ResetBy,
 /// BothFlags<[CoreOption], " my boolean option.">;
 ///
 ///   The Clang driver now knows two new command line flags: the "positive"
-///   -my-boolean-option and the "negative" -no-my-boolean-option. The positive
-///   flag is also available on the CC1 command line.
+///   -fmy-boolean-option and the "negative" -fno-my-boolean-option. The
+///   positive flag is also available on the CC1 command line.
 ///
 ///   * When the command line contains neither of the flags, the keypath value
 /// defaults to false.
 ///   * When the command line contains the positive -my-boolean-option, the
 /// keypath value changes to true.
-///   * When the command line contains the negative -no-my-bool-option, the
+///   * When the command line contains the negative -fno-my-bool-option, the
 /// keypath value resets to false.
 ///
 ///   The help text for -my-boolean-option is "Enable my boolean option." and
-///   "Disable my boolean option." for -no-my-boolean-option.
-multiclass BoolOption,
-  string name_prefix = ""> {
+  ResetBy reset_by, BothFlags both = BothFlags<[], "">> {
   defvar default = Default;
 
   defvar changed_by_flag = FlagDef;
 
-  defm NAME : BoolOptionBase;
+  defm NAME : BoolOptionBase;
 }
 
 /// Creates a BoolOption with the changing available on the CC1 command line.
-multiclass BoolCC1Option,
- string name_prefix = ""> {
+ ResetBy reset_by, BothFlags both = BothFlags<[], "">> 
{
   defvar changed_by_cc1
 = ChangedBy;
 
-  defm NAME : BoolOption;
+  defm NAME : BoolOption;
 }
 
 /// Creates a BoolOption where both of the flags are prefixed with "f", are in
@@ -494,8 +492,8 @@ multiclass BoolCC1Option> {
-  defm NAME : BoolCC1Option,
+  defm NAME : BoolCC1Option<"f", flag_base, kpm, defaults_to, changed_by,
+reset_by, both>,
   Group;
 }
 
@@ -505,8 +503,8 @@ multiclass BoolFOption> {
-  defm NAME : BoolCC1Option,
+  defm NAME : BoolCC1Option<"g", flag_base, kpm, defaults_to, changed_by,
+reset_by, both>,
   Group;
 }
 
@@ -1269,11 +1267,11 @@ def fcommon : Flag<["-"], "fcommon">, Group,
   Flags<[CoreOption, CC1Option]>, HelpText<"Place uninitialized global 
variables in a common block">,
   MarshallingInfoNegativeFlag>;
 def fcompile_resource_EQ : Joined<["-"], "fcompile-resource=">, Group;
-defm complete_member_pointers : BoolOption<"complete-member-pointers",
+defm complete_member_pointers : BoolOption<"f", "complete-member-pointers",
   LangOpts<"CompleteMemberPointers">, DefaultsToFalse,
   ChangedBy, ResetBy,
   BothFlags<[CoreOption], " member pointer base types to be complete if they"
-" would be significant under the Microsoft ABI">, "f">,
+" would be significant under the Micros

[llvm-branch-commits] [clang] 209f461 - [clang][cli] NFC: Pass CC1Option explicitly to BoolOption

2021-01-25 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-25T09:15:33+01:00
New Revision: 209f4618891365f5f655214581ab4edd27cacde4

URL: 
https://github.com/llvm/llvm-project/commit/209f4618891365f5f655214581ab4edd27cacde4
DIFF: 
https://github.com/llvm/llvm-project/commit/209f4618891365f5f655214581ab4edd27cacde4.diff

LOG: [clang][cli] NFC: Pass CC1Option explicitly to BoolOption

When `Bool{F,G}Option` were introduced, they were designed after the existing 
`Opt{In,Out}FFlag` in that they implied `CC1Option` for the `ChangedBy` flag.

This means less typing, but can be misleading in situations when the `ResetBy` 
has explicit `CC1Option` and `ChangedBy` doesn't.

This patch stops implicitly putting `CC1Option` to `ChangedBy` flag.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D95225

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2747ee27cb8d..dd7978435ff1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -473,38 +473,23 @@ multiclass BoolOption;
 }
 
-/// Creates a BoolOption with the changing available on the CC1 command line.
-multiclass BoolCC1Option> 
{
-  defvar changed_by_cc1
-= ChangedBy;
-
-  defm NAME : BoolOption;
-}
-
-/// Creates a BoolOption where both of the flags are prefixed with "f", are in
-/// the Group, and the changing flag is also available on the CC1
-/// command line.
+/// Creates a BoolOption where both of the flags are prefixed with "f" and have
+/// the Group.
 multiclass BoolFOption> {
-  defm NAME : BoolCC1Option<"f", flag_base, kpm, defaults_to, changed_by,
-reset_by, both>,
+  defm NAME : BoolOption<"f", flag_base, kpm, defaults_to, changed_by, 
reset_by,
+ both>,
   Group;
 }
 
-// Creates a BoolOption where both of the flags are prefixed with "g", are in
-// the Group, and the changing flag is also available on the CC1
-// command line.
+// Creates a BoolOption where both of the flags are prefixed with "g" and have
+// the Group.
 multiclass BoolGOption> {
-  defm NAME : BoolCC1Option<"g", flag_base, kpm, defaults_to, changed_by,
-reset_by, both>,
+  defm NAME : BoolOption<"g", flag_base, kpm, defaults_to, changed_by, 
reset_by,
+ both>,
   Group;
 }
 
@@ -951,7 +936,7 @@ defm cuda_approx_transcendentals : 
OptInFFlag<"cuda-approx-transcendentals", "Us
   " approximate transcendental functions">;
 defm gpu_rdc : BoolFOption<"gpu-rdc",
   LangOpts<"GPURelocatableDeviceCode">, DefaultsToFalse,
-  ChangedBy,
+  ChangedBy,
   ResetBy>;
 def : Flag<["-"], "fcuda-rdc">, Alias;
 def : Flag<["-"], "fno-cuda-rdc">, Alias;
@@ -971,17 +956,17 @@ def fhip_dump_offload_linker_script : Flag<["-"], 
"fhip-dump-offload-linker-scri
   Group, Flags<[NoArgumentUnused, HelpHidden]>;
 defm hip_new_launch_api : BoolFOption<"hip-new-launch-api",
   LangOpts<"HIPUseNewLaunchAPI">, DefaultsToFalse,
-  ChangedBy, ResetBy,
+  ChangedBy, ResetBy,
   BothFlags<[], " new kernel launching API for HIP">>;
 defm gpu_allow_device_init : OptInFFlag<"gpu-allow-device-init",
   "Allow", "Don't allow", " device side init function in HIP">;
 defm gpu_defer_diag : BoolFOption<"gpu-defer-diag",
   LangOpts<"GPUDeferDiag">, DefaultsToFalse,
-  ChangedBy, ResetBy,
+  ChangedBy, ResetBy,
   BothFlags<[], " host/device related diagnostic messages for CUDA/HIP">>;
 defm gpu_exclude_wrong_side_overloads : 
BoolFOption<"gpu-exclude-wrong-side-overloads",
   LangOpts<"GPUExcludeWrongSideOverloads">, DefaultsToFalse,
-  ChangedBy,
+  ChangedBy,
   ResetBy,
   BothFlags<[HelpHidden], " in overloading resolution for CUDA/HIP">>;
 def gpu_max_threads_per_block_EQ : Joined<["--"], 
"gpu-max-threads-per-block=">,
@@ -1043,14 +1028,14 @@ def fPIE : Flag<["-"], "fPIE">, Group;
 def fno_PIE : Flag<["-"], "fno-PIE">, Group;
 defm access_control : BoolFOption<"access-control",
   LangOpts<"AccessControl">, DefaultsToTrue,
-  ChangedBy,
+  ChangedBy,
   ResetBy>;
 def falign_functions : Flag<["-"], "falign-functions">, Group;
 def falign_functions_EQ : Joined<["-"], "falign-functions=">, Group;
 def fno_align_functions: Flag<["-"], "fno-align-functions">, Group;
 defm allow_editor_placeholders : BoolFOption<"allow-editor-placeholders",
   LangOpts<"AllowEditorPlaceholders">, DefaultsToFalse,
-  ChangedBy,
+  ChangedBy,
   ResetBy>;
 def fallow_unsupported : Flag<["-"], "fallow-unsupported">, Group;
 def fapple_kext : Flag<["-"], "fapple-kext">, Group, 
Flags<[CC1Option]>,
@@ -1058,7 +1043,7 @@ def fapple_kext : Flag<["-"], "fapple-kext">, 
Group, Flags<[CC1Option]>
   MarshallingInfoFlag>;
 defm apple_pragma_pack : BoolFOption<"apple-pragma-pack",
   LangOpts<"ApplePragmaPack">, DefaultsToFalse,
-  ChangedBy,
+  ChangedBy,
   ResetBy>;

[llvm-branch-commits] [clang] 3bccd87 - [clang][cli] NFC: Remove SSPBufferSize assignment

2021-01-14 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-14T13:21:44+01:00
New Revision: 3bccd87a588b3c320b669686c8f006b92ff72182

URL: 
https://github.com/llvm/llvm-project/commit/3bccd87a588b3c320b669686c8f006b92ff72182
DIFF: 
https://github.com/llvm/llvm-project/commit/3bccd87a588b3c320b669686c8f006b92ff72182.diff

LOG: [clang][cli] NFC: Remove SSPBufferSize assignment

This should've been part of D84669, but got overlooked. Removing the assignment 
is NFC, as it's also done by the marshalling infrastructure for the 
stack_protector_buffer_size option.

Reviewed By: dexonsmith in D94488

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index f496c1d65bc5..cbe038224323 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1142,8 +1142,6 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, 
ArgList &Args, InputKind IK,
 }
 Opts.LinkBitcodeFiles.push_back(F);
   }
-  Opts.SSPBufferSize =
-  getLastArgIntValue(Args, OPT_stack_protector_buffer_size, 8, Diags);
 
   Opts.StackProtectorGuard =
   std::string(Args.getLastArgValue(OPT_mstack_protector_guard_EQ));



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] fa2fe96 - [clang][cli] Port more CodeGenOptions to marshalling infrastructure

2021-01-14 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-14T13:21:44+01:00
New Revision: fa2fe9608c1c1b402296960b1edc157230c30062

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

LOG: [clang][cli] Port more CodeGenOptions to marshalling infrastructure

Leveraging the recently added TableGen constructs (ShouldParseIf and 
MarshallingInfoStringInt) to shift from manual command line parsing to 
automatic TableGen-driver marshalling.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D94488

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9ea3feccddff..2123ac226ffc 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1162,12 +1162,22 @@ def fno_profile_instr_use : Flag<["-"], 
"fno-profile-instr-use">,
 HelpText<"Disable using instrumentation data for profile-guided 
optimization">;
 def fno_profile_use : Flag<["-"], "fno-profile-use">,
 Alias;
+defm profile_arcs : BoolFOption<"profile-arcs",
+  "CodeGenOpts.EmitGcovArcs", DefaultsToFalse,
+  ChangedBy, ResetBy>;
+defm test_coverage : BoolFOption<"test-coverage",
+  "CodeGenOpts.EmitGcovNotes", DefaultsToFalse,
+  ChangedBy, ResetBy>;
 def fprofile_filter_files_EQ : Joined<["-"], "fprofile-filter-files=">,
 Group, Flags<[CC1Option, CoreOption]>,
-HelpText<"Instrument only functions from files where names match any regex 
separated by a semi-colon">;
+HelpText<"Instrument only functions from files where names match any regex 
separated by a semi-colon">,
+MarshallingInfoString<"CodeGenOpts.ProfileFilterFiles">,
+ShouldParseIf;
 def fprofile_exclude_files_EQ : Joined<["-"], "fprofile-exclude-files=">,
 Group, Flags<[CC1Option, CoreOption]>,
-HelpText<"Instrument only functions from files where names don't match all 
the regexes separated by a semi-colon">;
+HelpText<"Instrument only functions from files where names don't match all 
the regexes separated by a semi-colon">,
+MarshallingInfoString<"CodeGenOpts.ProfileExcludeFiles">,
+ShouldParseIf;
 def fprofile_update_EQ : Joined<["-"], "fprofile-update=">,
 Group, Flags<[CC1Option, CoreOption]>, 
Values<"atomic,prefer-atomic,single">,
 MetaVarName<"">, HelpText<"Set update method of profile counters 
(atomic,prefer-atomic,single)">,
@@ -1318,9 +1328,10 @@ defm eliminate_unused_debug_types : 
OptOutFFlag<"eliminate-unused-debug-types",
 def femit_all_decls : Flag<["-"], "femit-all-decls">, Group, 
Flags<[CC1Option]>,
   HelpText<"Emit all declarations, even if unused">,
   MarshallingInfoFlag<"LangOpts->EmitAllDecls">;
-def femulated_tls : Flag<["-"], "femulated-tls">, Group, 
Flags<[CC1Option]>,
-  HelpText<"Use emutls functions to access thread_local variables">;
-def fno_emulated_tls : Flag<["-"], "fno-emulated-tls">, Group, 
Flags<[CC1Option]>;
+defm emulated_tls : BoolFOption<"emulated-tls",
+  "CodeGenOpts.EmulatedTLS", DefaultsToFalse,
+  ChangedBy,
+  ResetBy, BothFlags<[CC1Option]>>;
 def fencoding_EQ : Joined<["-"], "fencoding=">, Group;
 def ferror_limit_EQ : Joined<["-"], "ferror-limit=">, Group, 
Flags<[CoreOption]>;
 defm exceptions : BoolFOption<"exceptions",
@@ -1759,12 +1770,14 @@ def fxray_instrumentation_bundle :
 def fxray_function_groups :
   Joined<["-"], "fxray-function-groups=">,
   Group, Flags<[CC1Option]>,
-  HelpText<"Only instrument 1 of N groups">;
+  HelpText<"Only instrument 1 of N groups">,
+  MarshallingInfoStringInt<"CodeGenOpts.XRayTotalFunctionGroups", "1">;
 
 def fxray_selected_function_group :
   Joined<["-"], "fxray-selected-function-group=">,
   Group, Flags<[CC1Option]>,
-  HelpText<"When using -fxray-function-groups, select which group of functions 
to instrument. Valid range is 0 to fxray-function-groups - 1">;
+  HelpText<"When using -fxray-function-groups, select which group of functions 
to instrument. Valid range is 0 to fxray-function-groups - 1">,
+  MarshallingInfoStringInt<"CodeGenOpts.XRaySelectedFunctionGroup", "0">;
 
 
 defm fine_grained_bitfield_accesses : 
BoolOption<"fine-grained-bitfield-accesses",
@@ -2223,9 +2236,6 @@ defm preserve_as_comments : 
BoolFOption<"preserve-as-comments",
   "CodeGenOpts.PreserveAsmComments", DefaultsToTrue,
   ChangedBy,
   ResetBy>;
-defm profile_arcs : BoolFOption<"profile-arcs",
-  "CodeGenOpts.EmitGcovArcs", DefaultsToFalse,
-  ChangedBy, ResetBy>;
 def framework : Separate<["-"], "framework">, Flags<[LinkerInput]>;
 def frandom_seed_EQ : Joined<["-"], "frandom-seed=">, 
Group;
 def freg_struct_return : Flag<["-"], "freg-struct-return">, Group, 
Flags<[CC1Option]>,
@@ -2348,9 +2358,6 @@ def foptimization_record_passes_EQ : 

[llvm-branch-commits] [clang] c495dfe - [clang][cli] NFC: Decrease the scope of ParseLangArgs parameters

2021-01-15 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-15T08:41:50+01:00
New Revision: c495dfe0268bc2be8737725d657411baa1399e9d

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

LOG: [clang][cli] NFC: Decrease the scope of ParseLangArgs parameters

Instead of passing the whole `TargetOptions` and `PreprocessorOptions` to 
`ParseLangArgs` give it only the necessary members.
This makes tracking the dependencies between various parsers and option groups 
easier.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D94674

Added: 


Modified: 
clang/include/clang/Frontend/CompilerInvocation.h
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/CompilerInvocation.h 
b/clang/include/clang/Frontend/CompilerInvocation.h
index c723fc084c85..9f16c5077154 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -176,11 +176,12 @@ class CompilerInvocation : public CompilerInvocationBase {
   /// \param Opts - The LangOptions object to set up.
   /// \param IK - The input language.
   /// \param T - The target triple.
-  /// \param PPOpts - The PreprocessorOptions affected.
+  /// \param Includes - The affected list of included files.
   /// \param LangStd - The input language standard.
-  static void setLangDefaults(LangOptions &Opts, InputKind IK,
-   const llvm::Triple &T, PreprocessorOptions &PPOpts,
-   LangStandard::Kind LangStd = 
LangStandard::lang_unspecified);
+  static void
+  setLangDefaults(LangOptions &Opts, InputKind IK, const llvm::Triple &T,
+  std::vector &Includes,
+  LangStandard::Kind LangStd = LangStandard::lang_unspecified);
 
   /// Retrieve a module hash string that is suitable for uniquely
   /// identifying the conditions under which the module was built.

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 6327723699d2..d80d1f79c692 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1889,7 +1889,7 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions 
&Opts, ArgList &Args,
 
 void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
  const llvm::Triple &T,
- PreprocessorOptions &PPOpts,
+ std::vector &Includes,
  LangStandard::Kind LangStd) {
   // Set some properties which depend solely on the input kind; it would be 
nice
   // to move these to the language standard, and have the driver resolve the
@@ -2000,9 +2000,9 @@ void CompilerInvocation::setLangDefaults(LangOptions 
&Opts, InputKind IK,
 if (Opts.IncludeDefaultHeader) {
   if (Opts.DeclareOpenCLBuiltins) {
 // Only include base header file for builtin types and constants.
-PPOpts.Includes.push_back("opencl-c-base.h");
+Includes.push_back("opencl-c-base.h");
   } else {
-PPOpts.Includes.push_back("opencl-c.h");
+Includes.push_back("opencl-c.h");
   }
 }
   }
@@ -2138,8 +2138,8 @@ static const StringRef GetInputKindName(InputKind IK) {
 }
 
 static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
-  const TargetOptions &TargetOpts,
-  PreprocessorOptions &PPOpts,
+  const llvm::Triple &T,
+  std::vector &Includes,
   DiagnosticsEngine &Diags) {
   // FIXME: Cleanup per-file based stuff.
   LangStandard::Kind LangStd = LangStandard::lang_unspecified;
@@ -2212,8 +2212,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, InputKind IK,
 
   Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device);
 
-  llvm::Triple T(TargetOpts.Triple);
-  CompilerInvocation::setLangDefaults(Opts, IK, T, PPOpts, LangStd);
+  CompilerInvocation::setLangDefaults(Opts, IK, T, Includes, LangStd);
 
   // -cl-strict-aliasing needs to emit diagnostic in the case where CL > 1.0.
   // This option should be deprecated for CL > 1.0 because
@@ -2490,7 +2489,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, InputKind IK,
   Diags.Report(diag::err_drv_argument_not_allowed_with)
   << A->getSpelling() << "-fdefault-calling-conv";
 else {
-  llvm::Triple T(TargetOpts.Triple);
   if (T.getArch() != llvm::Triple::x86)
 Diags.Report(diag::err_drv_argument_not_allowed_with)
 << A->getSpelling() << T.getTriple();
@@ -2527,8 +2525,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, Input

[llvm-branch-commits] [clang] 1a49944 - [clang][cli] NFC: Decrease the scope of ParseCodeGenArgs parameters

2021-01-15 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-15T08:42:30+01:00
New Revision: 1a49944b59dbbfd62bd860b564919087f274a5bf

URL: 
https://github.com/llvm/llvm-project/commit/1a49944b59dbbfd62bd860b564919087f274a5bf
DIFF: 
https://github.com/llvm/llvm-project/commit/1a49944b59dbbfd62bd860b564919087f274a5bf.diff

LOG: [clang][cli] NFC: Decrease the scope of ParseCodeGenArgs parameters

Instead of passing the whole `TargetOptions` and `FrontendOptions` to 
`ParseCodeGenArgs` give it only the necessary members.
This makes tracking the dependencies between various parsers and option groups 
easier.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D94675

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index d80d1f79c692..6d5b4a84c233 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -405,6 +405,8 @@ static void FixupInvocation(CompilerInvocation &Invocation,
   llvm::Triple T(TargetOpts.Triple);
   llvm::Triple::ArchType Arch = T.getArch();
 
+  CodeGenOpts.CodeModel = TargetOpts.CodeModel;
+
   if (LangOpts.getExceptionHandling() != llvm::ExceptionHandling::None &&
   T.isWindowsMSVCEnvironment())
 Diags.Report(diag::err_fe_invalid_exception_model)
@@ -901,11 +903,9 @@ static void setPGOUseInstrumentor(CodeGenOptions &Opts,
 }
 
 static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
- DiagnosticsEngine &Diags,
- const TargetOptions &TargetOpts,
- const FrontendOptions &FrontendOpts) {
+ DiagnosticsEngine &Diags, const llvm::Triple &T,
+ const std::string &OutputFile) {
   bool Success = true;
-  llvm::Triple Triple = llvm::Triple(TargetOpts.Triple);
 
   unsigned OptimizationLevel = getOptimizationLevel(Args, IK, Diags);
   // TODO: This could be done in Driver
@@ -964,7 +964,6 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList 
&Args, InputKind IK,
   llvm::Triple::arm, llvm::Triple::armeb, llvm::Triple::mips,
   llvm::Triple::mipsel, llvm::Triple::mips64, llvm::Triple::mips64el};
 
-  llvm::Triple T(TargetOpts.Triple);
   if (Opts.OptimizationLevel > 0 && Opts.hasReducedDebugInfo() &&
   llvm::is_contained(DebugEntryValueArchs, T.getArch()))
 Opts.EmitCallSiteInfo = true;
@@ -990,8 +989,6 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList 
&Args, InputKind IK,
   if (!Opts.ProfileInstrumentUsePath.empty())
 setPGOUseInstrumentor(Opts, Opts.ProfileInstrumentUsePath);
 
-  Opts.CodeModel = TargetOpts.CodeModel;
-
   if (const Arg *A = Args.getLastArg(OPT_ftime_report, OPT_ftime_report_EQ)) {
 Opts.TimePasses = true;
 
@@ -1036,8 +1033,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, 
ArgList &Args, InputKind IK,
   if (Arg *A = Args.getLastArg(OPT_save_temps_EQ))
 Opts.SaveTempsFilePrefix =
 llvm::StringSwitch(A->getValue())
-.Case("obj", FrontendOpts.OutputFile)
-.Default(llvm::sys::path::filename(FrontendOpts.OutputFile).str());
+.Case("obj", OutputFile)
+.Default(llvm::sys::path::filename(OutputFile).str());
 
   // The memory profile runtime appends the pid to make this name more unique.
   const char *MemProfileBasename = "memprof.profraw";
@@ -2937,11 +2934,11 @@ bool 
CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
   InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), Args, Diags,
   LangOpts.IsHeaderFile);
   ParseTargetArgs(Res.getTargetOpts(), Args, Diags);
-  Success &= ParseCodeGenArgs(Res.getCodeGenOpts(), Args, DashX, Diags,
-  Res.getTargetOpts(), Res.getFrontendOpts());
+  llvm::Triple T(Res.getTargetOpts().Triple);
+  Success &= ParseCodeGenArgs(Res.getCodeGenOpts(), Args, DashX, Diags, T,
+  Res.getFrontendOpts().OutputFile);
   ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), Args,
 Res.getFileSystemOpts().WorkingDir);
-  llvm::Triple T(Res.getTargetOpts().Triple);
   if (DashX.getFormat() == InputKind::Precompiled ||
   DashX.getLanguage() == Language::LLVM_IR) {
 // ObjCAAutoRefCount and Sanitize LangOpts are used to setup the



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 791634b - [clang][cli] Parse & generate options necessary for LangOptions defaults manually

2021-01-15 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-15T15:38:43+01:00
New Revision: 791634b999e33e029aeeda91eeb5fae13757dcdc

URL: 
https://github.com/llvm/llvm-project/commit/791634b999e33e029aeeda91eeb5fae13757dcdc
DIFF: 
https://github.com/llvm/llvm-project/commit/791634b999e33e029aeeda91eeb5fae13757dcdc.diff

LOG: [clang][cli] Parse & generate options necessary for LangOptions defaults 
manually

It turns out we need to handle `LangOptions` separately from the rest of the 
options. `LangOptions` used to be conditionally parsed only when 
`!(DashX.getFormat() == InputKind::Precompiled || DashX.getLanguage() == 
Language::LLVM_IR)` and we need to restore this order (for more info, see 
D94682).

D94682 moves the parsing of marshalled `LangOpts` from `parseSimpleArgs` back 
to `ParseLangArgs`.

We need to parse marshalled `LangOpts` **after** `ParseLangArgs` calls 
`setLangDefaults`. This will enable future patches, where values of some 
`LangOpts` depend on the defaults.

However, two language options (`-finclude-default-header` and 
`-fdeclare-opencl-builtins`) need to be parsed **before** `ParseLangArgs` calls 
`setLangDefaults`, because they are necessary for setting up OpenCL defaults 
correctly.
This patch implements this by removing their marshalling info and manually 
parsing (and generating) them exactly where necessary.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D94678

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2f7bd9e552e1..3722192c7eee 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5207,12 +5207,13 @@ def fdefault_calling_conv_EQ : Joined<["-"], 
"fdefault-calling-conv=">,
   NormalizedValuesScope<"LangOptions">,
   NormalizedValues<["DCC_CDecl", "DCC_FastCall", "DCC_StdCall", 
"DCC_VectorCall", "DCC_RegCall"]>,
   MarshallingInfoString, "DCC_None">, 
AutoNormalizeEnum;
+
+// These options cannot be marshalled, because they are used to set up the 
LangOptions defaults.
 def finclude_default_header : Flag<["-"], "finclude-default-header">,
-  HelpText<"Include default header file for OpenCL">,
-  MarshallingInfoFlag>;
+  HelpText<"Include default header file for OpenCL">;
 def fdeclare_opencl_builtins : Flag<["-"], "fdeclare-opencl-builtins">,
-  HelpText<"Add OpenCL builtin function declarations (experimental)">,
-  MarshallingInfoFlag>;
+  HelpText<"Add OpenCL builtin function declarations (experimental)">;
+
 def fpreserve_vec3_type : Flag<["-"], "fpreserve-vec3-type">,
   HelpText<"Preserve 3-component vector type">,
   MarshallingInfoFlag>;

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 37d7f6f3f0fa..c85b0f9d65cf 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -491,6 +491,11 @@ static unsigned getOptimizationLevelSize(ArgList &Args) {
   return 0;
 }
 
+static std::string GetOptName(llvm::opt::OptSpecifier OptSpecifier) {
+  static const OptTable &OptTable = getDriverOptTable();
+  return OptTable.getOption(OptSpecifier).getPrefixedName();
+}
+
 static void addDiagnosticArgs(ArgList &Args, OptSpecifier Group,
   OptSpecifier GroupWithValue,
   std::vector &Diagnostics) {
@@ -2137,6 +2142,15 @@ static const StringRef GetInputKindName(InputKind IK) {
   llvm_unreachable("unknown input language");
 }
 
+static void GenerateLangArgs(const LangOptions &Opts,
+ SmallVectorImpl &Args,
+ CompilerInvocation::StringAllocator SA) {
+  if (Opts.IncludeDefaultHeader)
+Args.push_back(SA(GetOptName(OPT_finclude_default_header)));
+  if (Opts.DeclareOpenCLBuiltins)
+Args.push_back(SA(GetOptName(OPT_fdeclare_opencl_builtins)));
+}
+
 static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
   const llvm::Triple &T,
   std::vector &Includes,
@@ -2212,6 +2226,10 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, InputKind IK,
 
   Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device);
 
+  // These need to be parsed now. They are used to set OpenCL defaults.
+  Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header);
+  Opts.DeclareOpenCLBuiltins = Args.hasArg(OPT_fdeclare_opencl_builtins);
+
   CompilerInvocation::setLangDefaults(Opts, IK, T, Includes, LangStd);
 
   // -cl-strict-aliasing needs to emit diagnostic in the case where CL > 1.0.
@@ -3163,6 +3181,8 @@ void CompilerInvocation::generateCC1CommandLine(
 #undef DIAG_OPTION_WITH_MARSHALLING
 #undef OPTION_WITH_MARSHALLING
 #undef GENERATE_OPTION_WITH_MARSHALLING
+
+  GenerateLan

[llvm-branch-commits] [clang] 3832629 - [clang][cli] NFC: Add PIE parsing for precompiled input and IR

2021-01-15 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-15T16:41:34+01:00
New Revision: 383262933045e1c138362105be4ee4d1b62ab4cc

URL: 
https://github.com/llvm/llvm-project/commit/383262933045e1c138362105be4ee4d1b62ab4cc
DIFF: 
https://github.com/llvm/llvm-project/commit/383262933045e1c138362105be4ee4d1b62ab4cc.diff

LOG: [clang][cli] NFC: Add PIE parsing for precompiled input and IR

This patch effectively reverts a small part of D83979.

When we stop parsing `LangOpts` unconditionally in `parseSimpleArgs` (above the 
diff) and move them back to `ParseLangArgs` (called in `else` branch) in 
D94682, `LangOpts.PIE` would never get parsed in this `if` branch. This patch 
ensures this doesn't happen.

Right now, this causes `LangOpts.PIE` to be parsed twice, but that will be 
immediately corrected in D94682.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D94679

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index c85b0f9d65cf..d261eb7f45cd 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2970,6 +2970,7 @@ bool 
CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
 // PIClevel and PIELevel are needed during code generation and this should 
be
 // set regardless of the input type.
 LangOpts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags);
+LangOpts.PIE = Args.hasArg(OPT_pic_is_pie);
 parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
 Diags, LangOpts.Sanitize);
   } else {



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] a7dcd3a - [clang][cli] NFC: Parse some LangOpts after the defaults are set

2021-01-15 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-15T16:41:34+01:00
New Revision: a7dcd3aeb0fb58ad774bc89428ed6c925f31f8aa

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

LOG: [clang][cli] NFC: Parse some LangOpts after the defaults are set

This patch ensures we only parse the necessary options before calling 
`setLangDefaults` (explained in D94678).

Because neither `LangOpts.CFProtectionBranch` nor `LangOpts.SYCLIsDevice` are 
used in `setLangDefaults`, this is a NFC.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D94680

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index d261eb7f45cd..c672834a7970 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2196,12 +2196,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, InputKind IK,
 }
   }
 
-  if (const Arg *A = Args.getLastArg(OPT_fcf_protection_EQ)) {
-StringRef Name = A->getValue();
-if (Name == "full" || Name == "branch") {
-  Opts.CFProtectionBranch = 1;
-}
-  }
   // -cl-std only applies for OpenCL language standards.
   // Override the -std option in this case.
   if (const Arg *A = Args.getLastArg(OPT_cl_std_EQ)) {
@@ -2224,14 +2218,21 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, InputKind IK,
   LangStd = OpenCLLangStd;
   }
 
-  Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device);
-
   // These need to be parsed now. They are used to set OpenCL defaults.
   Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header);
   Opts.DeclareOpenCLBuiltins = Args.hasArg(OPT_fdeclare_opencl_builtins);
 
   CompilerInvocation::setLangDefaults(Opts, IK, T, Includes, LangStd);
 
+  if (const Arg *A = Args.getLastArg(OPT_fcf_protection_EQ)) {
+StringRef Name = A->getValue();
+if (Name == "full" || Name == "branch") {
+  Opts.CFProtectionBranch = 1;
+}
+  }
+
+  Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device);
+
   // -cl-strict-aliasing needs to emit diagnostic in the case where CL > 1.0.
   // This option should be deprecated for CL > 1.0 because
   // this option was added for compatibility with OpenCL 1.0.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 1744f4c - [clang][cli] NFC: Promote ParseLangArgs and ParseCodeGenArgs to members

2021-01-15 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-15T16:41:34+01:00
New Revision: 1744f4c676411ebd2e38afd5a6b56e5dd533c6ac

URL: 
https://github.com/llvm/llvm-project/commit/1744f4c676411ebd2e38afd5a6b56e5dd533c6ac
DIFF: 
https://github.com/llvm/llvm-project/commit/1744f4c676411ebd2e38afd5a6b56e5dd533c6ac.diff

LOG: [clang][cli] NFC: Promote ParseLangArgs and ParseCodeGenArgs to members

This patch promotes `ParseLangArgs` and `ParseCodeGenArgs` to members of 
`CompilerInvocation`. That will be useful in the following patch D94682, where 
we need to access protected members of `LangOptions` and `CodeGenOptions`. Both 
of those classes already have `friend CompilerInvocation`.

This is cleaner than keeping those functions freestanding and having to specify 
the exact signature of both in extra `friend` declarations.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D94681

Added: 


Modified: 
clang/include/clang/Frontend/CompilerInvocation.h
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Frontend/CompilerInvocation.h 
b/clang/include/clang/Frontend/CompilerInvocation.h
index 9f16c5077154..b65b087510ce 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -247,6 +247,18 @@ class CompilerInvocation : public CompilerInvocationBase {
   /// \returns - True if parsing was successful, false otherwise
   bool parseSimpleArgs(const llvm::opt::ArgList &Args,
DiagnosticsEngine &Diags);
+
+  /// Parse command line options that map to LangOptions.
+  static void ParseLangArgs(LangOptions &Opts, llvm::opt::ArgList &Args,
+InputKind IK, const llvm::Triple &T,
+std::vector &Includes,
+DiagnosticsEngine &Diags);
+
+  /// Parse command line options that map to CodeGenOptions.
+  static bool ParseCodeGenArgs(CodeGenOptions &Opts, llvm::opt::ArgList &Args,
+   InputKind IK, DiagnosticsEngine &Diags,
+   const llvm::Triple &T,
+   const std::string &OutputFile);
 };
 
 IntrusiveRefCntPtr

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index c672834a7970..25b3610e50db 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -907,9 +907,11 @@ static void setPGOUseInstrumentor(CodeGenOptions &Opts,
 Opts.setProfileUse(CodeGenOptions::ProfileClangInstr);
 }
 
-static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
- DiagnosticsEngine &Diags, const llvm::Triple &T,
- const std::string &OutputFile) {
+bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
+  InputKind IK,
+  DiagnosticsEngine &Diags,
+  const llvm::Triple &T,
+  const std::string &OutputFile) {
   bool Success = true;
 
   unsigned OptimizationLevel = getOptimizationLevel(Args, IK, Diags);
@@ -2151,10 +2153,10 @@ static void GenerateLangArgs(const LangOptions &Opts,
 Args.push_back(SA(GetOptName(OPT_fdeclare_opencl_builtins)));
 }
 
-static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
-  const llvm::Triple &T,
-  std::vector &Includes,
-  DiagnosticsEngine &Diags) {
+void CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
+   InputKind IK, const llvm::Triple &T,
+   std::vector &Includes,
+   DiagnosticsEngine &Diags) {
   // FIXME: Cleanup per-file based stuff.
   LangStandard::Kind LangStd = LangStandard::lang_unspecified;
   if (const Arg *A = Args.getLastArg(OPT_std_EQ)) {



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 39a2a23 - [clang][cli] Parse Lang and CodeGen options separately

2021-01-19 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-19T09:52:46+01:00
New Revision: 39a2a233f88443e865758ba73c156787c77ead2c

URL: 
https://github.com/llvm/llvm-project/commit/39a2a233f88443e865758ba73c156787c77ead2c
DIFF: 
https://github.com/llvm/llvm-project/commit/39a2a233f88443e865758ba73c156787c77ead2c.diff

LOG: [clang][cli] Parse Lang and CodeGen options separately

This patch moves the parsing of `{Lang,CodeGen}Options` from `parseSimpleArgs` 
to the original `Parse{Lang,CodeGen}Args` functions.

This ensures all marshalled `LangOptions` are being parsed **after** the call 
`setLangDefaults`, which in turn enables us to marshall `LangOptions` that 
somehow depend on the defaults. (In a future patch.)

Now, `CodeGenOptions` need to be parsed **after** `LangOptions`, because 
`-cl-mad-enable` (a `CodeGenOpt`) depends on the value of 
`-cl-fast-relaxed-math` and `-cl-unsafe-math-optimizations` (`LangOpts`).

Unfortunately, this removes the nice property that marshalled options get 
parsed in the exact order they appear in the `.td` file. Now we cannot be sure 
that a TableGen record referenced in `ImpliedByAnyOf` has already been parsed. 
This might cause an ordering issues (i.e. reading value of uninitialized 
variable). I plan to mitigate this by moving each `XxxOpt` group from 
`parseSimpleArgs` back to their original parsing function. With this setup, if 
an option from group `A` references option from group `B` in TableGen, the 
compiler will require us to make the `CompilerInvocation` member for `B` 
visible in the parsing function for `A`. That's where we notice that `B` didn't 
get parsed yet.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D94682

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/include/clang/Frontend/CompilerInvocation.h
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Frontend/diagnostics-order.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3722192c7eee..e50c313450a9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -244,7 +244,7 @@ def clang_ignored_gcc_optimization_f_Group : OptionGroup<
 class DiagnosticOpts
   : KeyPathAndMacro<"DiagnosticOpts->", base, "DIAG_"> {}
 class LangOpts
-  : KeyPathAndMacro<"LangOpts->", base> {}
+  : KeyPathAndMacro<"LangOpts->", base, "LANG_"> {}
 class TargetOpts
   : KeyPathAndMacro<"TargetOpts->", base> {}
 class FrontendOpts
@@ -254,7 +254,7 @@ class PreprocessorOutputOpts
 class DependencyOutputOpts
   : KeyPathAndMacro<"DependencyOutputOpts.", base> {}
 class CodeGenOpts
-  : KeyPathAndMacro<"CodeGenOpts.", base> {}
+  : KeyPathAndMacro<"CodeGenOpts.", base, "CODEGEN_"> {}
 class HeaderSearchOpts
   : KeyPathAndMacro<"HeaderSearchOpts->", base> {}
 class PreprocessorOpts
@@ -510,6 +510,9 @@ multiclass BoolGOption;
 }
 
+// Key paths that are constant during parsing of options with the same key 
path prefix.
+defvar open_cl = LangOpts<"OpenCL">;
+
 /
 // Options
 
@@ -1820,9 +1823,13 @@ defm experimental_relative_cxx_abi_vtables : 
BoolFOption<"experimental-relative-
 def flat__namespace : Flag<["-"], "flat_namespace">;
 def flax_vector_conversions_EQ : Joined<["-"], "flax-vector-conversions=">, 
Group,
   HelpText<"Enable implicit vector bit-casts">, Values<"none,integer,all">, 
Flags<[CC1Option]>,
-  NormalizedValuesScope<"LangOptions::LaxVectorConversionKind">,
-  NormalizedValues<["None", "Integer", "All"]>,
-  MarshallingInfoString, "All">, 
AutoNormalizeEnum;
+  NormalizedValues<["LangOptions::LaxVectorConversionKind::None",
+"LangOptions::LaxVectorConversionKind::Integer",
+"LangOptions::LaxVectorConversionKind::All"]>,
+  MarshallingInfoString,
+!strconcat(open_cl.KeyPath, " ? 
LangOptions::LaxVectorConversionKind::None"
+" : 
LangOptions::LaxVectorConversionKind::All")>,
+  AutoNormalizeEnum;
 def flax_vector_conversions : Flag<["-"], "flax-vector-conversions">, 
Group,
   Alias, AliasArgs<["integer"]>;
 def flimited_precision_EQ : Joined<["-"], "flimited-precision=">, 
Group;

diff  --git a/clang/include/clang/Frontend/CompilerInvocation.h 
b/clang/include/clang/Frontend/CompilerInvocation.h
index b65b087510ce..0d83a228c301 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -258,7 +258,8 @@ class CompilerInvocation : public CompilerInvocationBase {
   static bool ParseCodeGenArgs(CodeGenOptions &Opts, llvm::opt::ArgList &Args,
InputKind IK, DiagnosticsEngine &Diags,
const llvm::Triple &T,
-   const std::string &OutputFile);
+   const std::string &OutputFile,
+ 

[llvm-branch-commits] [clang] e20d466 - [clang][cli] Port more options to new parsing system

2021-01-20 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-20T10:48:22+01:00
New Revision: e20d46628a31a984074f2e1029e67734d5c2ab0d

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

LOG: [clang][cli] Port more options to new parsing system

This patch adds marshalling information to more options.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D94957

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 8150b24e337b..500022c2c99b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3071,10 +3071,10 @@ def mwavefrontsize64 : Flag<["-"], "mwavefrontsize64">, 
Group,
 def mno_wavefrontsize64 : Flag<["-"], "mno-wavefrontsize64">, Group,
   HelpText<"Specify wavefront size 32 mode (AMDGPU only)">;
 
-def munsafe_fp_atomics : Flag<["-"], "munsafe-fp-atomics">, Group,
-  HelpText<"Enable unsafe floating point atomic instructions (AMDGPU only)">,
-  Flags<[CC1Option]>;
-def mno_unsafe_fp_atomics : Flag<["-"], "mno-unsafe-fp-atomics">, 
Group;
+defm unsafe_fp_atomics : BoolCC1Option<"unsafe-fp-atomics",
+  TargetOpts<"AllowAMDGPUUnsafeFPAtomics">, DefaultsToFalse,
+  ChangedBy,
+  ResetBy, BothFlags<[]>, "m">, Group;
 
 def faltivec : Flag<["-"], "faltivec">, Group, Flags<[NoXarchOption]>;
 def fno_altivec : Flag<["-"], "fno-altivec">, Group, 
Flags<[NoXarchOption]>;
@@ -4378,7 +4378,10 @@ def analyzer_checker_option_help_developer : Flag<["-"], 
"analyzer-checker-optio
   MarshallingInfoFlag>;
 
 def analyzer_config_compatibility_mode : Separate<["-"], 
"analyzer-config-compatibility-mode">,
-  HelpText<"Don't emit errors on invalid analyzer-config inputs">;
+  HelpText<"Don't emit errors on invalid analyzer-config inputs">,
+  Values<"true,false">, NormalizedValues<[[{false}], [{true}]]>,
+  MarshallingInfoString, 
[{true}]>,
+  AutoNormalizeEnum;
 
 def analyzer_config_compatibility_mode_EQ : Joined<["-"], 
"analyzer-config-compatibility-mode=">,
   Alias;
@@ -4842,7 +4845,8 @@ def plugin_arg : JoinedAndSeparate<["-"], "plugin-arg-">,
 MetaVarName<" ">,
 HelpText<"Pass  to plugin ">;
 def add_plugin : Separate<["-"], "add-plugin">, MetaVarName<"">,
-  HelpText<"Use the named plugin action in addition to the default action">;
+  HelpText<"Use the named plugin action in addition to the default action">,
+  MarshallingInfoStringVector>;
 def ast_dump_filter : Separate<["-"], "ast-dump-filter">,
   MetaVarName<"">,
   HelpText<"Use with -ast-dump or -ast-print to dump/print only AST 
declaration"
@@ -5118,10 +5122,13 @@ def fhalf_no_semantic_interposition : Flag<["-"], 
"fhalf-no-semantic-interpositi
 def fno_validate_pch : Flag<["-"], "fno-validate-pch">,
   HelpText<"Disable validation of precompiled headers">,
   MarshallingInfoFlag>;
-def fallow_pch_with_errors : Flag<["-"], "fallow-pch-with-compiler-errors">,
-  HelpText<"Accept a PCH file that was created with compiler errors">;
 def fallow_pcm_with_errors : Flag<["-"], "fallow-pcm-with-compiler-errors">,
-  HelpText<"Accept a PCM file that was created with compiler errors">;
+  HelpText<"Accept a PCM file that was created with compiler errors">,
+  MarshallingInfoFlag>;
+def fallow_pch_with_errors : Flag<["-"], "fallow-pch-with-compiler-errors">,
+  HelpText<"Accept a PCH file that was created with compiler errors">,
+  MarshallingInfoFlag>,
+  ImpliedByAnyOf<[fallow_pcm_with_errors]>;
 def dump_deserialized_pch_decls : Flag<["-"], "dump-deserialized-decls">,
   HelpText<"Dump declarations that are deserialized from PCH, for testing">,
   MarshallingInfoFlag>;

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index dac0dc6921a5..24b8fd19dd50 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -634,13 +634,6 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, 
ArgList &Args,
 }
   }
 
-  Opts.ShouldEmitErrorsOnInvalidConfigValue =
-  /* negated */!llvm::StringSwitch(
-   
Args.getLastArgValue(OPT_analyzer_config_compatibility_mode))
-.Case("true", true)
-.Case("false", false)
-.Default(false);
-
   Opts.CheckersAndPackages.clear();
   for (const Arg *A :
Args.filtered(OPT_analyzer_checker, OPT_analyzer_disable_checker)) {
@@ -828,10 +821,6 @@ static void parseAnalyzerConfigs(AnalyzerOptions &AnOpts,
<< "a filename";
 }
 
-static void ParseCommentArgs(CommentOptions &Opts, ArgList &Args) {
-  Opts.ParseAllComments = Args.hasArg(OPT_fparse_all_comments);
-}
-
 /// Create a new Regex instance out

[llvm-branch-commits] [clang] ff5f42e - [clang][cli] Port visibility LangOptions to marshalling system

2021-01-22 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-22T09:32:01+01:00
New Revision: ff5f42e413386b1b3730879abf7b35756891e1c3

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

LOG: [clang][cli] Port visibility LangOptions to marshalling system

This patch introduces Clang-specific MarshallingInfoVisibility TableGen class.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D95147

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a2800381be0e..3bb545f84132 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -510,6 +510,14 @@ multiclass BoolGOption;
 }
 
+// FIXME: Diagnose if target does not support protected visibility.
+class MarshallingInfoVisibility
+  : MarshallingInfoString,
+Values<"default,hidden,internal,protected">,
+NormalizedValues<["DefaultVisibility", "HiddenVisibility",
+  "HiddenVisibility", "ProtectedVisibility"]>,
+AutoNormalizeEnum {}
+
 // Key paths that are constant during parsing of options with the same key 
path prefix.
 defvar open_cl = LangOpts<"OpenCL">;
 
@@ -2482,15 +2490,26 @@ def fno_var_tracking : Flag<["-"], "fno-var-tracking">, 
Group, Group,
   HelpText<"Generate verbose assembly output">;
 def dA : Flag<["-"], "dA">, Alias;
-defm visibility_from_dllstorageclass : 
OptInFFlag<"visibility-from-dllstorageclass", "Set the visiblity of symbols in 
the generated code from their DLL storage class">;
+defm visibility_from_dllstorageclass : 
BoolFOption<"visibility-from-dllstorageclass",
+  LangOpts<"VisibilityFromDLLStorageClass">, DefaultsToFalse,
+  ChangedBy,
+  ResetBy>;
 def fvisibility_dllexport_EQ : Joined<["-"], "fvisibility-dllexport=">, 
Group, Flags<[CC1Option]>,
-  HelpText<"The visibility for dllexport defintions 
[-fvisibility-from-dllstorageclass]">, Values<"hidden,protected,default">;
+  HelpText<"The visibility for dllexport defintions 
[-fvisibility-from-dllstorageclass]">,
+  MarshallingInfoVisibility, 
"DefaultVisibility">,
+  ShouldParseIf;
 def fvisibility_nodllstorageclass_EQ : Joined<["-"], 
"fvisibility-nodllstorageclass=">, Group, Flags<[CC1Option]>,
-  HelpText<"The visibility for defintiions without an explicit DLL export 
class [-fvisibility-from-dllstorageclass]">, Values<"hidden,protected,default">;
+  HelpText<"The visibility for defintiions without an explicit DLL export 
class [-fvisibility-from-dllstorageclass]">,
+  MarshallingInfoVisibility, 
"HiddenVisibility">,
+  ShouldParseIf;
 def fvisibility_externs_dllimport_EQ : Joined<["-"], 
"fvisibility-externs-dllimport=">, Group, Flags<[CC1Option]>,
-  HelpText<"The visibility for dllimport external declarations 
[-fvisibility-from-dllstorageclass]">, Values<"hidden,protected,default">;
+  HelpText<"The visibility for dllimport external declarations 
[-fvisibility-from-dllstorageclass]">,
+  MarshallingInfoVisibility, 
"DefaultVisibility">,
+  ShouldParseIf;
 def fvisibility_externs_nodllstorageclass_EQ : Joined<["-"], 
"fvisibility-externs-nodllstorageclass=">, Group, Flags<[CC1Option]>,
-  HelpText<"The visibility for external declarations without an explicit DLL 
dllstorageclass [-fvisibility-from-dllstorageclass]">, 
Values<"hidden,protected,default">;
+  HelpText<"The visibility for external declarations without an explicit DLL 
dllstorageclass [-fvisibility-from-dllstorageclass]">,
+  MarshallingInfoVisibility, 
"HiddenVisibility">,
+  ShouldParseIf;
 def fvisibility_EQ : Joined<["-"], "fvisibility=">, Group,
   HelpText<"Set the default symbol visibility for all global declarations">, 
Values<"hidden,default">;
 def fvisibility_inlines_hidden : Flag<["-"], "fvisibility-inlines-hidden">, 
Group,
@@ -5148,14 +5167,12 @@ def stack_protector : Separate<["-"], 
"stack-protector">,
 def stack_protector_buffer_size : Separate<["-"], 
"stack-protector-buffer-size">,
   HelpText<"Lower bound for a buffer to be considered for stack protection">,
   MarshallingInfoStringInt, "8">;
-// FIXME: diagnose if target does not support protected visibility
-// Good place for this is CompilerInvocation::fixupInvocation. Do the same for 
parseVisibility.
 def fvisibility : Separate<["-"], "fvisibility">,
-  HelpText<"Default type and symbol visibility">, 
Values<"default,hidden,internal,protected">,
-  NormalizedValues<["DefaultVisibility", "HiddenVisibility", 
"HiddenVisibility", "ProtectedVisibility"]>,
-  MarshallingInfoString, "DefaultVisibility">, 
AutoNormalizeEnum;
+  HelpText<"Default type and symbol visibility">,
+  MarshallingInfoVisibility, 
"DefaultVisibility">;
 def ftype_visibility : Separate<["-"], "ftype-visibility">,
-  

[llvm-branch-commits] [clang] f111cf9 - [clang][cli] Specify correct integer width for -fbuild-session-timestamp

2021-01-05 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-05T20:10:07+01:00
New Revision: f111cf992df4ec00acfdd026eac12b36c3831999

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

LOG: [clang][cli] Specify correct integer width for -fbuild-session-timestamp

This fixes an issue where large integer values were rejected as invalid.

Reviewed By: arphaman

Differential Revision: https://reviews.llvm.org/D94101

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9a851f63a663..c7da888968a8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1767,7 +1767,7 @@ def fmodules_search_all : Flag <["-"], 
"fmodules-search-all">, Group,
 def fbuild_session_timestamp : Joined<["-"], "fbuild-session-timestamp=">,
   Group, Flags<[CC1Option]>, MetaVarName<"">,
   HelpText<"Time when the current build session started">,
-  MarshallingInfoStringInt<"HeaderSearchOpts->BuildSessionTimestamp">;
+  MarshallingInfoStringInt<"HeaderSearchOpts->BuildSessionTimestamp", "0", 
"uint64_t">;
 def fbuild_session_file : Joined<["-"], "fbuild-session-file=">,
   Group, MetaVarName<"">,
   HelpText<"Use the last modification time of  as the build session 
timestamp">;

diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 51b7ba8c147f..83ae169f9929 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -368,6 +368,18 @@ TEST_F(CommandLineTest, 
CanGenerateCC1COmmandLineSeparateEnumDefault) {
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("pic";
 }
 
+// Wide integer option.
+
+TEST_F(CommandLineTest, WideIntegerHighValue) {
+  const char *Args[] = {"-fbuild-session-timestamp=1609827494445723662"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_EQ(Invocation.getHeaderSearchOpts().BuildSessionTimestamp,
+1609827494445723662ull);
+}
+
 // Tree of boolean options that can be (directly or transitively) implied by
 // their parent:
 //



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 77db83a - [clang][cli] Allow users to specify a conditional to prevent parsing options with MarshallingInfo

2021-01-07 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-07T10:01:49+01:00
New Revision: 77db83ae997767400ffcbe0101f8ee867ebaa111

URL: 
https://github.com/llvm/llvm-project/commit/77db83ae997767400ffcbe0101f8ee867ebaa111
DIFF: 
https://github.com/llvm/llvm-project/commit/77db83ae997767400ffcbe0101f8ee867ebaa111.diff

LOG: [clang][cli] Allow users to specify a conditional to prevent parsing 
options with MarshallingInfo

Depends on D84189 & D93540.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D84674

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 428c14a7d9bb..33b5cd09004e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4091,7 +4091,9 @@ defm sycl : BoolOption<"sycl",
   BothFlags<[CoreOption], " SYCL kernels compilation for device">, "f">,
   Group;
 def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group, 
Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
-  HelpText<"SYCL language standard to compile for.">, Values<"2017, 121, 
1.2.1, sycl-1.2.1">;
+  HelpText<"SYCL language standard to compile for.">, 
Values<"2017,121,1.2.1,sycl-1.2.1">,
+  NormalizedValues<["SYCL_2017", "SYCL_2017", "SYCL_2017", "SYCL_2017"]>, 
NormalizedValuesScope<"LangOptions">,
+  MarshallingInfoString<"LangOpts->SYCLVersion", "SYCL_None">, 
ShouldParseIf, AutoNormalizeEnum;
 
 
//===--===//
 // FlangOption and FC1 Options

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 57027cea5659..962f72963cd2 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2282,23 +2282,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, InputKind IK,
   }
 
   Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device);
-  if (Opts.SYCL) {
-// -sycl-std applies to any SYCL source, not only those containing kernels,
-// but also those using the SYCL API
-if (const Arg *A = Args.getLastArg(OPT_sycl_std_EQ)) {
-  Opts.setSYCLVersion(
-  llvm::StringSwitch(A->getValue())
-  .Cases("2017", "1.2.1", "121", "sycl-1.2.1",
- LangOptions::SYCL_2017)
-  .Default(LangOptions::SYCL_None));
-
-  if (Opts.getSYCLVersion() == LangOptions::SYCL_None) {
-// User has passed an invalid value to the flag, this is an error
-Diags.Report(diag::err_drv_invalid_value)
-<< A->getAsString(Args) << A->getValue();
-  }
-}
-  }
 
   llvm::Triple T(TargetOpts.Triple);
   CompilerInvocation::setLangDefaults(Opts, IK, T, PPOpts, LangStd);
@@ -3003,16 +2986,17 @@ bool CompilerInvocation::parseSimpleArgs(const ArgList 
&Args,
  DiagnosticsEngine &Diags) {
 #define OPTION_WITH_MARSHALLING(   
\
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,
\
-HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  
\
-IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, 
\
-TABLE_INDEX)   
\
+HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH,   
\
+DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, 
\
+MERGER, EXTRACTOR, TABLE_INDEX)
\
   if ((FLAGS)&options::CC1Option) {
\
 this->KEYPATH = MERGER(this->KEYPATH, DEFAULT_VALUE);  
\
 if (IMPLIED_CHECK) 
\
   this->KEYPATH = MERGER(this->KEYPATH, IMPLIED_VALUE);
\
-if (auto MaybeValue = NORMALIZER(OPT_##ID, TABLE_INDEX, Args, Diags))  
\
-  this->KEYPATH = MERGER(  
\
-  this->KEYPATH, static_castKEYPATH)>(*MaybeValue));   
\
+if (SHOULD_PARSE)  
\
+  if (auto MaybeValue = NORMALIZER(OPT_##ID, TABLE_INDEX, Args, Diags))
\
+this->KEYPATH = MERGER(
\
+this->KEYPATH, static_castKEYPATH)>(*MaybeValue)); 
\
   }
 
 #include "clang/Driver/Options.inc"
@@ -3265,9 +3249,9 @@ void CompilerInvocation::generateCC1CommandLine(
   // with lifetime extension of the reference.
 #define OPTION_WITH_MARSHALLING(  

[llvm-branch-commits] [clang] c6ea4d5 - [clang][cli] Implement ContainsN Google Test matcher

2021-01-07 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-07T10:01:49+01:00
New Revision: c6ea4d5b2c0054f3e2fa06b911ed3933fe59bc5b

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

LOG: [clang][cli] Implement ContainsN Google Test matcher

This allows us to verify that we don't emit options multiple times.

In most cases, that would be benign, but for options with 
`MarshallingInfoVectorString`, emitting wrong number of arguments might change 
the semantics.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D93636

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 89d9c88cc604..8fcf34d5c874 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -39,6 +39,61 @@ class CommandLineTest : public ::testing::Test {
   }
 };
 
+template 
+std::string describeContainsN(M InnerMatcher, unsigned N, bool Negation) {
+  StringRef Contains = Negation ? "doesn't contain" : "contains";
+  StringRef Instance = N == 1 ? " instance " : " instances ";
+  StringRef Element = "of element that ";
+
+  std::ostringstream Inner;
+  InnerMatcher.impl().DescribeTo(&Inner);
+
+  return (Contains + " exactly " + Twine(N) + Instance + Element + Inner.str())
+  .str();
+}
+
+MATCHER_P2(ContainsN, InnerMatcher, N,
+   describeContainsN(InnerMatcher, N, negation)) {
+  auto InnerMatches = [this](const auto &Element) {
+::testing::internal::DummyMatchResultListener InnerListener;
+return InnerMatcher.impl().MatchAndExplain(Element, &InnerListener);
+  };
+
+  return count_if(arg, InnerMatches) == N;
+}
+
+TEST(ContainsN, Empty) {
+  const char *Array[] = {""};
+
+  ASSERT_THAT(Array, ContainsN(StrEq("x"), 0));
+  ASSERT_THAT(Array, Not(ContainsN(StrEq("x"), 1)));
+  ASSERT_THAT(Array, Not(ContainsN(StrEq("x"), 2)));
+}
+
+TEST(ContainsN, Zero) {
+  const char *Array[] = {"y"};
+
+  ASSERT_THAT(Array, ContainsN(StrEq("x"), 0));
+  ASSERT_THAT(Array, Not(ContainsN(StrEq("x"), 1)));
+  ASSERT_THAT(Array, Not(ContainsN(StrEq("x"), 2)));
+}
+
+TEST(ContainsN, One) {
+  const char *Array[] = {"a", "b", "x", "z"};
+
+  ASSERT_THAT(Array, Not(ContainsN(StrEq("x"), 0)));
+  ASSERT_THAT(Array, ContainsN(StrEq("x"), 1));
+  ASSERT_THAT(Array, Not(ContainsN(StrEq("x"), 2)));
+}
+
+TEST(ContainsN, Two) {
+  const char *Array[] = {"x", "a", "b", "x"};
+
+  ASSERT_THAT(Array, Not(ContainsN(StrEq("x"), 0)));
+  ASSERT_THAT(Array, Not(ContainsN(StrEq("x"), 1)));
+  ASSERT_THAT(Array, ContainsN(StrEq("x"), 2));
+}
+
 // Boolean option with a keypath that defaults to true.
 // The only flag with a negative spelling can set the keypath to false.
 
@@ -270,7 +325,7 @@ TEST_F(CommandLineTest, BoolOptionCC1ViaLetPresentPos) {
 
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
-  ASSERT_EQ(count(GeneratedArgs, StringRef("-fdebug-pass-manager")), 1);
+  ASSERT_THAT(GeneratedArgs, ContainsN(StrEq("-fdebug-pass-manager"), 1));
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fno-debug-pass-manager";
 }
 
@@ -418,7 +473,8 @@ TEST_F(CommandLineTest, StringVectorEmpty) {
   ASSERT_TRUE(Invocation.getFrontendOpts().ModuleMapFiles.empty());
 
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
-  ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-fmodule-map-file=";
+
+  ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-fmodule-map-file";
 }
 
 TEST_F(CommandLineTest, StringVectorSingle) {
@@ -431,7 +487,9 @@ TEST_F(CommandLineTest, StringVectorSingle) {
 std::vector({"a"}));
 
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
-  ASSERT_EQ(count(GeneratedArgs, StringRef("-fmodule-map-file=a")), 1);
+
+  ASSERT_THAT(GeneratedArgs, ContainsN(StrEq("-fmodule-map-file=a"), 1));
+  ASSERT_THAT(GeneratedArgs, ContainsN(HasSubstr("-fmodule-map-file"), 1));
 }
 
 TEST_F(CommandLineTest, StringVectorMultiple) {
@@ -444,8 +502,10 @@ TEST_F(CommandLineTest, StringVectorMultiple) {
   std::vector({"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);
+
+  ASSERT_THAT(GeneratedArgs, ContainsN(StrEq("-fmodule-map-file=a"), 1));
+  ASSERT_THAT(GeneratedArgs, ContainsN(StrEq("-fmodule-map-file=b"), 1));
+  ASSERT_THAT(GeneratedArgs, ContainsN(HasSubstr("-fmodule-map-file"), 2));
 }
 
 // A flag that should be parsed only if a condition is met.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https

[llvm-branch-commits] [clang] d0fa7a0 - Revert "[clang][cli] Allow users to specify a conditional to prevent parsing options with MarshallingInfo"

2021-01-07 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-07T10:12:53+01:00
New Revision: d0fa7a05be92617a0262ec8b622f158971a54c54

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

LOG: Revert "[clang][cli] Allow users to specify a conditional to prevent 
parsing options with MarshallingInfo"

This reverts commit 77db83ae

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 33b5cd09004e..428c14a7d9bb 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4091,9 +4091,7 @@ defm sycl : BoolOption<"sycl",
   BothFlags<[CoreOption], " SYCL kernels compilation for device">, "f">,
   Group;
 def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group, 
Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
-  HelpText<"SYCL language standard to compile for.">, 
Values<"2017,121,1.2.1,sycl-1.2.1">,
-  NormalizedValues<["SYCL_2017", "SYCL_2017", "SYCL_2017", "SYCL_2017"]>, 
NormalizedValuesScope<"LangOptions">,
-  MarshallingInfoString<"LangOpts->SYCLVersion", "SYCL_None">, 
ShouldParseIf, AutoNormalizeEnum;
+  HelpText<"SYCL language standard to compile for.">, Values<"2017, 121, 
1.2.1, sycl-1.2.1">;
 
 
//===--===//
 // FlangOption and FC1 Options

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 962f72963cd2..57027cea5659 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2282,6 +2282,23 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, InputKind IK,
   }
 
   Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device);
+  if (Opts.SYCL) {
+// -sycl-std applies to any SYCL source, not only those containing kernels,
+// but also those using the SYCL API
+if (const Arg *A = Args.getLastArg(OPT_sycl_std_EQ)) {
+  Opts.setSYCLVersion(
+  llvm::StringSwitch(A->getValue())
+  .Cases("2017", "1.2.1", "121", "sycl-1.2.1",
+ LangOptions::SYCL_2017)
+  .Default(LangOptions::SYCL_None));
+
+  if (Opts.getSYCLVersion() == LangOptions::SYCL_None) {
+// User has passed an invalid value to the flag, this is an error
+Diags.Report(diag::err_drv_invalid_value)
+<< A->getAsString(Args) << A->getValue();
+  }
+}
+  }
 
   llvm::Triple T(TargetOpts.Triple);
   CompilerInvocation::setLangDefaults(Opts, IK, T, PPOpts, LangStd);
@@ -2986,17 +3003,16 @@ bool CompilerInvocation::parseSimpleArgs(const ArgList 
&Args,
  DiagnosticsEngine &Diags) {
 #define OPTION_WITH_MARSHALLING(   
\
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,
\
-HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH,   
\
-DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, 
\
-MERGER, EXTRACTOR, TABLE_INDEX)
\
+HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  
\
+IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, 
\
+TABLE_INDEX)   
\
   if ((FLAGS)&options::CC1Option) {
\
 this->KEYPATH = MERGER(this->KEYPATH, DEFAULT_VALUE);  
\
 if (IMPLIED_CHECK) 
\
   this->KEYPATH = MERGER(this->KEYPATH, IMPLIED_VALUE);
\
-if (SHOULD_PARSE)  
\
-  if (auto MaybeValue = NORMALIZER(OPT_##ID, TABLE_INDEX, Args, Diags))
\
-this->KEYPATH = MERGER(
\
-this->KEYPATH, static_castKEYPATH)>(*MaybeValue)); 
\
+if (auto MaybeValue = NORMALIZER(OPT_##ID, TABLE_INDEX, Args, Diags))  
\
+  this->KEYPATH = MERGER(  
\
+  this->KEYPATH, static_castKEYPATH)>(*MaybeValue));   
\
   }
 
 #include "clang/Driver/Options.inc"
@@ -3249,9 +3265,9 @@ void CompilerInvocation::generateCC1CommandLine(
   // with lifetime extension of the reference.
 #define OPTION_WITH_MARSHALLING(   
\
 PREFIX_TYPE, NAME, ID, KIND, GROUP, A

[llvm-branch-commits] [llvm] 67a4c67 - Reapply "[clang][cli] Allow users to specify a conditional to prevent parsing options with MarshallingInfo"

2021-01-07 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-07T11:11:47+01:00
New Revision: 67a4c672b02359fa6f723249f633ffc76aff2174

URL: 
https://github.com/llvm/llvm-project/commit/67a4c672b02359fa6f723249f633ffc76aff2174
DIFF: 
https://github.com/llvm/llvm-project/commit/67a4c672b02359fa6f723249f633ffc76aff2174.diff

LOG: Reapply "[clang][cli] Allow users to specify a conditional to prevent 
parsing options with MarshallingInfo"

This reverts commit d0fa7a05 and fixes failing OptionMarshallingTest by adding 
the SHOULD_PARSE macro argument

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 428c14a7d9bb..33b5cd09004e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4091,7 +4091,9 @@ defm sycl : BoolOption<"sycl",
   BothFlags<[CoreOption], " SYCL kernels compilation for device">, "f">,
   Group;
 def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group, 
Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
-  HelpText<"SYCL language standard to compile for.">, Values<"2017, 121, 
1.2.1, sycl-1.2.1">;
+  HelpText<"SYCL language standard to compile for.">, 
Values<"2017,121,1.2.1,sycl-1.2.1">,
+  NormalizedValues<["SYCL_2017", "SYCL_2017", "SYCL_2017", "SYCL_2017"]>, 
NormalizedValuesScope<"LangOptions">,
+  MarshallingInfoString<"LangOpts->SYCLVersion", "SYCL_None">, 
ShouldParseIf, AutoNormalizeEnum;
 
 
//===--===//
 // FlangOption and FC1 Options

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 57027cea5659..962f72963cd2 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2282,23 +2282,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, InputKind IK,
   }
 
   Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device);
-  if (Opts.SYCL) {
-// -sycl-std applies to any SYCL source, not only those containing kernels,
-// but also those using the SYCL API
-if (const Arg *A = Args.getLastArg(OPT_sycl_std_EQ)) {
-  Opts.setSYCLVersion(
-  llvm::StringSwitch(A->getValue())
-  .Cases("2017", "1.2.1", "121", "sycl-1.2.1",
- LangOptions::SYCL_2017)
-  .Default(LangOptions::SYCL_None));
-
-  if (Opts.getSYCLVersion() == LangOptions::SYCL_None) {
-// User has passed an invalid value to the flag, this is an error
-Diags.Report(diag::err_drv_invalid_value)
-<< A->getAsString(Args) << A->getValue();
-  }
-}
-  }
 
   llvm::Triple T(TargetOpts.Triple);
   CompilerInvocation::setLangDefaults(Opts, IK, T, PPOpts, LangStd);
@@ -3003,16 +2986,17 @@ bool CompilerInvocation::parseSimpleArgs(const ArgList 
&Args,
  DiagnosticsEngine &Diags) {
 #define OPTION_WITH_MARSHALLING(   
\
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,
\
-HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  
\
-IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, 
\
-TABLE_INDEX)   
\
+HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH,   
\
+DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, 
\
+MERGER, EXTRACTOR, TABLE_INDEX)
\
   if ((FLAGS)&options::CC1Option) {
\
 this->KEYPATH = MERGER(this->KEYPATH, DEFAULT_VALUE);  
\
 if (IMPLIED_CHECK) 
\
   this->KEYPATH = MERGER(this->KEYPATH, IMPLIED_VALUE);
\
-if (auto MaybeValue = NORMALIZER(OPT_##ID, TABLE_INDEX, Args, Diags))  
\
-  this->KEYPATH = MERGER(  
\
-  this->KEYPATH, static_castKEYPATH)>(*MaybeValue));   
\
+if (SHOULD_PARSE)  
\
+  if (auto MaybeValue = NORMALIZER(OPT_##ID, TABLE_INDEX, Args, Diags))
\
+this->KEYPATH = MERGER(
\
+this->KEYPATH, static_castKEYPATH)>(*MaybeValue)); 
\
   }
 
 #include "clang/Driver/Options.inc"
@@ -3265,9 +3249,9 @@ void CompilerInvocation::generateCC1CommandLine(
   // with lifetime extension of the 

[llvm-branch-commits] [clang] a828fb4 - [clang][cli] Port a CommaJoined option to the marshalling infrastructure

2021-01-07 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-07T11:52:06+01:00
New Revision: a828fb463ed9f6085849bb3a4f225b3c84e7cf29

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

LOG: [clang][cli] Port a CommaJoined option to the marshalling infrastructure

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D93698

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 33b5cd09004e..6b5ae35ad7e0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1201,7 +1201,7 @@ def fansi_escape_codes : Flag<["-"], 
"fansi-escape-codes">, Group,
   MarshallingInfoFlag<"DiagnosticOpts->UseANSIEscapeCodes">;
 def fcomment_block_commands : CommaJoined<["-"], "fcomment-block-commands=">, 
Group, Flags<[CC1Option]>,
   HelpText<"Treat each comma separated argument in  as a documentation 
comment block command">,
-  MetaVarName<"">;
+  MetaVarName<"">, 
MarshallingInfoStringVector<"LangOpts->CommentOpts.BlockCommandNames">;
 def fparse_all_comments : Flag<["-"], "fparse-all-comments">, 
Group, Flags<[CC1Option]>,
   MarshallingInfoFlag<"LangOpts->CommentOpts.ParseAllComments">;
 def frecord_command_line : Flag<["-"], "frecord-command-line">,

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 962f72963cd2..da4213e8952e 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -328,8 +328,20 @@ static void denormalizeStringVector(SmallVectorImpl &Args,
 Option::OptionClass OptClass,
 unsigned TableIndex,
 const std::vector &Values) {
-  for (const std::string &Value : Values) {
-denormalizeString(Args, Spelling, SA, OptClass, TableIndex, Value);
+  if (OptClass == Option::OptionClass::CommaJoinedClass) {
+std::string CommaJoinedValue;
+if (!Values.empty()) {
+  CommaJoinedValue.append(Values.front());
+  for (const std::string &Value : llvm::drop_begin(Values, 1)) {
+CommaJoinedValue.append(",");
+CommaJoinedValue.append(Value);
+  }
+}
+denormalizeString(Args, Spelling, SA, Option::OptionClass::JoinedClass,
+  TableIndex, CommaJoinedValue);
+  } else if (OptClass == Option::OptionClass::JoinedClass) {
+for (const std::string &Value : Values)
+  denormalizeString(Args, Spelling, SA, OptClass, TableIndex, Value);
   }
 }
 
@@ -785,7 +797,6 @@ static void parseAnalyzerConfigs(AnalyzerOptions &AnOpts,
 }
 
 static void ParseCommentArgs(CommentOptions &Opts, ArgList &Args) {
-  Opts.BlockCommandNames = Args.getAllArgValues(OPT_fcomment_block_commands);
   Opts.ParseAllComments = Args.hasArg(OPT_fparse_all_comments);
 }
 

diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 8fcf34d5c874..7b8efb9af2e2 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -508,6 +508,53 @@ TEST_F(CommandLineTest, StringVectorMultiple) {
   ASSERT_THAT(GeneratedArgs, ContainsN(HasSubstr("-fmodule-map-file"), 2));
 }
 
+// CommaJoined option with MarshallingInfoStringVector.
+
+TEST_F(CommandLineTest, StringVectorCommaJoinedNone) {
+  const char *Args[] = {""};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_TRUE(Invocation.getLangOpts()->CommentOpts.BlockCommandNames.empty());
+
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
+
+  ASSERT_THAT(GeneratedArgs,
+  Not(Contains(HasSubstr("-fcomment-block-commands";
+}
+
+TEST_F(CommandLineTest, StringVectorCommaJoinedSingle) {
+  const char *Args[] = {"-fcomment-block-commands=x,y"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_EQ(Invocation.getLangOpts()->CommentOpts.BlockCommandNames,
+std::vector({"x", "y"}));
+
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
+
+  ASSERT_THAT(GeneratedArgs,
+  ContainsN(StrEq("-fcomment-block-commands=x,y"), 1));
+}
+
+TEST_F(CommandLineTest, StringVectorCommaJoinedMultiple) {
+  const char *Args[] = {"-fcomment-block-commands=x,y",
+"-fcomment-block-commands=a,b"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_EQ(Invocation.getLangOpts()->Co

[llvm-branch-commits] [clang] b6ba598 - [clang][cli] Port getAllArgumentValues to the marshalling infrastructure

2021-01-07 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-07T12:02:07+01:00
New Revision: b6ba59830796b4efad69a3d3c1fae56c20029f30

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

LOG: [clang][cli] Port getAllArgumentValues to the marshalling infrastructure

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D93679

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index ffa7fbd84df93..6585fd1ceb013 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -679,7 +679,8 @@ def MP : Flag<["-"], "MP">, Group, 
Flags<[CC1Option]>,
 def MQ : JoinedOrSeparate<["-"], "MQ">, Group, Flags<[CC1Option]>,
 HelpText<"Specify name of main file output to quote in depfile">;
 def MT : JoinedOrSeparate<["-"], "MT">, Group, Flags<[CC1Option]>,
-HelpText<"Specify name of main file output in depfile">;
+HelpText<"Specify name of main file output in depfile">,
+MarshallingInfoStringVector<"DependencyOutputOpts.Targets">;
 def MV : Flag<["-"], "MV">, Group, Flags<[CC1Option]>,
 HelpText<"Use NMake/Jom format for the depfile">,
 MarshallingInfoFlag<"DependencyOutputOpts.OutputFormat", 
"DependencyOutputFormat::Make">,
@@ -753,7 +754,8 @@ def Wp_COMMA : CommaJoined<["-"], "Wp,">,
   MetaVarName<"">, Group;
 def Wundef_prefix_EQ : CommaJoined<["-"], "Wundef-prefix=">, 
Group,
   Flags<[CC1Option, CoreOption, HelpHidden]>, MetaVarName<"">,
-  HelpText<"Enable warnings for undefined macros with a prefix in the comma 
separated list ">;
+  HelpText<"Enable warnings for undefined macros with a prefix in the comma 
separated list ">,
+  MarshallingInfoStringVector<"DiagnosticOpts->UndefPrefixes">;
 def Wwrite_strings : Flag<["-"], "Wwrite-strings">, Group, 
Flags<[CC1Option, HelpHidden]>;
 def Wno_write_strings : Flag<["-"], "Wno-write-strings">, Group, 
Flags<[CC1Option, HelpHidden]>;
 def W_Joined : Joined<["-"], "W">, Group, Flags<[CC1Option, 
CoreOption]>,
@@ -1387,7 +1389,8 @@ def fno_sanitize_EQ : CommaJoined<["-"], 
"fno-sanitize=">, Group,
   Flags<[CoreOption, NoXarchOption]>;
 def fsanitize_blacklist : Joined<["-"], "fsanitize-blacklist=">,
   Group,
-  HelpText<"Path to blacklist file for sanitizers">;
+  HelpText<"Path to blacklist file for sanitizers">,
+  
MarshallingInfoStringVector<"LangOpts->SanitizerBlacklistFiles">;
 def fsanitize_system_blacklist : Joined<["-"], "fsanitize-system-blacklist=">,
   HelpText<"Path to system blacklist file for sanitizers">,
   Flags<[CC1Option]>;
@@ -1405,13 +1408,15 @@ def fno_sanitize_coverage
"Sanitizers">, 
Values<"func,bb,edge,indirect-calls,trace-bb,trace-cmp,trace-div,trace-gep,8bit-counters,trace-pc,trace-pc-guard,no-prune,inline-8bit-counters,inline-bool-flag">;
 def fsanitize_coverage_allowlist : Joined<["-"], 
"fsanitize-coverage-allowlist=">,
 Group, Flags<[CoreOption, NoXarchOption]>,
-HelpText<"Restrict sanitizer coverage instrumentation exclusively to 
modules and functions that match the provided special case list, except the 
blocked ones">;
+HelpText<"Restrict sanitizer coverage instrumentation exclusively to 
modules and functions that match the provided special case list, except the 
blocked ones">,
+MarshallingInfoStringVector<"CodeGenOpts.SanitizeCoverageAllowlistFiles">;
 def : Joined<["-"], "fsanitize-coverage-whitelist=">,
   Group, Flags<[CoreOption, HelpHidden]>, 
Alias,
   HelpText<"Deprecated, use -fsanitize-coverage-allowlist= instead">;
 def fsanitize_coverage_blocklist : Joined<["-"], 
"fsanitize-coverage-blocklist=">,
 Group, Flags<[CoreOption, NoXarchOption]>,
-HelpText<"Disable sanitizer coverage instrumentation for modules and 
functions that match the provided special case list, even the allowed ones">;
+HelpText<"Disable sanitizer coverage instrumentation for modules and 
functions that match the provided special case list, even the allowed ones">,
+MarshallingInfoStringVector<"CodeGenOpts.SanitizeCoverageBlocklistFiles">;
 def : Joined<["-"], "fsanitize-coverage-blacklist=">,
   Group, Flags<[CoreOption, HelpHidden]>, 
Alias,
   HelpText<"Deprecated, use -fsanitize-coverage-blocklist= instead">;
@@ -1616,7 +1621,8 @@ defm delete_null_pointer_checks : 
BoolFOption<"delete-null-pointer-checks",
 
 def frewrite_map_file : Separate<["-"], "frewrite-map-file">,
 Group,
-Flags<[ NoXarchOption, CC1Option ]>;
+Flags<[ NoXarchOption, CC1Option ]>,
+
M

[llvm-branch-commits] [clang] 33f90f3 - [clang][cli] Report the actual argument parsing result

2021-01-07 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-07T12:37:04+01:00
New Revision: 33f90f38e11c7c23d6e2a23ca526f8b0d8f53771

URL: 
https://github.com/llvm/llvm-project/commit/33f90f38e11c7c23d6e2a23ca526f8b0d8f53771
DIFF: 
https://github.com/llvm/llvm-project/commit/33f90f38e11c7c23d6e2a23ca526f8b0d8f53771.diff

LOG: [clang][cli] Report the actual argument parsing result

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D93700

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 49447f16637f..7fb7ec896e64 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -129,10 +129,9 @@ CompilerInvocationBase::~CompilerInvocationBase() = 
default;
 #include "clang/Driver/Options.inc"
 #undef SIMPLE_ENUM_VALUE_TABLE
 
-static llvm::Optional normalizeSimpleFlag(OptSpecifier Opt,
-unsigned TableIndex,
-const ArgList &Args,
-DiagnosticsEngine &Diags) {
+static llvm::Optional
+normalizeSimpleFlag(OptSpecifier Opt, unsigned TableIndex, const ArgList &Args,
+DiagnosticsEngine &Diags, bool &Success) {
   if (Args.hasArg(Opt))
 return true;
   return None;
@@ -140,7 +139,8 @@ static llvm::Optional 
normalizeSimpleFlag(OptSpecifier Opt,
 
 static Optional normalizeSimpleNegativeFlag(OptSpecifier Opt, unsigned,
   const ArgList &Args,
-  DiagnosticsEngine &) {
+  DiagnosticsEngine &,
+  bool &Success) {
   if (Args.hasArg(Opt))
 return false;
   return None;
@@ -166,7 +166,7 @@ template (), bool> = false>
 static auto makeFlagToValueNormalizer(T Value) {
   return [Value](OptSpecifier Opt, unsigned, const ArgList &Args,
- DiagnosticsEngine &) -> Optional {
+ DiagnosticsEngine &, bool &Success) -> Optional {
 if (Args.hasArg(Opt))
   return Value;
 return None;
@@ -182,8 +182,8 @@ static auto makeFlagToValueNormalizer(T Value) {
 static auto makeBooleanOptionNormalizer(bool Value, bool OtherValue,
 OptSpecifier OtherOpt) {
   return [Value, OtherValue, OtherOpt](OptSpecifier Opt, unsigned,
-   const ArgList &Args,
-   DiagnosticsEngine &) -> Optional {
+   const ArgList &Args, DiagnosticsEngine 
&,
+   bool &Success) -> Optional {
 if (const Arg *A = Args.getLastArg(Opt, OtherOpt)) {
   return A->getOption().matches(Opt) ? Value : OtherValue;
 }
@@ -246,10 +246,9 @@ findValueTableByValue(const SimpleEnumValueTable &Table, 
unsigned Value) {
   return None;
 }
 
-static llvm::Optional normalizeSimpleEnum(OptSpecifier Opt,
-unsigned TableIndex,
-const ArgList &Args,
-DiagnosticsEngine &Diags) {
+static llvm::Optional
+normalizeSimpleEnum(OptSpecifier Opt, unsigned TableIndex, const ArgList &Args,
+DiagnosticsEngine &Diags, bool &Success) {
   assert(TableIndex < SimpleEnumValueTablesSize);
   const SimpleEnumValueTable &Table = SimpleEnumValueTables[TableIndex];
 
@@ -261,6 +260,7 @@ static llvm::Optional 
normalizeSimpleEnum(OptSpecifier Opt,
   if (auto MaybeEnumVal = findValueTableByName(Table, ArgValue))
 return MaybeEnumVal->Value;
 
+  Success = false;
   Diags.Report(diag::err_drv_invalid_value)
   << Arg->getAsString(Args) << ArgValue;
   return None;
@@ -294,7 +294,8 @@ static void denormalizeSimpleEnum(SmallVectorImpl &Args,
 
 static Optional normalizeString(OptSpecifier Opt, int TableIndex,
  const ArgList &Args,
- DiagnosticsEngine &Diags) {
+ DiagnosticsEngine &Diags,
+ bool &Success) {
   auto *Arg = Args.getLastArg(Opt);
   if (!Arg)
 return None;
@@ -302,14 +303,15 @@ static Optional normalizeString(OptSpecifier 
Opt, int TableIndex,
 }
 
 template 
-static Optional normalizeStringIntegral(OptSpecifier Opt, int,
-   const ArgList &Args,
-   DiagnosticsEngine &Diags) {
+static Optional
+normalizeStringIntegral(OptSpecifier Opt, int, const ArgList

[llvm-branch-commits] [clang] e72cdc5 - [clang][cli] NFC: Ensure non-null DiagnosticsEngine in ParseDiagnosticArgs

2021-01-07 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-07T14:15:08+01:00
New Revision: e72cdc5ba1e65ecd8632663b6604eb9be8d1a162

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

LOG: [clang][cli] NFC: Ensure non-null DiagnosticsEngine in ParseDiagnosticArgs

Before this patch, ParseDiagnosticArgs can be called with a nullptr 
DiagnosticsEngine *. This happens early on in the compilation process, where no 
proper DiagnosticEngine exists, because the diagnostic options (passed through 
command line) are not known yet.

This patch ensures nullptr is replaced by an ignoring DiagnosticEngine in 
ParseDiagnosticArgs, which allows to switch from pointer to a reference in some 
utility functions.

Besides simplifying the code, this patch enables a future patch (D84673) that 
ports diagnostic options to the new marshalling infrastructure.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D93701

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 7fb7ec896e64..7f3e39ede281 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -830,7 +830,7 @@ GenerateOptimizationRemarkRegex(DiagnosticsEngine &Diags, 
ArgList &Args,
 
 static bool parseDiagnosticLevelMask(StringRef FlagName,
  const std::vector &Levels,
- DiagnosticsEngine *Diags,
+ DiagnosticsEngine &Diags,
  DiagnosticLevelMask &M) {
   bool Success = true;
   for (const auto &Level : Levels) {
@@ -843,8 +843,7 @@ static bool parseDiagnosticLevelMask(StringRef FlagName,
 .Default(DiagnosticLevelMask::None);
 if (PM == DiagnosticLevelMask::None) {
   Success = false;
-  if (Diags)
-Diags->Report(diag::err_drv_invalid_value) << FlagName << Level;
+  Diags.Report(diag::err_drv_invalid_value) << FlagName << Level;
 }
 M = M | PM;
   }
@@ -1383,7 +1382,7 @@ static bool parseShowColorsArgs(const ArgList &Args, bool 
DefaultColor) {
 }
 
 static bool checkVerifyPrefixes(const std::vector &VerifyPrefixes,
-DiagnosticsEngine *Diags) {
+DiagnosticsEngine &Diags) {
   bool Success = true;
   for (const auto &Prefix : VerifyPrefixes) {
 // Every prefix must start with a letter and contain only alphanumeric
@@ -1393,10 +1392,8 @@ static bool checkVerifyPrefixes(const 
std::vector &VerifyPrefixes,
 });
 if (BadChar != Prefix.end() || !isLetter(Prefix[0])) {
   Success = false;
-  if (Diags) {
-Diags->Report(diag::err_drv_invalid_value) << "-verify=" << Prefix;
-Diags->Report(diag::note_drv_verify_prefix_spelling);
-  }
+  Diags.Report(diag::err_drv_invalid_value) << "-verify=" << Prefix;
+  Diags.Report(diag::note_drv_verify_prefix_spelling);
 }
   }
   return Success;
@@ -1405,6 +1402,13 @@ static bool checkVerifyPrefixes(const 
std::vector &VerifyPrefixes,
 bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
 DiagnosticsEngine *Diags,
 bool DefaultDiagColor) {
+  Optional IgnoringDiags;
+  if (!Diags) {
+IgnoringDiags.emplace(new DiagnosticIDs(), new DiagnosticOptions(),
+  new IgnoringDiagConsumer());
+Diags = &*IgnoringDiags;
+  }
+
   bool Success = true;
 
   Opts.DiagnosticLogFile =
@@ -1439,10 +1443,9 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, 
ArgList &Args,
 Opts.setShowOverloads(Ovl_All);
   else {
 Success = false;
-if (Diags)
-  Diags->Report(diag::err_drv_invalid_value)
-  << Args.getLastArg(OPT_fshow_overloads_EQ)->getAsString(Args)
-  << ShowOverloads;
+Diags->Report(diag::err_drv_invalid_value)
+<< Args.getLastArg(OPT_fshow_overloads_EQ)->getAsString(Args)
+<< ShowOverloads;
   }
 
   StringRef ShowCategory =
@@ -1455,10 +1458,9 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, 
ArgList &Args,
 Opts.ShowCategories = 2;
   else {
 Success = false;
-if (Diags)
-  Diags->Report(diag::err_drv_invalid_value)
-  << Args.getLastArg(OPT_fdiagnostics_show_category)->getAsString(Args)
-  << ShowCategory;
+Diags->Report(diag::err_drv_invalid_value)
+<< Args.getLastArg(OPT_fdiagnostics_show_category)->getAsString(Args)
+<< ShowCategory;
   }
 
   StringRef Format =
@@ -1474,10 +1476,9 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, 
ArgList &Args,
 Opts.setFormat(DiagnosticOptions::Vi);
   else {
 Success = false;
-

[llvm-branch-commits] [clang] 75d6363 - [clang][cli] NFC: Move parseSimpleArgs

2021-01-07 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-07T14:15:08+01:00
New Revision: 75d63630ebb197c338801d6b100ae2e06800c4ce

URL: 
https://github.com/llvm/llvm-project/commit/75d63630ebb197c338801d6b100ae2e06800c4ce
DIFF: 
https://github.com/llvm/llvm-project/commit/75d63630ebb197c338801d6b100ae2e06800c4ce.diff

LOG: [clang][cli] NFC: Move parseSimpleArgs

This patch moves `parseSimpleArgs` closer to `ParseDiagnosticArgs` so that 
sharing the parsing macro between them can be done more locally in a future 
patch.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D94172

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 7f3e39ede281..8b641aabd1af 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1399,6 +1399,32 @@ static bool checkVerifyPrefixes(const 
std::vector &VerifyPrefixes,
   return Success;
 }
 
+bool CompilerInvocation::parseSimpleArgs(const ArgList &Args,
+ DiagnosticsEngine &Diags) {
+  bool Success = true;
+
+#define OPTION_WITH_MARSHALLING(   
\
+PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,
\
+HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH,   
\
+DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, 
\
+MERGER, EXTRACTOR, TABLE_INDEX)
\
+  if ((FLAGS)&options::CC1Option) {
\
+this->KEYPATH = MERGER(this->KEYPATH, DEFAULT_VALUE);  
\
+if (IMPLIED_CHECK) 
\
+  this->KEYPATH = MERGER(this->KEYPATH, IMPLIED_VALUE);
\
+if (SHOULD_PARSE)  
\
+  if (auto MaybeValue =
\
+  NORMALIZER(OPT_##ID, TABLE_INDEX, Args, Diags, Success)) 
\
+this->KEYPATH = MERGER(
\
+this->KEYPATH, static_castKEYPATH)>(*MaybeValue)); 
\
+  }
+
+#include "clang/Driver/Options.inc"
+#undef OPTION_WITH_MARSHALLING
+
+  return Success;
+}
+
 bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
 DiagnosticsEngine *Diags,
 bool DefaultDiagColor) {
@@ -2971,32 +2997,6 @@ static void ParseTargetArgs(TargetOptions &Opts, ArgList 
&Args,
   }
 }
 
-bool CompilerInvocation::parseSimpleArgs(const ArgList &Args,
- DiagnosticsEngine &Diags) {
-  bool Success = true;
-
-#define OPTION_WITH_MARSHALLING(   
\
-PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,
\
-HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH,   
\
-DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, 
\
-MERGER, EXTRACTOR, TABLE_INDEX)
\
-  if ((FLAGS)&options::CC1Option) {
\
-this->KEYPATH = MERGER(this->KEYPATH, DEFAULT_VALUE);  
\
-if (IMPLIED_CHECK) 
\
-  this->KEYPATH = MERGER(this->KEYPATH, IMPLIED_VALUE);
\
-if (SHOULD_PARSE)  
\
-  if (auto MaybeValue = \
-NORMALIZER(OPT_##ID, TABLE_INDEX, Args, Diags, Success))\
-this->KEYPATH = MERGER(
\
-this->KEYPATH, static_castKEYPATH)>(*MaybeValue)); 
\
-  }
-
-#include "clang/Driver/Options.inc"
-#undef OPTION_WITH_MARSHALLING
-
-  return Success;
-}
-
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
 ArrayRef CommandLineArgs,
 DiagnosticsEngine &Diags,



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] fcd1e35 - [clang][cli] NFC: Make parsing macro reusable

2021-01-07 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-07T14:25:48+01:00
New Revision: fcd1e35e4cc6887c3fb880126e60676458e60680

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

LOG: [clang][cli] NFC: Make parsing macro reusable

This is necessary for a future patch, where we start using this macro in 
another function.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D93702

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 8b641aabd1af..348f5582bde2 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1399,32 +1399,42 @@ static bool checkVerifyPrefixes(const 
std::vector &VerifyPrefixes,
   return Success;
 }
 
-bool CompilerInvocation::parseSimpleArgs(const ArgList &Args,
- DiagnosticsEngine &Diags) {
-  bool Success = true;
-
-#define OPTION_WITH_MARSHALLING(   
\
-PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,
\
-HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH,   
\
-DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, 
\
-MERGER, EXTRACTOR, TABLE_INDEX)
\
+#define PARSE_OPTION_WITH_MARSHALLING(ARGS, DIAGS, SUCCESS, ID, FLAGS, PARAM,  
\
+  SHOULD_PARSE, KEYPATH, DEFAULT_VALUE,
\
+  IMPLIED_CHECK, IMPLIED_VALUE,
\
+  NORMALIZER, MERGER, TABLE_INDEX) 
\
   if ((FLAGS)&options::CC1Option) {
\
 this->KEYPATH = MERGER(this->KEYPATH, DEFAULT_VALUE);  
\
 if (IMPLIED_CHECK) 
\
   this->KEYPATH = MERGER(this->KEYPATH, IMPLIED_VALUE);
\
 if (SHOULD_PARSE)  
\
   if (auto MaybeValue =
\
-  NORMALIZER(OPT_##ID, TABLE_INDEX, Args, Diags, Success)) 
\
+  NORMALIZER(OPT_##ID, TABLE_INDEX, ARGS, DIAGS, SUCCESS)) 
\
 this->KEYPATH = MERGER(
\
 this->KEYPATH, static_castKEYPATH)>(*MaybeValue)); 
\
   }
 
+bool CompilerInvocation::parseSimpleArgs(const ArgList &Args,
+ DiagnosticsEngine &Diags) {
+  bool Success = true;
+
+#define OPTION_WITH_MARSHALLING(   
\
+PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,
\
+HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH,   
\
+DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, 
\
+MERGER, EXTRACTOR, TABLE_INDEX)
\
+  PARSE_OPTION_WITH_MARSHALLING(Args, Diags, Success, ID, FLAGS, PARAM,
\
+SHOULD_PARSE, KEYPATH, DEFAULT_VALUE,  
\
+IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER,  
\
+MERGER, TABLE_INDEX)
 #include "clang/Driver/Options.inc"
 #undef OPTION_WITH_MARSHALLING
 
   return Success;
 }
 
+#undef PARSE_OPTION_WITH_MARSHALLING
+
 bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
 DiagnosticsEngine *Diags,
 bool DefaultDiagColor) {



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 8e3230f - [clang][cli] Port DiagnosticOpts to new option parsing system

2021-01-08 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-08T10:44:22+01:00
New Revision: 8e3230ffa3ad2994c3bbddffc3e53b3bccb2ee41

URL: 
https://github.com/llvm/llvm-project/commit/8e3230ffa3ad2994c3bbddffc3e53b3bccb2ee41
DIFF: 
https://github.com/llvm/llvm-project/commit/8e3230ffa3ad2994c3bbddffc3e53b3bccb2ee41.diff

LOG: [clang][cli] Port DiagnosticOpts to new option parsing system

This patch introduces additional infrastructure necessary to accommodate 
DiagnosticOptions.

DiagnosticOptions are unique in that they are parsed by the same function in 
cc1 AND in the Clang driver. The call to the parsing function from the driver 
occurs early on in the compilation process, where no proper DiagnosticEngine 
exists, because the diagnostic options (passed through command line) are not 
known yet.

To preserve the current behavior, we need to be able to selectively parse:
* all options (for -cc1),
* only diagnostic options (for driver).

This patch achieves that in the following way:
* new MacroPrefix field is added to the Option TableGen class,
* new IsDiag TableGen mixin sets MacroPrefix to "DIAG_",
* TableGen backend serializes option records into a macro with the prefix,
* CompilerInvocation parse/generate methods define the 
[DIAG_]OPTION_WITH_MARSHALLING macros to handle diagnostic options separately.

Depends on D93700, D93701 & D93702.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D84673

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticOptions.h
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/unittests/Frontend/CompilerInvocationTest.cpp
llvm/include/llvm/Option/OptParser.td
llvm/utils/TableGen/OptParserEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticOptions.h 
b/clang/include/clang/Basic/DiagnosticOptions.h
index 7fbe534c5994..17533b38ff5f 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.h
+++ b/clang/include/clang/Basic/DiagnosticOptions.h
@@ -15,7 +15,14 @@
 #include 
 #include 
 
+namespace llvm {
+namespace opt {
+class ArgList;
+} // namespace opt
+} // namespace llvm
+
 namespace clang {
+class DiagnosticsEngine;
 
 /// Specifies which overload candidates to display when overload
 /// resolution fails.
@@ -61,6 +68,11 @@ raw_ostream& operator<<(raw_ostream& Out, 
DiagnosticLevelMask M);
 
 /// Options for controlling the compiler diagnostics engine.
 class DiagnosticOptions : public RefCountedBase{
+  friend bool ParseDiagnosticArgs(DiagnosticOptions &, llvm::opt::ArgList &,
+  clang::DiagnosticsEngine *, bool);
+
+  friend class CompilerInvocation;
+
 public:
   enum TextDiagnosticFormat { Clang, MSVC, Vi };
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6585fd1ceb01..3cefcc2c6654 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -241,6 +241,8 @@ def mno_mpx : Flag<["-"], "mno-mpx">, 
Group;
 def clang_ignored_gcc_optimization_f_Group : OptionGroup<
   "">, Group, 
Flags<[Ignored]>;
 
+class IsDiag { string MacroPrefix = "DIAG_"; }
+
 // A boolean option which is opt-in in CC1. The positive option exists in CC1 
and
 // Args.hasArg(OPT_ffoo) is used to check that the flag is enabled.
 // This is useful if the option is usually disabled.
@@ -755,7 +757,7 @@ def Wp_COMMA : CommaJoined<["-"], "Wp,">,
 def Wundef_prefix_EQ : CommaJoined<["-"], "Wundef-prefix=">, 
Group,
   Flags<[CC1Option, CoreOption, HelpHidden]>, MetaVarName<"">,
   HelpText<"Enable warnings for undefined macros with a prefix in the comma 
separated list ">,
-  MarshallingInfoStringVector<"DiagnosticOpts->UndefPrefixes">;
+  MarshallingInfoStringVector<"UndefPrefixes">, IsDiag;
 def Wwrite_strings : Flag<["-"], "Wwrite-strings">, Group, 
Flags<[CC1Option, HelpHidden]>;
 def Wno_write_strings : Flag<["-"], "Wno-write-strings">, Group, 
Flags<[CC1Option, HelpHidden]>;
 def W_Joined : Joined<["-"], "W">, Group, Flags<[CC1Option, 
CoreOption]>,
@@ -1188,7 +1190,9 @@ defm borland_extensions : 
BoolFOption<"borland-extensions",
 def fbuiltin : Flag<["-"], "fbuiltin">, Group, Flags<[CoreOption]>;
 def fbuiltin_module_map : Flag <["-"], "fbuiltin-module-map">, Group,
   Flags<[NoXarchOption]>, HelpText<"Load the clang builtins module map file.">;
-defm caret_diagnostics : OptOutFFlag<"caret-diagnostics", "", "">;
+defm caret_diagnostics : BoolFOption<"caret-diagnostics",
+  "ShowCarets", DefaultsToTrue,
+  ChangedBy, ResetBy>, IsDiag;
 def fclang_abi_compat_EQ : Joined<["-"], "fclang-abi-compat=">, 
Group,
   Flags<[CC1Option]>, MetaVarName<"">, 
Values<".,latest">,
   HelpText<"Attempt to match the ABI of Clang ">;
@@ -1200,7 +1204,7 @@ def fdiagnostics_color : Flag<["-"], 
"fdiagnostics-color">, Group,
 def fdiagnostics_color_EQ : Joined<["-"], "fdiagnostics-color=">, 
Group;
 def fansi_escape_codes : F

[llvm-branch-commits] [clang] 8e3e148 - Revert "[clang][cli] Port DiagnosticOpts to new option parsing system"

2021-01-08 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-08T10:53:12+01:00
New Revision: 8e3e148c888e1d9d2b11721112a54a62e33a635a

URL: 
https://github.com/llvm/llvm-project/commit/8e3e148c888e1d9d2b11721112a54a62e33a635a
DIFF: 
https://github.com/llvm/llvm-project/commit/8e3e148c888e1d9d2b11721112a54a62e33a635a.diff

LOG: Revert "[clang][cli] Port DiagnosticOpts to new option parsing system"

This reverts commit 8e3230ff

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticOptions.h
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/unittests/Frontend/CompilerInvocationTest.cpp
llvm/include/llvm/Option/OptParser.td
llvm/utils/TableGen/OptParserEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticOptions.h 
b/clang/include/clang/Basic/DiagnosticOptions.h
index 17533b38ff5f..7fbe534c5994 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.h
+++ b/clang/include/clang/Basic/DiagnosticOptions.h
@@ -15,14 +15,7 @@
 #include 
 #include 
 
-namespace llvm {
-namespace opt {
-class ArgList;
-} // namespace opt
-} // namespace llvm
-
 namespace clang {
-class DiagnosticsEngine;
 
 /// Specifies which overload candidates to display when overload
 /// resolution fails.
@@ -68,11 +61,6 @@ raw_ostream& operator<<(raw_ostream& Out, 
DiagnosticLevelMask M);
 
 /// Options for controlling the compiler diagnostics engine.
 class DiagnosticOptions : public RefCountedBase{
-  friend bool ParseDiagnosticArgs(DiagnosticOptions &, llvm::opt::ArgList &,
-  clang::DiagnosticsEngine *, bool);
-
-  friend class CompilerInvocation;
-
 public:
   enum TextDiagnosticFormat { Clang, MSVC, Vi };
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3cefcc2c6654..6585fd1ceb01 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -241,8 +241,6 @@ def mno_mpx : Flag<["-"], "mno-mpx">, 
Group;
 def clang_ignored_gcc_optimization_f_Group : OptionGroup<
   "">, Group, 
Flags<[Ignored]>;
 
-class IsDiag { string MacroPrefix = "DIAG_"; }
-
 // A boolean option which is opt-in in CC1. The positive option exists in CC1 
and
 // Args.hasArg(OPT_ffoo) is used to check that the flag is enabled.
 // This is useful if the option is usually disabled.
@@ -757,7 +755,7 @@ def Wp_COMMA : CommaJoined<["-"], "Wp,">,
 def Wundef_prefix_EQ : CommaJoined<["-"], "Wundef-prefix=">, 
Group,
   Flags<[CC1Option, CoreOption, HelpHidden]>, MetaVarName<"">,
   HelpText<"Enable warnings for undefined macros with a prefix in the comma 
separated list ">,
-  MarshallingInfoStringVector<"UndefPrefixes">, IsDiag;
+  MarshallingInfoStringVector<"DiagnosticOpts->UndefPrefixes">;
 def Wwrite_strings : Flag<["-"], "Wwrite-strings">, Group, 
Flags<[CC1Option, HelpHidden]>;
 def Wno_write_strings : Flag<["-"], "Wno-write-strings">, Group, 
Flags<[CC1Option, HelpHidden]>;
 def W_Joined : Joined<["-"], "W">, Group, Flags<[CC1Option, 
CoreOption]>,
@@ -1190,9 +1188,7 @@ defm borland_extensions : 
BoolFOption<"borland-extensions",
 def fbuiltin : Flag<["-"], "fbuiltin">, Group, Flags<[CoreOption]>;
 def fbuiltin_module_map : Flag <["-"], "fbuiltin-module-map">, Group,
   Flags<[NoXarchOption]>, HelpText<"Load the clang builtins module map file.">;
-defm caret_diagnostics : BoolFOption<"caret-diagnostics",
-  "ShowCarets", DefaultsToTrue,
-  ChangedBy, ResetBy>, IsDiag;
+defm caret_diagnostics : OptOutFFlag<"caret-diagnostics", "", "">;
 def fclang_abi_compat_EQ : Joined<["-"], "fclang-abi-compat=">, 
Group,
   Flags<[CC1Option]>, MetaVarName<"">, 
Values<".,latest">,
   HelpText<"Attempt to match the ABI of Clang ">;
@@ -1204,7 +1200,7 @@ def fdiagnostics_color : Flag<["-"], 
"fdiagnostics-color">, Group,
 def fdiagnostics_color_EQ : Joined<["-"], "fdiagnostics-color=">, 
Group;
 def fansi_escape_codes : Flag<["-"], "fansi-escape-codes">, Group,
   Flags<[CoreOption, CC1Option]>, HelpText<"Use ANSI escape codes for 
diagnostics">,
-  MarshallingInfoFlag<"UseANSIEscapeCodes">, IsDiag;
+  MarshallingInfoFlag<"DiagnosticOpts->UseANSIEscapeCodes">;
 def fcomment_block_commands : CommaJoined<["-"], "fcomment-block-commands=">, 
Group, Flags<[CC1Option]>,
   HelpText<"Treat each comma separated argument in  as a documentation 
comment block command">,
   MetaVarName<"">, 
MarshallingInfoStringVector<"LangOpts->CommentOpts.BlockCommandNames">;
@@ -1257,16 +1253,11 @@ def fdebug_pass_structure : Flag<["-"], 
"fdebug-pass-structure">, Group
 def fdepfile_entry : Joined<["-"], "fdepfile-entry=">,
 Group, Flags<[CC1Option]>;
 def fdiagnostics_fixit_info : Flag<["-"], "fdiagnostics-fixit-info">, 
Group;
-def fno_diagnostics_fixit_info : Flag<["-"], "fno-diagnostics-fixit-info">, 
Group,
-  Flags<[CC1Option]>, HelpText<"Do not include fixit information in 
diagnostics">,
-  MarshallingInfoNegativeFlag<"ShowFixits

[llvm-branch-commits] [llvm] 9710064 - Reapply "[clang][cli] Port DiagnosticOpts to new option parsing system"

2021-01-11 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-11T10:05:53+01:00
New Revision: 97100646d1b4526de1eac3aacdb0b098739c6ec9

URL: 
https://github.com/llvm/llvm-project/commit/97100646d1b4526de1eac3aacdb0b098739c6ec9
DIFF: 
https://github.com/llvm/llvm-project/commit/97100646d1b4526de1eac3aacdb0b098739c6ec9.diff

LOG: Reapply "[clang][cli] Port DiagnosticOpts to new option parsing system"

This reverts commit 8e3e148c

This commit fixes two issues with the original patch:
* The sanitizer build bot reported an uninitialized value. This was caused by 
normalizeStringIntegral not returning None on failure.
* Some build bots complained about inaccessible keypaths. To mitigate that, 
"this->" was added back to the keypath to restore the previous behavior.

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticOptions.h
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/unittests/Frontend/CompilerInvocationTest.cpp
llvm/include/llvm/Option/OptParser.td
llvm/utils/TableGen/OptParserEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticOptions.h 
b/clang/include/clang/Basic/DiagnosticOptions.h
index 7fbe534c5994..17533b38ff5f 100644
--- a/clang/include/clang/Basic/DiagnosticOptions.h
+++ b/clang/include/clang/Basic/DiagnosticOptions.h
@@ -15,7 +15,14 @@
 #include 
 #include 
 
+namespace llvm {
+namespace opt {
+class ArgList;
+} // namespace opt
+} // namespace llvm
+
 namespace clang {
+class DiagnosticsEngine;
 
 /// Specifies which overload candidates to display when overload
 /// resolution fails.
@@ -61,6 +68,11 @@ raw_ostream& operator<<(raw_ostream& Out, 
DiagnosticLevelMask M);
 
 /// Options for controlling the compiler diagnostics engine.
 class DiagnosticOptions : public RefCountedBase{
+  friend bool ParseDiagnosticArgs(DiagnosticOptions &, llvm::opt::ArgList &,
+  clang::DiagnosticsEngine *, bool);
+
+  friend class CompilerInvocation;
+
 public:
   enum TextDiagnosticFormat { Clang, MSVC, Vi };
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 741c28aa1f01..b18c89931cee 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -241,6 +241,8 @@ def mno_mpx : Flag<["-"], "mno-mpx">, 
Group;
 def clang_ignored_gcc_optimization_f_Group : OptionGroup<
   "">, Group, 
Flags<[Ignored]>;
 
+class IsDiag { string MacroPrefix = "DIAG_"; }
+
 // A boolean option which is opt-in in CC1. The positive option exists in CC1 
and
 // Args.hasArg(OPT_ffoo) is used to check that the flag is enabled.
 // This is useful if the option is usually disabled.
@@ -755,7 +757,7 @@ def Wp_COMMA : CommaJoined<["-"], "Wp,">,
 def Wundef_prefix_EQ : CommaJoined<["-"], "Wundef-prefix=">, 
Group,
   Flags<[CC1Option, CoreOption, HelpHidden]>, MetaVarName<"">,
   HelpText<"Enable warnings for undefined macros with a prefix in the comma 
separated list ">,
-  MarshallingInfoStringVector<"DiagnosticOpts->UndefPrefixes">;
+  MarshallingInfoStringVector<"UndefPrefixes">, IsDiag;
 def Wwrite_strings : Flag<["-"], "Wwrite-strings">, Group, 
Flags<[CC1Option, HelpHidden]>;
 def Wno_write_strings : Flag<["-"], "Wno-write-strings">, Group, 
Flags<[CC1Option, HelpHidden]>;
 def W_Joined : Joined<["-"], "W">, Group, Flags<[CC1Option, 
CoreOption]>,
@@ -1188,7 +1190,9 @@ defm borland_extensions : 
BoolFOption<"borland-extensions",
 def fbuiltin : Flag<["-"], "fbuiltin">, Group, Flags<[CoreOption]>;
 def fbuiltin_module_map : Flag <["-"], "fbuiltin-module-map">, Group,
   Flags<[NoXarchOption]>, HelpText<"Load the clang builtins module map file.">;
-defm caret_diagnostics : OptOutFFlag<"caret-diagnostics", "", "">;
+defm caret_diagnostics : BoolFOption<"caret-diagnostics",
+  "ShowCarets", DefaultsToTrue,
+  ChangedBy, ResetBy>, IsDiag;
 def fclang_abi_compat_EQ : Joined<["-"], "fclang-abi-compat=">, 
Group,
   Flags<[CC1Option]>, MetaVarName<"">, 
Values<".,latest">,
   HelpText<"Attempt to match the ABI of Clang ">;
@@ -1200,7 +1204,7 @@ def fdiagnostics_color : Flag<["-"], 
"fdiagnostics-color">, Group,
 def fdiagnostics_color_EQ : Joined<["-"], "fdiagnostics-color=">, 
Group;
 def fansi_escape_codes : Flag<["-"], "fansi-escape-codes">, Group,
   Flags<[CoreOption, CC1Option]>, HelpText<"Use ANSI escape codes for 
diagnostics">,
-  MarshallingInfoFlag<"DiagnosticOpts->UseANSIEscapeCodes">;
+  MarshallingInfoFlag<"UseANSIEscapeCodes">, IsDiag;
 def fcomment_block_commands : CommaJoined<["-"], "fcomment-block-commands=">, 
Group, Flags<[CC1Option]>,
   HelpText<"Treat each comma separated argument in  as a documentation 
comment block command">,
   MetaVarName<"">, 
MarshallingInfoStringVector<"LangOpts->CommentOpts.BlockCommandNames">;
@@ -1253,11 +1257,16 @@ def fdebug_pass_structure : Flag<["-"], 
"fdebug-pass-structure">, Group
 def fdepfile_entry : Joined<["-"], "fd

[llvm-branch-commits] [clang] 7ab8030 - [clang][cli] Remove -f[no-]trapping-math from -cc1 command line

2021-01-12 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2021-01-12T10:00:23+01:00
New Revision: 7ab803095ae58445996dc4694acb216e3a32ee64

URL: 
https://github.com/llvm/llvm-project/commit/7ab803095ae58445996dc4694acb216e3a32ee64
DIFF: 
https://github.com/llvm/llvm-project/commit/7ab803095ae58445996dc4694acb216e3a32ee64.diff

LOG: [clang][cli] Remove -f[no-]trapping-math from -cc1 command line

This patch removes the -f[no-]trapping-math flags from the -cc1 command line. 
These flags are ignored in the command line parser and their semantics is fully 
handled by -ffp-exception-mode.

This patch does not remove -f[no-]trapping-math from the driver command line. 
The driver flags are being used and do affect compilation.

Reviewed By: dexonsmith, SjoerdMeijer

Differential Revision: https://reviews.llvm.org/D93395

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/fpconstrained.c
clang/test/CodeGen/fpconstrained.cpp
clang/test/CodeGen/noexceptionsfpmath.c
clang/test/CodeGenCUDA/propagate-metadata.cu
clang/test/Driver/fast-math.c
clang/test/Driver/fp-model.c
clang/test/Parser/fp-floatcontrol-syntax.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b18c89931cee..35643701f97e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1600,8 +1600,8 @@ def frounding_math : Flag<["-"], "frounding-math">, 
Group, Flags<[CC1Op
   MarshallingInfoFlag<"LangOpts->FPRoundingMode", 
"llvm::RoundingMode::NearestTiesToEven">,
   Normalizer<"makeFlagToValueNormalizer(llvm::RoundingMode::Dynamic)">;
 def fno_rounding_math : Flag<["-"], "fno-rounding-math">, Group, 
Flags<[CC1Option]>;
-def ftrapping_math : Flag<["-"], "ftrapping-math">, Group, 
Flags<[CC1Option]>;
-def fno_trapping_math : Flag<["-"], "fno-trapping-math">, Group, 
Flags<[CC1Option]>;
+def ftrapping_math : Flag<["-"], "ftrapping-math">, Group;
+def fno_trapping_math : Flag<["-"], "fno-trapping-math">, Group;
 def ffp_contract : Joined<["-"], "ffp-contract=">, Group,
   Flags<[CC1Option]>, HelpText<"Form fused FP ops (e.g. FMAs):"
   " fast (fuses across statements disregarding pragmas)"

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index be4fe7f8eddd..4a20936ddda1 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2833,9 +2833,7 @@ static void RenderFloatingPointOptions(const ToolChain 
&TC, const Driver &D,
   if (TrappingMath) {
 // FP Exception Behavior is also set to strict
 assert(FPExceptionBehavior.equals("strict"));
-CmdArgs.push_back("-ftrapping-math");
-  } else if (TrappingMathPresent)
-CmdArgs.push_back("-fno-trapping-math");
+  }
 
   // The default is IEEE.
   if (DenormalFPMath != llvm::DenormalMode::getIEEE()) {

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 07906f4a36ef..cc3b038a7746 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2684,14 +2684,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, InputKind IK,
   Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val;
   }
 
-  if (Args.hasArg(OPT_ftrapping_math)) {
-Opts.setFPExceptionMode(LangOptions::FPE_Strict);
-  }
-
-  if (Args.hasArg(OPT_fno_trapping_math)) {
-Opts.setFPExceptionMode(LangOptions::FPE_Ignore);
-  }
-
   LangOptions::FPExceptionModeKind FPEB = LangOptions::FPE_Ignore;
   if (Arg *A = Args.getLastArg(OPT_ffp_exception_behavior_EQ)) {
 StringRef Val = A->getValue();

diff  --git a/clang/test/CodeGen/fpconstrained.c 
b/clang/test/CodeGen/fpconstrained.c
index 0307ebbd357f..643c0120eac5 100644
--- a/clang/test/CodeGen/fpconstrained.c
+++ b/clang/test/CodeGen/fpconstrained.c
@@ -1,11 +1,11 @@
-// RUN: %clang_cc1 -ftrapping-math -frounding-math 
-ffp-exception-behavior=strict -fexperimental-strict-floating-point -emit-llvm 
-o - %s | FileCheck %s -check-prefix=FPMODELSTRICT
+// RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=strict 
-fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s 
-check-prefix=FPMODELSTRICT
 // RUN: %clang_cc1 -ffp-contract=fast -emit-llvm -o - %s | FileCheck %s 
-check-prefix=PRECISE
 // RUN: %clang_cc1 -ffast-math -ffp-contract=fast -emit-llvm -o - %s | 
FileCheck %s -check-prefix=FAST
 // RUN: %clang_cc1 -ffast-math -emit-llvm -o - %s | FileCheck %s 
-check-prefix=FASTNOCONTRACT
 // RUN: %clang_cc1 -ffast-math -ffp-contract=fast 
-ffp-exception-behavior=ignore -emit-llvm -o - %s | FileCheck %s 
-check-prefix=FAST
 // RUN: %clang_cc1 -ffast-math -ffp-contract=fast 
-ffp-exception-behavior=strict -fexperimental-strict-floating-point -emit-llvm 

[llvm-branch-commits] [clang] 844e372 - [clang][deps] Always generate module paths

2022-08-10 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2022-08-10T11:55:17-07:00
New Revision: 844e3728fff59f00f9b4d6552acbcc0de41b6dd0

URL: 
https://github.com/llvm/llvm-project/commit/844e3728fff59f00f9b4d6552acbcc0de41b6dd0
DIFF: 
https://github.com/llvm/llvm-project/commit/844e3728fff59f00f9b4d6552acbcc0de41b6dd0.diff

LOG: [clang][deps] Always generate module paths

Since D129389 (and downstream PR 
https://github.com/apple/llvm-project/pull/4965), the dependency scanner is 
responsible for generating full command-lines, including the modules paths. 
This patch removes the flag that was making this an opt-in behavior in 
clang-scan-deps.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D131420

Added: 


Modified: 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/test/ClangScanDeps/diagnostics.c
clang/test/ClangScanDeps/generate-modules-path-args.c
clang/test/ClangScanDeps/modulemap-via-vfs.m
clang/test/ClangScanDeps/modules-context-hash-module-map-path.c
clang/test/ClangScanDeps/modules-context-hash-outputs.c
clang/test/ClangScanDeps/modules-context-hash.c
clang/test/ClangScanDeps/modules-disable-free.c
clang/test/ClangScanDeps/modules-file-path-isolation.c
clang/test/ClangScanDeps/modules-fmodule-name-no-module-built.m
clang/test/ClangScanDeps/modules-full.cpp
clang/test/ClangScanDeps/modules-inferred-explicit-build.m
clang/test/ClangScanDeps/modules-inferred.m
clang/test/ClangScanDeps/modules-no-undeclared-includes.c
clang/test/ClangScanDeps/modules-pch-common-submodule.c
clang/test/ClangScanDeps/modules-pch-common-via-submodule.c
clang/test/ClangScanDeps/modules-pch-dangling.c
clang/test/ClangScanDeps/modules-pch.c
clang/test/ClangScanDeps/modules-symlink.c
clang/test/ClangScanDeps/removed-args.c
clang/test/ClangScanDeps/submodule-order.c
clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 




diff  --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
index 0a092a433a22c..77263cd6233b8 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
@@ -53,9 +53,6 @@ struct FullDependencies {
   std::vector getCommandLine(
   llvm::function_ref
   LookupModuleOutput) const;
-
-  /// Get the full command line, excluding -fmodule-file=" arguments.
-  std::vector getCommandLineWithoutModulePaths() const;
 };
 
 struct FullDependenciesResult {

diff  --git 
a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h 
b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index f4f13a34b1746..18c342ee85c11 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -138,10 +138,6 @@ struct ModuleDeps {
   std::vector getCanonicalCommandLine(
   llvm::function_ref
   LookupModuleOutput) const;
-
-  /// Gets the canonical command line suitable for passing to clang, excluding
-  /// "-fmodule-file=" and "-o" arguments.
-  std::vector getCanonicalCommandLineWithoutModulePaths() const;
 };
 
 class ModuleDepCollector;

diff  --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
index 411fd9676ffdb..03ad6dcc51b30 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
@@ -16,24 +16,15 @@ using namespace dependencies;
 std::vector FullDependencies::getCommandLine(
 llvm::function_ref
 LookupModuleOutput) const {
-  std::vector Ret = getCommandLineWithoutModulePaths();
-
-  for (ModuleID MID : ClangModuleDeps) {
-auto PCM = LookupModuleOutput(MID, ModuleOutputKind::ModuleFile);
-Ret.push_back("-fmodule-file=" + PCM);
-  }
-
-  return Ret;
-}
-
-std::vector
-FullDependencies::getCommandLineWithoutModulePaths() const {
   std::vector Args = OriginalCommandLine;
 
   Args.push_back("-fno-implicit-modules");
   Args.push_back("-fno-implicit-module-maps");
   for (const PrebuiltModuleDep &PMD : PrebuiltModuleDeps)
 Args.push_back("-fmodule-file=" + PMD.PCMFile);
+  for (ModuleID MID : ClangModuleDeps)
+Args.push_back("-fmodule-file=" +
+   LookupModuleOutput(MID, ModuleOutputKind::ModuleFile));
 
   // These arguments are unused in explicit compiles.
   llvm::erase_if(Args, [](StringRef Arg) {

diff  --git a/clang/lib/Tooling/DependencyScanning/ModuleDe

[llvm-branch-commits] [clang] f24e58d - [clang][cli] Create accessors for exception models in LangOptions

2020-12-15 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-15T10:15:58+01:00
New Revision: f24e58df7ddf2dc9f13c8f8fc259f0374f04aca3

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

LOG: [clang][cli] Create accessors for exception models in LangOptions

This abstracts away the members that are being replaced in a follow-up patch.

Depends on D83979.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D93214

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.h
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/CodeGen/CGException.cpp
clang/lib/Frontend/InitPreprocessor.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 203c45fdd9a7..d4791650ec6b 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -380,6 +380,11 @@ class LangOptions : public LangOptionsBase {
   bool isSignReturnAddressScopeAll() const {
 return getSignReturnAddressScope() == SignReturnAddressScopeKind::All;
   }
+
+  bool hasSjLjExceptions() const { return SjLjExceptions; }
+  bool hasSEHExceptions() const { return SEHExceptions; }
+  bool hasDWARFExceptions() const { return DWARFExceptions; }
+  bool hasWasmExceptions() const { return WasmExceptions; }
 };
 
 /// Floating point control options

diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 554688ac987b..2dbf30ef171f 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -497,13 +497,13 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
   // Set EABI version.
   Options.EABIVersion = TargetOpts.EABIVersion;
 
-  if (LangOpts.SjLjExceptions)
+  if (LangOpts.hasSjLjExceptions())
 Options.ExceptionModel = llvm::ExceptionHandling::SjLj;
-  if (LangOpts.SEHExceptions)
+  if (LangOpts.hasSEHExceptions())
 Options.ExceptionModel = llvm::ExceptionHandling::WinEH;
-  if (LangOpts.DWARFExceptions)
+  if (LangOpts.hasDWARFExceptions())
 Options.ExceptionModel = llvm::ExceptionHandling::DwarfCFI;
-  if (LangOpts.WasmExceptions)
+  if (LangOpts.hasWasmExceptions())
 Options.ExceptionModel = llvm::ExceptionHandling::Wasm;
 
   Options.NoInfsFPMath = LangOpts.NoHonorInfs;

diff  --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 85604cf5e611..f8a486909e41 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -121,11 +121,11 @@ static const EHPersonality &getCPersonality(const 
TargetInfo &Target,
   const llvm::Triple &T = Target.getTriple();
   if (T.isWindowsMSVCEnvironment())
 return EHPersonality::MSVC_CxxFrameHandler3;
-  if (L.SjLjExceptions)
+  if (L.hasSjLjExceptions())
 return EHPersonality::GNU_C_SJLJ;
-  if (L.DWARFExceptions)
+  if (L.hasDWARFExceptions())
 return EHPersonality::GNU_C;
-  if (L.SEHExceptions)
+  if (L.hasSEHExceptions())
 return EHPersonality::GNU_C_SEH;
   return EHPersonality::GNU_C;
 }
@@ -149,9 +149,9 @@ static const EHPersonality &getObjCPersonality(const 
TargetInfo &Target,
 LLVM_FALLTHROUGH;
   case ObjCRuntime::GCC:
   case ObjCRuntime::ObjFW:
-if (L.SjLjExceptions)
+if (L.hasSjLjExceptions())
   return EHPersonality::GNU_ObjC_SJLJ;
-if (L.SEHExceptions)
+if (L.hasSEHExceptions())
   return EHPersonality::GNU_ObjC_SEH;
 return EHPersonality::GNU_ObjC;
   }
@@ -165,13 +165,13 @@ static const EHPersonality &getCXXPersonality(const 
TargetInfo &Target,
 return EHPersonality::MSVC_CxxFrameHandler3;
   if (T.isOSAIX())
 return EHPersonality::XL_CPlusPlus;
-  if (L.SjLjExceptions)
+  if (L.hasSjLjExceptions())
 return EHPersonality::GNU_CPlusPlus_SJLJ;
-  if (L.DWARFExceptions)
+  if (L.hasDWARFExceptions())
 return EHPersonality::GNU_CPlusPlus;
-  if (L.SEHExceptions)
+  if (L.hasSEHExceptions())
 return EHPersonality::GNU_CPlusPlus_SEH;
-  if (L.WasmExceptions)
+  if (L.hasWasmExceptions())
 return EHPersonality::GNU_Wasm_CPlusPlus;
   return EHPersonality::GNU_CPlusPlus;
 }
@@ -476,7 +476,7 @@ void CodeGenFunction::EmitStartEHSpec(const Decl *D) {
 // In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
 // case of throw with types, we ignore it and print a warning for now.
 // TODO Correctly handle exception specification in wasm
-if (CGM.getLangOpts().WasmExceptions) {
+if (CGM.getLangOpts().hasWasmExceptions()) {
   if (EST == EST_DynamicNone)
 EHStack.pushTerminate();
   else
@@ -564,7 +564,7 @@ void CodeGenFunction::EmitEndEHSpec(const Decl *D) {
 // In wasm we currently treat 'throw()' in the same way as 'noexcept'. In
 // case of throw with types, we ignore it and print a warning for now.
 // TO

[llvm-branch-commits] [clang] 573255b - [clang][cli] Squash exception model in LangOptions into one member

2020-12-15 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-15T10:15:58+01:00
New Revision: 573255b47eb9b210e74a1c620fee363dfaa52794

URL: 
https://github.com/llvm/llvm-project/commit/573255b47eb9b210e74a1c620fee363dfaa52794
DIFF: 
https://github.com/llvm/llvm-project/commit/573255b47eb9b210e74a1c620fee363dfaa52794.diff

LOG: [clang][cli] Squash exception model in LangOptions into one member

This squashes multiple members in LangOptions into one. This is leveraged in a 
follow-up patch that implements marshalling of related command-line options.

Depends on D93214.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D93215

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/LangOptions.h
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 19fb4ae82b89..251fd68f4df8 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -129,10 +129,8 @@ LANGOPT(ZVector   , 1, 0, "System z vector 
extensions")
 LANGOPT(Exceptions, 1, 0, "exception handling")
 LANGOPT(ObjCExceptions, 1, 0, "Objective-C exceptions")
 LANGOPT(CXXExceptions , 1, 0, "C++ exceptions")
-LANGOPT(DWARFExceptions   , 1, 0, "dwarf exception handling")
-LANGOPT(SjLjExceptions, 1, 0, "setjmp-longjump exception handling")
-LANGOPT(SEHExceptions , 1, 0, "SEH .xdata exception handling")
-LANGOPT(WasmExceptions, 1, 0, "WebAssembly exception handling")
+ENUM_LANGOPT(ExceptionHandling, ExceptionHandlingKind, 3,
+ ExceptionHandlingKind::None, "exception handling")
 LANGOPT(IgnoreExceptions  , 1, 0, "ignore exceptions")
 LANGOPT(ExternCNoUnwind   , 1, 0, "Assume extern C functions don't unwind")
 LANGOPT(TraditionalCPP, 1, 0, "traditional CPP emulation")

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index d4791650ec6b..2780e4bf35fd 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -22,6 +22,7 @@
 #include "llvm/ADT/FloatingPointMode.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
+#include "llvm/MC/MCTargetOptions.h"
 #include 
 #include 
 
@@ -209,6 +210,9 @@ class LangOptions : public LangOptionsBase {
 FPE_Strict
   };
 
+  /// Possible exception handling behavior.
+  using ExceptionHandlingKind = llvm::ExceptionHandling;
+
   enum class LaxVectorConversionKind {
 /// Permit no implicit vector bitcasts.
 None,
@@ -381,10 +385,21 @@ class LangOptions : public LangOptionsBase {
 return getSignReturnAddressScope() == SignReturnAddressScopeKind::All;
   }
 
-  bool hasSjLjExceptions() const { return SjLjExceptions; }
-  bool hasSEHExceptions() const { return SEHExceptions; }
-  bool hasDWARFExceptions() const { return DWARFExceptions; }
-  bool hasWasmExceptions() const { return WasmExceptions; }
+  bool hasSjLjExceptions() const {
+return getExceptionHandling() == llvm::ExceptionHandling::SjLj;
+  }
+
+  bool hasSEHExceptions() const {
+return getExceptionHandling() == llvm::ExceptionHandling::WinEH;
+  }
+
+  bool hasDWARFExceptions() const {
+return getExceptionHandling() == llvm::ExceptionHandling::DwarfCFI;
+  }
+
+  bool hasWasmExceptions() const {
+return getExceptionHandling() == llvm::ExceptionHandling::Wasm;
+  }
 };
 
 /// Floating point control options

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index c1d5364d72ea..e4058cfc1915 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2981,10 +2981,14 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, InputKind IK,
   Diags.Report(diag::err_fe_invalid_exception_model)
   << Opt.getName() << T.str();
 
-Opts.SjLjExceptions = Opt.matches(options::OPT_fsjlj_exceptions);
-Opts.SEHExceptions = Opt.matches(options::OPT_fseh_exceptions);
-Opts.DWARFExceptions = Opt.matches(options::OPT_fdwarf_exceptions);
-Opts.WasmExceptions = Opt.matches(options::OPT_fwasm_exceptions);
+if (Opt.matches(options::OPT_fsjlj_exceptions))
+  Opts.setExceptionHandling(llvm::ExceptionHandling::SjLj);
+else if (Opt.matches(options::OPT_fseh_exceptions))
+  Opts.setExceptionHandling(llvm::ExceptionHandling::WinEH);
+else if (Opt.matches(options::OPT_fdwarf_exceptions))
+  Opts.setExceptionHandling(llvm::ExceptionHandling::DwarfCFI);
+else if (Opt.matches(options::OPT_fwasm_exceptions))
+  Opts.setExceptionHandling(llvm::ExceptionHandling::Wasm);
   }
 
   Opts.ExternCNoUnwind = Args.hasArg(OPT_fexternc_nounwind);



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.or

[llvm-branch-commits] [clang] 56c5548 - [clang][cli] Squash multiple cc1 -fxxx-exceptions flags into single -exception-model=xxx option

2020-12-15 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-15T10:15:58+01:00
New Revision: 56c5548d7f07f5853a2e40562db08dc2e56ece03

URL: 
https://github.com/llvm/llvm-project/commit/56c5548d7f07f5853a2e40562db08dc2e56ece03
DIFF: 
https://github.com/llvm/llvm-project/commit/56c5548d7f07f5853a2e40562db08dc2e56ece03.diff

LOG: [clang][cli] Squash multiple cc1 -fxxx-exceptions flags into single 
-exception-model=xxx option

This patch enables marshalling of the exception model options while enforcing 
their mutual exclusivity. The clang driver interface remains the same, this 
only affects the cc1 command line.

Depends on D93215.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D93216

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/exceptions.c
clang/test/CodeGen/personality.c
clang/test/CodeGenCXX/mingw-w64-exceptions.c
clang/test/CodeGenCXX/mingw-w64-seh-exceptions.cpp
clang/test/CodeGenCXX/personality.cpp
clang/test/CodeGenCXX/wasm-eh.cpp
clang/test/CodeGenObjC/personality.m
clang/test/CodeGenObjCXX/objfw-exceptions.mm
clang/test/CodeGenObjCXX/personality.mm
clang/test/Driver/arch-armv7k.c
clang/test/Driver/freebsd.c
clang/test/Driver/fsjlj-exceptions.c
clang/test/Driver/ve-toolchain.c
clang/test/Driver/ve-toolchain.cpp
clang/test/Driver/windows-exceptions.cpp
clang/test/Frontend/windows-exceptions.cpp
clang/test/Preprocessor/init-arm.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 0f1b68bd0e7d..def189f65994 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -111,7 +111,7 @@ def err_fe_invalid_alignment : Error<
 def err_fe_invalid_wchar_type
 : Error<"invalid wchar_t type '%0'; must be one of 'char', 'short', 
'int'">;
 def err_fe_invalid_exception_model
-   : Error<"invalid exception model '%0' for target '%1'">;
+   : Error<"invalid exception model 
'%select{none|dwarf|sjlj|arm|seh|wasm|aix}0' for target '%1'">;
 def warn_fe_concepts_ts_flag : Warning<
   "-fconcepts-ts is deprecated - use '-std=c++20' for Concepts support">,
   InGroup;

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 2780e4bf35fd..be2c7a004e0b 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -31,6 +31,8 @@ namespace clang {
 /// Bitfields of LangOptions, split out from LangOptions in order to ensure 
that
 /// this large collection of bitfields is a trivial class type.
 class LangOptionsBase {
+  friend class CompilerInvocation;
+
 public:
   // Define simple language options (with no accessors).
 #define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 67d41c3711f5..f3aa6750b794 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1265,13 +1265,22 @@ def fencoding_EQ : Joined<["-"], "fencoding=">, 
Group;
 def ferror_limit_EQ : Joined<["-"], "ferror-limit=">, Group, 
Flags<[CoreOption]>;
 defm exceptions : OptInFFlag<"exceptions", "Enable", "Disable", " support for 
exception handling">;
 def fdwarf_exceptions : Flag<["-"], "fdwarf-exceptions">, Group,
-  Flags<[CC1Option]>, HelpText<"Use DWARF style exceptions">;
+  HelpText<"Use DWARF style exceptions">;
 def fsjlj_exceptions : Flag<["-"], "fsjlj-exceptions">, Group,
-  Flags<[CC1Option]>, HelpText<"Use SjLj style exceptions">;
+  HelpText<"Use SjLj style exceptions">;
 def fseh_exceptions : Flag<["-"], "fseh-exceptions">, Group,
-  Flags<[CC1Option]>, HelpText<"Use SEH style exceptions">;
+  HelpText<"Use SEH style exceptions">;
 def fwasm_exceptions : Flag<["-"], "fwasm-exceptions">, Group,
-  Flags<[CC1Option]>, HelpText<"Use WebAssembly style exceptions">;
+  HelpText<"Use WebAssembly style exceptions">;
+def exception_model : Separate<["-"], "exception-model">,
+  Flags<[CC1Option, NoDriverOption]>, HelpText<"The exception model: 
dwarf|sjlj|seh|wasm">,
+  Values<"dwarf,sjlj,seh,wasm">,
+  NormalizedValuesScope<"llvm::ExceptionHandling">,
+  NormalizedValues<["DwarfCFI", "SjLj", "WinEH", "Wasm"]>,
+  MarshallingInfoString<"LangOpts->ExceptionHandling", "None">,
+  AutoNormalizeEnum;
+def exception_model_EQ : Joined<["-"], "exception-model=">,
+  Flags<[CC1Option, NoDriverOption]>, Alias;
 def fignore_exceptions : Flag<["-"], "fignore-exceptions">, Group, 
Flags<[CC1Option]>,
   HelpText<"Enable support for ignoring exception handling constructs">;
 def fexcess_pr

[llvm-branch-commits] [clang] 95114f2 - [clang][cli] Do not marshall only CC1Option flags in BoolOption

2020-12-16 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-16T09:29:40+01:00
New Revision: 95114f21f5bf1704672dadb45ca7c25efca72e03

URL: 
https://github.com/llvm/llvm-project/commit/95114f21f5bf1704672dadb45ca7c25efca72e03
DIFF: 
https://github.com/llvm/llvm-project/commit/95114f21f5bf1704672dadb45ca7c25efca72e03.diff

LOG: [clang][cli] Do not marshall only CC1Option flags in BoolOption

We cannot be sure whether a flag is CC1Option inside the definition of 
`BoolOption`. Take the example below:

```
let Flags = [CC1Option] in {
  defm xxx : BoolOption<...>;
}
```

where TableGen applies `Flags = [CC1Option]` to the `xxx` and `no_xxx` records 
**after** they have been is fully declared by `BoolOption`.

For the refactored `-f[no-]debug-pass-manager` flags (see the diff), this means 
`BoolOption` never adds any marshalling info, as it doesn't see either of the 
flags as `CC1Option`.

For that reason, we should defensively append the marshalling information to 
both flags inside `BoolOption`. Now the check for `CC1Option` needs to happen 
later, in the parsing macro, when all TableGen logic has been resolved.

However, for some flags defined through `BoolOption`, we can run into issues:

```
// Options.td
def fenable_xxx : /* ... */;

// Both flags are CC1Option, the first is implied.
defm xxx : BoolOption<"xxx,
  "Opts.Xxx", DefaultsToFalse,
  ChangedBy,
  ResetBy>;
```

When parsing `clang -cc1 -fenable-xxx`:
* we run parsing for `PosFlag`:
  * set `Opts.Xxx` to default `false`,
  * discover `PosFlag` is implied by `-fenable-xxx`: set `Opts.Xxx` to `true`,
  * don't see `-fxxx` on command line: do nothing,
* we run parsing for `NegFlag`:
  * set `Opts.Xxx` to default `false`,
  * discover `NegFlag` cannot be implied: do nothing,
  * don't see `-fno-xxx` on command line: do nothing.

Now we ended up with `Opts.Xxx` set to `false` instead of `true`. For this 
reason, we need to ensure to append the same `ImpliedByAnyOf` instance to both 
flags.

This means both parsing runs now behave identically (they set the same default 
value, run the same "implied by" check, and call `makeBooleanOptionNormalizer` 
that already has information on both flags, so it returns the same value in 
both calls).

The solution works well, but what might be confusing is this: you have defined 
a flag **A** that is not `CC1Option`, but can be implied by another flag **B** 
that is `CC1Option`:
* if **A** is defined manually, it will never get implied, as the code never 
runs
```
def no_signed_zeros : Flag<["-"], "fno-signed-zeros">, Group, 
Flags<[]>,
  MarshallingInfoFlag<"LangOpts->NoSignedZero">, 
ImpliedByAnyOf<[menable_unsafe_fp_math]>;
```
* if **A** is defined by `BoolOption`, it could get implied, as the code is run 
by its `CC1Option` counterpart:
```
defm signed_zeros : BoolOption<"signed-zeros",
  "LangOpts->NoSignedZero", DefaultsToFalse,
  ChangedBy,
  ResetBy, "f">, Group;
```

This is a surprising inconsistency.

One solution might be to somehow propagate the final `Flags` of the implied 
flag in `ImpliedByAnyOf` and check whether it has `CC1Option` in the parsing 
macro. However, I think it doesn't make sense to spend time thinking about a 
corner case that won't come up in real code.

An observation: it is unfortunate that the marshalling information is a part of 
the flag definition. If we represented it in a separate structure, we could 
avoid the "double parsing" problem by having a single source of truth. This 
would require a lot of additional work though.

Note: the original patch missed the `CC1Option` check in the parsing macro, 
making my reasoning here incomplete. Moreover, it contained a change to 
denormalization that wasn't necessarily related to these changes, so I've 
extracted that to a follow-up patch: D93094.

Reviewed By: dexonsmith, Bigcheese

Differential Revision: https://reviews.llvm.org/D93008

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f3aa6750b794..0da6a43b6986 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -325,10 +325,6 @@ class FlagDefExpanded
   string Spelling
 = prefix#!cond(flag.Polarity.Value : "", true : "no-")#spelling;
 
-  // Does the flag have CC1Option?
-  bit IsCC1 = !not(!empty(!filter(opt_flag, flag.OptionFlags,
-  !eq(opt_flag, CC1Option;
-
   // Can the flag be implied by another flag?
   bit CanBeImplied = !not(!empty(flag.ImpliedBy));
 
@@ -336,18 +332,14 @@ class FlagDefExpanded
   code ValueAsCode = !cond(flag.Value : "true", true: "false");
 }
 
-// Creates simple flag record.
-class BoolOptionFlag
-  : Flag<["-"], flag.Spelling>, Flags, HelpText {}
-
-// Creates marshalled flag rec

[llvm-branch-commits] [llvm] f2661be - [clang][cli] Prevent double denormalization

2020-12-16 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-16T09:44:54+01:00
New Revision: f2661bed185e14a8f5aa9a54565a8b938a7a10aa

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

LOG: [clang][cli] Prevent double denormalization

If both flags created through BoolOption are CC1Option and the keypath has a 
non-default or non-implied value, the denormalizer gets called twice. If the 
denormalizer has the ability to generate both flags, we can end up generating 
the same flag twice.

Reviewed By: dexonsmith, Bigcheese

Differential Revision: https://reviews.llvm.org/D93094

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 0da6a43b6986..a2208f2e2c5c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -338,7 +338,7 @@ class BoolOptionFlag, Flags, HelpText,
 MarshallingInfoBooleanFlag,
+   other.RecordName>,
 ImpliedByAnyOf {}
 
 // Generates TableGen records for two command line flags that control the same

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 1a863a739156..bdadaa9a0b5c 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -197,12 +197,11 @@ static auto makeBooleanOptionNormalizer(bool Value, bool 
OtherValue,
   };
 }
 
-static auto makeBooleanOptionDenormalizer(bool Value,
-  const char *OtherSpelling) {
-  return [Value, OtherSpelling](
- SmallVectorImpl &Args, const char *Spelling,
- CompilerInvocation::StringAllocator, unsigned, bool KeyPath) {
-Args.push_back(KeyPath == Value ? Spelling : OtherSpelling);
+static auto makeBooleanOptionDenormalizer(bool Value) {
+  return [Value](SmallVectorImpl &Args, const char *Spelling,
+ CompilerInvocation::StringAllocator, unsigned, bool KeyPath) {
+if (KeyPath == Value)
+  Args.push_back(Spelling);
   };
 }
 

diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 156e3393acd6..51b7ba8c147f 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -269,7 +269,7 @@ TEST_F(CommandLineTest, BoolOptionCC1ViaLetPresentPos) {
 
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
-  ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fdebug-pass-manager")));
+  ASSERT_EQ(count(GeneratedArgs, StringRef("-fdebug-pass-manager")), 1);
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fno-debug-pass-manager";
 }
 

diff  --git a/llvm/include/llvm/Option/OptParser.td 
b/llvm/include/llvm/Option/OptParser.td
index 9e0ff1450920..d35a3e5fec7f 100644
--- a/llvm/include/llvm/Option/OptParser.td
+++ b/llvm/include/llvm/Option/OptParser.td
@@ -176,10 +176,10 @@ class MarshallingInfoBitfieldFlag
 
 // Marshalling info for booleans. Applied to the flag setting keypath to false.
 class MarshallingInfoBooleanFlag
+ code other_value, code other_name>
   : MarshallingInfoFlag {
   code Normalizer = "makeBooleanOptionNormalizer("#value#", "#other_value#", 
OPT_"#other_name#")";
-  code Denormalizer = "makeBooleanOptionDenormalizer("#value#", 
\""#other_spelling#"\")";
+  code Denormalizer = "makeBooleanOptionDenormalizer("#value#")";
 }
 
 // Mixins for additional marshalling attributes.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 741978d - [clang][cli] Port CodeGen option flags to new option parsing system

2020-12-16 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-16T10:00:33+01:00
New Revision: 741978d727a445fa279d5952a86ea634adb7dc52

URL: 
https://github.com/llvm/llvm-project/commit/741978d727a445fa279d5952a86ea634adb7dc52
DIFF: 
https://github.com/llvm/llvm-project/commit/741978d727a445fa279d5952a86ea634adb7dc52.diff

LOG: [clang][cli] Port CodeGen option flags to new option parsing system

Depends on D83697.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D83892

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a2208f2e2c5c2..65c3ad1a3943d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1053,7 +1053,8 @@ def fprofile_sample_accurate : Flag<["-"], 
"fprofile-sample-accurate">,
 DocBrief<[{Specifies that the sample profile is accurate. If the sample
profile is accurate, callsites without profile samples are 
marked
as cold. Otherwise, treat callsites without profile samples as 
if
-   we have no profile}]>;
+   we have no profile}]>,
+   MarshallingInfoFlag<"CodeGenOpts.ProfileSampleAccurate">;
 def fno_profile_sample_accurate : Flag<["-"], "fno-profile-sample-accurate">,
   Group, Flags<[NoXarchOption]>;
 def fauto_profile : Flag<["-"], "fauto-profile">, Group,
@@ -1072,8 +1073,10 @@ def fdebug_compilation_dir : Separate<["-"], 
"fdebug-compilation-dir">,
 def fdebug_compilation_dir_EQ : Joined<["-"], "fdebug-compilation-dir=">,
 Group, Flags<[CC1Option, CC1AsOption, CoreOption]>,
 Alias;
-defm debug_info_for_profiling : OptInFFlag<"debug-info-for-profiling",
-  "Emit extra debug info to make sample profile more accurate">;
+defm debug_info_for_profiling : BoolFOption<"debug-info-for-profiling",
+  "CodeGenOpts.DebugInfoForProfiling", DefaultsToFalse,
+  ChangedBy,
+  ResetBy>;
 def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
 Group, Flags<[CoreOption]>,
 HelpText<"Generate instrumented code to collect execution counts into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;
@@ -1090,9 +1093,10 @@ def fprofile_remapping_file_EQ : Joined<["-"], 
"fprofile-remapping-file=">,
 HelpText<"Use the remappings described in  to match the profile data 
against names in the program">;
 def fprofile_remapping_file : Separate<["-"], "fprofile-remapping-file">,
 Group, Flags<[CoreOption]>, Alias;
-defm coverage_mapping : OptInFFlag<"coverage-mapping",
-  "Generate coverage mapping to enable code coverage analysis", "Disable code 
coverage analysis", "",
-  [CoreOption]>;
+defm coverage_mapping : BoolFOption<"coverage-mapping",
+  "CodeGenOpts.CoverageMapping", DefaultsToFalse,
+  ChangedBy,
+  ResetBy, 
BothFlags<[CoreOption]>>;
 def fprofile_generate : Flag<["-"], "fprofile-generate">,
 Group, Flags<[CoreOption]>,
 HelpText<"Generate instrumented code to collect execution counts into 
default.profraw (overridden by LLVM_PROFILE_FILE env var)">;
@@ -1129,18 +1133,20 @@ def fprofile_exclude_files_EQ : Joined<["-"], 
"fprofile-exclude-files=">,
 HelpText<"Instrument only functions from files where names don't match all 
the regexes separated by a semi-colon">;
 def fprofile_update_EQ : Joined<["-"], "fprofile-update=">,
 Group, Flags<[CC1Option, CoreOption]>, 
Values<"atomic,prefer-atomic,single">,
-MetaVarName<"">, HelpText<"Set update method of profile counters 
(atomic,prefer-atomic,single)">;
-def fpseudo_probe_for_profiling : Flag<["-"], "fpseudo-probe-for-profiling">,
-Group, Flags<[NoXarchOption, CC1Option]>,
-HelpText<"Emit pseudo probes for sample profiler">;
-def fno_pseudo_probe_for_profiling : Flag<["-"], 
"fno-pseudo-probe-for-profiling">,
-Group, Flags<[NoXarchOption, CC1Option]>,
-HelpText<"Do not emit pseudo probes for sample profiler.">;
+MetaVarName<"">, HelpText<"Set update method of profile counters 
(atomic,prefer-atomic,single)">,
+MarshallingInfoFlag<"CodeGenOpts.AtomicProfileUpdate">;
+defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
+  "CodeGenOpts.PseudoProbeForProfiling", DefaultsToFalse,
+  ChangedBy, ResetBy,
+  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiler">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Flags<[CC1Option, CoreOption]>,
 HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;
 
-defm addrsig : OptInFFlag<"addrsig", "Emit", "Don't emit", " an 
address-significance table", [CoreOption]>;
+defm addrsig : BoolFOption<"addrsig",
+  "CodeGenOpts.Addrsig", DefaultsToFalse,
+  ChangedBy, Re

[llvm-branch-commits] [clang] 383778e - [clang][cli] Port LangOpts option flags to new option parsing system

2020-12-16 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-16T10:16:27+01:00
New Revision: 383778e2171b4993f555433745466e211e713548

URL: 
https://github.com/llvm/llvm-project/commit/383778e2171b4993f555433745466e211e713548
DIFF: 
https://github.com/llvm/llvm-project/commit/383778e2171b4993f555433745466e211e713548.diff

LOG: [clang][cli] Port LangOpts option flags to new option parsing system

Depends on D83892 & D83694 & D93104.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D83979

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 65c3ad1a3943..76deb9de708b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -908,8 +908,10 @@ def fcuda_flush_denormals_to_zero : Flag<["-"], 
"fcuda-flush-denormals-to-zero">
 def fno_cuda_flush_denormals_to_zero : Flag<["-"], 
"fno-cuda-flush-denormals-to-zero">;
 defm cuda_approx_transcendentals : OptInFFlag<"cuda-approx-transcendentals", 
"Use", "Don't use",
   " approximate transcendental functions">;
-defm gpu_rdc : OptInFFlag<"gpu-rdc",
-  "Generate relocatable device code, also known as separate compilation mode", 
"", "">;
+defm gpu_rdc : BoolFOption<"gpu-rdc",
+  "LangOpts->GPURelocatableDeviceCode", DefaultsToFalse,
+  ChangedBy,
+  ResetBy>;
 def : Flag<["-"], "fcuda-rdc">, Alias;
 def : Flag<["-"], "fno-cuda-rdc">, Alias;
 defm cuda_short_ptr : OptInFFlag<"cuda-short-ptr",
@@ -926,16 +928,21 @@ def hip_version_EQ : Joined<["--"], "hip-version=">,
   HelpText<"HIP version in the format of major.minor.patch">;
 def fhip_dump_offload_linker_script : Flag<["-"], 
"fhip-dump-offload-linker-script">,
   Group, Flags<[NoArgumentUnused, HelpHidden]>;
-defm hip_new_launch_api : OptInFFlag<"hip-new-launch-api",
-  "Use", "Don't use", " new kernel launching API for HIP">;
+defm hip_new_launch_api : BoolFOption<"hip-new-launch-api",
+  "LangOpts->HIPUseNewLaunchAPI", DefaultsToFalse,
+  ChangedBy, ResetBy,
+  BothFlags<[], " new kernel launching API for HIP">>;
 defm gpu_allow_device_init : OptInFFlag<"gpu-allow-device-init",
   "Allow", "Don't allow", " device side init function in HIP">;
-defm gpu_defer_diag : OptInFFlag<"gpu-defer-diag",
-  "Defer", "Don't defer", " host/device related diagnostic messages"
-  " for CUDA/HIP">;
-defm gpu_exclude_wrong_side_overloads : 
OptInFFlag<"gpu-exclude-wrong-side-overloads",
-  "Always exclude wrong side overloads", "Exclude wrong side overloads only if 
there are same side overloads",
-  " in overloading resolution for CUDA/HIP", [HelpHidden]>;
+defm gpu_defer_diag : BoolFOption<"gpu-defer-diag",
+  "LangOpts->GPUDeferDiag", DefaultsToFalse,
+  ChangedBy, ResetBy,
+  BothFlags<[], " host/device related diagnostic messages for CUDA/HIP">>;
+defm gpu_exclude_wrong_side_overloads : 
BoolFOption<"gpu-exclude-wrong-side-overloads",
+  "LangOpts->GPUExcludeWrongSideOverloads", DefaultsToFalse,
+  ChangedBy,
+  ResetBy,
+  BothFlags<[HelpHidden], " in overloading resolution for CUDA/HIP">>;
 def gpu_max_threads_per_block_EQ : Joined<["--"], 
"gpu-max-threads-per-block=">,
   Flags<[CC1Option]>,
   HelpText<"Default max threads per block for kernel launch bounds for HIP">;
@@ -989,16 +996,25 @@ def fPIC : Flag<["-"], "fPIC">, Group;
 def fno_PIC : Flag<["-"], "fno-PIC">, Group;
 def fPIE : Flag<["-"], "fPIE">, Group;
 def fno_PIE : Flag<["-"], "fno-PIE">, Group;
-defm access_control : OptOutFFlag<"access-control", "", "Disable C++ access 
control">;
+defm access_control : BoolFOption<"access-control",
+  "LangOpts->AccessControl", DefaultsToTrue,
+  ChangedBy,
+  ResetBy>;
 def falign_functions : Flag<["-"], "falign-functions">, Group;
 def falign_functions_EQ : Joined<["-"], "falign-functions=">, Group;
 def fno_align_functions: Flag<["-"], "fno-align-functions">, Group;
-defm allow_editor_placeholders : OptInFFlag<"allow-editor-placeholders", 
"Treat editor placeholders as valid source code">;
+defm allow_editor_placeholders : BoolFOption<"allow-editor-placeholders",
+  "LangOpts->AllowEditorPlaceholders", DefaultsToFalse,
+  ChangedBy,
+  ResetBy>;
 def fallow_unsupported : Flag<["-"], "fallow-unsupported">, Group;
 def fapple_kext : Flag<["-"], "fapple-kext">, Group, 
Flags<[CC1Option]>,
-  HelpText<"Use Apple's kernel extensions ABI">;
-def fapple_pragma_pack : Flag<["-"], "fapple-pragma-pack">, Group, 
Flags<[CC1Option]>,
-  HelpText<"Enable Apple gcc-compatible #pragma pack handling">;
+  HelpText<"Use Apple's kernel extensions ABI">,
+  MarshallingInfoFlag<"LangOpts->AppleKext">;
+defm apple_pragma_pack : BoolFOption<"apple-pragma-pack",
+  "LangOpts->ApplePragmaPack", DefaultsToFalse,
+  ChangedBy,
+  ResetBy>;
 def shared_libsan : Flag<["-"], "shared-libsan">,
   HelpText<"Dynamically link the sanitizer runtime">;
 def stati

[llvm-branch-commits] [clang] 0da240c - [clang][cli] Port DependencyOutput string based options to new option parsing system

2020-12-16 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-16T10:28:37+01:00
New Revision: 0da240c2d050303c99564f1901b0d1548ffe2323

URL: 
https://github.com/llvm/llvm-project/commit/0da240c2d050303c99564f1901b0d1548ffe2323
DIFF: 
https://github.com/llvm/llvm-project/commit/0da240c2d050303c99564f1901b0d1548ffe2323.diff

LOG: [clang][cli] Port DependencyOutput string based options to new option 
parsing system

Depends on D84186

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D84187

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 76deb9de708b..dd23d810e388 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -960,11 +960,14 @@ def dM : Flag<["-"], "dM">, Group, 
Flags<[CC1Option]>,
   HelpText<"Print macro definitions in -E mode instead of normal output">;
 def dead__strip : Flag<["-"], "dead_strip">;
 def dependency_file : Separate<["-"], "dependency-file">, Flags<[CC1Option]>,
-  HelpText<"Filename (or -) to write dependency output to">;
+  HelpText<"Filename (or -) to write dependency output to">,
+  MarshallingInfoString<"DependencyOutputOpts.OutputFile">;
 def dependency_dot : Separate<["-"], "dependency-dot">, Flags<[CC1Option]>,
-  HelpText<"Filename to write DOT-formatted header dependencies to">;
+  HelpText<"Filename to write DOT-formatted header dependencies to">,
+  MarshallingInfoString<"DependencyOutputOpts.DOTOutputFile">;
 def module_dependency_dir : Separate<["-"], "module-dependency-dir">,
-  Flags<[CC1Option]>, HelpText<"Directory to dump module dependencies to">;
+  Flags<[CC1Option]>, HelpText<"Directory to dump module dependencies to">,
+  MarshallingInfoString<"DependencyOutputOpts.ModuleDependencyOutputDir">;
 def dsym_dir : JoinedOrSeparate<["-"], "dsym-dir">,
   Flags<[NoXarchOption, RenderAsInput]>,
   HelpText<"Directory to output dSYM's (if any) to">, MetaVarName<"">;
@@ -4514,7 +4517,8 @@ def module_file_deps : Flag<["-"], "module-file-deps">,
   HelpText<"Include module files in dependency output">,
   MarshallingInfoFlag<"DependencyOutputOpts.IncludeModuleFiles">;
 def header_include_file : Separate<["-"], "header-include-file">,
-  HelpText<"Filename (or -) to write header include output to">;
+  HelpText<"Filename (or -) to write header include output to">,
+  MarshallingInfoString<"DependencyOutputOpts.HeaderIncludeOutputFile">;
 def show_includes : Flag<["--"], "show-includes">,
   HelpText<"Print cl.exe style /showIncludes to stdout">;
 

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 2d6cb3bb878f..5fbafa3b2583 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1447,10 +1447,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, 
ArgList &Args, InputKind IK,
 
 static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts,
   ArgList &Args) {
-  Opts.OutputFile = std::string(Args.getLastArgValue(OPT_dependency_file));
   Opts.Targets = Args.getAllArgValues(OPT_MT);
-  Opts.HeaderIncludeOutputFile =
-  std::string(Args.getLastArgValue(OPT_header_include_file));
   if (Args.hasArg(OPT_show_includes)) {
 // Writing both /showIncludes and preprocessor output to stdout
 // would produce interleaved output, so use stderr for /showIncludes.
@@ -1462,9 +1459,6 @@ static void 
ParseDependencyOutputArgs(DependencyOutputOptions &Opts,
   } else {
 Opts.ShowIncludesDest = ShowIncludesDestination::None;
   }
-  Opts.DOTOutputFile = std::string(Args.getLastArgValue(OPT_dependency_dot));
-  Opts.ModuleDependencyOutputDir =
-  std::string(Args.getLastArgValue(OPT_module_dependency_dir));
   // Add sanitizer blacklists as extra dependencies.
   // They won't be discovered by the regular preprocessor, so
   // we let make / ninja to know about this implicit dependency.



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] caeb565 - [clang][cli] Convert Analyzer option string based options to new option parsing system

2020-12-18 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-18T08:56:06+01:00
New Revision: caeb56503ec897c7244cff0657c11e87d2644f82

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

LOG: [clang][cli] Convert Analyzer option string based options to new option 
parsing system

Depends on D84185

Reviewed By: dexonsmith

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D84186

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
clang/lib/Frontend/CompilerInvocation.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 ca9615e2e769..9987143009d3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4110,7 +4110,8 @@ def analyzer_display_progress : Flag<["-"], 
"analyzer-display-progress">,
   HelpText<"Emit verbose output about the analyzer's progress">,
   MarshallingInfoFlag<"AnalyzerOpts->AnalyzerDisplayProgress">;
 def analyze_function : Separate<["-"], "analyze-function">,
-  HelpText<"Run analysis on specific function (for C++ include parameters in 
name)">;
+  HelpText<"Run analysis on specific function (for C++ include parameters in 
name)">,
+  MarshallingInfoString<"AnalyzerOpts->AnalyzeSpecificFunction">;
 def analyze_function_EQ : Joined<["-"], "analyze-function=">, 
Alias;
 def trim_egraph : Flag<["-"], "trim-egraph">,
   HelpText<"Only show error-related paths in the analysis graph">,
@@ -4124,7 +4125,9 @@ def analyzer_dump_egraph : Separate<["-"], 
"analyzer-dump-egraph">,
 def analyzer_dump_egraph_EQ : Joined<["-"], "analyzer-dump-egraph=">, 
Alias;
 
 def analyzer_inline_max_stack_depth : Separate<["-"], 
"analyzer-inline-max-stack-depth">,
-  HelpText<"Bound on stack depth while inlining (4 by default)">;
+  HelpText<"Bound on stack depth while inlining (4 by default)">,
+  // Cap the stack depth at 4 calls (5 stack frames, base + 4 calls).
+  MarshallingInfoStringInt<"AnalyzerOpts->InlineMaxStackDepth", "5">;
 def analyzer_inline_max_stack_depth_EQ : Joined<["-"], 
"analyzer-inline-max-stack-depth=">,
   Alias;
 
@@ -4137,7 +4140,8 @@ def analyzer_disable_retry_exhausted : Flag<["-"], 
"analyzer-disable-retry-exhau
   MarshallingInfoFlag<"AnalyzerOpts->NoRetryExhausted">;
 
 def analyzer_max_loop : Separate<["-"], "analyzer-max-loop">,
-  HelpText<"The maximum number of times the analyzer will go through a loop">;
+  HelpText<"The maximum number of times the analyzer will go through a loop">,
+  MarshallingInfoStringInt<"AnalyzerOpts->maxBlockVisitOnPath", "4">;
 def analyzer_stats : Flag<["-"], "analyzer-stats">,
   HelpText<"Print internal analyzer statistics.">,
   MarshallingInfoFlag<"AnalyzerOpts->PrintStats">;

diff  --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h 
b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
index e1093772e02c..ccf35e0a81ec 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -259,8 +259,7 @@ class AnalyzerOptions : public 
RefCountedBase {
   bool AnalyzerWerror : 1;
 
   /// The inlining stack depth limit.
-  // Cap the stack depth at 4 calls (5 stack frames, base + 4 calls).
-  unsigned InlineMaxStackDepth = 5;
+  unsigned InlineMaxStackDepth;
 
   /// The mode of function selection used during inlining.
   AnalysisInliningMode InliningMode = NoRedundancy;

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 5fbafa3b2583..d2b590f08507 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -93,6 +93,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -282,12 +283,38 @@ static Optional normalizeString(OptSpecifier 
Opt, int TableIndex,
 
 static void denormalizeString(SmallVectorImpl &Args,
   const char *Spelling,
-  CompilerInvocation::StringAllocator SA,
-  unsigned TableIndex, const std::string &Value) {
+  CompilerInvocation::StringAllocator SA, unsigned,
+  Twine Value) {
   Args.push_back(Spelling);
   Args.push_back(SA(Value));
 }
 
+template ::value &&
+   std::is_constructible::value,
+   bool> = false>
+static void denormalizeString(SmallVectorImpl &Args,
+  const char *Spelling,
+  CompilerInvocation::StringAllocator SA,
+  unsigned TableIndex, T Value) {
+  denormalizeString(Args, S

[llvm-branch-commits] [clang] f4511ae - [clang][cli] Port HeaderSearch simple string options to new option parsing system

2020-12-18 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-18T09:30:32+01:00
New Revision: f4511aec2bf482f2ae5bbd14138a229b72c41c80

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

LOG: [clang][cli] Port HeaderSearch simple string options to new option parsing 
system

Depends on D84669

Reviewed By: Bigcheese

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D84670

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 9987143009d3..7275e84d7c53 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1797,7 +1797,8 @@ def fmodules_cache_path : Joined<["-"], 
"fmodules-cache-path=">, Group,
   HelpText<"Specify the module cache path">;
 def fmodules_user_build_path : Separate<["-"], "fmodules-user-build-path">, 
Group,
   Flags<[NoXarchOption, CC1Option]>, MetaVarName<"">,
-  HelpText<"Specify the module user build path">;
+  HelpText<"Specify the module user build path">,
+  MarshallingInfoString<"HeaderSearchOpts->ModuleUserBuildPath">;
 def fprebuilt_module_path : Joined<["-"], "fprebuilt-module-path=">, 
Group,
   Flags<[NoXarchOption, CC1Option]>, MetaVarName<"">,
   HelpText<"Specify the prebuilt module path">;
@@ -1806,16 +1807,19 @@ defm prebuilt_implicit_modules : 
OptInFFlag<"prebuilt-implicit-modules",
   [NoXarchOption, CC1Option], 
"HeaderSearchOpts->EnablePrebuiltImplicitModules">;
 def fmodules_prune_interval : Joined<["-"], "fmodules-prune-interval=">, 
Group,
   Flags<[CC1Option]>, MetaVarName<"">,
-  HelpText<"Specify the interval (in seconds) between attempts to prune the 
module cache">;
+  HelpText<"Specify the interval (in seconds) between attempts to prune the 
module cache">,
+  MarshallingInfoStringInt<"HeaderSearchOpts->ModuleCachePruneInterval", "7 * 
24 * 60 * 60">;
 def fmodules_prune_after : Joined<["-"], "fmodules-prune-after=">, 
Group,
   Flags<[CC1Option]>, MetaVarName<"">,
-  HelpText<"Specify the interval (in seconds) after which a module file will 
be considered unused">;
+  HelpText<"Specify the interval (in seconds) after which a module file will 
be considered unused">,
+  MarshallingInfoStringInt<"HeaderSearchOpts->ModuleCachePruneAfter", "31 * 24 
* 60 * 60">;
 def fmodules_search_all : Flag <["-"], "fmodules-search-all">, Group,
   Flags<[NoXarchOption, CC1Option]>,
   HelpText<"Search even non-imported modules to resolve references">;
 def fbuild_session_timestamp : Joined<["-"], "fbuild-session-timestamp=">,
   Group, Flags<[CC1Option]>, MetaVarName<"">,
-  HelpText<"Time when the current build session started">;
+  HelpText<"Time when the current build session started">,
+  MarshallingInfoStringInt<"HeaderSearchOpts->BuildSessionTimestamp">;
 def fbuild_session_file : Joined<["-"], "fbuild-session-file=">,
   Group, MetaVarName<"">,
   HelpText<"Use the last modification time of  as the build session 
timestamp">;
@@ -2602,7 +2606,8 @@ def iprefix : JoinedOrSeparate<["-"], "iprefix">, 
Group, Flags<[C
 def iquote : JoinedOrSeparate<["-"], "iquote">, Group, 
Flags<[CC1Option]>,
   HelpText<"Add directory to QUOTE include search path">, 
MetaVarName<"">;
 def isysroot : JoinedOrSeparate<["-"], "isysroot">, Group, 
Flags<[CC1Option]>,
-  HelpText<"Set the system root directory (usually /)">, MetaVarName<"">;
+  HelpText<"Set the system root directory (usually /)">, MetaVarName<"">,
+  MarshallingInfoString<"HeaderSearchOpts->Sysroot", [{"/"}]>;
 def isystem : JoinedOrSeparate<["-"], "isystem">, Group,
   Flags<[CC1Option]>,
   HelpText<"Add directory to SYSTEM include search path">, 
MetaVarName<"">;
@@ -3330,7 +3335,8 @@ def rewrite_legacy_objc : Flag<["-"], 
"rewrite-legacy-objc">, Flags<[NoXarchOpti
 def rdynamic : Flag<["-"], "rdynamic">, Group;
 def resource_dir : Separate<["-"], "resource-dir">,
   Flags<[NoXarchOption, CC1Option, CoreOption, HelpHidden]>,
-  HelpText<"The directory which holds the compiler resource files">;
+  HelpText<"The directory which holds the compiler resource files">,
+  MarshallingInfoString<"HeaderSearchOpts->ResourceDir">;
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[NoXarchOption, 
CoreOption]>,
   Alias;
 def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>, Group;
@@ -4671,7 +4677,8 @@ def fmodules_debuginfo :
   MarshallingInfoFlag<"LangOpts->ModulesDebugInfo">;
 def fmodule_format_EQ : Joined<["-"], "fmodule-format=">,
   HelpText<"Select the container format for clang modules and PCH. "
-   "Supported options are 'raw' and 'obj'.">;
+   "Supported options are 'raw' and 'obj'.">,
+  MarshallingInfoString<"HeaderSearchOpts->ModuleFormat", [{"ra

[llvm-branch-commits] [clang] ff4b76d - [clang][cli] Port TargetOpts simple string based options to new option parsing system

2020-12-18 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-18T09:40:56+01:00
New Revision: ff4b76d74f38a3816495c9914789e87a95525cf4

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

LOG: [clang][cli] Port TargetOpts simple string based options to new option 
parsing system

Depends on D84190

Reviewed By: Bigcheese

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D84668

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7275e84d7c53..b92244fd2f18 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2690,7 +2690,8 @@ def mwatchos_simulator_version_min_EQ : Joined<["-"], 
"mwatchos-simulator-versio
 def mwatchsimulator_version_min_EQ : Joined<["-"], 
"mwatchsimulator-version-min=">, Alias;
 def march_EQ : Joined<["-"], "march=">, Group, Flags<[CoreOption]>;
 def masm_EQ : Joined<["-"], "masm=">, Group, Flags<[NoXarchOption]>;
-def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group, Flags<[CC1Option]>;
+def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group, Flags<[CC1Option]>,
+  MarshallingInfoString<"TargetOpts->CodeModel", [{"default"}]>;
 def mtls_size_EQ : Joined<["-"], "mtls-size=">, Group, 
Flags<[NoXarchOption, CC1Option]>,
   HelpText<"Specify bit size of immediate TLS offsets (AArch64 ELF only): "
"12 (for 4KB) | 24 (for 16MB, default) | 32 (for 4GB) | 48 (for 
256TB, needs -mcmodel=large)">;
@@ -2760,7 +2761,10 @@ def mno_stack_arg_probe : Flag<["-"], 
"mno-stack-arg-probe">, Group, Fl
 def mthread_model : Separate<["-"], "mthread-model">, Group, 
Flags<[CC1Option]>,
   HelpText<"The thread model to use, e.g. posix, single (posix by default)">, 
Values<"posix,single">;
 def meabi : Separate<["-"], "meabi">, Group, Flags<[CC1Option]>,
-  HelpText<"Set EABI type, e.g. 4, 5 or gnu (default depends on triple)">, 
Values<"default,4,5,gnu">;
+  HelpText<"Set EABI type, e.g. 4, 5 or gnu (default depends on triple)">, 
Values<"default,4,5,gnu">,
+  MarshallingInfoString<"TargetOpts->EABIVersion", "Default">,
+  NormalizedValuesScope<"llvm::EABI">,
+  NormalizedValues<["Default", "EABI4", "EABI5", "GNU"]>, AutoNormalizeEnum;
 
 def mno_constant_cfstrings : Flag<["-"], "mno-constant-cfstrings">, 
Group;
 def mno_global_merge : Flag<["-"], "mno-global-merge">, Group, 
Flags<[CC1Option]>,
@@ -4052,9 +4056,11 @@ let Flags = [CC1Option, NoDriverOption] in {
 let Flags = [CC1Option, CC1AsOption, NoDriverOption] in {
 
 def target_cpu : Separate<["-"], "target-cpu">,
-  HelpText<"Target a specific cpu type">;
+  HelpText<"Target a specific cpu type">,
+  MarshallingInfoString<"TargetOpts->CPU">;
 def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">;
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString<"TargetOpts->TuneCPU">;
 def target_feature : Separate<["-"], "target-feature">,
   HelpText<"Target specific attributes">;
 def triple : Separate<["-"], "triple">,
@@ -4062,17 +4068,20 @@ def triple : Separate<["-"], "triple">,
   MarshallingInfoString<"TargetOpts->Triple", 
"llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple())">,
   AlwaysEmit, Normalizer<"normalizeTriple">;
 def target_abi : Separate<["-"], "target-abi">,
-  HelpText<"Target a particular ABI type">;
+  HelpText<"Target a particular ABI type">,
+  MarshallingInfoString<"TargetOpts->ABI">;
 def target_sdk_version_EQ : Joined<["-"], "target-sdk-version=">,
   HelpText<"The version of target SDK used for compilation">;
 
 }
 
 def target_linker_version : Separate<["-"], "target-linker-version">,
-  HelpText<"Target linker version">;
+  HelpText<"Target linker version">,
+  MarshallingInfoString<"TargetOpts->LinkerVersion">;
 def triple_EQ : Joined<["-"], "triple=">, Alias;
 def mfpmath : Separate<["-"], "mfpmath">,
-  HelpText<"Which unit to use for fp math">;
+  HelpText<"Which unit to use for fp math">,
+  MarshallingInfoString<"TargetOpts->FPMath">;
 
 def fpadding_on_unsigned_fixed_point : Flag<["-"], 
"fpadding-on-unsigned-fixed-point">,
   HelpText<"Force each unsigned fixed point type to have an extra bit of 
padding to align their scales with those of signed fixed point types">;

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index f7bb2308953f..ea0cc74217ff 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -244,10 +244,10 @@ static llvm::Optional 
normalizeSimpleEnum(OptSpecifier Opt,
   return None;
 }
 
-static void denormalizeSimpleEnum(SmallVectorImpl &Args,
-  const char *Spelling,
-   

[llvm-branch-commits] [clang] aec2991 - [clang][cli] Port LangOpts simple string based options to new option parsing system

2020-12-18 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-18T09:44:02+01:00
New Revision: aec2991d083a9c5b92f94d84a7b3a7bbed405af8

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

LOG: [clang][cli] Port LangOpts simple string based options to new option 
parsing system

Depends on D84670

Reviewed By: Bigcheese

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D84671

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index def189f65994..b9f8c78e43da 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -108,8 +108,6 @@ def err_fe_action_not_available : Error<
 "action %0 not compiled in">;
 def err_fe_invalid_alignment : Error<
 "invalid value '%1' in '%0'; alignment must be a power of 2">;
-def err_fe_invalid_wchar_type
-: Error<"invalid wchar_t type '%0'; must be one of 'char', 'short', 
'int'">;
 def err_fe_invalid_exception_model
: Error<"invalid exception model 
'%select{none|dwarf|sjlj|arm|seh|wasm|aix}0' for target '%1'">;
 def warn_fe_concepts_ts_flag : Warning<

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b92244fd2f18..f7e3b298bccd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -994,7 +994,8 @@ def interface_stub_version_EQ : JoinedOrSeparate<["-"], 
"interface-stub-version=
 def exported__symbols__list : Separate<["-"], "exported_symbols_list">;
 def e : JoinedOrSeparate<["-"], "e">, Flags<[LinkerInput]>, Group;
 def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group, 
Flags<[CC1Option]>,
-  HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">;
+  HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">,
+  MarshallingInfoStringInt<"LangOpts->MaxTokens">;
 def fPIC : Flag<["-"], "fPIC">, Group;
 def fno_PIC : Flag<["-"], "fno-PIC">, Group;
 def fPIE : Flag<["-"], "fPIE">, Group;
@@ -1212,7 +1213,10 @@ defm complete_member_pointers : 
BoolOption<"complete-member-pointers",
 " would be significant under the Microsoft ABI">, "f">,
   Group;
 def fcf_runtime_abi_EQ : Joined<["-"], "fcf-runtime-abi=">, Group,
-Flags<[CC1Option]>;
+Flags<[CC1Option]>, 
Values<"unspecified,standalone,objc,swift,swift-5.0,swift-4.2,swift-4.1">,
+NormalizedValuesScope<"LangOptions::CoreFoundationABI">,
+NormalizedValues<["ObjectiveC", "ObjectiveC", "ObjectiveC", "Swift5_0", 
"Swift5_0", "Swift4_2", "Swift4_1"]>,
+MarshallingInfoString<"LangOpts->CFRuntime", "ObjectiveC">, 
AutoNormalizeEnum;
 defm constant_cfstrings : BoolFOption<"constant-cfstrings",
   "LangOpts->NoConstantCFStrings", DefaultsToFalse,
   ChangedBy,
@@ -1420,7 +1424,8 @@ defm sanitize_memory_use_after_dtor : 
BoolOption<"sanitize-memory-use-after-dtor
   Group;
 def fsanitize_address_field_padding : Joined<["-"], 
"fsanitize-address-field-padding=">,
 Group,
-HelpText<"Level of field padding for 
AddressSanitizer">;
+HelpText<"Level of field padding for 
AddressSanitizer">,
+
MarshallingInfoStringInt<"LangOpts->SanitizeAddressFieldPadding">;
 defm sanitize_address_use_after_scope : 
BoolOption<"sanitize-address-use-after-scope",
   "CodeGenOpts.SanitizeAddressUseAfterScope", DefaultsToFalse,
   ChangedBy, ResetBy,
@@ -1739,7 +1744,10 @@ defm experimental_relative_cxx_abi_vtables : 
BoolFOption<"experimental-relative-
 
 def flat__namespace : Flag<["-"], "flat_namespace">;
 def flax_vector_conversions_EQ : Joined<["-"], "flax-vector-conversions=">, 
Group,
-  HelpText<"Enable implicit vector bit-casts">, Values<"none,integer,all">, 
Flags<[CC1Option]>;
+  HelpText<"Enable implicit vector bit-casts">, Values<"none,integer,all">, 
Flags<[CC1Option]>,
+  NormalizedValuesScope<"LangOptions::LaxVectorConversionKind">,
+  NormalizedValues<["None", "Integer", "All"]>,
+  MarshallingInfoString<"LangOpts->LaxVectorConversions", "All">, 
AutoNormalizeEnum;
 def flax_vector_conversions : Flag<["-"], "flax-vector-conversions">, 
Group,
   Alias, AliasArgs<["integer"]>;
 def flimited_precision_EQ : Joined<["-"], "flimited-precision=">, 
Group;
@@ -1791,7 +1799,12 @@ defm delayed_template_parsing : 
BoolFOption<"delayed-template-parsing",
   ChangedBy,
   ResetBy,
   BothFlags<[CoreOption]>>;
-def fms_memptr_rep_EQ : Joined<["-"], "fms-memptr-rep=">, Group, 
Flags<[CC1Op

[llvm-branch-commits] [clang] d1b3f82 - [clang][cli] Port PreprocessorOpts simple string based options to new option parsing system

2020-12-18 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-18T09:52:20+01:00
New Revision: d1b3f82e51378dd9fb5a23806d8fa906151f5e7b

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

LOG: [clang][cli] Port PreprocessorOpts simple string based options to new 
option parsing system

Depends on D84671

Reviewed By: Bigcheese

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D84672

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f7e3b298bccd..01ee6f747e51 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2615,7 +2615,8 @@ def image__base : Separate<["-"], "image_base">;
 def include_ : JoinedOrSeparate<["-", "--"], "include">, Group, 
EnumName<"include">,
 MetaVarName<"">, HelpText<"Include file before parsing">, 
Flags<[CC1Option]>;
 def include_pch : Separate<["-"], "include-pch">, Group, 
Flags<[CC1Option]>,
-  HelpText<"Include precompiled header file">, MetaVarName<"">;
+  HelpText<"Include precompiled header file">, MetaVarName<"">,
+  MarshallingInfoString<"PreprocessorOpts->ImplicitPCHInclude">;
 def relocatable_pch : Flag<["-", "--"], "relocatable-pch">, Flags<[CC1Option]>,
   HelpText<"Whether to build a relocatable precompiled header">,
   MarshallingInfoFlag<"FrontendOpts.RelocatablePCH">;
@@ -4857,7 +4858,8 @@ def foverride_record_layout_EQ : Joined<["-"], 
"foverride-record-layout=">,
   HelpText<"Override record layouts with those in the given file">;
 def pch_through_header_EQ : Joined<["-"], "pch-through-header=">,
   HelpText<"Stop PCH generation after including this file.  When using a PCH, "
-   "skip tokens until after this file is included.">;
+   "skip tokens until after this file is included.">,
+  MarshallingInfoString<"PreprocessorOpts->PCHThroughHeader">;
 def pch_through_hdrstop_create : Flag<["-"], "pch-through-hdrstop-create">,
   HelpText<"When creating a PCH, stop PCH generation after #pragma hdrstop.">,
   MarshallingInfoFlag<"PreprocessorOpts->PCHWithHdrStopCreate">;
@@ -4904,7 +4906,9 @@ def fconstant_string_class : Separate<["-"], 
"fconstant-string-class">,
   HelpText<"Specify the class to use for constant Objective-C string 
objects.">,
   MarshallingInfoString<"LangOpts->ObjCConstantStringClass">;
 def fobjc_arc_cxxlib_EQ : Joined<["-"], "fobjc-arc-cxxlib=">,
-  HelpText<"Objective-C++ Automatic Reference Counting standard library 
kind">, Values<"libc++,libstdc++,none">;
+  HelpText<"Objective-C++ Automatic Reference Counting standard library 
kind">, Values<"libc++,libstdc++,none">,
+  NormalizedValues<["ARCXX_libcxx", "ARCXX_libstdcxx", "ARCXX_nolib"]>,
+  MarshallingInfoString<"PreprocessorOpts->ObjCXXARCStandardLibrary", 
"ARCXX_nolib">, AutoNormalizeEnum;
 def fobjc_runtime_has_weak : Flag<["-"], "fobjc-runtime-has-weak">,
   HelpText<"The target Objective-C runtime supports ARC weak operations">;
 def fobjc_dispatch_method_EQ : Joined<["-"], "fobjc-dispatch-method=">,

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 5eea882e502b..a2ff437208f6 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3115,11 +3115,8 @@ static bool 
isStrictlyPreprocessorAction(frontend::ActionKind Action) {
 static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
   DiagnosticsEngine &Diags,
   frontend::ActionKind Action) {
-  Opts.ImplicitPCHInclude = std::string(Args.getLastArgValue(OPT_include_pch));
   Opts.PCHWithHdrStop = Args.hasArg(OPT_pch_through_hdrstop_create) ||
 Args.hasArg(OPT_pch_through_hdrstop_use);
-  Opts.PCHThroughHeader =
-  std::string(Args.getLastArgValue(OPT_pch_through_header_EQ));
   Opts.AllowPCHWithCompilerErrors =
   Args.hasArg(OPT_fallow_pch_with_errors, OPT_fallow_pcm_with_errors);
 
@@ -3187,19 +3184,6 @@ static void ParsePreprocessorArgs(PreprocessorOptions 
&Opts, ArgList &Args,
 Opts.addRemappedFile(Split.first, Split.second);
   }
 
-  if (Arg *A = Args.getLastArg(OPT_fobjc_arc_cxxlib_EQ)) {
-StringRef Name = A->getValue();
-unsigned Library = llvm::StringSwitch(Name)
-  .Case("libc++", ARCXX_libcxx)
-  .Case("libstdc++", ARCXX_libstdcxx)
-  .Case("none", ARCXX_nolib)
-  .Default(~0U);
-if (Library == ~0U)
-  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << 
Name;
-else
-  Opts.ObjCXXARCStandardLibrary = (ObjCXXARCStandardLibraryKind)Library;
-  }
-
   // Always avoid lexing editor placeh

[llvm-branch-commits] [clang] 333d41e - [clang][cli] Port FrontendOpts simple string based options to new option parsing system

2020-12-18 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-18T10:00:03+01:00
New Revision: 333d41e9eb8b5f6cd67d318e84ee8dba99b840cc

URL: 
https://github.com/llvm/llvm-project/commit/333d41e9eb8b5f6cd67d318e84ee8dba99b840cc
DIFF: 
https://github.com/llvm/llvm-project/commit/333d41e9eb8b5f6cd67d318e84ee8dba99b840cc.diff

LOG: [clang][cli] Port FrontendOpts simple string based options to new option 
parsing system

Depends on D84189

Reviewed By: dexonsmith

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D84190

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 01ee6f747e51..d143781d1d09 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -542,7 +542,8 @@ def ccc_arcmt_modify : Flag<["-"], "ccc-arcmt-modify">, 
InternalDriverOpt,
 def ccc_arcmt_migrate : Separate<["-"], "ccc-arcmt-migrate">, 
InternalDriverOpt,
   HelpText<"Apply modifications and produces temporary files that conform to 
ARC">;
 def arcmt_migrate_report_output : Separate<["-"], 
"arcmt-migrate-report-output">,
-  HelpText<"Output path for the plist report">,  Flags<[CC1Option]>;
+  HelpText<"Output path for the plist report">,  Flags<[CC1Option]>,
+  MarshallingInfoString<"FrontendOpts.ARCMTMigrateReportOut">;
 def arcmt_migrate_emit_arc_errors : Flag<["-"], "arcmt-migrate-emit-errors">,
   HelpText<"Emit ARC errors even if the migrator can fix them">, 
Flags<[CC1Option]>,
   MarshallingInfoFlag<"FrontendOpts.ARCMTMigrateEmitARCErrors">;
@@ -605,7 +606,8 @@ def objcmt_migrate_designated_init : Flag<["-"], 
"objcmt-migrate-designated-init
   MarshallingInfoBitfieldFlag<"FrontendOpts.ObjCMTAction", 
"FrontendOptions::ObjCMT_DesignatedInitializer">;
 
 def objcmt_whitelist_dir_path: Joined<["-"], "objcmt-whitelist-dir-path=">, 
Flags<[CC1Option]>,
-  HelpText<"Only modify files with a filename contained in the provided 
directory path">;
+  HelpText<"Only modify files with a filename contained in the provided 
directory path">,
+  MarshallingInfoString<"FrontendOpts.ObjCMTWhiteListPath">;
 // The misspelt "white-list" [sic] alias is due for removal.
 def : Joined<["-"], "objcmt-white-list-dir-path=">, Flags<[CC1Option]>,
 Alias;
@@ -2339,7 +2341,8 @@ can be analyzed with chrome://tracing or `Speedscope App
   MarshallingInfoFlag<"FrontendOpts.TimeTrace">;
 def ftime_trace_granularity_EQ : Joined<["-"], "ftime-trace-granularity=">, 
Group,
   HelpText<"Minimum time granularity (in microseconds) traced by time 
profiler">,
-  Flags<[CC1Option, CoreOption]>;
+  Flags<[CC1Option, CoreOption]>,
+  MarshallingInfoStringInt<"FrontendOpts.TimeTraceGranularity", "500u">;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
@@ -3309,7 +3312,8 @@ def nostdlibxx : Flag<["-"], "nostdlib++">;
 def object : Flag<["-"], "object">;
 def o : JoinedOrSeparate<["-"], "o">, Flags<[NoXarchOption, RenderAsInput,
   CC1Option, CC1AsOption, FC1Option, FlangOption]>,
-  HelpText<"Write output to ">, MetaVarName<"">;
+  HelpText<"Write output to ">, MetaVarName<"">,
+  MarshallingInfoString<"FrontendOpts.OutputFile">;
 def pagezero__size : JoinedOrSeparate<["-"], "pagezero_size">;
 def pass_exit_codes : Flag<["-", "--"], "pass-exit-codes">, 
Flags<[Unsupported]>;
 def pedantic_errors : Flag<["-", "--"], "pedantic-errors">, 
Group, Flags<[CC1Option]>;
@@ -4626,7 +4630,8 @@ def aux_target_cpu : Separate<["-"], "aux-target-cpu">,
 def aux_target_feature : Separate<["-"], "aux-target-feature">,
   HelpText<"Target specific auxiliary attributes">;
 def aux_triple : Separate<["-"], "aux-triple">,
-  HelpText<"Auxiliary target triple.">;
+  HelpText<"Auxiliary target triple.">,
+  MarshallingInfoString<"FrontendOpts.AuxTriple">;
 def code_completion_at : Separate<["-"], "code-completion-at">,
   MetaVarName<"::">,
   HelpText<"Dump code-completion information at a location">;
@@ -4672,7 +4677,8 @@ def ast_dump_filter : Separate<["-"], "ast-dump-filter">,
   MetaVarName<"">,
   HelpText<"Use with -ast-dump or -ast-print to dump/print only AST 
declaration"
" nodes having a certain substring in a qualified name. Use"
-   " -ast-list to list all filterable declaration node names.">;
+   " -ast-list to list all filterable declaration node names.">,
+  MarshallingInfoString<"FrontendOpts.ASTDumpFilter">;
 def fno_modules_global_index : Flag<["-"], "fno-modules-global-index">,
   HelpText<"Do not automatically generate or update the global module index">,
   MarshallingInfoFlag<"FrontendOpts.UseGlobalModuleIndex", "true">, IsNegative;
@@ -4815,7 +4821,8 @@ defm emit_llvm_uselists : BoolOption<"emit-llvm-useli

[llvm-branch-commits] [clang] 95d3cc6 - [clang][cli] Port CodeGenOpts simple string flags to new option parsing system

2020-12-18 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-18T10:28:48+01:00
New Revision: 95d3cc67caac04668ef808f65c30ced60ed14f5d

URL: 
https://github.com/llvm/llvm-project/commit/95d3cc67caac04668ef808f65c30ced60ed14f5d
DIFF: 
https://github.com/llvm/llvm-project/commit/95d3cc67caac04668ef808f65c30ced60ed14f5d.diff

LOG: [clang][cli] Port CodeGenOpts simple string flags to new option parsing 
system

Depends on D84668

Reviewed By: Bigcheese

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D84669

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Profile/c-generate.c

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 5c540812ed31..ef4fa31256cd 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -30,6 +30,8 @@ namespace clang {
 /// Bitfields of CodeGenOptions, split out from CodeGenOptions to ensure
 /// that this large collection of bitfields is a trivial class type.
 class CodeGenOptionsBase {
+  friend class CompilerInvocation;
+
 public:
 #define CODEGENOPT(Name, Bits, Default) unsigned Name : Bits;
 #define ENUM_CODEGENOPT(Name, Type, Bits, Default)

diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 0e85be8f058b..c67cce099a28 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -86,8 +86,6 @@ def err_drv_invalid_thread_model_for_target : Error<
   "invalid thread model '%0' in '%1' for this target">;
 def err_drv_invalid_linker_name : Error<
   "invalid linker name in argument '%0'">;
-def err_drv_invalid_pgo_instrumentor : Error<
-  "invalid PGO instrumentor in argument '%0'">;
 def err_drv_invalid_rtlib_name : Error<
   "invalid runtime library name in argument '%0'">;
 def err_drv_unsupported_rtlib_for_platform : Error<

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d143781d1d09..3e4fbf1fbb8f 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1053,7 +1053,10 @@ defm coroutines_ts : OptInFFlag<"coroutines-ts", "Enable 
support for the C++ Cor
 
 def fembed_bitcode_EQ : Joined<["-"], "fembed-bitcode=">,
 Group, Flags<[NoXarchOption, CC1Option, CC1AsOption]>, 
MetaVarName<"">,
-HelpText<"Embed LLVM bitcode (option: off, all, bitcode, marker)">;
+HelpText<"Embed LLVM bitcode (option: off, all, bitcode, marker)">,
+Values<"off,all,bitcode,marker">, NormalizedValuesScope<"CodeGenOptions">,
+NormalizedValues<["Embed_Off", "Embed_All", "Embed_Bitcode", 
"Embed_Marker"]>,
+MarshallingInfoString<"CodeGenOpts.EmbedBitcode", "Embed_Off">, 
AutoNormalizeEnum;
 def fembed_bitcode : Flag<["-"], "fembed-bitcode">, Group,
   Alias, AliasArgs<["all"]>,
   HelpText<"Embed LLVM IR bitcode as data">;
@@ -1070,7 +1073,8 @@ def fno_profile_sample_use : Flag<["-"], 
"fno-profile-sample-use">, Group;
 def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">,
 Group, Flags<[NoXarchOption, CC1Option]>,
-HelpText<"Enable sample-based profile guided optimizations">;
+HelpText<"Enable sample-based profile guided optimizations">,
+MarshallingInfoString<"CodeGenOpts.SampleProfileFile">;
 def fprofile_sample_accurate : Flag<["-"], "fprofile-sample-accurate">,
 Group, Flags<[NoXarchOption, CC1Option]>,
 HelpText<"Specifies that the sample profile is accurate">,
@@ -1093,7 +1097,8 @@ def fno_auto_profile_accurate : Flag<["-"], 
"fno-auto-profile-accurate">,
 Group, Alias;
 def fdebug_compilation_dir : Separate<["-"], "fdebug-compilation-dir">,
 Group, Flags<[CC1Option, CC1AsOption, CoreOption]>,
-HelpText<"The compilation directory to embed in the debug info.">;
+HelpText<"The compilation directory to embed in the debug info.">,
+MarshallingInfoString<"CodeGenOpts.DebugCompilationDir">;
 def fdebug_compilation_dir_EQ : Joined<["-"], "fdebug-compilation-dir=">,
 Group, Flags<[CC1Option, CC1AsOption, CoreOption]>,
 Alias;
@@ -1114,7 +1119,8 @@ def fprofile_instr_use_EQ : Joined<["-"], 
"fprofile-instr-use=">,
 HelpText<"Use instrumentation data for profile-guided optimization">;
 def fprofile_remapping_file_EQ : Joined<["-"], "fprofile-remapping-file=">,
 Group, Flags<[CC1Option, CoreOption]>, MetaVarName<"">,
-HelpText<"Use the remappings described in  to match the profile data 
against names in the program">;
+HelpText<"Use the remappings described in  to match the profile data 
against names in the program">,
+MarshallingInfoString<"CodeGenOpts.ProfileRemappingFile">;
 def fprofile_re

[llvm-branch-commits] [clang] 27b7d64 - [clang][cli] Streamline MarshallingInfoFlag description

2020-12-21 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-21T11:32:46+01:00
New Revision: 27b7d646886d499c70dec3481dfc3c82dfc43dd7

URL: 
https://github.com/llvm/llvm-project/commit/27b7d646886d499c70dec3481dfc3c82dfc43dd7
DIFF: 
https://github.com/llvm/llvm-project/commit/27b7d646886d499c70dec3481dfc3c82dfc43dd7.diff

LOG: [clang][cli] Streamline MarshallingInfoFlag description

This replaces the existing `MarshallingInfoFlag<...>, IsNegative` with simpler 
`MarshallingInfoNegativeFlag`.

Reviewed By: dexonsmith

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D84675

Added: 


Modified: 
clang/include/clang/Driver/Options.td
llvm/include/llvm/Option/OptParser.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 63a5b5484f0f..29ee948f1849 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -696,7 +696,7 @@ def O_flag : Flag<["-"], "O">, Flags<[CC1Option]>, 
Alias, AliasArgs<["1"]>;
 def Ofast : Joined<["-"], "Ofast">, Group, Flags<[CC1Option]>;
 def P : Flag<["-"], "P">, Flags<[CC1Option]>, Group,
   HelpText<"Disable linemarker output in -E mode">,
-  MarshallingInfoFlag<"PreprocessorOutputOpts.ShowLineMarkers", "true">, 
IsNegative;
+  MarshallingInfoNegativeFlag<"PreprocessorOutputOpts.ShowLineMarkers">;
 def Qy : Flag<["-"], "Qy">, Flags<[CC1Option]>,
   HelpText<"Emit metadata containing compiler name and version">;
 def Qn : Flag<["-"], "Qn">, Flags<[CC1Option]>,
@@ -1212,7 +1212,7 @@ def : Flag<["-"], "frecord-gcc-switches">, 
Alias;
 def : Flag<["-"], "fno-record-gcc-switches">, Alias;
 def fcommon : Flag<["-"], "fcommon">, Group,
   Flags<[CoreOption, CC1Option]>, HelpText<"Place uninitialized global 
variables in a common block">,
-  MarshallingInfoFlag<"CodeGenOpts.NoCommon", "true">, IsNegative;
+  MarshallingInfoNegativeFlag<"CodeGenOpts.NoCommon">;
 def fcompile_resource_EQ : Joined<["-"], "fcompile-resource=">, Group;
 defm complete_member_pointers : BoolOption<"complete-member-pointers",
   "LangOpts->CompleteMemberPointers", DefaultsToFalse,
@@ -1856,7 +1856,7 @@ def fmodules_validate_once_per_build_session : 
Flag<["-"], "fmodules-validate-on
 def fmodules_disable_diagnostic_validation : Flag<["-"], 
"fmodules-disable-diagnostic-validation">,
   Group, Flags<[CC1Option]>,
   HelpText<"Disable validation of the diagnostic options when loading the 
module">,
-  MarshallingInfoFlag<"HeaderSearchOpts->ModulesValidateDiagnosticOptions", 
"true">, IsNegative;
+  
MarshallingInfoNegativeFlag<"HeaderSearchOpts->ModulesValidateDiagnosticOptions">;
 defm modules_validate_system_headers : 
BoolOption<"modules-validate-system-headers",
   "HeaderSearchOpts->ModulesValidateSystemHeaders", DefaultsToFalse,
   ChangedBy,
@@ -1944,7 +1944,7 @@ def fno_asm : Flag<["-"], "fno-asm">, Group;
 def fno_asynchronous_unwind_tables : Flag<["-"], 
"fno-asynchronous-unwind-tables">, Group;
 def fno_assume_sane_operator_new : Flag<["-"], 
"fno-assume-sane-operator-new">, Group,
   HelpText<"Don't assume that C++'s global operator new can't alias any 
pointer">,
-  Flags<[CC1Option]>, MarshallingInfoFlag<"CodeGenOpts.AssumeSaneOperatorNew", 
"true">, IsNegative;
+  Flags<[CC1Option]>, 
MarshallingInfoNegativeFlag<"CodeGenOpts.AssumeSaneOperatorNew">;
 def fno_builtin : Flag<["-"], "fno-builtin">, Group, 
Flags<[CC1Option, CoreOption]>,
   HelpText<"Disable implicit builtin knowledge of functions">;
 def fno_builtin_ : Joined<["-"], "fno-builtin-">, Group, 
Flags<[CC1Option, CoreOption]>,
@@ -2022,7 +2022,7 @@ def fno_strict_overflow : Flag<["-"], 
"fno-strict-overflow">, Group;
 def fno_temp_file : Flag<["-"], "fno-temp-file">, Group,
   Flags<[CC1Option, CoreOption]>, HelpText<
   "Directly create compilation output files. This may lead to incorrect 
incremental builds if the compiler crashes">,
-  MarshallingInfoFlag<"FrontendOpts.UseTemporary", "true">, IsNegative;
+  MarshallingInfoNegativeFlag<"FrontendOpts.UseTemporary">;
 defm use_cxa_atexit : BoolFOption<"use-cxa-atexit",
   "CodeGenOpts.CXAAtExit", DefaultsToTrue,
   ChangedBy,
@@ -2030,7 +2030,7 @@ defm use_cxa_atexit : BoolFOption<"use-cxa-atexit",
 def fno_unit_at_a_time : Flag<["-"], "fno-unit-at-a-time">, Group;
 def fno_unwind_tables : Flag<["-"], "fno-unwind-tables">, Group;
 def fno_verbose_asm : Flag<["-"], "fno-verbose-asm">, Group, 
Flags<[CC1Option]>,
-  MarshallingInfoFlag<"CodeGenOpts.AsmVerbose", "true">, IsNegative;
+  MarshallingInfoNegativeFlag<"CodeGenOpts.AsmVerbose">;
 def fno_working_directory : Flag<["-"], "fno-working-directory">, 
Group;
 def fno_wrapv : Flag<["-"], "fno-wrapv">, Group;
 def fobjc_arc : Flag<["-"], "fobjc-arc">, Group, Flags<[CC1Option]>,
@@ -3313,7 +3313,7 @@ def no_pedantic : Flag<["-", "--"], "no-pedantic">, 
Group;
 def no__dead__strip__inits__and__terms : Flag<["-"], 
"no_dead_strip_inits_and_ter

[llvm-branch-commits] [clang] 70410a2 - [clang][cli] Let denormalizer decide how to render the option based on the option class

2020-12-21 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-21T11:32:47+01:00
New Revision: 70410a264949101ced3ce3458f37dd4cc2f5af85

URL: 
https://github.com/llvm/llvm-project/commit/70410a264949101ced3ce3458f37dd4cc2f5af85
DIFF: 
https://github.com/llvm/llvm-project/commit/70410a264949101ced3ce3458f37dd4cc2f5af85.diff

LOG: [clang][cli] Let denormalizer decide how to render the option based on the 
option class

Before this patch, you needed to use `AutoNormalizeEnumJoined` whenever you 
wanted to **de**normalize joined enum.
Besides the naming confusion, this means the fact the option is joined is 
specified in two places: in the normalization multiclass and in the 
`Joined<["-"], ...>` multiclass.
This patch makes this work automatically, taking into account the `OptionClass` 
of options.

Also, the enum denormalizer now just looks up the spelling of the present enum 
case in a table and forwards it to the string denormalizer.

I also added more tests that exercise this.

Reviewed By: dexonsmith

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D84189

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 29ee948f1849..82c4e9399d9d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4882,7 +4882,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">,
-  AutoNormalizeEnumJoined;
+  AutoNormalizeEnum;
 
 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 00615a70d730..f71b14eabc49 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -152,8 +152,8 @@ static Optional 
normalizeSimpleNegativeFlag(OptSpecifier Opt, unsigned,
 /// argument.
 static void denormalizeSimpleFlag(SmallVectorImpl &Args,
   const char *Spelling,
-  CompilerInvocation::StringAllocator, 
unsigned,
-  /*T*/...) {
+  CompilerInvocation::StringAllocator,
+  Option::OptionClass, unsigned, /*T*/...) {
   Args.push_back(Spelling);
 }
 
@@ -200,12 +200,41 @@ static auto makeBooleanOptionNormalizer(bool Value, bool 
OtherValue,
 
 static auto makeBooleanOptionDenormalizer(bool Value) {
   return [Value](SmallVectorImpl &Args, const char *Spelling,
- CompilerInvocation::StringAllocator, unsigned, bool KeyPath) {
+ CompilerInvocation::StringAllocator, Option::OptionClass,
+ unsigned, bool KeyPath) {
 if (KeyPath == Value)
   Args.push_back(Spelling);
   };
 }
 
+static void denormalizeStringImpl(SmallVectorImpl &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 
+static void
+denormalizeString(SmallVectorImpl &Args, const char *Spelling,
+  CompilerInvocation::StringAllocator SA,
+  Option::OptionClass OptClass, unsigned TableIndex, T Value) {
+  denormalizeStringImpl(Args, Spelling, SA, OptClass, TableIndex, 
Twine(Value));
+}
+
 static Optional
 findValueTableByName(const SimpleEnumValueTable &Table, StringRef Name) {
   for (int I = 0, E = Table.Size; I != E; ++I)
@@ -247,12 +276,13 @@ static llvm::Optional 
normalizeSimpleEnum(OptSpecifier Opt,
 static void denormalizeSimpleEnumImpl(SmallVectorImpl &Args,
   const char *Spelling,
   CompilerInvocation::StringAllocator SA,
+  Option::OptionClass OptClass,
   unsigned TableIndex, unsigned Value) {
   assert(TableIndex < SimpleEnu

[llvm-branch-commits] [clang] 5a85526 - [clang] Use enum for LangOptions::SYCLVersion instead of unsigned

2020-12-21 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-21T11:32:47+01:00
New Revision: 5a85526728c9e57efe26f322e4718fffd2634d23

URL: 
https://github.com/llvm/llvm-project/commit/5a85526728c9e57efe26f322e4718fffd2634d23
DIFF: 
https://github.com/llvm/llvm-project/commit/5a85526728c9e57efe26f322e4718fffd2634d23.diff

LOG: [clang] Use enum for LangOptions::SYCLVersion instead of unsigned

`LangOptions::SYCLVersion` can only have two values. This patch introduces an 
enum that allows us to reduce the member size from 32 bits to 1 bit.

Consequently, this also makes marshalling of this option fit into our model for 
enums: D84674.

Reviewed By: bader

Differential Revision: https://reviews.llvm.org/D93540

Added: 


Modified: 
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/LangOptions.h
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Frontend/InitPreprocessor.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 251fd68f4df8..cc5eb939dbd2 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -246,7 +246,7 @@ LANGOPT(GPUExcludeWrongSideOverloads, 1, 0, "always exclude 
wrong side overloads
 
 LANGOPT(SYCL  , 1, 0, "SYCL")
 LANGOPT(SYCLIsDevice  , 1, 0, "Generate code for SYCL device")
-LANGOPT(SYCLVersion   , 32, 0, "Version of the SYCL standard used")
+ENUM_LANGOPT(SYCLVersion  , SYCLMajorVersion, 1, SYCL_None, "Version of the 
SYCL standard used")
 
 LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP")
 

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index ed9f729417af..8b3fb562561f 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -125,6 +125,11 @@ class LangOptions : public LangOptionsBase {
 MSVC2019 = 1920,
   };
 
+  enum SYCLMajorVersion {
+SYCL_None,
+SYCL_2017,
+  };
+
   /// Clang versions with 
diff erent platform ABI conformance.
   enum class ClangABI {
 /// Attempt to be ABI-compatible with code generated by Clang 3.8.x

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index f71b14eabc49..fc5fd1547599 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2277,11 +2277,13 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, InputKind IK,
 // -sycl-std applies to any SYCL source, not only those containing kernels,
 // but also those using the SYCL API
 if (const Arg *A = Args.getLastArg(OPT_sycl_std_EQ)) {
-  Opts.SYCLVersion = llvm::StringSwitch(A->getValue())
- .Cases("2017", "1.2.1", "121", "sycl-1.2.1", 2017)
- .Default(0U);
+  Opts.setSYCLVersion(
+  llvm::StringSwitch(A->getValue())
+  .Cases("2017", "1.2.1", "121", "sycl-1.2.1",
+ LangOptions::SYCL_2017)
+  .Default(LangOptions::SYCL_None));
 
-  if (Opts.SYCLVersion == 0U) {
+  if (Opts.getSYCLVersion() == LangOptions::SYCL_None) {
 // User has passed an invalid value to the flag, this is an error
 Diags.Report(diag::err_drv_invalid_value)
 << A->getAsString(Args) << A->getValue();

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index d4b77a65aa63..87af9247b91c 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -476,7 +476,7 @@ static void InitializeStandardPredefinedMacros(const 
TargetInfo &TI,
 
   if (LangOpts.SYCL) {
 // SYCL Version is set to a value when building SYCL applications
-if (LangOpts.SYCLVersion == 2017)
+if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2017)
   Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121");
   }
 



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 06b83fd - [TableGen] NFC: Switch to range-based for loops in OptParserEmitter

2020-12-21 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-21T12:36:46+01:00
New Revision: 06b83fd6c75b48a6a93dc580fb4409e13608a045

URL: 
https://github.com/llvm/llvm-project/commit/06b83fd6c75b48a6a93dc580fb4409e13608a045
DIFF: 
https://github.com/llvm/llvm-project/commit/06b83fd6c75b48a6a93dc580fb4409e13608a045.diff

LOG: [TableGen] NFC: Switch to range-based for loops in OptParserEmitter

This simplifies the code a bit. No functionality change.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D93526

Added: 


Modified: 
llvm/utils/TableGen/OptParserEmitter.cpp

Removed: 




diff  --git a/llvm/utils/TableGen/OptParserEmitter.cpp 
b/llvm/utils/TableGen/OptParserEmitter.cpp
index b3fe9d7a91d1..794485256d50 100644
--- a/llvm/utils/TableGen/OptParserEmitter.cpp
+++ b/llvm/utils/TableGen/OptParserEmitter.cpp
@@ -219,8 +219,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
   PrefixesT Prefixes;
   Prefixes.insert(std::make_pair(PrefixKeyT(), "prefix_0"));
   unsigned CurPrefix = 0;
-  for (unsigned i = 0, e = Opts.size(); i != e; ++i) {
-const Record &R = *Opts[i];
+  for (const Record &R : llvm::make_pointee_range(Opts)) {
 std::vector prf = R.getValueAsListOfStrings("Prefixes");
 PrefixKeyT prfkey(prf.begin(), prf.end());
 unsigned NewPrefix = CurPrefix + 1;
@@ -235,19 +234,16 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream 
&OS) {
   OS << "// Prefixes\n\n";
   OS << "#ifdef PREFIX\n";
   OS << "#define COMMA ,\n";
-  for (PrefixesT::const_iterator I = Prefixes.begin(), E = Prefixes.end();
-  I != E; ++I) {
+  for (const auto &Prefix : Prefixes) {
 OS << "PREFIX(";
 
 // Prefix name.
-OS << I->second;
+OS << Prefix.second;
 
 // Prefix values.
 OS << ", {";
-for (PrefixKeyT::const_iterator PI = I->first.begin(),
-PE = I->first.end(); PI != PE; ++PI) {
-  OS << "\"" << *PI << "\" COMMA ";
-}
+for (StringRef PrefixKey : Prefix.first)
+  OS << "\"" << PrefixKey << "\" COMMA ";
 OS << "nullptr})\n";
   }
   OS << "#undef COMMA\n";
@@ -256,9 +252,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
   OS << "/\n";
   OS << "// Groups\n\n";
   OS << "#ifdef OPTION\n";
-  for (unsigned i = 0, e = Groups.size(); i != e; ++i) {
-const Record &R = *Groups[i];
-
+  for (const Record &R : llvm::make_pointee_range(Groups)) {
 // Start a single option entry.
 OS << "OPTION(";
 
@@ -343,8 +337,8 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
   OS << "nullptr";
 } else {
   OS << "\"";
-  for (size_t i = 0, e = AliasArgs.size(); i != e; ++i)
-OS << AliasArgs[i] << "\\0";
+  for (StringRef AliasArg : AliasArgs)
+OS << AliasArg << "\\0";
   OS << "\"";
 }
 
@@ -394,9 +388,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
   };
 
   std::vector OptsWithMarshalling;
-  for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
-const Record &R = *Opts[I];
-
+  for (const Record &R : llvm::make_pointee_range(Opts)) {
 // Start a single option entry.
 OS << "OPTION(";
 WriteOptRecordFields(OS, R);
@@ -462,8 +454,7 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
   OS << "#ifdef OPTTABLE_ARG_INIT\n";
   OS << "//\n";
   OS << "// Option Values\n\n";
-  for (unsigned I = 0, E = Opts.size(); I != E; ++I) {
-const Record &R = *Opts[I];
+  for (const Record &R : llvm::make_pointee_range(Opts)) {
 if (isa(R.getValueInit("ValuesCode")))
   continue;
 OS << "{\n";



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 164bcbd - [TableGen] NFC: Rename variables in OptParserEmitter

2020-12-21 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-21T12:36:46+01:00
New Revision: 164bcbd40e6d10cd8a01477e2e9029b955fea93b

URL: 
https://github.com/llvm/llvm-project/commit/164bcbd40e6d10cd8a01477e2e9029b955fea93b
DIFF: 
https://github.com/llvm/llvm-project/commit/164bcbd40e6d10cd8a01477e2e9029b955fea93b.diff

LOG: [TableGen] NFC: Rename variables in OptParserEmitter

Switch to the LLVM naming convention.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D93527

Added: 


Modified: 
llvm/utils/TableGen/OptParserEmitter.cpp

Removed: 




diff  --git a/llvm/utils/TableGen/OptParserEmitter.cpp 
b/llvm/utils/TableGen/OptParserEmitter.cpp
index 794485256d50..a08a837e5e70 100644
--- a/llvm/utils/TableGen/OptParserEmitter.cpp
+++ b/llvm/utils/TableGen/OptParserEmitter.cpp
@@ -220,11 +220,11 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream 
&OS) {
   Prefixes.insert(std::make_pair(PrefixKeyT(), "prefix_0"));
   unsigned CurPrefix = 0;
   for (const Record &R : llvm::make_pointee_range(Opts)) {
-std::vector prf = R.getValueAsListOfStrings("Prefixes");
-PrefixKeyT prfkey(prf.begin(), prf.end());
+std::vector RPrefixes = R.getValueAsListOfStrings("Prefixes");
+PrefixKeyT PrefixKey(RPrefixes.begin(), RPrefixes.end());
 unsigned NewPrefix = CurPrefix + 1;
-if (Prefixes.insert(std::make_pair(prfkey, (Twine("prefix_") +
-  Twine(NewPrefix)).str())).second)
+std::string Prefix = (Twine("prefix_") + Twine(NewPrefix)).str();
+if (Prefixes.insert(std::make_pair(PrefixKey, Prefix)).second)
   CurPrefix = NewPrefix;
   }
 
@@ -299,8 +299,8 @@ void EmitOptParser(RecordKeeper &Records, raw_ostream &OS) {
 
   auto WriteOptRecordFields = [&](raw_ostream &OS, const Record &R) {
 // The option prefix;
-std::vector prf = R.getValueAsListOfStrings("Prefixes");
-OS << Prefixes[PrefixKeyT(prf.begin(), prf.end())] << ", ";
+std::vector RPrefixes = R.getValueAsListOfStrings("Prefixes");
+OS << Prefixes[PrefixKeyT(RPrefixes.begin(), RPrefixes.end())] << ", ";
 
 // The option string.
 emitNameUsingSpelling(OS, R);



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 63a2481 - [clang][cli] Implement `getAllArgValues` marshalling

2020-12-22 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-22T14:11:16+01:00
New Revision: 63a24816f561a5d8e28ca7054892bd8602618be4

URL: 
https://github.com/llvm/llvm-project/commit/63a24816f561a5d8e28ca7054892bd8602618be4
DIFF: 
https://github.com/llvm/llvm-project/commit/63a24816f561a5d8e28ca7054892bd8602618be4.diff

LOG: [clang][cli] Implement `getAllArgValues` marshalling

This infrastructure can be used ~30 more command line options.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D93631

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 82c4e9399d9d..3373984b76ae 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1915,7 +1915,8 @@ def fsystem_module : Flag<["-"], "fsystem-module">, 
Flags<[CC1Option]>,
   MarshallingInfoFlag<"FrontendOpts.IsSystemModule">;
 def fmodule_map_file : Joined<["-"], "fmodule-map-file=">,
   Group, Flags<[NoXarchOption,CC1Option]>, MetaVarName<"">,
-  HelpText<"Load this module map file">;
+  HelpText<"Load this module map file">,
+  MarshallingInfoStringVector<"FrontendOpts.ModuleMapFiles">;
 def fmodule_file : Joined<["-"], "fmodule-file=">,
   Group, Flags<[NoXarchOption,CC1Option]>, 
MetaVarName<"[=]">,
   HelpText<"Specify the mapping of module name to precompiled module file, or 
load a module file if name is omitted.">;

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index fc5fd1547599..d7c1a6ffd600 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -323,6 +323,23 @@ static Optional 
normalizeStringIntegral(OptSpecifier Opt, int,
   return Res;
 }
 
+static Optional>
+normalizeStringVector(OptSpecifier Opt, int, const ArgList &Args,
+  DiagnosticsEngine &) {
+  return Args.getAllArgValues(Opt);
+}
+
+static void denormalizeStringVector(SmallVectorImpl &Args,
+const char *Spelling,
+CompilerInvocation::StringAllocator SA,
+Option::OptionClass OptClass,
+unsigned TableIndex,
+const std::vector &Values) {
+  for (const std::string &Value : Values) {
+denormalizeString(Args, Spelling, SA, OptClass, TableIndex, Value);
+  }
+}
+
 static Optional normalizeTriple(OptSpecifier Opt, int TableIndex,
  const ArgList &Args,
  DiagnosticsEngine &Diags) {
@@ -1715,7 +1732,6 @@ 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= form.
   for (const auto *A : Args.filtered(OPT_fmodule_file)) {
 StringRef Val = A->getValue();

diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 71e8d0907fc8..5738f7079171 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -18,6 +18,7 @@ using namespace llvm;
 using namespace clang;
 
 using ::testing::Contains;
+using ::testing::HasSubstr;
 using ::testing::StrEq;
 
 namespace {
@@ -408,6 +409,45 @@ TEST_F(CommandLineTest, JoinedEnumDefault) {
   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({"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(I

[llvm-branch-commits] [clang] bef9eb8 - [clang] NFC: Refactor custom class into a lambda in CompilerInvocation

2020-12-22 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-22T14:45:29+01:00
New Revision: bef9eb84b2fb17b22ca771c8c5c34a85f141168d

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

LOG: [clang] NFC: Refactor custom class into a lambda in CompilerInvocation

Change `makeFlagToValueNormalizer` so that one specialization converts all 
integral/enum arguments into `uint64_t` and forwards them to the more generic 
version.

This makes it easy to replace the custom `FlagToValueNormalizer` struct with a 
lambda, which is the common approach in other (de)normalizers.

Finally, drop custom `is_int_convertbile` in favor of 
`llvm::is_integral_or_enum`.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D93628

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index d7c1a6ffd600..44453ad462c4 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -157,33 +157,26 @@ static void denormalizeSimpleFlag(SmallVectorImpl &Args,
   Args.push_back(Spelling);
 }
 
-namespace {
-template  struct FlagToValueNormalizer {
-  T Value;
+template  static constexpr bool is_uint64_t_convertible() {
+  return !std::is_same::value &&
+ llvm::is_integral_or_enum::value;
+}
 
-  Optional operator()(OptSpecifier Opt, unsigned, const ArgList &Args,
- DiagnosticsEngine &) {
+template (), bool> = false>
+static auto makeFlagToValueNormalizer(T Value) {
+  return [Value](OptSpecifier Opt, unsigned, const ArgList &Args,
+ DiagnosticsEngine &) -> Optional {
 if (Args.hasArg(Opt))
   return Value;
 return None;
-  }
-};
-} // namespace
-
-template  static constexpr bool is_int_convertible() {
-  return sizeof(T) <= sizeof(uint64_t) &&
- std::is_trivially_constructible::value &&
- std::is_trivially_constructible::value;
-}
-
-template (), bool> = false>
-static FlagToValueNormalizer makeFlagToValueNormalizer(T Value) {
-  return FlagToValueNormalizer{Value};
+  };
 }
 
-template (), bool> = false>
-static FlagToValueNormalizer makeFlagToValueNormalizer(T Value) {
-  return FlagToValueNormalizer{std::move(Value)};
+template (), bool> = false>
+static auto makeFlagToValueNormalizer(T Value) {
+  return makeFlagToValueNormalizer(uint64_t(Value));
 }
 
 static auto makeBooleanOptionNormalizer(bool Value, bool OtherValue,



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] a325856 - [clang][cli] Port Target option flags to new option parsing system

2020-11-26 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-11-26T15:32:38+01:00
New Revision: a3258566868b3a16b131e8963932ac21888cb90b

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

LOG: [clang][cli] Port Target option flags to new option parsing system

Depends on D83697

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D83698

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 88af70116304..0014ced5dca7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -693,7 +693,8 @@ defm gpu_rdc : OptInFFlag<"gpu-rdc",
 def : Flag<["-"], "fcuda-rdc">, Alias;
 def : Flag<["-"], "fno-cuda-rdc">, Alias;
 defm cuda_short_ptr : OptInFFlag<"cuda-short-ptr",
-  "Use 32-bit pointers for accessing const/local/shared address spaces">;
+  "Use 32-bit pointers for accessing const/local/shared address spaces", "", 
"",
+  [], "TargetOpts->NVPTXUseShortPointers">;
 def rocm_path_EQ : Joined<["--"], "rocm-path=">, Group,
   HelpText<"ROCm installation path, used for finding and automatically linking 
required bitcode libraries.">;
 def rocm_device_lib_path_EQ : Joined<["--"], "rocm-device-lib-path=">, 
Group,
@@ -1049,7 +1050,7 @@ def fbracket_depth_EQ : Joined<["-"], "fbracket-depth=">, 
Group, Flags<
 def fsignaling_math : Flag<["-"], "fsignaling-math">, Group;
 def fno_signaling_math : Flag<["-"], "fno-signaling-math">, Group;
 defm jump_tables : OptOutFFlag<"jump-tables", "Use", "Do not use", " jump 
tables for lowering switches">;
-defm force_enable_int128 : OptInFFlag<"force-enable-int128", "Enable", 
"Disable", " support for int128_t type">;
+defm force_enable_int128 : OptInFFlag<"force-enable-int128", "Enable", 
"Disable", " support for int128_t type", [], "TargetOpts->ForceEnableInt128">;
 defm keep_static_consts : OptInFFlag<"keep-static-consts", "Keep", "Don't 
keep", " static const variables if unused", [NoXarchOption]>;
 defm fixed_point : OptInFFlag<"fixed-point", "Enable", "Disable", " fixed 
point types">;
 defm cxx_static_destructors : OptOutFFlag<"c++-static-destructors", "",

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 144bbe84abeb..fb79dea06320 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3753,9 +3753,6 @@ static void ParseTargetArgs(TargetOptions &Opts, ArgList 
&Args,
   Opts.LinkerVersion =
   std::string(Args.getLastArgValue(OPT_target_linker_version));
   Opts.OpenCLExtensionsAsWritten = Args.getAllArgValues(OPT_cl_ext_EQ);
-  Opts.ForceEnableInt128 = Args.hasArg(OPT_fforce_enable_int128);
-  Opts.NVPTXUseShortPointers = Args.hasFlag(
-  options::OPT_fcuda_short_ptr, options::OPT_fno_cuda_short_ptr, false);
   Opts.AllowAMDGPUUnsafeFPAtomics =
   Args.hasFlag(options::OPT_munsafe_fp_atomics,
options::OPT_mno_unsafe_fp_atomics, false);



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 9738436 - [clang][cli] Factor out call to EXTRACTOR in generateCC1CommandLine (NFC)

2020-12-01 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-01T09:24:04+01:00
New Revision: 973843681b9df4ba9303e98f7b4531ba31c2b1bf

URL: 
https://github.com/llvm/llvm-project/commit/973843681b9df4ba9303e98f7b4531ba31c2b1bf
DIFF: 
https://github.com/llvm/llvm-project/commit/973843681b9df4ba9303e98f7b4531ba31c2b1bf.diff

LOG: [clang][cli] Factor out call to EXTRACTOR in generateCC1CommandLine (NFC)

Reviewed By: Bigcheese, dexonsmith

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D83211

Added: 


Modified: 
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index a2dec66692bb..35cd1a4f949e 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4062,13 +4062,17 @@ std::string CompilerInvocation::getModuleHash() const {
 
 void CompilerInvocation::generateCC1CommandLine(
 SmallVectorImpl &Args, StringAllocator SA) const {
+  // Capture the extracted value as a lambda argument to avoid potential issues
+  // with lifetime extension of the reference.
 #define OPTION_WITH_MARSHALLING(   
\
 PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,
\
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  
\
 NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)  
\
-  if (((FLAGS) & options::CC1Option) &&
\
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != (DEFAULT_VALUE))) {  
\
-DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, EXTRACTOR(this->KEYPATH));   
\
+  if ((FLAGS)&options::CC1Option) {
\
+[&](const auto &Extracted) {   
\
+  if (ALWAYS_EMIT || Extracted != (DEFAULT_VALUE)) 
\
+DENORMALIZER(Args, SPELLING, SA, TABLE_INDEX, Extracted);  
\
+}(EXTRACTOR(this->KEYPATH));   
\
   }
 
 #define OPTION_WITH_MARSHALLING_BOOLEAN(   
\
@@ -4076,10 +4080,10 @@ void CompilerInvocation::generateCC1CommandLine(
 HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  
\
 NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX, NEG_ID,  
\
 NEG_SPELLING)  
\
-  if (((FLAGS)&options::CC1Option) &&  
\
-  (ALWAYS_EMIT || EXTRACTOR(this->KEYPATH) != DEFAULT_VALUE)) {
\
-DENORMALIZER(Args, SPELLING, NEG_SPELLING, SA, TABLE_INDEX,
\
- EXTRACTOR(this->KEYPATH));
\
+  if ((FLAGS)&options::CC1Option) {
\
+bool Extracted = EXTRACTOR(this->KEYPATH); 
\
+if (ALWAYS_EMIT || Extracted != (DEFAULT_VALUE))   
\
+  DENORMALIZER(Args, SPELLING, NEG_SPELLING, SA, TABLE_INDEX, Extracted);  
\
   }
 
 #include "clang/Driver/Options.inc"



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 88ab384 - [clang][cli] Split DefaultAnyOf into a default value and ImpliedByAnyOf

2020-12-01 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-01T09:50:11+01:00
New Revision: 88ab38449b49bf002ed7794d1b81d362aa9f9df2

URL: 
https://github.com/llvm/llvm-project/commit/88ab38449b49bf002ed7794d1b81d362aa9f9df2
DIFF: 
https://github.com/llvm/llvm-project/commit/88ab38449b49bf002ed7794d1b81d362aa9f9df2.diff

LOG: [clang][cli] Split DefaultAnyOf into a default value and ImpliedByAnyOf

This makes the options API composable, allows boolean flags to imply 
non-boolean values and makes the code more logical (IMO).

Differential Revision: https://reviews.llvm.org/D91861

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
clang/unittests/Frontend/CompilerInvocationTest.cpp
llvm/include/llvm/Option/OptParser.td
llvm/unittests/Option/OptionMarshallingTest.cpp
llvm/unittests/Option/Opts.td
llvm/utils/TableGen/OptParserEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 48d9607e734a..09c02989a6a8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -246,10 +246,11 @@ def clang_ignored_gcc_optimization_f_Group : OptionGroup<
 // This is useful if the option is usually disabled.
 multiclass OptInFFlag flags=[], code 
keypath="",
-  DefaultAnyOf defaults = DefaultAnyOf<[]>> {
+  list enablers = []> {
   def f#NAME : Flag<["-"], "f"#name>, Flags,
Group, HelpText,
-   MarshallingInfoFlag;
+   MarshallingInfoFlag,
+   ImpliedByAnyOf;
   def fno_#NAME : Flag<["-"], "fno-"#name>, Flags,
Group, HelpText;
 }
@@ -258,12 +259,13 @@ multiclass OptInFFlag flags=[], code 
keypath="",
-   DefaultAnyOf defaults = DefaultAnyOf<[]>> {
+   list disablers = []> {
   def f#NAME : Flag<["-"], "f"#name>, Flags,
Group, HelpText;
   def fno_#NAME : Flag<["-"], "fno-"#name>, Flags,
Group, HelpText,
-   MarshallingInfoFlag;
+   MarshallingInfoFlag,
+   ImpliedByAnyOf;
 }
 
 multiclass BooleanMarshalledFFlag {
@@ -606,7 +608,8 @@ def cl_fast_relaxed_math : Flag<["-"], 
"cl-fast-relaxed-math">, GroupFastRelaxedMath">;
 def cl_mad_enable : Flag<["-"], "cl-mad-enable">, Group, 
Flags<[CC1Option]>,
   HelpText<"OpenCL only. Allow use of less precise MAD computations in the 
generated binary.">,
-  MarshallingInfoFlag<"CodeGenOpts.LessPreciseFPMAD", 
DefaultAnyOf<[cl_unsafe_math_optimizations, cl_fast_relaxed_math]>>;
+  MarshallingInfoFlag<"CodeGenOpts.LessPreciseFPMAD">,
+  ImpliedByAnyOf<[cl_unsafe_math_optimizations, cl_fast_relaxed_math]>;
 def cl_no_signed_zeros : Flag<["-"], "cl-no-signed-zeros">, 
Group, Flags<[CC1Option]>,
   HelpText<"OpenCL only. Allow use of less precise no signed zeros 
computations in the generated binary.">,
   MarshallingInfoFlag<"LangOpts->CLNoSignedZero">;
@@ -1048,10 +1051,11 @@ def ffp_model_EQ : Joined<["-"], "ffp-model=">, 
Group, Flags<[NoXarchOp
 def ffp_exception_behavior_EQ : Joined<["-"], "ffp-exception-behavior=">, 
Group, Flags<[CC1Option]>,
   HelpText<"Specifies the exception behavior of floating-point operations.">;
 defm fast_math : OptInFFlag<"fast-math", "Allow aggressive, lossy 
floating-point optimizations", "", "", [],
-  "LangOpts->FastMath", DefaultAnyOf<[cl_fast_relaxed_math]>>;
+  "LangOpts->FastMath", [cl_fast_relaxed_math]>;
 def menable_unsafe_fp_math : Flag<["-"], "menable-unsafe-fp-math">, 
Flags<[CC1Option]>,
   HelpText<"Allow unsafe floating-point math optimizations which may decrease 
precision">,
-  MarshallingInfoFlag<"LangOpts->UnsafeFPMath", 
DefaultAnyOf<[cl_unsafe_math_optimizations, ffast_math]>>;
+  MarshallingInfoFlag<"LangOpts->UnsafeFPMath">,
+  ImpliedByAnyOf<[cl_unsafe_math_optimizations, ffast_math]>;
 defm math_errno : OptInFFlag<"math-errno", "Require math functions to indicate 
errors by setting errno">;
 def fbracket_depth_EQ : Joined<["-"], "fbracket-depth=">, Group, 
Flags<[CoreOption]>;
 def fsignaling_math : Flag<["-"], "fsignaling-math">, Group;
@@ -1265,13 +1269,13 @@ def fno_unsafe_math_optimizations : Flag<["-"], 
"fno-unsafe-math-optimizations">
 def fassociative_math : Flag<["-"], "fassociative-math">, Group;
 def fno_associative_math : Flag<["-"], "fno-associative-math">, Group;
 defm reciprocal_math : OptInFFlag<"reciprocal-math", "Allow division 
operations to be reassociated", "", "", [],
-  "LangOpts->AllowRecip", DefaultAnyOf<[menable_unsafe_fp_math]>>;
+  "LangOpts->AllowRecip", [menable_unsafe_fp_math]>;
 def fapprox_func : Flag<["-"], "fapprox-func">, Group, 
Flags<[CC1Option, NoDriverOption]>,
-  MarshallingInfoFlag<"LangOpts->ApproxFunc", 
DefaultAnyOf<[menable_unsafe_fp_math]>>;
+  MarshallingInfoFlag<"LangOpts->ApproxFunc">, 
ImpliedByAnyOf<[menable_unsafe_fp_mat

[llvm-branch-commits] [clang] 2b84efa - [clang][cli] Port Frontend option flags to new option parsing system

2020-12-01 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-01T10:02:08+01:00
New Revision: 2b84efa00040410d97aff403788ee5d96b1046e2

URL: 
https://github.com/llvm/llvm-project/commit/2b84efa00040410d97aff403788ee5d96b1046e2
DIFF: 
https://github.com/llvm/llvm-project/commit/2b84efa00040410d97aff403788ee5d96b1046e2.diff

LOG: [clang][cli] Port Frontend option flags to new option parsing system

Depends on D91861.

Reviewed By: dexonsmith

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D83697

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 09c02989a6a8..a8ab5cc2494c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -335,8 +335,8 @@ def ccc_arcmt_migrate : Separate<["-"], 
"ccc-arcmt-migrate">, InternalDriverOpt,
 def arcmt_migrate_report_output : Separate<["-"], 
"arcmt-migrate-report-output">,
   HelpText<"Output path for the plist report">,  Flags<[CC1Option]>;
 def arcmt_migrate_emit_arc_errors : Flag<["-"], "arcmt-migrate-emit-errors">,
-  HelpText<"Emit ARC errors even if the migrator can fix them">,
-  Flags<[CC1Option]>;
+  HelpText<"Emit ARC errors even if the migrator can fix them">, 
Flags<[CC1Option]>,
+  MarshallingInfoFlag<"FrontendOpts.ARCMTMigrateEmitARCErrors">;
 def gen_reproducer: Flag<["-"], "gen-reproducer">, InternalDebugOpt,
   HelpText<"Auto-generates preprocessed source files and a reproduction 
script">;
 def gen_cdb_fragment_path: Separate<["-"], "gen-cdb-fragment-path">, 
InternalDebugOpt,
@@ -1577,7 +1577,8 @@ def fmodule_name : Separate<["-"], "fmodule-name">, 
Alias;
 def fmodule_implementation_of : Separate<["-"], "fmodule-implementation-of">,
   Flags<[CC1Option]>, Alias;
 def fsystem_module : Flag<["-"], "fsystem-module">, Flags<[CC1Option]>,
-  HelpText<"Build this module as a system module. Only used with 
-emit-module">;
+  HelpText<"Build this module as a system module. Only used with 
-emit-module">,
+  MarshallingInfoFlag<"FrontendOpts.IsSystemModule">;
 def fmodule_map_file : Joined<["-"], "fmodule-map-file=">,
   Group, Flags<[NoXarchOption,CC1Option]>, MetaVarName<"">,
   HelpText<"Load this module map file">;
@@ -1702,7 +1703,8 @@ def fno_strict_vtable_pointers: Flag<["-"], 
"fno-strict-vtable-pointers">,
 def fno_strict_overflow : Flag<["-"], "fno-strict-overflow">, Group;
 def fno_temp_file : Flag<["-"], "fno-temp-file">, Group,
   Flags<[CC1Option, CoreOption]>, HelpText<
-  "Directly create compilation output files. This may lead to incorrect 
incremental builds if the compiler crashes">;
+  "Directly create compilation output files. This may lead to incorrect 
incremental builds if the compiler crashes">,
+  MarshallingInfoFlag<"FrontendOpts.UseTemporary", "true">, IsNegative;
 def fno_threadsafe_statics : Flag<["-"], "fno-threadsafe-statics">, 
Group,
   Flags<[CC1Option]>, HelpText<"Do not emit code to make initialization of 
local statics thread safe">;
 def fno_use_cxa_atexit : Flag<["-"], "fno-use-cxa-atexit">, Group, 
Flags<[CC1Option]>,
@@ -1990,14 +1992,16 @@ def Wframe_larger_than_EQ : Joined<["-"], 
"Wframe-larger-than=">, Group
 
 def : Flag<["-"], "fterminated-vtables">, Alias;
 def fthreadsafe_statics : Flag<["-"], "fthreadsafe-statics">, Group;
-def ftime_report : Flag<["-"], "ftime-report">, Group, 
Flags<[CC1Option]>;
+def ftime_report : Flag<["-"], "ftime-report">, Group, 
Flags<[CC1Option]>,
+  MarshallingInfoFlag<"FrontendOpts.ShowTimers">;
 def ftime_trace : Flag<["-"], "ftime-trace">, Group,
   HelpText<"Turn on time profiler. Generates JSON file based on output 
filename.">,
   DocBrief<[{
 Turn on time profiler. Generates JSON file based on output filename. Results
 can be analyzed with chrome://tracing or `Speedscope App
 `_ for flamegraph visualization.}]>,
-  Flags<[CC1Option, CoreOption]>;
+  Flags<[CC1Option, CoreOption]>,
+  MarshallingInfoFlag<"FrontendOpts.TimeTrace">;
 def ftime_trace_granularity_EQ : Joined<["-"], "ftime-trace-granularity=">, 
Group,
   HelpText<"Minimum time granularity (in microseconds) traced by time 
profiler">,
   Flags<[CC1Option, CoreOption]>;
@@ -2210,7 +2214,8 @@ def gno_embed_source : Flag<["-"], "gno-embed-source">, 
Group,
 HelpText<"Restore the default behavior of not embedding source text in 
DWARF debug sections">;
 def headerpad__max__install__names : Joined<["-"], 
"headerpad_max_install_names">;
 def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption, FC1Option,
-FlangOption]>, HelpText<"Display available options">;
+FlangOption]>, HelpText<"Display available options">,
+MarshallingInfoFlag<"FrontendOpts.ShowHelp">;
 def ibu

[llvm-branch-commits] [clang] 8e41a68 - [clang][cli] Port DependencyOutput option flags to new option parsing system

2020-12-01 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-01T10:36:12+01:00
New Revision: 8e41a688a5b1000b51c61b9d103545791c54af17

URL: 
https://github.com/llvm/llvm-project/commit/8e41a688a5b1000b51c61b9d103545791c54af17
DIFF: 
https://github.com/llvm/llvm-project/commit/8e41a688a5b1000b51c61b9d103545791c54af17.diff

LOG: [clang][cli] Port DependencyOutput option flags to new option parsing 
system

Depends on D91861.

Reviewed By: dexonsmith

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D83694

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.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 a8ab5cc2494c..24662f15539d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -429,7 +429,8 @@ def G : JoinedOrSeparate<["-"], "G">, 
Flags<[NoXarchOption]>, Group,
 "into small data section (MIPS / Hexagon)">;
 def G_EQ : Joined<["-"], "G=">, Flags<[NoXarchOption]>, Group, 
Alias;
 def H : Flag<["-"], "H">, Flags<[CC1Option]>, Group,
-HelpText<"Show header includes and nesting depth">;
+HelpText<"Show header includes and nesting depth">,
+MarshallingInfoFlag<"DependencyOutputOpts.ShowHeaderIncludes">;
 def I_ : Flag<["-"], "I-">, Group,
 HelpText<"Restrict all prior -I flags to double-quoted inclusion and "
  "remove current directory from include path">;
@@ -455,17 +456,21 @@ def MF : JoinedOrSeparate<["-"], "MF">, Group,
 HelpText<"Write depfile output from -MMD, -MD, -MM, or -M to ">,
 MetaVarName<"">;
 def MG : Flag<["-"], "MG">, Group, Flags<[CC1Option]>,
-HelpText<"Add missing headers to depfile">;
+HelpText<"Add missing headers to depfile">,
+MarshallingInfoFlag<"DependencyOutputOpts.AddMissingHeaderDeps">;
 def MJ : JoinedOrSeparate<["-"], "MJ">, Group,
 HelpText<"Write a compilation database entry per input">;
 def MP : Flag<["-"], "MP">, Group, Flags<[CC1Option]>,
-HelpText<"Create phony target for each dependency (other than main file)">;
+HelpText<"Create phony target for each dependency (other than main file)">,
+MarshallingInfoFlag<"DependencyOutputOpts.UsePhonyTargets">;
 def MQ : JoinedOrSeparate<["-"], "MQ">, Group, Flags<[CC1Option]>,
 HelpText<"Specify name of main file output to quote in depfile">;
 def MT : JoinedOrSeparate<["-"], "MT">, Group, Flags<[CC1Option]>,
 HelpText<"Specify name of main file output in depfile">;
 def MV : Flag<["-"], "MV">, Group, Flags<[CC1Option]>,
-HelpText<"Use NMake/Jom format for the depfile">;
+HelpText<"Use NMake/Jom format for the depfile">,
+MarshallingInfoFlag<"DependencyOutputOpts.OutputFormat", 
"DependencyOutputFormat::Make">,
+Normalizer<"makeFlagToValueNormalizer(DependencyOutputFormat::NMake)">;
 def Mach : Flag<["-"], "Mach">, Group;
 def O0 : Flag<["-"], "O0">, Group, Flags<[CC1Option, HelpHidden]>;
 def O4 : Flag<["-"], "O4">, Group, Flags<[CC1Option, HelpHidden]>;

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index f23d1e398a4a..761f9ebd2381 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -144,20 +144,44 @@ static Optional 
normalizeSimpleNegativeFlag(OptSpecifier Opt, unsigned,
   return None;
 }
 
-void denormalizeSimpleFlag(SmallVectorImpl &Args,
-   const char *Spelling,
-   CompilerInvocation::StringAllocator SA,
-   unsigned TableIndex, unsigned Value) {
+/// The tblgen-erated code passes in a fifth parameter of an arbitrary type, 
but
+/// denormalizeSimpleFlags never looks at it. Avoid bloating compile-time with
+/// unnecessary template instantiations and just ignore it with a variadic
+/// argument.
+static void denormalizeSimpleFlag(SmallVectorImpl &Args,
+  const char *Spelling,
+  CompilerInvocation::StringAllocator, 
unsigned,
+  /*T*/...) {
   Args.push_back(Spelling);
 }
 
-template 
-static llvm::Optional
-normalizeFlagToValue(OptSpecifier Opt, unsigned TableIndex, const ArgList 
&Args,
- DiagnosticsEngine &Diags) {
-  if (Args.hasArg(Opt))
-return Value;
-  return None;
+namespace {
+template  struct FlagToValueNormalizer {
+  T Value;
+
+  Optional operator()(OptSpecifier Opt, unsigned, const ArgList &Args,
+ DiagnosticsEngine &) {
+if (Args.hasArg(Opt))
+  return Value;
+return None;
+  }
+};
+} // namespace
+
+template  static constexpr bool is_int_convertible() {
+  return sizeof(T) <= sizeof(uint64_t) &&
+ std::is_trivially_constructible::value &&
+ std::is_trivially_constr

[llvm-branch-commits] [clang] 398b729 - [clang][cli] Port HeaderSearch option flags to new option parsing system

2020-12-01 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-01T10:52:00+01:00
New Revision: 398b729243b12bdfbc7a75b46d39b547545cbd2d

URL: 
https://github.com/llvm/llvm-project/commit/398b729243b12bdfbc7a75b46d39b547545cbd2d
DIFF: 
https://github.com/llvm/llvm-project/commit/398b729243b12bdfbc7a75b46d39b547545cbd2d.diff

LOG: [clang][cli] Port HeaderSearch option flags to new option parsing system

Depends on D83697.

Reviewed By: dexonsmith

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D83940

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 24662f15539d..48d0e2d6235b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1501,11 +1501,9 @@ def fmodules_user_build_path : Separate<["-"], 
"fmodules-user-build-path">, Grou
 def fprebuilt_module_path : Joined<["-"], "fprebuilt-module-path=">, 
Group,
   Flags<[NoXarchOption, CC1Option]>, MetaVarName<"">,
   HelpText<"Specify the prebuilt module path">;
-def fprebuilt_implicit_modules : Flag<["-"], "fprebuilt-implicit-modules">, 
Group,
-  Flags<[NoXarchOption, CC1Option]>,
-  HelpText<"Look up implicit modules in the prebuilt module path">;
-def fno_prebuilt_implicit_modules : Flag<["-"], 
"fno_prebuilt-implicit-modules">, Group,
-  Flags<[NoXarchOption, CC1Option]>;
+defm prebuilt_implicit_modules : OptInFFlag<"prebuilt-implicit-modules",
+  "Look up implicit modules in the prebuilt module path", "", "",
+  [NoXarchOption, CC1Option], 
"HeaderSearchOpts->EnablePrebuiltImplicitModules">;
 def fmodules_prune_interval : Joined<["-"], "fmodules-prune-interval=">, 
Group,
   Flags<[CC1Option]>, MetaVarName<"">,
   HelpText<"Specify the interval (in seconds) between attempts to prune the 
module cache">;
@@ -1524,13 +1522,17 @@ def fbuild_session_file : Joined<["-"], 
"fbuild-session-file=">,
 def fmodules_validate_once_per_build_session : Flag<["-"], 
"fmodules-validate-once-per-build-session">,
   Group, Flags<[CC1Option]>,
   HelpText<"Don't verify input files for the modules if the module has been "
-   "successfully validated or loaded during this build session">;
+   "successfully validated or loaded during this build session">,
+  MarshallingInfoFlag<"HeaderSearchOpts->ModulesValidateOncePerBuildSession">;
 def fmodules_disable_diagnostic_validation : Flag<["-"], 
"fmodules-disable-diagnostic-validation">,
   Group, Flags<[CC1Option]>,
-  HelpText<"Disable validation of the diagnostic options when loading the 
module">;
+  HelpText<"Disable validation of the diagnostic options when loading the 
module">,
+  MarshallingInfoFlag<"HeaderSearchOpts->ModulesValidateDiagnosticOptions", 
"true">, IsNegative;
+// todo: simplify these into a version of OptInFFlag that accepts 
diff erent flags for each record and does not imply group
 def fmodules_validate_system_headers : Flag<["-"], 
"fmodules-validate-system-headers">,
   Group, Flags<[CC1Option]>,
-  HelpText<"Validate the system headers that a module depends on when loading 
the module">;
+  HelpText<"Validate the system headers that a module depends on when loading 
the module">,
+  MarshallingInfoFlag<"HeaderSearchOpts->ModulesValidateSystemHeaders">;
 def fno_modules_validate_system_headers : Flag<["-"], 
"fno-modules-validate-system-headers">,
   Group, Flags<[NoXarchOption]>;
 
@@ -1539,7 +1541,8 @@ def fvalidate_ast_input_files_content:
   Group, Flags<[CC1Option]>,
   HelpText<"Compute and store the hash of input files used to build an AST."
" Files with mismatching mtime's are considered valid"
-   " if both contents is identical">;
+   " if both contents is identical">,
+  MarshallingInfoFlag<"HeaderSearchOpts->ValidateASTInputFilesContent">;
 def fmodules_validate_input_files_content:
   Flag <["-"], "fmodules-validate-input-files-content">,
   Group, Flags<[NoXarchOption]>,
@@ -1571,7 +1574,8 @@ def fmodules : Flag <["-"], "fmodules">, Group,
   HelpText<"Enable the 'modules' language feature">;
 def fimplicit_module_maps : Flag <["-"], "fimplicit-module-maps">, 
Group,
   Flags<[NoXarchOption, CC1Option]>,
-  HelpText<"Implicitly search the file system for module map files.">;
+  HelpText<"Implicitly search the file system for module map files.">,
+  MarshallingInfoFlag<"HeaderSearchOpts->ImplicitModuleMaps">;
 def fmodules_ts : Flag <["-"], "fmodules-ts">, Group,
   Flags<[CC1Option]>, HelpText<"Enable support for the C++ Modules TS">;
 def fmodule_maps : Flag <["-"], "fmodule-maps">, Alias;
@@ -2888,7 +2892,8 @@ def no_integrated_cpp : Flag<["-", "--"], 
"no-integrated-cpp">, Flags<[NoXarchOp
 def no_pedantic : Flag<["-", "--"], "no-pedantic">, Group;
 def no__dead__strip__inits__and__terms : Flag<["-"], 
"no_dead_strip_inits_and_terms">;

[llvm-branch-commits] [llvm] 083e035 - [clang][cli] Unify boolean marshalling

2020-12-08 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-08T13:47:30+01:00
New Revision: 083e035c47f6c73084ecf5ab7f41cddca19ce332

URL: 
https://github.com/llvm/llvm-project/commit/083e035c47f6c73084ecf5ab7f41cddca19ce332
DIFF: 
https://github.com/llvm/llvm-project/commit/083e035c47f6c73084ecf5ab7f41cddca19ce332.diff

LOG: [clang][cli] Unify boolean marshalling

Use lambdas with captures to replace the redundant infrastructure for 
marshalling of two boolean flags that control the same keypath.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D92773

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp
llvm/include/llvm/Option/OptParser.td
llvm/utils/TableGen/OptParserEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c6159f50b781..794aa24f997d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -271,7 +271,7 @@ multiclass OptOutFFlag {
   def fno_#NAME : Flag<["-"], "fno-"#name>, HelpText;
   def f#NAME : Flag<["-"], "f"#name>, HelpText,
-MarshallingInfoBooleanFlag("fno_"#NAME)>;
+MarshallingInfoBooleanFlag;
 }
 
 /

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index e31f6aa34b36..547dadd37931 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -185,25 +185,21 @@ static FlagToValueNormalizer 
makeFlagToValueNormalizer(T Value) {
   return FlagToValueNormalizer{std::move(Value)};
 }
 
-static Optional normalizeBooleanFlag(OptSpecifier PosOpt,
-   OptSpecifier NegOpt,
-   unsigned TableIndex,
-   const ArgList &Args,
-   DiagnosticsEngine &Diags) {
-  if (const Arg *A = Args.getLastArg(PosOpt, NegOpt))
-return A->getOption().matches(PosOpt);
-  return None;
+static auto makeBooleanFlagNormalizer(OptSpecifier NegOpt) {
+  return [NegOpt](OptSpecifier PosOpt, unsigned, const ArgList &Args,
+  DiagnosticsEngine &) -> Optional {
+if (const Arg *A = Args.getLastArg(PosOpt, NegOpt))
+  return A->getOption().matches(PosOpt);
+return None;
+  };
 }
 
-static void denormalizeBooleanFlag(SmallVectorImpl &Args,
-   const char *Spelling,
-   const char *NegSpelling,
-   CompilerInvocation::StringAllocator SA,
-   unsigned TableIndex, unsigned Value) {
-  if (Value)
-Args.push_back(Spelling);
-  else
-Args.push_back(NegSpelling);
+static auto makeBooleanFlagDenormalizer(const char *NegSpelling) {
+  return [NegSpelling](
+ SmallVectorImpl &Args, const char *PosSpelling,
+ CompilerInvocation::StringAllocator, unsigned, unsigned Value) {
+Args.push_back(Value ? PosSpelling : NegSpelling);
+  };
 }
 
 static Optional
@@ -3779,23 +3775,7 @@ bool CompilerInvocation::parseSimpleArgs(const ArgList 
&Args,
   this->KEYPATH, static_castKEYPATH)>(*MaybeValue));   
\
   }
 
-#define OPTION_WITH_MARSHALLING_BOOLEAN(   
\
-PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,
\
-HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  
\
-IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, 
\
-TABLE_INDEX, NEG_ID, NEG_SPELLING) 
\
-  {
\
-this->KEYPATH = MERGER(this->KEYPATH, DEFAULT_VALUE);  
\
-if (IMPLIED_CHECK) 
\
-  this->KEYPATH = MERGER(this->KEYPATH, IMPLIED_VALUE);
\
-if (auto MaybeValue =  
\
-NORMALIZER(OPT_##ID, OPT_##NEG_ID, TABLE_INDEX, Args, Diags))  
\
-  this->KEYPATH = MERGER(  
\
-  this->KEYPATH, static_castKEYPATH)>(*MaybeValue));   
\
-  }
-
 #include "clang/Driver/Options.inc"
-#undef OPTION_WITH_MARSHALLING_BOOLEAN
 #undef OPTION_WITH_MARSHALLING
   return true;
 }
@@ -4060,20 +4040,7 @@ void CompilerInvocation::generateCC1CommandLine(
 }(EXTRACTOR(this->KEYPATH));   
\
   }
 
-#define OPTION_WITH_MARSHALLING_BOOLEAN(   
\
-PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,
\
-HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,  
\
-IMPLIED_CHECK, IMPLIED_

[llvm-branch-commits] [clang] cf2bb22 - [clang][cli] CompilerInvocationTest: join two test fixtures into one

2020-12-09 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-09T08:58:45+01:00
New Revision: cf2bb2239252c0e1970e646308ae6fb552fcb002

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

LOG: [clang][cli] CompilerInvocationTest: join two test fixtures into one

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D92825

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index cad27749c38e..0394308e8015 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -22,29 +22,22 @@ using ::testing::StrEq;
 using ::testing::StrNe;
 
 namespace {
-struct OptsPopulationTest : public ::testing::Test {
-  IntrusiveRefCntPtr Diags;
-  CompilerInvocation CInvok;
-
-  OptsPopulationTest()
-  : Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions())) {}
-};
-
-class CC1CommandLineGenerationTest : public ::testing::Test {
+class CommandLineTest : public ::testing::Test {
 public:
   IntrusiveRefCntPtr Diags;
   SmallVector GeneratedArgs;
   SmallVector GeneratedArgsStorage;
+  CompilerInvocation CInvok;
 
   const char *operator()(const Twine &Arg) {
 return GeneratedArgsStorage.emplace_back(Arg.str()).c_str();
   }
 
-  CC1CommandLineGenerationTest()
+  CommandLineTest()
   : Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions())) {}
 };
 
-TEST_F(OptsPopulationTest, OptIsInitializedWithCustomDefaultValue) {
+TEST_F(CommandLineTest, OptIsInitializedWithCustomDefaultValue) {
   const char *Args[] = {"clang", "-xc++"};
 
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
@@ -52,7 +45,7 @@ TEST_F(OptsPopulationTest, 
OptIsInitializedWithCustomDefaultValue) {
   ASSERT_TRUE(CInvok.getFrontendOpts().UseTemporary);
 }
 
-TEST_F(OptsPopulationTest, OptOfNegativeFlagIsPopulatedWithFalse) {
+TEST_F(CommandLineTest, OptOfNegativeFlagIsPopulatedWithFalse) {
   const char *Args[] = {"clang", "-xc++", "-fno-temp-file"};
 
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
@@ -60,7 +53,7 @@ TEST_F(OptsPopulationTest, 
OptOfNegativeFlagIsPopulatedWithFalse) {
   ASSERT_FALSE(CInvok.getFrontendOpts().UseTemporary);
 }
 
-TEST_F(OptsPopulationTest, OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
+TEST_F(CommandLineTest, OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
   const char *Args[] = {"clang", "-xc++", "-cl-unsafe-math-optimizations"};
 
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
@@ -76,10 +69,9 @@ TEST_F(OptsPopulationTest, 
OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
   ASSERT_TRUE(CInvok.getLangOpts()->AllowRecip);
 }
 
-TEST_F(CC1CommandLineGenerationTest, CanGenerateCC1CommandLineFlag) {
+TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) {
   const char *Args[] = {"clang", "-xc++", "-fmodules-strict-context-hash", 
"-"};
 
-  CompilerInvocation CInvok;
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
 
   CInvok.generateCC1CommandLine(GeneratedArgs, *this);
@@ -87,11 +79,10 @@ TEST_F(CC1CommandLineGenerationTest, 
CanGenerateCC1CommandLineFlag) {
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fmodules-strict-context-hash")));
 }
 
-TEST_F(CC1CommandLineGenerationTest, CanGenerateCC1CommandLineSeparate) {
+TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparate) {
   const char *TripleCStr = "i686-apple-darwin9";
   const char *Args[] = {"clang", "-xc++", "-triple", TripleCStr, "-"};
 
-  CompilerInvocation CInvok;
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
 
   CInvok.generateCC1CommandLine(GeneratedArgs, *this);
@@ -99,14 +90,12 @@ TEST_F(CC1CommandLineGenerationTest, 
CanGenerateCC1CommandLineSeparate) {
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(TripleCStr)));
 }
 
-TEST_F(CC1CommandLineGenerationTest,
-   CanGenerateCC1CommandLineSeparateRequiredPresent) {
+TEST_F(CommandLineTest,  CanGenerateCC1CommandLineSeparateRequiredPresent) {
   const std::string DefaultTriple =
   llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple());
   const char *Args[] = {"clang", "-xc++", "-triple", DefaultTriple.c_str(),
 "-"};
 
-  CompilerInvocation CInvok;
   CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
 
   CInvok.generateCC1CommandLine(GeneratedArgs, *this);
@@ -115,13 +104,11 @@ TEST_F(CC1CommandLineGenerationTest,
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(DefaultTriple.c_str(;
 }
 
-TEST_F(CC1CommandLineGenerationTest,
-   CanGenerateCC1CommandLineSeparateRequiredAbsent) {
+TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateRequiredAbsent) {
   const std::string DefaultTriple =
   llvm::Triple::normalize(

[llvm-branch-commits] [clang] f825ec8 - [clang][cli] CompilerInvocationTest: rename member variable in fixture

2020-12-09 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-09T08:58:45+01:00
New Revision: f825ec86e14b1369a9edf382d65259351eae679e

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

LOG: [clang][cli] CompilerInvocationTest: rename member variable in fixture

Depends on D92825.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D92826

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 0394308e8015..69a807056f29 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -27,7 +27,7 @@ class CommandLineTest : public ::testing::Test {
   IntrusiveRefCntPtr Diags;
   SmallVector GeneratedArgs;
   SmallVector GeneratedArgsStorage;
-  CompilerInvocation CInvok;
+  CompilerInvocation Invocation;
 
   const char *operator()(const Twine &Arg) {
 return GeneratedArgsStorage.emplace_back(Arg.str()).c_str();
@@ -40,41 +40,41 @@ class CommandLineTest : public ::testing::Test {
 TEST_F(CommandLineTest, OptIsInitializedWithCustomDefaultValue) {
   const char *Args[] = {"clang", "-xc++"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  ASSERT_TRUE(CInvok.getFrontendOpts().UseTemporary);
+  ASSERT_TRUE(Invocation.getFrontendOpts().UseTemporary);
 }
 
 TEST_F(CommandLineTest, OptOfNegativeFlagIsPopulatedWithFalse) {
   const char *Args[] = {"clang", "-xc++", "-fno-temp-file"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  ASSERT_FALSE(CInvok.getFrontendOpts().UseTemporary);
+  ASSERT_FALSE(Invocation.getFrontendOpts().UseTemporary);
 }
 
 TEST_F(CommandLineTest, OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
   const char *Args[] = {"clang", "-xc++", "-cl-unsafe-math-optimizations"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
   // Explicitly provided flag.
-  ASSERT_TRUE(CInvok.getLangOpts()->CLUnsafeMath);
+  ASSERT_TRUE(Invocation.getLangOpts()->CLUnsafeMath);
 
   // Flags directly implied by explicitly provided flag.
-  ASSERT_TRUE(CInvok.getCodeGenOpts().LessPreciseFPMAD);
-  ASSERT_TRUE(CInvok.getLangOpts()->UnsafeFPMath);
+  ASSERT_TRUE(Invocation.getCodeGenOpts().LessPreciseFPMAD);
+  ASSERT_TRUE(Invocation.getLangOpts()->UnsafeFPMath);
 
   // Flag transitively implied by explicitly provided flag.
-  ASSERT_TRUE(CInvok.getLangOpts()->AllowRecip);
+  ASSERT_TRUE(Invocation.getLangOpts()->AllowRecip);
 }
 
 TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) {
   const char *Args[] = {"clang", "-xc++", "-fmodules-strict-context-hash", 
"-"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  CInvok.generateCC1CommandLine(GeneratedArgs, *this);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fmodules-strict-context-hash")));
 }
@@ -83,9 +83,9 @@ TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparate) {
   const char *TripleCStr = "i686-apple-darwin9";
   const char *Args[] = {"clang", "-xc++", "-triple", TripleCStr, "-"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  CInvok.generateCC1CommandLine(GeneratedArgs, *this);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(TripleCStr)));
 }
@@ -96,9 +96,9 @@ TEST_F(CommandLineTest,  
CanGenerateCC1CommandLineSeparateRequiredPresent) {
   const char *Args[] = {"clang", "-xc++", "-triple", DefaultTriple.c_str(),
 "-"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  CInvok.generateCC1CommandLine(GeneratedArgs, *this);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   // Triple should always be emitted even if it is the default
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(DefaultTriple.c_str(;
@@ -109,9 +109,9 @@ TEST_F(CommandLineTest, 
CanGenerateCC1CommandLineSeparateRequiredAbsent) {
   llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple());
   const char *Args[] = {"clang", "-xc++", "-"};
 
-  CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  CInvok.generateCC1CommandLine(GeneratedArgs, *this);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
  

[llvm-branch-commits] [clang] 5afff86 - [clang][cli] CompilerInvocationTest: split enum test into two

2020-12-09 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-09T08:58:45+01:00
New Revision: 5afff86d26163bc3ba93fb299ccfc2522d3fdc94

URL: 
https://github.com/llvm/llvm-project/commit/5afff86d26163bc3ba93fb299ccfc2522d3fdc94
DIFF: 
https://github.com/llvm/llvm-project/commit/5afff86d26163bc3ba93fb299ccfc2522d3fdc94.diff

LOG: [clang][cli] CompilerInvocationTest: split enum test into two

Depends on D92826.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D92827

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 69a807056f29..39929b8fc032 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -17,9 +17,7 @@ using namespace llvm;
 using namespace clang;
 
 using ::testing::Contains;
-using ::testing::Each;
 using ::testing::StrEq;
-using ::testing::StrNe;
 
 namespace {
 class CommandLineTest : public ::testing::Test {
@@ -117,27 +115,26 @@ TEST_F(CommandLineTest, 
CanGenerateCC1CommandLineSeparateRequiredAbsent) {
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(DefaultTriple.c_str(;
 }
 
-TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateEnum) {
-  const char *RelocationModelCStr = "static";
-  const char *Args[] = {"clang", "-xc++", "-mrelocation-model",
-RelocationModelCStr, "-"};
+TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateEnumNonDefault) {
+  const char *Args[] = {"clang", "-xc++", "-mrelocation-model", "static", "-"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
-  // Non default relocation model
-  ASSERT_THAT(GeneratedArgs, Contains(StrEq(RelocationModelCStr)));
-  GeneratedArgs.clear();
+  // Non default relocation model.
+  ASSERT_THAT(GeneratedArgs, Contains(StrEq("static")));
+}
+
+TEST_F(CommandLineTest, CanGenerateCC1COmmandLineSeparateEnumDefault) {
+  const char *Args[] = {"clang", "-xc++", "-mrelocation-model", "pic", "-"};
 
-  RelocationModelCStr = "pic";
-  Args[3] = RelocationModelCStr;
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  CompilerInvocation Invocation2;
-  CompilerInvocation::CreateFromArgs(Invocation2, Args, *Diags);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
-  Invocation2.generateCC1CommandLine(GeneratedArgs, *this);
-  ASSERT_THAT(GeneratedArgs, Each(StrNe(RelocationModelCStr)));
+  // Default relocation model.
+  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("pic";
 }
 
 TEST_F(CommandLineTest, NotPresentNegativeFlagNotGenerated) {



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 4894e42 - [clang][cli] CompilerInvocationTest: remove unnecessary command line arguments

2020-12-09 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-09T08:58:45+01:00
New Revision: 4894e423e7b4b121bd4fb23cdba9870ff0f2a6b6

URL: 
https://github.com/llvm/llvm-project/commit/4894e423e7b4b121bd4fb23cdba9870ff0f2a6b6
DIFF: 
https://github.com/llvm/llvm-project/commit/4894e423e7b4b121bd4fb23cdba9870ff0f2a6b6.diff

LOG: [clang][cli] CompilerInvocationTest: remove unnecessary command line 
arguments

Depends on D92827.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D92828

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 39929b8fc032..0eb76a13972c 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -36,7 +36,7 @@ class CommandLineTest : public ::testing::Test {
 };
 
 TEST_F(CommandLineTest, OptIsInitializedWithCustomDefaultValue) {
-  const char *Args[] = {"clang", "-xc++"};
+  const char *Args[] = {""};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -44,7 +44,7 @@ TEST_F(CommandLineTest, 
OptIsInitializedWithCustomDefaultValue) {
 }
 
 TEST_F(CommandLineTest, OptOfNegativeFlagIsPopulatedWithFalse) {
-  const char *Args[] = {"clang", "-xc++", "-fno-temp-file"};
+  const char *Args[] = {"-fno-temp-file"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -52,7 +52,7 @@ TEST_F(CommandLineTest, 
OptOfNegativeFlagIsPopulatedWithFalse) {
 }
 
 TEST_F(CommandLineTest, OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
-  const char *Args[] = {"clang", "-xc++", "-cl-unsafe-math-optimizations"};
+  const char *Args[] = {"-cl-unsafe-math-optimizations"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -68,7 +68,7 @@ TEST_F(CommandLineTest, 
OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
 }
 
 TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) {
-  const char *Args[] = {"clang", "-xc++", "-fmodules-strict-context-hash", 
"-"};
+  const char *Args[] = {"-fmodules-strict-context-hash"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -79,7 +79,7 @@ TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) {
 
 TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparate) {
   const char *TripleCStr = "i686-apple-darwin9";
-  const char *Args[] = {"clang", "-xc++", "-triple", TripleCStr, "-"};
+  const char *Args[] = {"-triple", TripleCStr};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -91,8 +91,7 @@ TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparate) {
 TEST_F(CommandLineTest,  CanGenerateCC1CommandLineSeparateRequiredPresent) {
   const std::string DefaultTriple =
   llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple());
-  const char *Args[] = {"clang", "-xc++", "-triple", DefaultTriple.c_str(),
-"-"};
+  const char *Args[] = {"-triple", DefaultTriple.c_str()};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -105,7 +104,7 @@ TEST_F(CommandLineTest,  
CanGenerateCC1CommandLineSeparateRequiredPresent) {
 TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateRequiredAbsent) {
   const std::string DefaultTriple =
   llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple());
-  const char *Args[] = {"clang", "-xc++", "-"};
+  const char *Args[] = {""};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -116,7 +115,7 @@ TEST_F(CommandLineTest, 
CanGenerateCC1CommandLineSeparateRequiredAbsent) {
 }
 
 TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateEnumNonDefault) {
-  const char *Args[] = {"clang", "-xc++", "-mrelocation-model", "static", "-"};
+  const char *Args[] = {"-mrelocation-model", "static"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -127,7 +126,7 @@ TEST_F(CommandLineTest, 
CanGenerateCC1CommandLineSeparateEnumNonDefault) {
 }
 
 TEST_F(CommandLineTest, CanGenerateCC1COmmandLineSeparateEnumDefault) {
-  const char *Args[] = {"clang", "-xc++", "-mrelocation-model", "pic", "-"};
+  const char *Args[] = {"-mrelocation-model", "pic"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -138,7 +137,7 @@ TEST_F(CommandLineTest, 
CanGenerateCC1COmmandLineSeparateEnumDefault) {
 }
 
 TEST_F(CommandLineTest, NotPresentNegativeFlagNotGenerated) {
-  const char *Args[] = {"clang", "-xc++"};
+  const char *Args[] = {""};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -148,7 +147,7 @@ TEST_F(CommandLineTest, NotPresentNegativeFlagNotGenerated) 
{
 }
 
 TEST_F(CommandLineTest, PresentNegativeFlagGenerated) {
-  const char *Args[] = {"clang", "-xc++", "-fno-temp-file"};
+  const char *Args[] = {"-fno-temp-file"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
@@ -158,7 +157,7 

[llvm-branch-commits] [clang] 03692ba - [clang][cli] CompilerInvocationTest: check arg parsing does not produce diagnostics

2020-12-09 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-09T08:58:45+01:00
New Revision: 03692bae1fc9b6232de7caea3b57ad2f3dc2a9d0

URL: 
https://github.com/llvm/llvm-project/commit/03692bae1fc9b6232de7caea3b57ad2f3dc2a9d0
DIFF: 
https://github.com/llvm/llvm-project/commit/03692bae1fc9b6232de7caea3b57ad2f3dc2a9d0.diff

LOG: [clang][cli] CompilerInvocationTest: check arg parsing does not produce 
diagnostics

Depends on D92828.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D92829

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 0eb76a13972c..7712dd00b191 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -8,6 +8,7 @@
 
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/TextDiagnosticBuffer.h"
 #include "llvm/Support/Host.h"
 
 #include "gmock/gmock.h"
@@ -32,7 +33,9 @@ class CommandLineTest : public ::testing::Test {
   }
 
   CommandLineTest()
-  : Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions())) {}
+  : Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions(),
+  new TextDiagnosticBuffer())) 
{
+  }
 };
 
 TEST_F(CommandLineTest, OptIsInitializedWithCustomDefaultValue) {
@@ -40,6 +43,8 @@ TEST_F(CommandLineTest, 
OptIsInitializedWithCustomDefaultValue) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   ASSERT_TRUE(Invocation.getFrontendOpts().UseTemporary);
 }
 
@@ -48,6 +53,8 @@ TEST_F(CommandLineTest, 
OptOfNegativeFlagIsPopulatedWithFalse) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   ASSERT_FALSE(Invocation.getFrontendOpts().UseTemporary);
 }
 
@@ -56,6 +63,8 @@ TEST_F(CommandLineTest, 
OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   // Explicitly provided flag.
   ASSERT_TRUE(Invocation.getLangOpts()->CLUnsafeMath);
 
@@ -72,6 +81,8 @@ TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fmodules-strict-context-hash")));
@@ -83,6 +94,8 @@ TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparate) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   ASSERT_THAT(GeneratedArgs, Contains(StrEq(TripleCStr)));
@@ -95,6 +108,8 @@ TEST_F(CommandLineTest,  
CanGenerateCC1CommandLineSeparateRequiredPresent) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   // Triple should always be emitted even if it is the default
@@ -108,6 +123,8 @@ TEST_F(CommandLineTest, 
CanGenerateCC1CommandLineSeparateRequiredAbsent) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   // Triple should always be emitted even if it is the default
@@ -119,6 +136,8 @@ TEST_F(CommandLineTest, 
CanGenerateCC1CommandLineSeparateEnumNonDefault) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   // Non default relocation model.
@@ -130,6 +149,8 @@ TEST_F(CommandLineTest, 
CanGenerateCC1COmmandLineSeparateEnumDefault) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   // Default relocation model.
@@ -141,6 +162,8 @@ TEST_F(CommandLineTest, NotPresentNegativeFlagNotGenerated) 
{
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fno-temp-file";
@@ -151,6 +174,8 @@ TEST_F(CommandLineTest, PresentNegativeFlagGenerated) {
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
   ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fno-temp-file")));
@@ -161,

[llvm-branch-commits] [clang] 216d430 - [clang][cli] CompilerInvocationTest: join and add test cases

2020-12-09 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-09T08:58:45+01:00
New Revision: 216d43053b4e7327e5f9eb5705a7c8e4f6ae850b

URL: 
https://github.com/llvm/llvm-project/commit/216d43053b4e7327e5f9eb5705a7c8e4f6ae850b
DIFF: 
https://github.com/llvm/llvm-project/commit/216d43053b4e7327e5f9eb5705a7c8e4f6ae850b.diff

LOG: [clang][cli] CompilerInvocationTest: join and add test cases

Depends on D92829.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D92830

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 7712dd00b191..c3bdd6bff65c 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -38,42 +38,43 @@ class CommandLineTest : public ::testing::Test {
   }
 };
 
-TEST_F(CommandLineTest, OptIsInitializedWithCustomDefaultValue) {
+// Boolean option with a keypath that defaults to true.
+// The only flag with a negative spelling can set the keypath to false.
+
+TEST_F(CommandLineTest, BoolOptionDefaultTrueSingleFlagNotPresent) {
   const char *Args[] = {""};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
   ASSERT_FALSE(Diags->hasErrorOccurred());
-
   ASSERT_TRUE(Invocation.getFrontendOpts().UseTemporary);
+
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
+
+  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fno-temp-file";
 }
 
-TEST_F(CommandLineTest, OptOfNegativeFlagIsPopulatedWithFalse) {
+TEST_F(CommandLineTest, BoolOptionDefaultTrueSingleFlagPresent) {
   const char *Args[] = {"-fno-temp-file"};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
   ASSERT_FALSE(Diags->hasErrorOccurred());
-
   ASSERT_FALSE(Invocation.getFrontendOpts().UseTemporary);
-}
 
-TEST_F(CommandLineTest, OptsOfImpliedPositiveFlagArePopulatedWithTrue) {
-  const char *Args[] = {"-cl-unsafe-math-optimizations"};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
-  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fno-temp-file")));
+}
 
-  // Explicitly provided flag.
-  ASSERT_TRUE(Invocation.getLangOpts()->CLUnsafeMath);
+TEST_F(CommandLineTest, BoolOptionDefaultTrueSingleFlagUnknownPresent) {
+  const char *Args[] = {"-ftemp-file"};
 
-  // Flags directly implied by explicitly provided flag.
-  ASSERT_TRUE(Invocation.getCodeGenOpts().LessPreciseFPMAD);
-  ASSERT_TRUE(Invocation.getLangOpts()->UnsafeFPMath);
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
-  // Flag transitively implied by explicitly provided flag.
-  ASSERT_TRUE(Invocation.getLangOpts()->AllowRecip);
+  // Driver-only flag.
+  ASSERT_TRUE(Diags->hasErrorOccurred());
+  ASSERT_TRUE(Invocation.getFrontendOpts().UseTemporary);
 }
 
 TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) {
@@ -157,75 +158,101 @@ TEST_F(CommandLineTest, 
CanGenerateCC1COmmandLineSeparateEnumDefault) {
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("pic";
 }
 
-TEST_F(CommandLineTest, NotPresentNegativeFlagNotGenerated) {
-  const char *Args[] = {""};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-
-  ASSERT_FALSE(Diags->hasErrorOccurred());
-
-  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
-
-  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fno-temp-file";
-}
-
-TEST_F(CommandLineTest, PresentNegativeFlagGenerated) {
-  const char *Args[] = {"-fno-temp-file"};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-
-  ASSERT_FALSE(Diags->hasErrorOccurred());
-
-  Invocation.generateCC1CommandLine(GeneratedArgs, *this);
-
-  ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fno-temp-file")));
-}
+// Tree of boolean options that can be (directly or transitively) implied by
+// their parent:
+//
+//   * -cl-unsafe-math-optimizations
+// * -cl-mad-enable
+// * -menable-unsafe-fp-math
+//   * -freciprocal-math
 
-TEST_F(CommandLineTest, NotPresentAndNotImpliedNotGenerated) {
+TEST_F(CommandLineTest, ImpliedBoolOptionsNoFlagPresent) {
   const char *Args[] = {""};
 
   CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
 
   ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_FALSE(Invocation.getLangOpts()->CLUnsafeMath);
+  ASSERT_FALSE(Invocation.getCodeGenOpts().LessPreciseFPMAD);
+  ASSERT_FALSE(Invocation.getLangOpts()->UnsafeFPMath);
+  ASSERT_FALSE(Invocation.getLangOpts()->AllowRecip);
 
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
-  // Missing options are not generated.
+  // Not generated - missing.
   ASSERT_THAT(GeneratedArgs,
   Not(Contains(StrEq("-cl-unsafe-math-optimizations";
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-cl-mad-enable";
   ASSE

[llvm-branch-commits] [clang] 35621cc - [clang][cli] CompilerInvocationTest: add tests for boolean options

2020-12-09 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-09T08:58:46+01:00
New Revision: 35621cc2e3b3778abc2bacf37f3b1e9dfac52895

URL: 
https://github.com/llvm/llvm-project/commit/35621cc2e3b3778abc2bacf37f3b1e9dfac52895
DIFF: 
https://github.com/llvm/llvm-project/commit/35621cc2e3b3778abc2bacf37f3b1e9dfac52895.diff

LOG: [clang][cli] CompilerInvocationTest: add tests for boolean options

Add more tests of the command line marshalling infrastructure.

The new tests now make a "round-trip": from arguments, to CompilerInvocation 
instance to arguments again in a single test case.

The TODOs are resolved in a follow-up patch.

Depends on D92830.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D92774

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index c3bdd6bff65c..b0fe11dd8d5b 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -77,6 +77,150 @@ TEST_F(CommandLineTest, 
BoolOptionDefaultTrueSingleFlagUnknownPresent) {
   ASSERT_TRUE(Invocation.getFrontendOpts().UseTemporary);
 }
 
+// Boolean option with a keypath that defaults to true.
+// The flag with negative spelling can set the keypath to false.
+// The flag with positive spelling can reset the keypath to true.
+
+TEST_F(CommandLineTest, BoolOptionDefaultTruePresentNone) {
+  const char *Args[] = {""};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_TRUE(Invocation.getCodeGenOpts().Autolink);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultTruePresentNegChange) {
+  const char *Args[] = {"-fno-autolink"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_FALSE(Invocation.getCodeGenOpts().Autolink);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultTruePresentPosReset) {
+  const char *Args[] = {"-fautolink"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_TRUE(Diags->hasErrorOccurred()); // Driver-only flag.
+  ASSERT_TRUE(Invocation.getCodeGenOpts().Autolink);
+}
+
+// Boolean option with a keypath that defaults to false.
+// The flag with negative spelling can set the keypath to true.
+// The flag with positive spelling can reset the keypath to false.
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNone) {
+  const char *Args[] = {""};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_FALSE(Invocation.getCodeGenOpts().NoInlineLineTables);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNegChange) {
+  const char *Args[] = {"-gno-inline-line-tables"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_TRUE(Invocation.getCodeGenOpts().NoInlineLineTables);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentPosReset) {
+  const char *Args[] = {"-ginline-line-tables"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_TRUE(Diags->hasErrorOccurred()); // Driver-only flag.
+  ASSERT_FALSE(Invocation.getCodeGenOpts().NoInlineLineTables);
+}
+
+// Boolean option with a keypath that defaults to false.
+// The flag with positive spelling can set the keypath to true.
+// The flag with negative spelling can reset the keypath to false.
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNoneX) {
+  const char *Args[] = {""};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_FALSE(Invocation.getCodeGenOpts().CodeViewGHash);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentPosChange) {
+  const char *Args[] = {"-gcodeview-ghash"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_TRUE(Invocation.getCodeGenOpts().CodeViewGHash);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNegReset) {
+  const char *Args[] = {"-gno-codeview-ghash"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_TRUE(Diags->hasErrorOccurred()); // Driver-only flag.
+  ASSERT_FALSE(Invocation.getCodeGenOpts().CodeViewGHash);
+}
+
+// Boolean option with a keypath that defaults to an arbitrary expression.
+// The flag with positive spelling can set the keypath to true.
+// The flag with negative spelling can set the keypath to false.
+
+// NOTE: The following tests need to be updated wh

[llvm-branch-commits] [clang] 13e4e5e - Revert "[clang][cli] CompilerInvocationTest: add tests for boolean options"

2020-12-09 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-09T10:35:07+01:00
New Revision: 13e4e5ed59c92d81ee5fee55f20ecf1842ec8cf3

URL: 
https://github.com/llvm/llvm-project/commit/13e4e5ed59c92d81ee5fee55f20ecf1842ec8cf3
DIFF: 
https://github.com/llvm/llvm-project/commit/13e4e5ed59c92d81ee5fee55f20ecf1842ec8cf3.diff

LOG: Revert "[clang][cli] CompilerInvocationTest: add tests for boolean options"

Differential Revision of original patch: https://reviews.llvm.org/D92774

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index b0fe11dd8d5b..c3bdd6bff65c 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -77,150 +77,6 @@ TEST_F(CommandLineTest, 
BoolOptionDefaultTrueSingleFlagUnknownPresent) {
   ASSERT_TRUE(Invocation.getFrontendOpts().UseTemporary);
 }
 
-// Boolean option with a keypath that defaults to true.
-// The flag with negative spelling can set the keypath to false.
-// The flag with positive spelling can reset the keypath to true.
-
-TEST_F(CommandLineTest, BoolOptionDefaultTruePresentNone) {
-  const char *Args[] = {""};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-  ASSERT_FALSE(Diags->hasErrorOccurred());
-  ASSERT_TRUE(Invocation.getCodeGenOpts().Autolink);
-
-  // TODO: Test argument generation.
-}
-
-TEST_F(CommandLineTest, BoolOptionDefaultTruePresentNegChange) {
-  const char *Args[] = {"-fno-autolink"};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-  ASSERT_FALSE(Diags->hasErrorOccurred());
-  ASSERT_FALSE(Invocation.getCodeGenOpts().Autolink);
-
-  // TODO: Test argument generation.
-}
-
-TEST_F(CommandLineTest, BoolOptionDefaultTruePresentPosReset) {
-  const char *Args[] = {"-fautolink"};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-  ASSERT_TRUE(Diags->hasErrorOccurred()); // Driver-only flag.
-  ASSERT_TRUE(Invocation.getCodeGenOpts().Autolink);
-}
-
-// Boolean option with a keypath that defaults to false.
-// The flag with negative spelling can set the keypath to true.
-// The flag with positive spelling can reset the keypath to false.
-
-TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNone) {
-  const char *Args[] = {""};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-  ASSERT_FALSE(Diags->hasErrorOccurred());
-  ASSERT_FALSE(Invocation.getCodeGenOpts().NoInlineLineTables);
-
-  // TODO: Test argument generation.
-}
-
-TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNegChange) {
-  const char *Args[] = {"-gno-inline-line-tables"};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-  ASSERT_FALSE(Diags->hasErrorOccurred());
-  ASSERT_TRUE(Invocation.getCodeGenOpts().NoInlineLineTables);
-
-  // TODO: Test argument generation.
-}
-
-TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentPosReset) {
-  const char *Args[] = {"-ginline-line-tables"};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-  ASSERT_TRUE(Diags->hasErrorOccurred()); // Driver-only flag.
-  ASSERT_FALSE(Invocation.getCodeGenOpts().NoInlineLineTables);
-}
-
-// Boolean option with a keypath that defaults to false.
-// The flag with positive spelling can set the keypath to true.
-// The flag with negative spelling can reset the keypath to false.
-
-TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNoneX) {
-  const char *Args[] = {""};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-  ASSERT_FALSE(Diags->hasErrorOccurred());
-  ASSERT_FALSE(Invocation.getCodeGenOpts().CodeViewGHash);
-
-  // TODO: Test argument generation.
-}
-
-TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentPosChange) {
-  const char *Args[] = {"-gcodeview-ghash"};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-  ASSERT_FALSE(Diags->hasErrorOccurred());
-  ASSERT_TRUE(Invocation.getCodeGenOpts().CodeViewGHash);
-
-  // TODO: Test argument generation.
-}
-
-TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNegReset) {
-  const char *Args[] = {"-gno-codeview-ghash"};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-  ASSERT_TRUE(Diags->hasErrorOccurred()); // Driver-only flag.
-  ASSERT_FALSE(Invocation.getCodeGenOpts().CodeViewGHash);
-}
-
-// Boolean option with a keypath that defaults to an arbitrary expression.
-// The flag with positive spelling can set the keypath to true.
-// The flag with negative spelling can set the keypath to false.
-
-// NOTE: The following tests need to be updated when we start enabling the new
-// pass manager by default.
-
-TEST_F(CommandLineTest, BoolOptionDefaultArbitraryTwoFlagsPresentNone) {
-  const char *Args = {""};
-
-  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
-
-  ASSERT_FALSE(Diags->hasE

[llvm-branch-commits] [clang] 6f26a6d - Reland "[clang][cli] CompilerInvocationTest: add tests for boolean options"

2020-12-12 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-12T09:46:20+01:00
New Revision: 6f26a6de489e66830c3181b747f6b18e439f36be

URL: 
https://github.com/llvm/llvm-project/commit/6f26a6de489e66830c3181b747f6b18e439f36be
DIFF: 
https://github.com/llvm/llvm-project/commit/6f26a6de489e66830c3181b747f6b18e439f36be.diff

LOG: Reland "[clang][cli] CompilerInvocationTest: add tests for boolean options"

Add more tests of the command line marshalling infrastructure.

The new tests now make a "round-trip": from arguments, to CompilerInvocation 
instance to arguments again in a single test case.

The TODOs are resolved in a follow-up patch.

Depends on D92830.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D92774

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index c3bdd6bff65c..c2dc35ce5d32 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -77,6 +77,155 @@ TEST_F(CommandLineTest, 
BoolOptionDefaultTrueSingleFlagUnknownPresent) {
   ASSERT_TRUE(Invocation.getFrontendOpts().UseTemporary);
 }
 
+// Boolean option with a keypath that defaults to true.
+// The flag with negative spelling can set the keypath to false.
+// The flag with positive spelling can reset the keypath to true.
+
+TEST_F(CommandLineTest, BoolOptionDefaultTruePresentNone) {
+  const char *Args[] = {""};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_TRUE(Invocation.getCodeGenOpts().Autolink);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultTruePresentNegChange) {
+  const char *Args[] = {"-fno-autolink"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_FALSE(Invocation.getCodeGenOpts().Autolink);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultTruePresentPosReset) {
+  const char *Args[] = {"-fautolink"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_TRUE(Diags->hasErrorOccurred()); // Driver-only flag.
+  ASSERT_TRUE(Invocation.getCodeGenOpts().Autolink);
+}
+
+// Boolean option with a keypath that defaults to false.
+// The flag with negative spelling can set the keypath to true.
+// The flag with positive spelling can reset the keypath to false.
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNone) {
+  const char *Args[] = {""};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_FALSE(Invocation.getCodeGenOpts().NoInlineLineTables);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNegChange) {
+  const char *Args[] = {"-gno-inline-line-tables"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_TRUE(Invocation.getCodeGenOpts().NoInlineLineTables);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentPosReset) {
+  const char *Args[] = {"-ginline-line-tables"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_TRUE(Diags->hasErrorOccurred()); // Driver-only flag.
+  ASSERT_FALSE(Invocation.getCodeGenOpts().NoInlineLineTables);
+}
+
+// Boolean option with a keypath that defaults to false.
+// The flag with positive spelling can set the keypath to true.
+// The flag with negative spelling can reset the keypath to false.
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNoneX) {
+  const char *Args[] = {""};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_FALSE(Invocation.getCodeGenOpts().CodeViewGHash);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentPosChange) {
+  const char *Args[] = {"-gcodeview-ghash"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_FALSE(Diags->hasErrorOccurred());
+  ASSERT_TRUE(Invocation.getCodeGenOpts().CodeViewGHash);
+
+  // TODO: Test argument generation.
+}
+
+TEST_F(CommandLineTest, BoolOptionDefaultFalsePresentNegReset) {
+  const char *Args[] = {"-gno-codeview-ghash"};
+
+  CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+  ASSERT_TRUE(Diags->hasErrorOccurred()); // Driver-only flag.
+  ASSERT_FALSE(Invocation.getCodeGenOpts().CodeViewGHash);
+}
+
+// Boolean option with a keypath that defaults to an arbitrary expression.
+// The flag with positive spelling can set the keypath to true.
+// The flag with negative spelling can set the keypath to false.
+
+static constexpr unsigned PassManagerDefa

[llvm-branch-commits] [llvm] 10f4057 - [clang][cli] Don't always emit -f[no-]legacy-pass-manager

2020-12-12 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-12T10:11:23+01:00
New Revision: 10f40576f7b482dc55b9a0ba780c294c4e45817c

URL: 
https://github.com/llvm/llvm-project/commit/10f40576f7b482dc55b9a0ba780c294c4e45817c
DIFF: 
https://github.com/llvm/llvm-project/commit/10f40576f7b482dc55b9a0ba780c294c4e45817c.diff

LOG: [clang][cli] Don't always emit -f[no-]legacy-pass-manager

We don't need to always generate `-f[no-]experimental-new-pass-manager`.

This patch does not change the behavior of any other command line flag. (For 
example `-triple` is still being always generated.)

Reviewed By: dexonsmith, Bigcheese

Differential Revision: https://reviews.llvm.org/D92857

Added: 


Modified: 
clang/unittests/Frontend/CompilerInvocationTest.cpp
llvm/include/llvm/Option/OptParser.td

Removed: 




diff  --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp 
b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index c2dc35ce5d32..d5b5d15b1071 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -198,7 +198,7 @@ TEST_F(CommandLineTest, 
BoolOptionDefaultArbitraryTwoFlagsPresentNone) {
 
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
 
-  ASSERT_THAT(GeneratedArgs, Contains(StrEq(PassManagerResetByFlag)));
+  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq(PassManagerResetByFlag;
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq(PassManagerChangedByFlag;
 }
 
@@ -222,7 +222,7 @@ TEST_F(CommandLineTest, 
BoolOptionDefaultArbitraryTwoFlagsPresentReset) {
   ASSERT_EQ(Invocation.getCodeGenOpts().LegacyPassManager, PassManagerDefault);
 
   Invocation.generateCC1CommandLine(GeneratedArgs, *this);
-  ASSERT_THAT(GeneratedArgs, Contains(StrEq(PassManagerResetByFlag)));
+  ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq(PassManagerResetByFlag;
   ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq(PassManagerChangedByFlag;
 }
 

diff  --git a/llvm/include/llvm/Option/OptParser.td 
b/llvm/include/llvm/Option/OptParser.td
index 9a935b5d9e6e..f08dfd3ccf04 100644
--- a/llvm/include/llvm/Option/OptParser.td
+++ b/llvm/include/llvm/Option/OptParser.td
@@ -173,7 +173,6 @@ class MarshallingInfoBitfieldFlag
 
 class MarshallingInfoBooleanFlag
   : MarshallingInfoFlag {
-  bit ShouldAlwaysEmit = 1;
   code Normalizer = "makeBooleanFlagNormalizer(OPT_"#neg_name#")";
   code Denormalizer = "makeBooleanFlagDenormalizer(\""#neg_spelling#"\")";
 }



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] 6baa976 - [clang][cli] Add flexible TableGen multiclass for boolean options

2020-12-12 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-12T10:53:28+01:00
New Revision: 6baa9769ed573741290fb186d02df7cf676fc8de

URL: 
https://github.com/llvm/llvm-project/commit/6baa9769ed573741290fb186d02df7cf676fc8de
DIFF: 
https://github.com/llvm/llvm-project/commit/6baa9769ed573741290fb186d02df7cf676fc8de.diff

LOG: [clang][cli] Add flexible TableGen multiclass for boolean options

This introduces more flexible multiclass for declaring two flags controlling 
the same boolean keypath.

Compared to existing Opt{In,Out}FFlag multiclasses, the new syntax makes it 
easier to read option declarations and reason about the keypath.

This also makes specifying common properties of both flags possible.

I'm open to suggestions on the class names. Not 100% sure the benefits are 
worth the added complexity.

Depends on D92774.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D92775

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 725afc7e1bb3..86760d0f400e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -268,10 +268,234 @@ multiclass OptOutFFlag;
 }
 
-multiclass BooleanMarshalledFFlag {
-  def fno_#NAME : Flag<["-"], "fno-"#name>, HelpText;
-  def f#NAME : Flag<["-"], "f"#name>, HelpText,
-MarshallingInfoBooleanFlag;
+//===--===//
+// BoolOptionBase
+//===--===//
+
+// Default value of the keypath associated with a marshalled bool option.
+class Default { code Value = value; }
+
+class FlagPolarity { bit Value = value; }
+def PosFlag : FlagPolarity {}
+def NegFlag : FlagPolarity {}
+
+// Definition of a single command line flag.
+class FlagDef option_flags,
+  string help, list implied_by_options = []> {
+  // Negative polarity (false) implies a command line spelling prefixed with
+  // "no-" and a TableGen record whose name is prefixed with "no_".
+  FlagPolarity Polarity = polarity;
+
+  // The value assigned to keypath when the flag is present on the command 
line.
+  bit Value = value;
+
+  // List of OptionFlag records that control the visibility of the flag in
+  // 
diff erent scenarios.
+  list OptionFlags = option_flags;
+
+  // The help text associated with the flag.
+  string Help = help;
+
+  // List of options that imply this flag when present on command line.
+  list ImpliedBy = implied_by_options;
+}
+
+// Information extending a FlagDef.
+class FlagDefSuffix option_flags, string help> {
+  list OptionFlags = option_flags;
+  string Help = help;
+}
+
+// Extend the flag definition with a suffix.
+class ApplySuffix {
+  FlagDef Result
+= FlagDef;
+}
+
+// FlagDef extension. Convenient for creation of TableGen records.
+class FlagDefExpanded
+  : FlagDef {
+  // Name of the TableGen record.
+  string RecordName = prefix#!cond(flag.Polarity.Value : "", true : 
"no_")#name;
+
+  // Spelling of the flag.
+  string Spelling
+= prefix#!cond(flag.Polarity.Value : "", true : "no-")#spelling;
+
+  // Does the flag have CC1Option?
+  bit IsCC1 = !not(!empty(!filter(opt_flag, flag.OptionFlags,
+  !eq(opt_flag, CC1Option;
+
+  // Can the flag be implied by another flag?
+  bit CanBeImplied = !not(!empty(flag.ImpliedBy));
+
+  // C++ code that will be assigned to the keypath when the flag is present.
+  code ValueAsCode = !cond(flag.Value : "true", true: "false");
+}
+
+// Creates simple flag record.
+class BoolOptionFlag
+  : Flag<["-"], flag.Spelling>, Flags, HelpText {}
+
+// Creates marshalled flag record.
+class CC1BoolOptionFlag
+  : Flag<["-"], flag.Spelling>, Flags, HelpText,
+MarshallingInfoBooleanFlag,
+ImpliedByAnyOf {}
+
+// Generates TableGen records for two command line flags that control the same
+// keypath via the marshalling infrastructure.
+// Names of the records consist of the specified prefix, "no_" for the negative
+// flag, and NAME.
+// BoolOption is the API that should be used most of the time. Use this only
+// when you need more control (e.g. to represent a marshalled option whose
+// keypath defaults to an arbitrarily complex boolean expression).
+multiclass BoolOptionBase,
+  string prefix = ""> {
+  defvar flag1 = FlagDefExpanded.Result,
+ prefix, NAME, spelling_base>;
+
+  defvar flag2 = FlagDefExpanded.Result,
+ prefix, NAME, spelling_base>;
+
+  // TODO: Assert that the flags have 
diff erent polarity.
+  // TODO: Assert that the flags have 
diff erent value.
+  // TODO: Assert that 

[llvm-branch-commits] [clang] adf3c27 - [clang][cli] Revert accidental access-control flag rename

2020-12-12 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-12T11:26:53+01:00
New Revision: adf3c27742ed272e0785a305995a70078eda6fe3

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

LOG: [clang][cli] Revert accidental access-control flag rename

This commit 
 
introduced an accidental change, which renames `-faccess-control` and 
`-fno-access-control` to `-fno-access-control` and `-fno-no-access-control`.

Reviewed By: dexonsmith, MaskRay

Differential Revision: https://reviews.llvm.org/D93104

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 86760d0f400e..f7f5dd3547e3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1000,7 +1000,7 @@ def fPIC : Flag<["-"], "fPIC">, Group;
 def fno_PIC : Flag<["-"], "fno-PIC">, Group;
 def fPIE : Flag<["-"], "fPIE">, Group;
 def fno_PIE : Flag<["-"], "fno-PIE">, Group;
-defm access_control : OptOutFFlag<"no-access-control", "", "Disable C++ access 
control">;
+defm access_control : OptOutFFlag<"access-control", "", "Disable C++ access 
control">;
 def falign_functions : Flag<["-"], "falign-functions">, Group;
 def falign_functions_EQ : Joined<["-"], "falign-functions=">, Group;
 def fno_align_functions: Flag<["-"], "fno-align-functions">, Group;



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 4b6f294 - [clang][cli] Port Preprocessor and PreprocessorOutput option flags to new option parsing system

2020-12-14 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-14T09:19:57+01:00
New Revision: 4b6f29413c59b1a016f127bc3c3e1c15c6bea2a9

URL: 
https://github.com/llvm/llvm-project/commit/4b6f29413c59b1a016f127bc3c3e1c15c6bea2a9
DIFF: 
https://github.com/llvm/llvm-project/commit/4b6f29413c59b1a016f127bc3c3e1c15c6bea2a9.diff

LOG: [clang][cli] Port Preprocessor and PreprocessorOutput option flags to new 
option parsing system

Depends on D83979

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D84018

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f7f5dd3547e3..36e816e5345c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -638,9 +638,11 @@ def A : JoinedOrSeparate<["-"], "A">, 
Flags<[RenderJoined]>, Group, MetaVarName<"">,
 HelpText<"Add  to search path for binaries and object files used 
implicitly">;
 def CC : Flag<["-"], "CC">, Flags<[CC1Option]>, Group,
-HelpText<"Include comments from within macros in preprocessed output">;
+HelpText<"Include comments from within macros in preprocessed output">,
+MarshallingInfoFlag<"PreprocessorOutputOpts.ShowMacroComments">;
 def C : Flag<["-"], "C">, Flags<[CC1Option]>, Group,
-HelpText<"Include comments in preprocessed output">;
+HelpText<"Include comments in preprocessed output">,
+MarshallingInfoFlag<"PreprocessorOutputOpts.ShowComments">;
 def D : JoinedOrSeparate<["-"], "D">, Group,
 Flags<[CC1Option]>, MetaVarName<"=">,
 HelpText<"Define  to  (or 1 if  omitted)">;
@@ -706,7 +708,8 @@ def O : Joined<["-"], "O">, Group, 
Flags<[CC1Option]>;
 def O_flag : Flag<["-"], "O">, Flags<[CC1Option]>, Alias, AliasArgs<["1"]>;
 def Ofast : Joined<["-"], "Ofast">, Group, Flags<[CC1Option]>;
 def P : Flag<["-"], "P">, Flags<[CC1Option]>, Group,
-  HelpText<"Disable linemarker output in -E mode">;
+  HelpText<"Disable linemarker output in -E mode">,
+  MarshallingInfoFlag<"PreprocessorOutputOpts.ShowLineMarkers", "true">, 
IsNegative;
 def Qy : Flag<["-"], "Qy">, Flags<[CC1Option]>,
   HelpText<"Emit metadata containing compiler name and version">;
 def Qn : Flag<["-"], "Qn">, Flags<[CC1Option]>,
@@ -959,7 +962,8 @@ def libomptarget_nvptx_path_EQ : Joined<["--"], 
"libomptarget-nvptx-path=">, Gro
 def dD : Flag<["-"], "dD">, Group, Flags<[CC1Option]>,
   HelpText<"Print macro definitions in -E mode in addition to normal output">;
 def dI : Flag<["-"], "dI">, Group, Flags<[CC1Option]>,
-  HelpText<"Print include directives in -E mode in addition to normal output">;
+  HelpText<"Print include directives in -E mode in addition to normal output">,
+  MarshallingInfoFlag<"PreprocessorOutputOpts.ShowIncludeDirectives">;
 def dM : Flag<["-"], "dM">, Group, Flags<[CC1Option]>,
   HelpText<"Print macro definitions in -E mode instead of normal output">;
 def dead__strip : Flag<["-"], "dead_strip">;
@@ -1541,8 +1545,12 @@ defm strict_float_cast_overflow : 
OptOutFFlag<"strict-float-cast-overflow",
 def ffor_scope : Flag<["-"], "ffor-scope">, Group;
 def fno_for_scope : Flag<["-"], "fno-for-scope">, Group;
 
-defm rewrite_imports : OptInFFlag<"rewrite-imports", "">;
-defm rewrite_includes : OptInFFlag<"rewrite-includes", "">;
+defm rewrite_imports : BoolFOption<"rewrite-imports",
+  "PreprocessorOutputOpts.RewriteImports", DefaultsToFalse,
+  ChangedBy, ResetBy>;
+defm rewrite_includes : BoolFOption<"rewrite-includes",
+  "PreprocessorOutputOpts.RewriteIncludes", DefaultsToFalse,
+  ChangedBy, ResetBy>;
 
 defm delete_null_pointer_checks : OptOutFFlag<"delete-null-pointer-checks",
   "Treat usage of null pointers as undefined behavior (default)",
@@ -1556,7 +1564,9 @@ def frewrite_map_file_EQ : Joined<["-"], 
"frewrite-map-file=">,
Group,
Flags<[NoXarchOption]>;
 
-defm use_line_directives : OptInFFlag<"use-line-directives", "Use #line in 
preprocessed output">;
+defm use_line_directives : BoolFOption<"use-line-directives",
+  "PreprocessorOutputOpts.UseLineDirectives", DefaultsToFalse,
+  ChangedBy, 
ResetBy>;
 
 def ffreestanding : Flag<["-"], "ffreestanding">, Group, 
Flags<[CC1Option]>,
   HelpText<"Assert that the compilation takes place in a freestanding 
environment">;
@@ -3309,7 +3319,8 @@ def t : Flag<["-"], "t">, Group;
 def umbrella : Separate<["-"], "umbrella">;
 def undefined : JoinedOrSeparate<["-"], "undefined">, Group;
 def undef : Flag<["-"], "undef">, Group, Flags<[CC1Option]>,
-  HelpText<"undef all system defines">;
+  HelpText<"undef all system defines">,
+  MarshallingInfoFlag<"PreprocessorOpts->UsePredefines", "true">, IsNegative;
 def unexported__symbols__list : Separate<["-"], "unexported_symbols_list">;
 def u : JoinedOrSeparate<["-"], "u">, Group;
 def v : Flag<["-"],

[llvm-branch-commits] [llvm] e2fc85c - [clang][cli] Better defaults for MarshallingInfoString

2020-12-14 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-14T09:59:56+01:00
New Revision: e2fc85c69b3f7aad89b5b59eca537bec96a24682

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

LOG: [clang][cli] Better defaults for MarshallingInfoString

Depends on D84018

Reviewed By: Bigcheese

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D84185

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.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 36e816e5345c..4af1c0447dc0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3933,7 +3933,7 @@ def target_feature : Separate<["-"], "target-feature">,
 def triple : Separate<["-"], "triple">,
   HelpText<"Specify target triple (e.g. i686-apple-darwin9)">,
   MarshallingInfoString<"TargetOpts->Triple", 
"llvm::Triple::normalize(llvm::sys::getDefaultTargetTriple())">,
-  AlwaysEmit, Normalizer<"normalizeTriple">, DenormalizeString;
+  AlwaysEmit, Normalizer<"normalizeTriple">;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">;
 def target_sdk_version_EQ : Joined<["-"], "target-sdk-version=">,
@@ -3998,7 +3998,8 @@ def analyzer_viz_egraph_graphviz : Flag<["-"], 
"analyzer-viz-egraph-graphviz">,
   HelpText<"Display exploded graph using GraphViz">,
   MarshallingInfoFlag<"AnalyzerOpts->visualizeExplodedGraphWithGraphViz">;
 def analyzer_dump_egraph : Separate<["-"], "analyzer-dump-egraph">,
-  HelpText<"Dump exploded graph to the specified file">;
+  HelpText<"Dump exploded graph to the specified file">,
+  MarshallingInfoString<"AnalyzerOpts->DumpExplodedGraphTo">;
 def analyzer_dump_egraph_EQ : Joined<["-"], "analyzer-dump-egraph=">, 
Alias;
 
 def analyzer_inline_max_stack_depth : Separate<["-"], 
"analyzer-inline-max-stack-depth">,

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 836f34c64e28..3add57ce60f4 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -272,6 +272,15 @@ static void 
denormalizeSimpleEnumJoined(SmallVectorImpl &Args,
  "the tablegen option description");
 }
 
+static Optional normalizeString(OptSpecifier Opt, int TableIndex,
+ const ArgList &Args,
+ DiagnosticsEngine &Diags) {
+  auto *Arg = Args.getLastArg(Opt);
+  if (!Arg)
+return None;
+  return std::string(Arg->getValue());
+}
+
 static void denormalizeString(SmallVectorImpl &Args,
   const char *Spelling,
   CompilerInvocation::StringAllocator SA,
@@ -498,8 +507,6 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, 
ArgList &Args,
 .Case("false", false)
 .Default(false);
 
-  Opts.DumpExplodedGraphTo =
-  std::string(Args.getLastArgValue(OPT_analyzer_dump_egraph));
   Opts.AnalyzeSpecificFunction =
   std::string(Args.getLastArgValue(OPT_analyze_function));
   Opts.maxBlockVisitOnPath =

diff  --git a/llvm/include/llvm/Option/OptParser.td 
b/llvm/include/llvm/Option/OptParser.td
index 5dfe7bc7acc3..9e0ff1450920 100644
--- a/llvm/include/llvm/Option/OptParser.td
+++ b/llvm/include/llvm/Option/OptParser.td
@@ -155,8 +155,11 @@ class MarshallingInfo {
   code DefaultValue = defaultvalue;
 }
 
-class MarshallingInfoString
-  : MarshallingInfo {}
+class MarshallingInfoString
+  : MarshallingInfo {
+  code Normalizer = "normalizeString";
+  code Denormalizer = "denormalizeString";
+}
 
 class MarshallingInfoFlag
   : MarshallingInfo {
@@ -189,7 +192,6 @@ class Normalizer { code Normalizer = 
normalizer; }
 class Denormalizer { code Denormalizer = denormalizer; }
 class NormalizedValuesScope { code NormalizedValuesScope = scope; }
 class NormalizedValues definitions> { list NormalizedValues = 
definitions; } 
-class DenormalizeString { code Denormalizer = "denormalizeString"; }
 class AutoNormalizeEnum {
   code Normalizer = "normalizeSimpleEnum";
   code Denormalizer = "denormalizeSimpleEnum";



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] 16aa00b - [clang][cli] Port FileSystem options to new option parsing system

2020-12-14 Thread Jan Svoboda via llvm-branch-commits

Author: Jan Svoboda
Date: 2020-12-14T10:17:23+01:00
New Revision: 16aa00b6228533890cc108bc32871f36eb116e0e

URL: 
https://github.com/llvm/llvm-project/commit/16aa00b6228533890cc108bc32871f36eb116e0e
DIFF: 
https://github.com/llvm/llvm-project/commit/16aa00b6228533890cc108bc32871f36eb116e0e.diff

LOG: [clang][cli] Port FileSystem options to new option parsing system

Depends on D84187

Reviewed By: dexonsmith

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D84188

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 4af1c0447dc0..67d41c3711f5 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3354,7 +3354,8 @@ def : Flag<["-"], "no-integrated-as">, 
Alias,
   Flags<[CC1Option, NoXarchOption]>;
 
 def working_directory : JoinedOrSeparate<["-"], "working-directory">, 
Flags<[CC1Option]>,
-  HelpText<"Resolve file paths relative to the specified directory">;
+  HelpText<"Resolve file paths relative to the specified directory">,
+  MarshallingInfoString<"FileSystemOpts.WorkingDir">;
 def working_directory_EQ : Joined<["-"], "working-directory=">, 
Flags<[CC1Option]>,
   Alias;
 

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 3add57ce60f4..c1d5364d72ea 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1876,10 +1876,6 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, 
ArgList &Args,
   return Success;
 }
 
-static void ParseFileSystemArgs(FileSystemOptions &Opts, ArgList &Args) {
-  Opts.WorkingDir = std::string(Args.getLastArgValue(OPT_working_directory));
-}
-
 /// Parse the argument to the -ftest-module-file-extension
 /// command-line argument.
 ///
@@ -3839,7 +3835,6 @@ bool 
CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
   Success &= ParseDiagnosticArgs(Res.getDiagnosticOpts(), Args, &Diags,
  /*DefaultDiagColor=*/false);
   ParseCommentArgs(LangOpts.CommentOpts, Args);
-  ParseFileSystemArgs(Res.getFileSystemOpts(), Args);
   // FIXME: We shouldn't have to pass the DashX option around here
   InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), Args, Diags,
   LangOpts.IsHeaderFile);



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] release/19.x: [clang-scan-deps] Don't inspect Args[0] as an option (#109050) (PR #109865)

2024-09-25 Thread Jan Svoboda via llvm-branch-commits
Martin =?utf-8?q?Storsj=C3=B6?= ,
Martin =?utf-8?q?Storsj=C3=B6?= ,
Martin =?utf-8?q?Storsj=C3=B6?= 
Message-ID:
In-Reply-To: 


https://github.com/jansvoboda11 approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/109865
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits