aboutsummaryrefslogtreecommitdiff
path: root/test/fuzzer/UseAfterDtor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/fuzzer/UseAfterDtor.cpp')
-rw-r--r--test/fuzzer/UseAfterDtor.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/fuzzer/UseAfterDtor.cpp b/test/fuzzer/UseAfterDtor.cpp
new file mode 100644
index 000000000000..dcefca5cc7d5
--- /dev/null
+++ b/test/fuzzer/UseAfterDtor.cpp
@@ -0,0 +1,27 @@
+#include <cstdint>
+#include <cstdio>
+
+struct Simple {
+ int x_;
+ Simple() {
+ x_ = 5;
+ }
+ ~Simple() {
+ x_ += 1;
+ }
+};
+
+Simple *volatile SimpleSink;
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ if (Size < 4) return 0;
+ if (Data[0] == 'F' && Data[1] == 'U' && Data[2] == 'Z' && Data[3] == 'Z') {
+ {
+ Simple S;
+ SimpleSink = &S;
+ }
+ if (SimpleSink->x_) fprintf(stderr, "Failed to catch use-after-dtor\n");
+ }
+ return 0;
+}
+