[PATCH] D82926: [libfuzzer] [clang] Add __has_feature(fuzzing_coverage)
Mitch Phillips via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 30 16:52:10 PDT 2020
hctim created this revision.
hctim added reviewers: morehouse, Dor1s.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Probably a useful feature for checking whether a file was built with
-fsanitize=fuzzer or -fsanitize=fuzzer-no-link.
N.B. __has_feature(fuzzing_coverage) doesn't cover instances where users
manually specify -fsanitize-coverage=... (even if the flags are
identical to ToT -fsanitize=fuzzer-no-link). IMHO this is WAI -
-fsanitize=fuzzer-no-link is not a stable set of flags and people that
want sancov for fuzzing should use fuzzer-no-link.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D82926
Files:
clang/include/clang/Basic/Features.def
clang/test/Lexer/has_feature_libfuzzer.cpp
Index: clang/test/Lexer/has_feature_libfuzzer.cpp
===================================================================
--- /dev/null
+++ clang/test/Lexer/has_feature_libfuzzer.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -E %s -o - | FileCheck --check-prefix=CHECK-NONE %s
+// RUN: %clang_cc1 -E -fsanitize=fuzzer %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ENABLED %s
+// RUN: %clang_cc1 -E -fsanitize=fuzzer-no-link %s -o - \
+// RUN: | FileCheck --check-prefix=CHECK-ENABLED %s
+
+#if __has_feature(fuzzing_coverage)
+int FuzzingCoverageEnabled();
+#else
+int FuzzingCoverageDisabled();
+#endif
+
+// CHECK-NONE: FuzzingCoverageEnabled
+// CHECK-ENABLED: FuzzingCoverageDisabled
Index: clang/include/clang/Basic/Features.def
===================================================================
--- clang/include/clang/Basic/Features.def
+++ clang/include/clang/Basic/Features.def
@@ -49,6 +49,9 @@
FEATURE(xray_instrument, LangOpts.XRayInstrument)
FEATURE(undefined_behavior_sanitizer,
LangOpts.Sanitize.hasOneOf(SanitizerKind::Undefined))
+FEATURE(fuzzing_coverage,
+ LangOpts.Sanitize.hasOneOf(SanitizerKind::Fuzzer |
+ SanitizerKind::FuzzerNoLink))
FEATURE(assume_nonnull, true)
FEATURE(attribute_analyzer_noreturn, true)
FEATURE(attribute_availability, true)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82926.274653.patch
Type: text/x-patch
Size: 1328 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200630/5bda9689/attachment-0001.bin>
More information about the cfe-commits
mailing list