Skip to content

Commit f1bf9b3

Browse files
author
Anthony Tran
committed
Emit warning and parse mismatched arguments
1 parent eadf3e5 commit f1bf9b3

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,30 @@ parseSanitizeSkipHotCutoffArgs(const Driver &D, const llvm::opt::ArgList &Args,
348348
return Cutoffs;
349349
}
350350

351+
// Given a set of mismatched bits, TrapOnly (bits the user asked to trap but
352+
// that aren’t actually enabled), emit a warning based on -fsanitize-trap=NAME
353+
static void diagnoseTrapOnly(const Driver &D, SanitizerMask &TrapOnly) {
354+
// Double pass: one for sanitizer groupings, one for leaves (ex: undefined vs.
355+
// signed-integer-overflow)
356+
#define SANITIZER(NAME, ID)
357+
#define SANITIZER_GROUP(NAME, ID, ALIAS) \
358+
if (TrapOnly & SanitizerKind::ID##Group) { \
359+
D.Diag(diag::warn_drv_sanitize_trap_mismatch) << NAME; \
360+
TrapOnly &= ~SanitizerKind::ID##Group; \
361+
TrapOnly &= ~SanitizerKind::ID; \
362+
}
363+
#include "clang/Basic/Sanitizers.def"
364+
365+
#undef SANITIZER_GROUP
366+
#define SANITIZER_GROUP(NAME, ID, ALIAS)
367+
#define SANITIZER(NAME, ID) \
368+
if (TrapOnly & SanitizerKind::ID) { \
369+
D.Diag(diag::warn_drv_sanitize_trap_mismatch) << NAME; \
370+
TrapOnly &= ~SanitizerKind::ID; \
371+
}
372+
#include "clang/Basic/Sanitizers.def"
373+
}
374+
351375
bool SanitizerArgs::needsFuzzerInterceptors() const {
352376
return needsFuzzer() && !needsAsanRt() && !needsTsanRt() && !needsMsanRt();
353377
}
@@ -730,6 +754,18 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
730754
options::OPT_fno_sanitize_recover_EQ);
731755
RecoverableKinds &= Kinds;
732756

757+
// Parse any -fsanitize-trap=<...> flags the user provided, then
758+
// diagnose any which do not have a matching -fsanitize=<...>
759+
if (DiagnoseErrors) {
760+
SanitizerMask ExplicitTrap = parseSanitizeArgs(
761+
D, Args, false, {}, {}, {}, options::OPT_fsanitize_trap_EQ,
762+
options::OPT_fno_sanitize_trap_EQ);
763+
SanitizerMask TrapOnly = ExplicitTrap & ~Kinds;
764+
765+
if (TrapOnly)
766+
diagnoseTrapOnly(D, TrapOnly);
767+
}
768+
733769
TrappingKinds &= Kinds;
734770
RecoverableKinds &= ~TrappingKinds;
735771

0 commit comments

Comments
 (0)