aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2020-12-16 13:14:50 +0100
committerJan Svoboda <jan_svoboda@apple.com>2020-12-18 08:56:06 +0100
commitcaeb56503ec897c7244cff0657c11e87d2644f82 (patch)
tree37b6cfdf8e120a96ad5a5de1251d1903db26483a /clang/lib/Frontend/CompilerInvocation.cpp
parent8c1f2d15b826591cdf6bd6b468b8a7d23377b29e (diff)
downloadllvm-caeb56503ec897c7244cff0657c11e87d2644f82.zip
llvm-caeb56503ec897c7244cff0657c11e87d2644f82.tar.gz
llvm-caeb56503ec897c7244cff0657c11e87d2644f82.tar.bz2
[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
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp39
1 files changed, 29 insertions, 10 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 5fbafa3..d2b590f 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -93,6 +93,7 @@
#include <memory>
#include <string>
#include <tuple>
+#include <type_traits>
#include <utility>
#include <vector>
@@ -282,12 +283,38 @@ static Optional<std::string> normalizeString(OptSpecifier Opt, int TableIndex,
static void denormalizeString(SmallVectorImpl<const char *> &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 <typename T,
+ std::enable_if_t<!std::is_convertible<T, Twine>::value &&
+ std::is_constructible<Twine, T>::value,
+ bool> = false>
+static void denormalizeString(SmallVectorImpl<const char *> &Args,
+ const char *Spelling,
+ CompilerInvocation::StringAllocator SA,
+ unsigned TableIndex, T Value) {
+ denormalizeString(Args, Spelling, SA, TableIndex, Twine(Value));
+}
+
+template <typename IntTy>
+static Optional<IntTy> normalizeStringIntegral(OptSpecifier Opt, int,
+ const ArgList &Args,
+ DiagnosticsEngine &Diags) {
+ auto *Arg = Args.getLastArg(Opt);
+ if (!Arg)
+ return None;
+ IntTy Res;
+ if (StringRef(Arg->getValue()).getAsInteger(0, Res)) {
+ Diags.Report(diag::err_drv_invalid_int_value)
+ << Arg->getAsString(Args) << Arg->getValue();
+ }
+ return Res;
+}
+
static Optional<std::string> normalizeTriple(OptSpecifier Opt, int TableIndex,
const ArgList &Args,
DiagnosticsEngine &Diags) {
@@ -522,14 +549,6 @@ static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
.Case("false", false)
.Default(false);
- Opts.AnalyzeSpecificFunction =
- std::string(Args.getLastArgValue(OPT_analyze_function));
- Opts.maxBlockVisitOnPath =
- getLastArgIntValue(Args, OPT_analyzer_max_loop, 4, Diags);
- Opts.InlineMaxStackDepth =
- getLastArgIntValue(Args, OPT_analyzer_inline_max_stack_depth,
- Opts.InlineMaxStackDepth, Diags);
-
Opts.CheckersAndPackages.clear();
for (const Arg *A :
Args.filtered(OPT_analyzer_checker, OPT_analyzer_disable_checker)) {