From 52be619c84d51713ccf7271c2be5dfefd04ee23a Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Mon, 5 Nov 2012 22:04:41 +0000 Subject: Add -fsanitize= argument to driver and frontend, and add -fno-sanitize= argument to driver. These allow ASan, TSan, and the various UBSan checks to be enabled and disabled separately. Right now, the different modes can't be combined, but the intention is that combining UBSan and the other sanitizers will be permitted in the near future. Currently, the UBSan checks will all be enabled if any of them is; that will be fixed by the next patch. llvm-svn: 167411 --- clang/lib/Frontend/CompilerInvocation.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 703b9e7..8cce72c 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1273,6 +1273,37 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, case 1: Opts.setStackProtector(LangOptions::SSPOn); break; case 2: Opts.setStackProtector(LangOptions::SSPReq); break; } + + // 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, +#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: + Diags.Report(diag::err_drv_invalid_value) + << "-fsanitize=" << Sanitizers[I]; + break; + } + } } static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args, -- cgit v1.1