Skip to content

Commit 1bcc20d

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

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,29 @@ 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 that aren’t actually enabled),
352+
// 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. signed-integer-overflow)
355+
#define SANITIZER(NAME, ID)
356+
#define SANITIZER_GROUP(NAME, ID, ALIAS) \
357+
if (TrapOnly & SanitizerKind::ID##Group) { \
358+
D.Diag(diag::warn_drv_sanitize_trap_mismatch) << NAME; \
359+
TrapOnly &= ~SanitizerKind::ID##Group; \
360+
TrapOnly &= ~SanitizerKind::ID; \
361+
}
362+
#include "clang/Basic/Sanitizers.def"
363+
364+
#undef SANITIZER_GROUP
365+
#define SANITIZER_GROUP(NAME, ID, ALIAS)
366+
#define SANITIZER(NAME, ID) \
367+
if (TrapOnly & SanitizerKind::ID) { \
368+
D.Diag(diag::warn_drv_sanitize_trap_mismatch) << NAME; \
369+
TrapOnly &= ~SanitizerKind::ID; \
370+
}
371+
#include "clang/Basic/Sanitizers.def"
372+
}
373+
351374
bool SanitizerArgs::needsFuzzerInterceptors() const {
352375
return needsFuzzer() && !needsAsanRt() && !needsTsanRt() && !needsMsanRt();
353376
}
@@ -730,6 +753,25 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
730753
options::OPT_fno_sanitize_recover_EQ);
731754
RecoverableKinds &= Kinds;
732755

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

0 commit comments

Comments
 (0)