@@ -247,39 +247,49 @@ static SanitizerMask setGroupBits(SanitizerMask Kinds) {
247
247
return Kinds;
248
248
}
249
249
250
- static SanitizerMask parseSanitizeTrapArgs (const Driver &D,
251
- const llvm::opt::ArgList &Args,
252
- bool DiagnoseErrors) {
253
- SanitizerMask TrapRemove; // During the loop below, the accumulated set of
254
- // sanitizers disabled by the current sanitizer
255
- // argument or any argument after it.
256
- SanitizerMask TrappingKinds;
257
- SanitizerMask TrappingSupportedWithGroups = setGroupBits (TrappingSupported);
250
+ // Computes the sanitizer mask based on the default plus opt-in (if supported)
251
+ // minus opt-out.
252
+ static SanitizerMask
253
+ parseSanitizeArgs (const Driver &D, const llvm::opt::ArgList &Args,
254
+ bool DiagnoseErrors, SanitizerMask Supported,
255
+ SanitizerMask Default, int OptInID, int OptOutID) {
256
+ SanitizerMask Remove; // During the loop below, the accumulated set of
257
+ // sanitizers disabled by the current sanitizer
258
+ // argument or any argument after it.
259
+ SanitizerMask Kinds;
260
+ SanitizerMask SupportedWithGroups = setGroupBits (Supported);
258
261
259
262
for (const llvm::opt::Arg *Arg : llvm::reverse (Args)) {
260
- if (Arg->getOption ().matches (options::OPT_fsanitize_trap_EQ )) {
263
+ if (Arg->getOption ().matches (OptInID )) {
261
264
Arg->claim ();
262
265
SanitizerMask Add = parseArgValues (D, Arg, true );
263
- Add &= ~TrapRemove ;
264
- SanitizerMask InvalidValues = Add & ~TrappingSupportedWithGroups ;
266
+ Add &= ~Remove ;
267
+ SanitizerMask InvalidValues = Add & ~SupportedWithGroups ;
265
268
if (InvalidValues && DiagnoseErrors) {
266
269
SanitizerSet S;
267
270
S.Mask = InvalidValues;
268
271
D.Diag (diag::err_drv_unsupported_option_argument)
269
272
<< Arg->getSpelling () << toString (S);
270
273
}
271
- TrappingKinds |= expandSanitizerGroups (Add) & ~TrapRemove ;
272
- } else if (Arg->getOption ().matches (options::OPT_fno_sanitize_trap_EQ )) {
274
+ Kinds |= expandSanitizerGroups (Add) & ~Remove ;
275
+ } else if (Arg->getOption ().matches (OptOutID )) {
273
276
Arg->claim ();
274
- TrapRemove |=
275
- expandSanitizerGroups (parseArgValues (D, Arg, DiagnoseErrors));
277
+ Remove |= expandSanitizerGroups (parseArgValues (D, Arg, DiagnoseErrors));
276
278
}
277
279
}
278
280
279
- // Apply default trapping behavior.
280
- TrappingKinds |= TrappingDefault & ~TrapRemove;
281
+ // Apply default behavior.
282
+ Kinds |= Default & ~Remove;
283
+
284
+ return Kinds;
285
+ }
281
286
282
- return TrappingKinds;
287
+ static SanitizerMask parseSanitizeTrapArgs (const Driver &D,
288
+ const llvm::opt::ArgList &Args,
289
+ bool DiagnoseErrors) {
290
+ return parseSanitizeArgs (D, Args, DiagnoseErrors, TrappingSupported,
291
+ TrappingDefault, options::OPT_fsanitize_trap_EQ,
292
+ options::OPT_fno_sanitize_trap_EQ);
283
293
}
284
294
285
295
bool SanitizerArgs::needsFuzzerInterceptors () const {
0 commit comments