[clang] [sanitizer] Refactor -f(no-)?sanitize-recover parsing (PR #119819)
Kirill Stoimenov via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 17 14:05:59 PST 2024
================
@@ -652,44 +679,12 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
// default in ASan?
// Parse -f(no-)?sanitize-recover flags.
- SanitizerMask RecoverableKinds = RecoverableByDefault | AlwaysRecoverable;
- SanitizerMask DiagnosedUnrecoverableKinds;
- SanitizerMask DiagnosedAlwaysRecoverableKinds;
- for (const auto *Arg : Args) {
- if (Arg->getOption().matches(options::OPT_fsanitize_recover_EQ)) {
- SanitizerMask Add = parseArgValues(D, Arg, DiagnoseErrors);
- // Report error if user explicitly tries to recover from unrecoverable
- // sanitizer.
- if (SanitizerMask KindsToDiagnose =
- Add & Unrecoverable & ~DiagnosedUnrecoverableKinds) {
- SanitizerSet SetToDiagnose;
- SetToDiagnose.Mask |= KindsToDiagnose;
- if (DiagnoseErrors)
- D.Diag(diag::err_drv_unsupported_option_argument)
- << Arg->getSpelling() << toString(SetToDiagnose);
- DiagnosedUnrecoverableKinds |= KindsToDiagnose;
- }
- RecoverableKinds |= expandSanitizerGroups(Add);
- Arg->claim();
- } else if (Arg->getOption().matches(options::OPT_fno_sanitize_recover_EQ)) {
- SanitizerMask Remove = parseArgValues(D, Arg, DiagnoseErrors);
- // Report error if user explicitly tries to disable recovery from
- // always recoverable sanitizer.
- if (SanitizerMask KindsToDiagnose =
- Remove & AlwaysRecoverable & ~DiagnosedAlwaysRecoverableKinds) {
- SanitizerSet SetToDiagnose;
- SetToDiagnose.Mask |= KindsToDiagnose;
- if (DiagnoseErrors)
- D.Diag(diag::err_drv_unsupported_option_argument)
- << Arg->getSpelling() << toString(SetToDiagnose);
- DiagnosedAlwaysRecoverableKinds |= KindsToDiagnose;
- }
- RecoverableKinds &= ~expandSanitizerGroups(Remove);
- Arg->claim();
- }
- }
+ SanitizerMask RecoverableKinds = parseSanitizeArgs(
----------------
kstoimenov wrote:
I am not sure if it is accepted as coding practice in LLVM code base, but functions invocations with many args are hard to read without looking at the function prototype. The way to deal with this is to do something like the code below. We could probably skip the 'obvious' parameter to make it less verbose.
parseSanitizeArgs(
D, Args, DiagnoseErrors,
/*Default = */ RecoverableByDefault,
/*AlwaysIn = */ AlwaysRecoverable,
/*AlwaysOut = */ Unrecoverable,
/*OptInID = */ options::OPT_fsanitize_recover_EQ,
/*OptOutID = */ options::OPT_fno_sanitize_recover_EQ);
https://github.com/llvm/llvm-project/pull/119819
More information about the cfe-commits
mailing list