blob: 3043481c713240908aa3ca581b0c3be3dc19d3a0 [file] [log] [blame]
Alexey Samsonovcf055962013-08-08 10:11:02 +00001//===--- SanitizerArgs.cpp - Arguments for sanitizer tools ---------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Alexey Samsonov609213f92013-08-19 09:14:21 +00009#include "clang/Driver/SanitizerArgs.h"
Peter Collingbourne581f4382015-07-02 01:48:12 +000010#include "Tools.h"
Peter Collingbournebf59c342015-05-11 21:39:20 +000011#include "clang/Basic/Sanitizers.h"
Alexey Samsonovcf055962013-08-08 10:11:02 +000012#include "clang/Driver/Driver.h"
13#include "clang/Driver/DriverDiagnostic.h"
14#include "clang/Driver/Options.h"
15#include "clang/Driver/ToolChain.h"
Evgeniy Stepanov2bfcaab2014-03-20 14:58:36 +000016#include "llvm/ADT/StringExtras.h"
Alexey Samsonovcf055962013-08-08 10:11:02 +000017#include "llvm/ADT/StringSwitch.h"
18#include "llvm/Support/FileSystem.h"
19#include "llvm/Support/Path.h"
Alexey Samsonovb7dd3292014-07-09 19:40:08 +000020#include "llvm/Support/SpecialCaseList.h"
Ahmed Charlesdfca6f92014-03-09 11:36:40 +000021#include <memory>
Alexey Samsonovcf055962013-08-08 10:11:02 +000022
Peter Collingbourne3eea6772015-05-11 21:39:14 +000023using namespace clang;
24using namespace clang::SanitizerKind;
Alexey Samsonovcf055962013-08-08 10:11:02 +000025using namespace clang::driver;
26using namespace llvm::opt;
27
Peter Collingbourne3eea6772015-05-11 21:39:14 +000028enum : SanitizerMask {
Peter Collingbourne6708c4a2015-06-19 01:51:54 +000029 NeedsUbsanRt = Undefined | Integer | CFI,
Alexey Samsonov9b873092015-06-25 23:14:32 +000030 NeedsUbsanCxxRt = Vptr | CFI,
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +000031 NotAllowedWithTrap = Vptr,
Dmitry Vyukov43419a72014-11-21 12:19:01 +000032 RequiresPIE = Memory | DataFlow,
Kostya Serebryany2d88f3d2015-01-06 01:02:48 +000033 NeedsUnwindTables = Address | Thread | Memory | DataFlow,
Kostya Serebryany6fe5fcb2015-03-20 00:06:52 +000034 SupportsCoverage = Address | Memory | Leak | Undefined | Integer | DataFlow,
Alexey Samsonov88459522015-01-12 22:39:12 +000035 RecoverableByDefault = Undefined | Integer,
36 Unrecoverable = Address | Unreachable | Return,
Peter Collingbournea4ccff32015-02-20 20:30:56 +000037 LegacyFsanitizeRecoverMask = Undefined | Integer,
Peter Collingbourne1a7488a2015-04-02 00:23:30 +000038 NeedsLTO = CFI,
Peter Collingbourne9881b782015-06-18 23:59:22 +000039 TrappingSupported =
Peter Collingbourne6708c4a2015-06-19 01:51:54 +000040 (Undefined & ~Vptr) | UnsignedIntegerOverflow | LocalBounds | CFI,
41 TrappingDefault = CFI,
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +000042};
Alexey Samsonovdfa908c2015-05-07 22:34:06 +000043
44enum CoverageFeature {
45 CoverageFunc = 1 << 0,
46 CoverageBB = 1 << 1,
47 CoverageEdge = 1 << 2,
48 CoverageIndirCall = 1 << 3,
49 CoverageTraceBB = 1 << 4,
50 CoverageTraceCmp = 1 << 5,
51 Coverage8bitCounters = 1 << 6,
52};
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +000053
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +000054/// Parse a -fsanitize= or -fno-sanitize= argument's values, diagnosing any
Peter Collingbourne3eea6772015-05-11 21:39:14 +000055/// invalid components. Returns a SanitizerMask.
56static SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A,
57 bool DiagnoseErrors);
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +000058
Alexey Samsonovdfa908c2015-05-07 22:34:06 +000059/// Parse -f(no-)?sanitize-coverage= flag values, diagnosing any invalid
60/// components. Returns OR of members of \c CoverageFeature enumeration.
61static int parseCoverageFeatures(const Driver &D, const llvm::opt::Arg *A);
62
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +000063/// Produce an argument string from ArgList \p Args, which shows how it
64/// provides some sanitizer kind from \p Mask. For example, the argument list
65/// "-fsanitize=thread,vptr -fsanitize=address" with mask \c NeedsUbsanRt
66/// would produce "-fsanitize=vptr".
67static std::string lastArgumentForMask(const Driver &D,
68 const llvm::opt::ArgList &Args,
Peter Collingbourne3eea6772015-05-11 21:39:14 +000069 SanitizerMask Mask);
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +000070
71/// Produce an argument string from argument \p A, which shows how it provides
72/// a value in \p Mask. For instance, the argument
73/// "-fsanitize=address,alignment" with mask \c NeedsUbsanRt would produce
74/// "-fsanitize=alignment".
Peter Collingbourne3eea6772015-05-11 21:39:14 +000075static std::string describeSanitizeArg(const llvm::opt::Arg *A,
76 SanitizerMask Mask);
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +000077
Alexey Samsonov1e715a62014-11-16 20:53:53 +000078/// Produce a string containing comma-separated names of sanitizers in \p
79/// Sanitizers set.
80static std::string toString(const clang::SanitizerSet &Sanitizers);
81
Peter Collingbourne3eea6772015-05-11 21:39:14 +000082static bool getDefaultBlacklist(const Driver &D, SanitizerMask Kinds,
Alexey Samsonovecf380e2015-03-20 18:45:06 +000083 std::string &BLPath) {
84 const char *BlacklistFile = nullptr;
Peter Collingbourne3eea6772015-05-11 21:39:14 +000085 if (Kinds & Address)
Alexey Samsonovecf380e2015-03-20 18:45:06 +000086 BlacklistFile = "asan_blacklist.txt";
Peter Collingbourne3eea6772015-05-11 21:39:14 +000087 else if (Kinds & Memory)
Alexey Samsonovecf380e2015-03-20 18:45:06 +000088 BlacklistFile = "msan_blacklist.txt";
Peter Collingbourne3eea6772015-05-11 21:39:14 +000089 else if (Kinds & Thread)
Alexey Samsonovecf380e2015-03-20 18:45:06 +000090 BlacklistFile = "tsan_blacklist.txt";
Peter Collingbourne3eea6772015-05-11 21:39:14 +000091 else if (Kinds & DataFlow)
Alexey Samsonovecf380e2015-03-20 18:45:06 +000092 BlacklistFile = "dfsan_abilist.txt";
93
94 if (BlacklistFile) {
95 clang::SmallString<64> Path(D.ResourceDir);
96 llvm::sys::path::append(Path, BlacklistFile);
97 BLPath = Path.str();
98 return true;
99 }
100 return false;
101}
102
Peter Collingbourne9881b782015-06-18 23:59:22 +0000103/// Sets group bits for every group that has at least one representative already
104/// enabled in \p Kinds.
105static SanitizerMask setGroupBits(SanitizerMask Kinds) {
106#define SANITIZER(NAME, ID)
107#define SANITIZER_GROUP(NAME, ID, ALIAS) \
108 if (Kinds & SanitizerKind::ID) \
109 Kinds |= SanitizerKind::ID##Group;
110#include "clang/Basic/Sanitizers.def"
111 return Kinds;
112}
113
114static SanitizerMask parseSanitizeTrapArgs(const Driver &D,
115 const llvm::opt::ArgList &Args) {
116 SanitizerMask TrapRemove = 0; // During the loop below, the accumulated set of
117 // sanitizers disabled by the current sanitizer
118 // argument or any argument after it.
119 SanitizerMask TrappingKinds = 0;
120 SanitizerMask TrappingSupportedWithGroups = setGroupBits(TrappingSupported);
121
122 for (ArgList::const_reverse_iterator I = Args.rbegin(), E = Args.rend();
123 I != E; ++I) {
124 const auto *Arg = *I;
125 if (Arg->getOption().matches(options::OPT_fsanitize_trap_EQ)) {
126 Arg->claim();
127 SanitizerMask Add = parseArgValues(D, Arg, true);
128 Add &= ~TrapRemove;
129 if (SanitizerMask InvalidValues = Add & ~TrappingSupportedWithGroups) {
130 SanitizerSet S;
131 S.Mask = InvalidValues;
132 D.Diag(diag::err_drv_unsupported_option_argument) << "-fsanitize-trap"
133 << toString(S);
134 }
135 TrappingKinds |= expandSanitizerGroups(Add) & ~TrapRemove;
136 } else if (Arg->getOption().matches(options::OPT_fno_sanitize_trap_EQ)) {
137 Arg->claim();
138 TrapRemove |= expandSanitizerGroups(parseArgValues(D, Arg, true));
139 } else if (Arg->getOption().matches(
140 options::OPT_fsanitize_undefined_trap_on_error)) {
141 Arg->claim();
142 TrappingKinds |=
143 expandSanitizerGroups(UndefinedGroup & ~TrapRemove) & ~TrapRemove;
144 } else if (Arg->getOption().matches(
145 options::OPT_fno_sanitize_undefined_trap_on_error)) {
146 Arg->claim();
147 TrapRemove |= expandSanitizerGroups(UndefinedGroup);
148 }
149 }
150
Peter Collingbourne6708c4a2015-06-19 01:51:54 +0000151 // Apply default trapping behavior.
152 TrappingKinds |= TrappingDefault & ~TrapRemove;
153
Peter Collingbourne9881b782015-06-18 23:59:22 +0000154 return TrappingKinds;
155}
156
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +0000157bool SanitizerArgs::needsUbsanRt() const {
Peter Collingbourne9881b782015-06-18 23:59:22 +0000158 return (Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) &&
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000159 !Sanitizers.has(Address) &&
160 !Sanitizers.has(Memory) &&
161 !Sanitizers.has(Thread);
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +0000162}
163
Dmitry Vyukov43419a72014-11-21 12:19:01 +0000164bool SanitizerArgs::requiresPIE() const {
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000165 return AsanZeroBaseShadow || (Sanitizers.Mask & RequiresPIE);
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +0000166}
167
168bool SanitizerArgs::needsUnwindTables() const {
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000169 return Sanitizers.Mask & NeedsUnwindTables;
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +0000170}
171
Alexey Samsonovbb14f342013-08-08 11:32:17 +0000172void SanitizerArgs::clear() {
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +0000173 Sanitizers.clear();
Alexey Samsonov88459522015-01-12 22:39:12 +0000174 RecoverableSanitizers.clear();
Peter Collingbourne9881b782015-06-18 23:59:22 +0000175 TrapSanitizers.clear();
Alexey Samsonova511cdd2015-02-04 17:40:08 +0000176 BlacklistFiles.clear();
Alexey Samsonovdfa908c2015-05-07 22:34:06 +0000177 CoverageFeatures = 0;
Evgeniy Stepanov2bfcaab2014-03-20 14:58:36 +0000178 MsanTrackOrigins = 0;
Kostya Serebryanyaed71a82014-10-09 17:53:04 +0000179 AsanFieldPadding = 0;
Peter Collingbourne32701642013-11-01 18:16:25 +0000180 AsanZeroBaseShadow = false;
Alexey Samsonovbdfa6c22014-04-01 13:31:10 +0000181 AsanSharedRuntime = false;
Alexey Samsonov90490af2014-08-08 22:47:17 +0000182 LinkCXXRuntimes = false;
Alexey Samsonovbb14f342013-08-08 11:32:17 +0000183}
Alexey Samsonovcf055962013-08-08 10:11:02 +0000184
Peter Collingbourne32701642013-11-01 18:16:25 +0000185SanitizerArgs::SanitizerArgs(const ToolChain &TC,
186 const llvm::opt::ArgList &Args) {
Alexey Samsonovbb14f342013-08-08 11:32:17 +0000187 clear();
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000188 SanitizerMask AllRemove = 0; // During the loop below, the accumulated set of
189 // sanitizers disabled by the current sanitizer
190 // argument or any argument after it.
Alexey Samsonovde0aff32015-05-21 01:07:52 +0000191 SanitizerMask AllAddedKinds = 0; // Mask of all sanitizers ever enabled by
192 // -fsanitize= flags (directly or via group
193 // expansion), some of which may be disabled
194 // later. Used to carefully prune
195 // unused-argument diagnostics.
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000196 SanitizerMask DiagnosedKinds = 0; // All Kinds we have diagnosed up to now.
197 // Used to deduplicate diagnostics.
198 SanitizerMask Kinds = 0;
Alexey Samsonov9b873092015-06-25 23:14:32 +0000199 const SanitizerMask Supported = setGroupBits(TC.getSupportedSanitizers());
Filipe Cabecinhasec5d0e62015-02-19 01:04:49 +0000200 ToolChain::RTTIMode RTTIMode = TC.getRTTIMode();
201
Peter Collingbourne32701642013-11-01 18:16:25 +0000202 const Driver &D = TC.getDriver();
Peter Collingbourne9881b782015-06-18 23:59:22 +0000203 SanitizerMask TrappingKinds = parseSanitizeTrapArgs(D, Args);
Alexey Samsonov7f2a0d22015-06-19 21:36:47 +0000204 SanitizerMask InvalidTrappingKinds = TrappingKinds & NotAllowedWithTrap;
Peter Collingbourne9881b782015-06-18 23:59:22 +0000205
Peter Collingbourne32701642013-11-01 18:16:25 +0000206 for (ArgList::const_reverse_iterator I = Args.rbegin(), E = Args.rend();
207 I != E; ++I) {
Alexey Samsonov799f7932014-12-19 02:35:16 +0000208 const auto *Arg = *I;
209 if (Arg->getOption().matches(options::OPT_fsanitize_EQ)) {
210 Arg->claim();
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000211 SanitizerMask Add = parseArgValues(D, Arg, true);
Alexey Samsonovde0aff32015-05-21 01:07:52 +0000212 AllAddedKinds |= expandSanitizerGroups(Add);
Peter Collingbourne32701642013-11-01 18:16:25 +0000213
Alexey Samsonov799f7932014-12-19 02:35:16 +0000214 // Avoid diagnosing any sanitizer which is disabled later.
215 Add &= ~AllRemove;
216 // At this point we have not expanded groups, so any unsupported
217 // sanitizers in Add are those which have been explicitly enabled.
218 // Diagnose them.
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000219 if (SanitizerMask KindsToDiagnose =
Alexey Samsonov7f2a0d22015-06-19 21:36:47 +0000220 Add & InvalidTrappingKinds & ~DiagnosedKinds) {
Peter Collingbourne9881b782015-06-18 23:59:22 +0000221 std::string Desc = describeSanitizeArg(*I, KindsToDiagnose);
222 D.Diag(diag::err_drv_argument_not_allowed_with)
223 << Desc << "-fsanitize-trap=undefined";
224 DiagnosedKinds |= KindsToDiagnose;
Peter Collingbourne9881b782015-06-18 23:59:22 +0000225 }
Alexey Samsonov7f2a0d22015-06-19 21:36:47 +0000226 Add &= ~InvalidTrappingKinds;
227 if (SanitizerMask KindsToDiagnose = Add & ~Supported & ~DiagnosedKinds) {
Alexey Samsonov799f7932014-12-19 02:35:16 +0000228 std::string Desc = describeSanitizeArg(*I, KindsToDiagnose);
229 D.Diag(diag::err_drv_unsupported_opt_for_target)
230 << Desc << TC.getTriple().str();
231 DiagnosedKinds |= KindsToDiagnose;
232 }
Alexey Samsonov7f2a0d22015-06-19 21:36:47 +0000233 Add &= Supported;
Peter Collingbourne32701642013-11-01 18:16:25 +0000234
Filipe Cabecinhasec5d0e62015-02-19 01:04:49 +0000235 // Test for -fno-rtti + explicit -fsanitizer=vptr before expanding groups
236 // so we don't error out if -fno-rtti and -fsanitize=undefined were
237 // passed.
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000238 if (Add & Vptr &&
Filipe Cabecinhasec5d0e62015-02-19 01:04:49 +0000239 (RTTIMode == ToolChain::RM_DisabledImplicitly ||
240 RTTIMode == ToolChain::RM_DisabledExplicitly)) {
241 if (RTTIMode == ToolChain::RM_DisabledImplicitly)
242 // Warn about not having rtti enabled if the vptr sanitizer is
243 // explicitly enabled
244 D.Diag(diag::warn_drv_disabling_vptr_no_rtti_default);
245 else {
246 const llvm::opt::Arg *NoRTTIArg = TC.getRTTIArg();
247 assert(NoRTTIArg &&
248 "RTTI disabled explicitly but we have no argument!");
249 D.Diag(diag::err_drv_argument_not_allowed_with)
250 << "-fsanitize=vptr" << NoRTTIArg->getAsString(Args);
251 }
252
253 // Take out the Vptr sanitizer from the enabled sanitizers
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000254 AllRemove |= Vptr;
Filipe Cabecinhasec5d0e62015-02-19 01:04:49 +0000255 }
256
Peter Collingbournebf59c342015-05-11 21:39:20 +0000257 Add = expandSanitizerGroups(Add);
Alexey Samsonov799f7932014-12-19 02:35:16 +0000258 // Group expansion may have enabled a sanitizer which is disabled later.
259 Add &= ~AllRemove;
260 // Silently discard any unsupported sanitizers implicitly enabled through
261 // group expansion.
Alexey Samsonov7f2a0d22015-06-19 21:36:47 +0000262 Add &= ~InvalidTrappingKinds;
263 Add &= Supported;
Alexey Samsonov1e715a62014-11-16 20:53:53 +0000264
Alexey Samsonov799f7932014-12-19 02:35:16 +0000265 Kinds |= Add;
266 } else if (Arg->getOption().matches(options::OPT_fno_sanitize_EQ)) {
267 Arg->claim();
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000268 SanitizerMask Remove = parseArgValues(D, Arg, true);
Peter Collingbournebf59c342015-05-11 21:39:20 +0000269 AllRemove |= expandSanitizerGroups(Remove);
Alexey Samsonov1e715a62014-11-16 20:53:53 +0000270 }
Alexey Samsonovcf055962013-08-08 10:11:02 +0000271 }
Alexey Samsonov1e715a62014-11-16 20:53:53 +0000272
Filipe Cabecinhasec5d0e62015-02-19 01:04:49 +0000273 // We disable the vptr sanitizer if it was enabled by group expansion but RTTI
274 // is disabled.
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000275 if ((Kinds & Vptr) &&
Filipe Cabecinhasec5d0e62015-02-19 01:04:49 +0000276 (RTTIMode == ToolChain::RM_DisabledImplicitly ||
277 RTTIMode == ToolChain::RM_DisabledExplicitly)) {
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000278 Kinds &= ~Vptr;
Filipe Cabecinhasec5d0e62015-02-19 01:04:49 +0000279 }
280
Alexey Samsonov907880e2015-06-19 19:57:46 +0000281 // Check that LTO is enabled if we need it.
282 if ((Kinds & NeedsLTO) && !D.IsUsingLTO(Args)) {
283 D.Diag(diag::err_drv_argument_only_allowed_with)
284 << lastArgumentForMask(D, Args, Kinds & NeedsLTO) << "-flto";
285 }
286
Alexey Samsonov9b873092015-06-25 23:14:32 +0000287 // Report error if there are non-trapping sanitizers that require
288 // c++abi-specific parts of UBSan runtime, and they are not provided by the
289 // toolchain. We don't have a good way to check the latter, so we just
290 // check if the toolchan supports vptr.
291 if (~Supported & Vptr) {
292 if (SanitizerMask KindsToDiagnose =
293 Kinds & ~TrappingKinds & NeedsUbsanCxxRt) {
294 SanitizerSet S;
295 S.Mask = KindsToDiagnose;
296 D.Diag(diag::err_drv_unsupported_opt_for_target)
297 << ("-fno-sanitize-trap=" + toString(S)) << TC.getTriple().str();
298 Kinds &= ~KindsToDiagnose;
299 }
300 }
301
Alexey Samsonovecf380e2015-03-20 18:45:06 +0000302 // Warn about incompatible groups of sanitizers.
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000303 std::pair<SanitizerMask, SanitizerMask> IncompatibleGroups[] = {
304 std::make_pair(Address, Thread), std::make_pair(Address, Memory),
305 std::make_pair(Thread, Memory), std::make_pair(Leak, Thread),
Alexander Potapenkob9b73ef2015-06-19 12:19:07 +0000306 std::make_pair(Leak, Memory), std::make_pair(KernelAddress, Address),
307 std::make_pair(KernelAddress, Leak),
308 std::make_pair(KernelAddress, Thread),
309 std::make_pair(KernelAddress, Memory)};
Alexey Samsonovecf380e2015-03-20 18:45:06 +0000310 for (auto G : IncompatibleGroups) {
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000311 SanitizerMask Group = G.first;
Alexey Samsonovecf380e2015-03-20 18:45:06 +0000312 if (Kinds & Group) {
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000313 if (SanitizerMask Incompatible = Kinds & G.second) {
Alexey Samsonovecf380e2015-03-20 18:45:06 +0000314 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
315 << lastArgumentForMask(D, Args, Group)
316 << lastArgumentForMask(D, Args, Incompatible);
317 Kinds &= ~Incompatible;
318 }
319 }
320 }
321 // FIXME: Currently -fsanitize=leak is silently ignored in the presence of
322 // -fsanitize=address. Perhaps it should print an error, or perhaps
323 // -f(-no)sanitize=leak should change whether leak detection is enabled by
324 // default in ASan?
325
Alexey Samsonov88459522015-01-12 22:39:12 +0000326 // Parse -f(no-)?sanitize-recover flags.
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000327 SanitizerMask RecoverableKinds = RecoverableByDefault;
328 SanitizerMask DiagnosedUnrecoverableKinds = 0;
Alexey Samsonov88459522015-01-12 22:39:12 +0000329 for (const auto *Arg : Args) {
Alexey Samsonovce2e77c2015-03-11 23:34:25 +0000330 const char *DeprecatedReplacement = nullptr;
Alexey Samsonov88459522015-01-12 22:39:12 +0000331 if (Arg->getOption().matches(options::OPT_fsanitize_recover)) {
Alexey Samsonovce2e77c2015-03-11 23:34:25 +0000332 DeprecatedReplacement = "-fsanitize-recover=undefined,integer";
Peter Collingbournebf59c342015-05-11 21:39:20 +0000333 RecoverableKinds |= expandSanitizerGroups(LegacyFsanitizeRecoverMask);
Alexey Samsonov88459522015-01-12 22:39:12 +0000334 Arg->claim();
335 } else if (Arg->getOption().matches(options::OPT_fno_sanitize_recover)) {
Alexey Samsonovce2e77c2015-03-11 23:34:25 +0000336 DeprecatedReplacement = "-fno-sanitize-recover=undefined,integer";
Peter Collingbournebf59c342015-05-11 21:39:20 +0000337 RecoverableKinds &= ~expandSanitizerGroups(LegacyFsanitizeRecoverMask);
Alexey Samsonov88459522015-01-12 22:39:12 +0000338 Arg->claim();
339 } else if (Arg->getOption().matches(options::OPT_fsanitize_recover_EQ)) {
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000340 SanitizerMask Add = parseArgValues(D, Arg, true);
Alexey Samsonov88459522015-01-12 22:39:12 +0000341 // Report error if user explicitly tries to recover from unrecoverable
342 // sanitizer.
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000343 if (SanitizerMask KindsToDiagnose =
Alexey Samsonov88459522015-01-12 22:39:12 +0000344 Add & Unrecoverable & ~DiagnosedUnrecoverableKinds) {
345 SanitizerSet SetToDiagnose;
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000346 SetToDiagnose.Mask |= KindsToDiagnose;
Alexey Samsonov88459522015-01-12 22:39:12 +0000347 D.Diag(diag::err_drv_unsupported_option_argument)
348 << Arg->getOption().getName() << toString(SetToDiagnose);
349 DiagnosedUnrecoverableKinds |= KindsToDiagnose;
350 }
Peter Collingbournebf59c342015-05-11 21:39:20 +0000351 RecoverableKinds |= expandSanitizerGroups(Add);
Alexey Samsonov88459522015-01-12 22:39:12 +0000352 Arg->claim();
353 } else if (Arg->getOption().matches(options::OPT_fno_sanitize_recover_EQ)) {
Peter Collingbournebf59c342015-05-11 21:39:20 +0000354 RecoverableKinds &= ~expandSanitizerGroups(parseArgValues(D, Arg, true));
Alexey Samsonov88459522015-01-12 22:39:12 +0000355 Arg->claim();
356 }
Alexey Samsonovce2e77c2015-03-11 23:34:25 +0000357 if (DeprecatedReplacement) {
358 D.Diag(diag::warn_drv_deprecated_arg) << Arg->getAsString(Args)
359 << DeprecatedReplacement;
360 }
Alexey Samsonov88459522015-01-12 22:39:12 +0000361 }
362 RecoverableKinds &= Kinds;
363 RecoverableKinds &= ~Unrecoverable;
Alexey Samsonovcf055962013-08-08 10:11:02 +0000364
Peter Collingbourne9881b782015-06-18 23:59:22 +0000365 TrappingKinds &= Kinds;
366
Alexey Samsonova511cdd2015-02-04 17:40:08 +0000367 // Setup blacklist files.
368 // Add default blacklist from resource directory.
369 {
Alexey Samsonovcf055962013-08-08 10:11:02 +0000370 std::string BLPath;
Alexey Samsonovecf380e2015-03-20 18:45:06 +0000371 if (getDefaultBlacklist(D, Kinds, BLPath) && llvm::sys::fs::exists(BLPath))
Alexey Samsonova511cdd2015-02-04 17:40:08 +0000372 BlacklistFiles.push_back(BLPath);
373 }
374 // Parse -f(no-)sanitize-blacklist options.
375 for (const auto *Arg : Args) {
376 if (Arg->getOption().matches(options::OPT_fsanitize_blacklist)) {
377 Arg->claim();
378 std::string BLPath = Arg->getValue();
379 if (llvm::sys::fs::exists(BLPath))
380 BlacklistFiles.push_back(BLPath);
381 else
382 D.Diag(clang::diag::err_drv_no_such_file) << BLPath;
383 } else if (Arg->getOption().matches(options::OPT_fno_sanitize_blacklist)) {
384 Arg->claim();
385 BlacklistFiles.clear();
386 }
387 }
388 // Validate blacklists format.
389 {
390 std::string BLError;
391 std::unique_ptr<llvm::SpecialCaseList> SCL(
392 llvm::SpecialCaseList::create(BlacklistFiles, BLError));
393 if (!SCL.get())
394 D.Diag(clang::diag::err_drv_malformed_sanitizer_blacklist) << BLError;
Alexey Samsonovcf055962013-08-08 10:11:02 +0000395 }
396
Evgeniy Stepanov2bfcaab2014-03-20 14:58:36 +0000397 // Parse -f[no-]sanitize-memory-track-origins[=level] options.
Alexey Samsonovde0aff32015-05-21 01:07:52 +0000398 if (AllAddedKinds & Memory) {
Evgeniy Stepanov2bfcaab2014-03-20 14:58:36 +0000399 if (Arg *A =
400 Args.getLastArg(options::OPT_fsanitize_memory_track_origins_EQ,
401 options::OPT_fsanitize_memory_track_origins,
402 options::OPT_fno_sanitize_memory_track_origins)) {
403 if (A->getOption().matches(options::OPT_fsanitize_memory_track_origins)) {
Evgeniy Stepanov6e09bca2015-02-26 15:59:30 +0000404 MsanTrackOrigins = 2;
Evgeniy Stepanov2bfcaab2014-03-20 14:58:36 +0000405 } else if (A->getOption().matches(
406 options::OPT_fno_sanitize_memory_track_origins)) {
407 MsanTrackOrigins = 0;
408 } else {
409 StringRef S = A->getValue();
410 if (S.getAsInteger(0, MsanTrackOrigins) || MsanTrackOrigins < 0 ||
411 MsanTrackOrigins > 2) {
Nico Weberf2a39a72015-04-13 20:03:03 +0000412 D.Diag(clang::diag::err_drv_invalid_value) << A->getAsString(Args) << S;
Evgeniy Stepanov2bfcaab2014-03-20 14:58:36 +0000413 }
414 }
415 }
416 }
417
Alexey Samsonovdfa908c2015-05-07 22:34:06 +0000418 // Parse -f(no-)?sanitize-coverage flags if coverage is supported by the
419 // enabled sanitizers.
Alexey Samsonovde0aff32015-05-21 01:07:52 +0000420 if (AllAddedKinds & SupportsCoverage) {
Alexey Samsonovdfa908c2015-05-07 22:34:06 +0000421 for (const auto *Arg : Args) {
422 if (Arg->getOption().matches(options::OPT_fsanitize_coverage)) {
423 Arg->claim();
424 int LegacySanitizeCoverage;
425 if (Arg->getNumValues() == 1 &&
426 !StringRef(Arg->getValue(0))
427 .getAsInteger(0, LegacySanitizeCoverage) &&
428 LegacySanitizeCoverage >= 0 && LegacySanitizeCoverage <= 4) {
429 // TODO: Add deprecation notice for this form.
430 switch (LegacySanitizeCoverage) {
431 case 0:
432 CoverageFeatures = 0;
433 break;
434 case 1:
435 CoverageFeatures = CoverageFunc;
436 break;
437 case 2:
438 CoverageFeatures = CoverageBB;
439 break;
440 case 3:
441 CoverageFeatures = CoverageEdge;
442 break;
443 case 4:
444 CoverageFeatures = CoverageEdge | CoverageIndirCall;
445 break;
446 }
447 continue;
448 }
449 CoverageFeatures |= parseCoverageFeatures(D, Arg);
450 } else if (Arg->getOption().matches(options::OPT_fno_sanitize_coverage)) {
451 Arg->claim();
452 CoverageFeatures &= ~parseCoverageFeatures(D, Arg);
453 }
Kostya Serebryany75b4f9e2014-11-11 22:15:07 +0000454 }
455 }
Alexey Samsonovdfa908c2015-05-07 22:34:06 +0000456 // Choose at most one coverage type: function, bb, or edge.
457 if ((CoverageFeatures & CoverageFunc) && (CoverageFeatures & CoverageBB))
458 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
459 << "-fsanitize-coverage=func"
460 << "-fsanitize-coverage=bb";
461 if ((CoverageFeatures & CoverageFunc) && (CoverageFeatures & CoverageEdge))
462 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
463 << "-fsanitize-coverage=func"
464 << "-fsanitize-coverage=edge";
465 if ((CoverageFeatures & CoverageBB) && (CoverageFeatures & CoverageEdge))
466 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
467 << "-fsanitize-coverage=bb"
468 << "-fsanitize-coverage=edge";
469 // Basic block tracing and 8-bit counters require some type of coverage
470 // enabled.
471 int CoverageTypes = CoverageFunc | CoverageBB | CoverageEdge;
472 if ((CoverageFeatures & CoverageTraceBB) &&
473 !(CoverageFeatures & CoverageTypes))
474 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
475 << "-fsanitize-coverage=trace-bb"
476 << "-fsanitize-coverage=(func|bb|edge)";
477 if ((CoverageFeatures & Coverage8bitCounters) &&
478 !(CoverageFeatures & CoverageTypes))
479 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
480 << "-fsanitize-coverage=8bit-counters"
481 << "-fsanitize-coverage=(func|bb|edge)";
Kostya Serebryany75b4f9e2014-11-11 22:15:07 +0000482
Alexey Samsonovde0aff32015-05-21 01:07:52 +0000483 if (AllAddedKinds & Address) {
Alexey Samsonovbdfa6c22014-04-01 13:31:10 +0000484 AsanSharedRuntime =
Evgeniy Stepanov6f0ae182014-06-05 11:14:00 +0000485 Args.hasArg(options::OPT_shared_libasan) ||
486 (TC.getTriple().getEnvironment() == llvm::Triple::Android);
Peter Collingbourne32701642013-11-01 18:16:25 +0000487 AsanZeroBaseShadow =
Evgeniy Stepanovd04b8612014-01-16 10:19:31 +0000488 (TC.getTriple().getEnvironment() == llvm::Triple::Android);
Kostya Serebryanyaed71a82014-10-09 17:53:04 +0000489 if (Arg *A =
490 Args.getLastArg(options::OPT_fsanitize_address_field_padding)) {
491 StringRef S = A->getValue();
492 // Legal values are 0 and 1, 2, but in future we may add more levels.
493 if (S.getAsInteger(0, AsanFieldPadding) || AsanFieldPadding < 0 ||
494 AsanFieldPadding > 2) {
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +0000495 D.Diag(clang::diag::err_drv_invalid_value) << A->getAsString(Args) << S;
Kostya Serebryanyaed71a82014-10-09 17:53:04 +0000496 }
497 }
Ehsan Akhgarie0db1962014-10-14 23:15:44 +0000498
499 if (Arg *WindowsDebugRTArg =
500 Args.getLastArg(options::OPT__SLASH_MTd, options::OPT__SLASH_MT,
501 options::OPT__SLASH_MDd, options::OPT__SLASH_MD,
502 options::OPT__SLASH_LDd, options::OPT__SLASH_LD)) {
503 switch (WindowsDebugRTArg->getOption().getID()) {
504 case options::OPT__SLASH_MTd:
505 case options::OPT__SLASH_MDd:
506 case options::OPT__SLASH_LDd:
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +0000507 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
Ehsan Akhgarie0db1962014-10-14 23:15:44 +0000508 << WindowsDebugRTArg->getAsString(Args)
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000509 << lastArgumentForMask(D, Args, Address);
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +0000510 D.Diag(clang::diag::note_drv_address_sanitizer_debug_runtime);
Ehsan Akhgarie0db1962014-10-14 23:15:44 +0000511 }
512 }
Alexey Samsonovbdfa6c22014-04-01 13:31:10 +0000513 }
Alexey Samsonov90490af2014-08-08 22:47:17 +0000514
515 // Parse -link-cxx-sanitizer flag.
516 LinkCXXRuntimes =
517 Args.hasArg(options::OPT_fsanitize_link_cxx_runtime) || D.CCCIsCXX();
Alexey Samsonovecf380e2015-03-20 18:45:06 +0000518
519 // Finally, initialize the set of available and recoverable sanitizers.
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000520 Sanitizers.Mask |= Kinds;
521 RecoverableSanitizers.Mask |= RecoverableKinds;
Peter Collingbourne9881b782015-06-18 23:59:22 +0000522 TrapSanitizers.Mask |= TrappingKinds;
Alexey Samsonovcf055962013-08-08 10:11:02 +0000523}
524
Alexey Samsonov1e715a62014-11-16 20:53:53 +0000525static std::string toString(const clang::SanitizerSet &Sanitizers) {
526 std::string Res;
527#define SANITIZER(NAME, ID) \
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000528 if (Sanitizers.has(ID)) { \
Alexey Samsonov1e715a62014-11-16 20:53:53 +0000529 if (!Res.empty()) \
530 Res += ","; \
531 Res += NAME; \
532 }
533#include "clang/Basic/Sanitizers.def"
534 return Res;
535}
536
Peter Collingbourne581f4382015-07-02 01:48:12 +0000537void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
538 llvm::opt::ArgStringList &CmdArgs,
539 types::ID InputType) const {
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +0000540 if (Sanitizers.empty())
Alexey Samsonovcf055962013-08-08 10:11:02 +0000541 return;
Alexey Samsonov1e715a62014-11-16 20:53:53 +0000542 CmdArgs.push_back(Args.MakeArgString("-fsanitize=" + toString(Sanitizers)));
543
Alexey Samsonov88459522015-01-12 22:39:12 +0000544 if (!RecoverableSanitizers.empty())
545 CmdArgs.push_back(Args.MakeArgString("-fsanitize-recover=" +
546 toString(RecoverableSanitizers)));
Alexey Samsonov1e715a62014-11-16 20:53:53 +0000547
Peter Collingbourne9881b782015-06-18 23:59:22 +0000548 if (!TrapSanitizers.empty())
549 CmdArgs.push_back(
550 Args.MakeArgString("-fsanitize-trap=" + toString(TrapSanitizers)));
Alexey Samsonov1e715a62014-11-16 20:53:53 +0000551
Alexey Samsonova511cdd2015-02-04 17:40:08 +0000552 for (const auto &BLPath : BlacklistFiles) {
Alexey Samsonovcf055962013-08-08 10:11:02 +0000553 SmallString<64> BlacklistOpt("-fsanitize-blacklist=");
Alexey Samsonova511cdd2015-02-04 17:40:08 +0000554 BlacklistOpt += BLPath;
Alexey Samsonovcf055962013-08-08 10:11:02 +0000555 CmdArgs.push_back(Args.MakeArgString(BlacklistOpt));
556 }
557
558 if (MsanTrackOrigins)
Evgeniy Stepanov2bfcaab2014-03-20 14:58:36 +0000559 CmdArgs.push_back(Args.MakeArgString("-fsanitize-memory-track-origins=" +
560 llvm::utostr(MsanTrackOrigins)));
Kostya Serebryanyaed71a82014-10-09 17:53:04 +0000561 if (AsanFieldPadding)
562 CmdArgs.push_back(Args.MakeArgString("-fsanitize-address-field-padding=" +
563 llvm::utostr(AsanFieldPadding)));
Alexey Samsonovdfa908c2015-05-07 22:34:06 +0000564 // Translate available CoverageFeatures to corresponding clang-cc1 flags.
565 std::pair<int, const char *> CoverageFlags[] = {
566 std::make_pair(CoverageFunc, "-fsanitize-coverage-type=1"),
567 std::make_pair(CoverageBB, "-fsanitize-coverage-type=2"),
568 std::make_pair(CoverageEdge, "-fsanitize-coverage-type=3"),
569 std::make_pair(CoverageIndirCall, "-fsanitize-coverage-indirect-calls"),
570 std::make_pair(CoverageTraceBB, "-fsanitize-coverage-trace-bb"),
571 std::make_pair(CoverageTraceCmp, "-fsanitize-coverage-trace-cmp"),
572 std::make_pair(Coverage8bitCounters, "-fsanitize-coverage-8bit-counters")};
573 for (auto F : CoverageFlags) {
574 if (CoverageFeatures & F.first)
575 CmdArgs.push_back(Args.MakeArgString(F.second));
Alexey Samsonov3f3b3ab2015-05-07 18:31:29 +0000576 }
Alexey Samsonovdfa908c2015-05-07 22:34:06 +0000577
578
Sergey Matveev2ba87782015-02-17 15:09:33 +0000579 // MSan: Workaround for PR16386.
580 // ASan: This is mainly to help LSan with cases such as
581 // https://code.google.com/p/address-sanitizer/issues/detail?id=373
582 // We can't make this conditional on -fsanitize=leak, as that flag shouldn't
583 // affect compilation.
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000584 if (Sanitizers.has(Memory) || Sanitizers.has(Address))
Alexey Samsonovcf055962013-08-08 10:11:02 +0000585 CmdArgs.push_back(Args.MakeArgString("-fno-assume-sane-operator-new"));
Peter Collingbourne581f4382015-07-02 01:48:12 +0000586
587 if (TC.getTriple().isOSWindows() && needsUbsanRt()) {
588 // Instruct the code generator to embed linker directives in the object file
589 // that cause the required runtime libraries to be linked.
590 CmdArgs.push_back(Args.MakeArgString(
591 "--dependent-lib=" + tools::getCompilerRT(TC, "ubsan_standalone")));
592 if (types::isCXX(InputType))
593 CmdArgs.push_back(
594 Args.MakeArgString("--dependent-lib=" +
595 tools::getCompilerRT(TC, "ubsan_standalone_cxx")));
596 }
Alexey Samsonovcf055962013-08-08 10:11:02 +0000597}
598
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000599SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A,
600 bool DiagnoseErrors) {
Alexey Samsonov799f7932014-12-19 02:35:16 +0000601 assert((A->getOption().matches(options::OPT_fsanitize_EQ) ||
Alexey Samsonov88459522015-01-12 22:39:12 +0000602 A->getOption().matches(options::OPT_fno_sanitize_EQ) ||
603 A->getOption().matches(options::OPT_fsanitize_recover_EQ) ||
Peter Collingbourne9881b782015-06-18 23:59:22 +0000604 A->getOption().matches(options::OPT_fno_sanitize_recover_EQ) ||
605 A->getOption().matches(options::OPT_fsanitize_trap_EQ) ||
606 A->getOption().matches(options::OPT_fno_sanitize_trap_EQ)) &&
Alexey Samsonov799f7932014-12-19 02:35:16 +0000607 "Invalid argument in parseArgValues!");
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000608 SanitizerMask Kinds = 0;
Alexey Samsonov83791e22015-03-03 22:15:32 +0000609 for (int i = 0, n = A->getNumValues(); i != n; ++i) {
610 const char *Value = A->getValue(i);
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000611 SanitizerMask Kind;
Alexey Samsonovabd5bea2014-12-19 18:41:43 +0000612 // Special case: don't accept -fsanitize=all.
613 if (A->getOption().matches(options::OPT_fsanitize_EQ) &&
614 0 == strcmp("all", Value))
615 Kind = 0;
616 else
Peter Collingbournebf59c342015-05-11 21:39:20 +0000617 Kind = parseSanitizerValue(Value, /*AllowGroups=*/true);
Alexey Samsonovabd5bea2014-12-19 18:41:43 +0000618
619 if (Kind)
620 Kinds |= Kind;
Alexey Samsonovcf055962013-08-08 10:11:02 +0000621 else if (DiagnoseErrors)
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +0000622 D.Diag(clang::diag::err_drv_unsupported_option_argument)
Alexey Samsonovabd5bea2014-12-19 18:41:43 +0000623 << A->getOption().getName() << Value;
Alexey Samsonovcf055962013-08-08 10:11:02 +0000624 }
Alexey Samsonovabd5bea2014-12-19 18:41:43 +0000625 return Kinds;
Alexey Samsonovcf055962013-08-08 10:11:02 +0000626}
627
Alexey Samsonovdfa908c2015-05-07 22:34:06 +0000628int parseCoverageFeatures(const Driver &D, const llvm::opt::Arg *A) {
629 assert(A->getOption().matches(options::OPT_fsanitize_coverage) ||
630 A->getOption().matches(options::OPT_fno_sanitize_coverage));
631 int Features = 0;
632 for (int i = 0, n = A->getNumValues(); i != n; ++i) {
633 const char *Value = A->getValue(i);
634 int F = llvm::StringSwitch<int>(Value)
635 .Case("func", CoverageFunc)
636 .Case("bb", CoverageBB)
637 .Case("edge", CoverageEdge)
638 .Case("indirect-calls", CoverageIndirCall)
639 .Case("trace-bb", CoverageTraceBB)
640 .Case("trace-cmp", CoverageTraceCmp)
641 .Case("8bit-counters", Coverage8bitCounters)
642 .Default(0);
643 if (F == 0)
644 D.Diag(clang::diag::err_drv_unsupported_option_argument)
645 << A->getOption().getName() << Value;
646 Features |= F;
647 }
648 return Features;
649}
650
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +0000651std::string lastArgumentForMask(const Driver &D, const llvm::opt::ArgList &Args,
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000652 SanitizerMask Mask) {
Alexey Samsonovcf055962013-08-08 10:11:02 +0000653 for (llvm::opt::ArgList::const_reverse_iterator I = Args.rbegin(),
654 E = Args.rend();
655 I != E; ++I) {
Alexey Samsonov799f7932014-12-19 02:35:16 +0000656 const auto *Arg = *I;
657 if (Arg->getOption().matches(options::OPT_fsanitize_EQ)) {
Peter Collingbournebf59c342015-05-11 21:39:20 +0000658 SanitizerMask AddKinds =
659 expandSanitizerGroups(parseArgValues(D, Arg, false));
Alexey Samsonov799f7932014-12-19 02:35:16 +0000660 if (AddKinds & Mask)
661 return describeSanitizeArg(Arg, Mask);
662 } else if (Arg->getOption().matches(options::OPT_fno_sanitize_EQ)) {
Peter Collingbournebf59c342015-05-11 21:39:20 +0000663 SanitizerMask RemoveKinds =
664 expandSanitizerGroups(parseArgValues(D, Arg, false));
Alexey Samsonov799f7932014-12-19 02:35:16 +0000665 Mask &= ~RemoveKinds;
666 }
Alexey Samsonovcf055962013-08-08 10:11:02 +0000667 }
668 llvm_unreachable("arg list didn't provide expected value");
669}
670
Peter Collingbourne3eea6772015-05-11 21:39:14 +0000671std::string describeSanitizeArg(const llvm::opt::Arg *A, SanitizerMask Mask) {
Alexey Samsonov4c12c6c2014-11-14 02:59:20 +0000672 assert(A->getOption().matches(options::OPT_fsanitize_EQ)
673 && "Invalid argument in describeSanitizerArg!");
Alexey Samsonovcf055962013-08-08 10:11:02 +0000674
Peter Collingbourne32701642013-11-01 18:16:25 +0000675 std::string Sanitizers;
Alexey Samsonov83791e22015-03-03 22:15:32 +0000676 for (int i = 0, n = A->getNumValues(); i != n; ++i) {
Peter Collingbournebf59c342015-05-11 21:39:20 +0000677 if (expandSanitizerGroups(
678 parseSanitizerValue(A->getValue(i), /*AllowGroups=*/true)) &
679 Mask) {
Peter Collingbourne32701642013-11-01 18:16:25 +0000680 if (!Sanitizers.empty())
681 Sanitizers += ",";
Alexey Samsonov83791e22015-03-03 22:15:32 +0000682 Sanitizers += A->getValue(i);
Peter Collingbourne32701642013-11-01 18:16:25 +0000683 }
684 }
Alexey Samsonovcf055962013-08-08 10:11:02 +0000685
Peter Collingbourne32701642013-11-01 18:16:25 +0000686 assert(!Sanitizers.empty() && "arg didn't provide expected value");
687 return "-fsanitize=" + Sanitizers;
Alexey Samsonovcf055962013-08-08 10:11:02 +0000688}