From edf99a92c00193fb72f3e94f4440b9f86789cca4 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Fri, 7 Nov 2014 22:29:38 +0000 Subject: Introduce a SanitizerKind enum to LangOptions. Use the bitmask to store the set of enabled sanitizers instead of a bitfield. On the negative side, it makes syntax for querying the set of enabled sanitizers a bit more clunky. On the positive side, we will be able to use SanitizerKind to eventually implement the new semantics for -fsanitize-recover= flag, that would allow us to make some sanitizers recoverable, and some non-recoverable. No functionality change. llvm-svn: 221558 --- clang/lib/Frontend/CompilerInvocation.cpp | 33 ++++++++----------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 340d4ab..f466588 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1610,33 +1610,16 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, // Parse -fsanitize= arguments. std::vector Sanitizers = Args.getAllArgValues(OPT_fsanitize_EQ); - for (unsigned I = 0, N = Sanitizers.size(); I != N; ++I) { - // Since the Opts.Sanitize* values are bitfields, it's a little tricky to - // efficiently map string values to them. Perform the mapping indirectly: - // convert strings to enumerated values, then switch over the enum to set - // the right bitfield value. - enum Sanitizer { -#define SANITIZER(NAME, ID) \ - ID, + for (const auto &Sanitizer : Sanitizers) { + SanitizerKind K = llvm::StringSwitch(Sanitizer) +#define SANITIZER(NAME, ID) .Case(NAME, SanitizerKind::ID) #include "clang/Basic/Sanitizers.def" - Unknown - }; - switch (llvm::StringSwitch(Sanitizers[I]) -#define SANITIZER(NAME, ID) \ - .Case(NAME, ID) -#include "clang/Basic/Sanitizers.def" - .Default(Unknown)) { -#define SANITIZER(NAME, ID) \ - case ID: \ - Opts.Sanitize.ID = true; \ - break; -#include "clang/Basic/Sanitizers.def" - - case Unknown: + .Default(SanitizerKind::Unknown); + if (K == SanitizerKind::Unknown) Diags.Report(diag::err_drv_invalid_value) - << "-fsanitize=" << Sanitizers[I]; - break; - } + << "-fsanitize=" << Sanitizer; + else + Opts.Sanitize.set(K, true); } // -fsanitize-address-field-padding=N has to be a LangOpt, parse it here. Opts.Sanitize.SanitizeAddressFieldPadding = -- cgit v1.1