@@ -348,6 +348,30 @@ 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
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
+
351
375
bool SanitizerArgs::needsFuzzerInterceptors () const {
352
376
return needsFuzzer () && !needsAsanRt () && !needsTsanRt () && !needsMsanRt ();
353
377
}
@@ -730,6 +754,18 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
730
754
options::OPT_fno_sanitize_recover_EQ);
731
755
RecoverableKinds &= Kinds;
732
756
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
+
733
769
TrappingKinds &= Kinds;
734
770
RecoverableKinds &= ~TrappingKinds;
735
771
0 commit comments