Skip to content

Commit

Permalink
[Lexer] Add udefined_behavior_sanitizer feature
Browse files Browse the repository at this point in the history
This can be used to detect whether the code is being built with UBSan using
the __has_feature(undefined_behavior_sanitizer) predicate.

Differential Revision: https://reviews.llvm.org/D52386

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342793 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
PiJoules committed Sep 22, 2018
1 parent 167b402 commit d05cbec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/clang/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ FEATURE(hwaddress_sanitizer,
LangOpts.Sanitize.hasOneOf(SanitizerKind::HWAddress |
SanitizerKind::KernelHWAddress))
FEATURE(xray_instrument, LangOpts.XRayInstrument)
FEATURE(undefined_behavior_sanitizer,
LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
FEATURE(assume_nonnull, true)
FEATURE(attribute_analyzer_noreturn, true)
FEATURE(attribute_availability, true)
Expand Down
13 changes: 13 additions & 0 deletions test/Lexer/has_feature_undefined_behavior_sanitizer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %clang -E -fsanitize=undefined %s -o - | FileCheck --check-prefix=CHECK-UBSAN %s
// RUN: %clang -E -fsanitize=alignment %s -o - | FileCheck --check-prefix=CHECK-ALIGNMENT %s
// RUN: %clang -E %s -o - | FileCheck --check-prefix=CHECK-NO-UBSAN %s

#if __has_feature(undefined_behavior_sanitizer)
int UBSanEnabled();
#else
int UBSanDisabled();
#endif

// CHECK-UBSAN: UBSanEnabled
// CHECK-ALIGNMENT: UBSanEnabled
// CHECK-NO-UBSAN: UBSanDisabled

0 comments on commit d05cbec

Please sign in to comment.