@@ -247,39 +247,49 @@ static SanitizerMask setGroupBits(SanitizerMask Kinds) {
247247 return Kinds;
248248}
249249
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);
258261
259262 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 )) {
261264 Arg->claim ();
262265 SanitizerMask Add = parseArgValues (D, Arg, true );
263- Add &= ~TrapRemove ;
264- SanitizerMask InvalidValues = Add & ~TrappingSupportedWithGroups ;
266+ Add &= ~Remove ;
267+ SanitizerMask InvalidValues = Add & ~SupportedWithGroups ;
265268 if (InvalidValues && DiagnoseErrors) {
266269 SanitizerSet S;
267270 S.Mask = InvalidValues;
268271 D.Diag (diag::err_drv_unsupported_option_argument)
269272 << Arg->getSpelling () << toString (S);
270273 }
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 )) {
273276 Arg->claim ();
274- TrapRemove |=
275- expandSanitizerGroups (parseArgValues (D, Arg, DiagnoseErrors));
277+ Remove |= expandSanitizerGroups (parseArgValues (D, Arg, DiagnoseErrors));
276278 }
277279 }
278280
279- // Apply default trapping behavior.
280- TrappingKinds |= TrappingDefault & ~TrapRemove;
281+ // Apply default behavior.
282+ Kinds |= Default & ~Remove;
283+
284+ return Kinds;
285+ }
281286
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);
283293}
284294
285295bool SanitizerArgs::needsFuzzerInterceptors () const {
0 commit comments