@@ -348,6 +348,29 @@ parseSanitizeSkipHotCutoffArgs(const Driver &D, const llvm::opt::ArgList &Args,
348
348
return Cutoffs;
349
349
}
350
350
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
+
351
374
bool SanitizerArgs::needsFuzzerInterceptors () const {
352
375
return needsFuzzer () && !needsAsanRt () && !needsTsanRt () && !needsMsanRt ();
353
376
}
@@ -730,6 +753,25 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
730
753
options::OPT_fno_sanitize_recover_EQ);
731
754
RecoverableKinds &= Kinds;
732
755
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
+
733
775
TrappingKinds &= Kinds;
734
776
RecoverableKinds &= ~TrappingKinds;
735
777
0 commit comments