Skip to content

Commit b0d3b39

Browse files
committed
Diagnose sanitizer use with scudo
Scudo is now a standalone sanitizer that must be used in isolation. Fixing the driver logic to identify and diagnose when it is used with any other sanitizer.
1 parent 955927e commit b0d3b39

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

lib/Option/SanitizerOptions.cpp

+18-27
Original file line numberDiff line numberDiff line change
@@ -182,36 +182,27 @@ OptionSet<SanitizerKind> swift::parseSanitizerArgValues(
182182
+ toStringRef(SanitizerKind::Thread)).toStringRef(b2));
183183
}
184184

185-
// Scudo can only be run with ubsan.
186-
if (sanitizerSet & SanitizerKind::Scudo) {
187-
OptionSet<SanitizerKind> allowedSet;
188-
allowedSet |= SanitizerKind::Scudo;
189-
allowedSet |= SanitizerKind::Undefined;
190-
191-
auto forbiddenOptions = sanitizerSet - allowedSet;
192-
193-
if (forbiddenOptions) {
194-
SanitizerKind forbidden;
195-
196-
if (forbiddenOptions & SanitizerKind::Address) {
197-
forbidden = SanitizerKind::Address;
198-
} else if (forbiddenOptions & SanitizerKind::Thread) {
199-
forbidden = SanitizerKind::Thread;
200-
} else {
201-
assert(forbiddenOptions & SanitizerKind::Fuzzer);
202-
forbidden = SanitizerKind::Fuzzer;
185+
// Scudo must be run standalone
186+
if (sanitizerSet.contains(SanitizerKind::Scudo) &&
187+
!sanitizerSet.containsOnly(SanitizerKind::Scudo)) {
188+
auto diagnoseSanitizerKind = [&Diags, A, &sanitizerSet](SanitizerKind kind) {
189+
// Don't diagnose Scudo, but diagnose anything else
190+
if (kind != SanitizerKind::Scudo && sanitizerSet.contains(kind)) {
191+
SmallString<128> b1;
192+
SmallString<128> b2;
193+
Diags.diagnose(SourceLoc(), diag::error_argument_not_allowed_with,
194+
(A->getOption().getPrefixedName()
195+
+ toStringRef(SanitizerKind::Scudo)).toStringRef(b1),
196+
(A->getOption().getPrefixedName()
197+
+ toStringRef(kind)).toStringRef(b2));
203198
}
199+
};
204200

205-
SmallString<128> b1;
206-
SmallString<128> b2;
207-
Diags.diagnose(SourceLoc(), diag::error_argument_not_allowed_with,
208-
(A->getOption().getPrefixedName()
209-
+ toStringRef(SanitizerKind::Scudo)).toStringRef(b1),
210-
(A->getOption().getPrefixedName()
211-
+ toStringRef(forbidden)).toStringRef(b2));
212-
}
213-
}
201+
#define SANITIZER(enm, kind, name, file) \
202+
diagnoseSanitizerKind(SanitizerKind::kind);
203+
#include "swift/Basic/Sanitizers.def"
214204

205+
}
215206
return sanitizerSet;
216207
}
217208

0 commit comments

Comments
 (0)