Skip to content

Commit

Permalink
[clang][cli] Better defaults for MarshallingInfoString
Browse files Browse the repository at this point in the history
Depends on D84018

Reviewed By: Bigcheese

Original patch by Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D84185
  • Loading branch information
jansvoboda11 committed Dec 14, 2020
1 parent 4e2e785 commit e2fc85c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 3 additions & 2 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -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=">,
Expand Down Expand Up @@ -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<analyzer_dump_egraph>;

def analyzer_inline_max_stack_depth : Separate<["-"], "analyzer-inline-max-stack-depth">,
Expand Down
11 changes: 9 additions & 2 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,15 @@ static void denormalizeSimpleEnumJoined(SmallVectorImpl<const char *> &Args,
"the tablegen option description");
}

static Optional<std::string> 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<const char *> &Args,
const char *Spelling,
CompilerInvocation::StringAllocator SA,
Expand Down Expand Up @@ -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 =
Expand Down
8 changes: 5 additions & 3 deletions llvm/include/llvm/Option/OptParser.td
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,11 @@ class MarshallingInfo<code keypath, code defaultvalue> {
code DefaultValue = defaultvalue;
}

class MarshallingInfoString<code keypath, code defaultvalue>
: MarshallingInfo<keypath, defaultvalue> {}
class MarshallingInfoString<code keypath, code defaultvalue="std::string()">
: MarshallingInfo<keypath, defaultvalue> {
code Normalizer = "normalizeString";
code Denormalizer = "denormalizeString";
}

class MarshallingInfoFlag<code keypath, code defaultvalue = "false">
: MarshallingInfo<keypath, defaultvalue> {
Expand Down Expand Up @@ -189,7 +192,6 @@ class Normalizer<code normalizer> { code Normalizer = normalizer; }
class Denormalizer<code denormalizer> { code Denormalizer = denormalizer; }
class NormalizedValuesScope<code scope> { code NormalizedValuesScope = scope; }
class NormalizedValues<list<code> definitions> { list<code> NormalizedValues = definitions; }
class DenormalizeString { code Denormalizer = "denormalizeString"; }
class AutoNormalizeEnum {
code Normalizer = "normalizeSimpleEnum";
code Denormalizer = "denormalizeSimpleEnum";
Expand Down

0 comments on commit e2fc85c

Please sign in to comment.