]> granicus.if.org Git - clang/commitdiff
[Lexer] Add udefined_behavior_sanitizer feature
authorLeonard Chan <leonardchan@google.com>
Sat, 22 Sep 2018 01:03:16 +0000 (01:03 +0000)
committerLeonard Chan <leonardchan@google.com>
Sat, 22 Sep 2018 01:03:16 +0000 (01:03 +0000)
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

include/clang/Basic/Features.def
test/Lexer/has_feature_undefined_behavior_sanitizer.cpp [new file with mode: 0644]

index f816d1894ed043b32a159c3e656d71ab7891b2e7..0061135be664eb5f2fc08db3f24ecec61b202652 100644 (file)
@@ -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)
diff --git a/test/Lexer/has_feature_undefined_behavior_sanitizer.cpp b/test/Lexer/has_feature_undefined_behavior_sanitizer.cpp
new file mode 100644 (file)
index 0000000..62e5316
--- /dev/null
@@ -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