[NFC][sanitizer] Add test for command line flag for enable-noundef-analysis.
authorKevin Athey <kda@google.com>
Wed, 24 Nov 2021 00:26:43 +0000 (16:26 -0800)
committerKevin Athey <kda@google.com>
Fri, 3 Dec 2021 23:44:36 +0000 (15:44 -0800)
A simple unit test to demonstrate the flags working correctly.

Reviewed By: vitalybuka

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

compiler-rt/test/msan/noundef_analysis.cpp [new file with mode: 0644]

diff --git a/compiler-rt/test/msan/noundef_analysis.cpp b/compiler-rt/test/msan/noundef_analysis.cpp
new file mode 100644 (file)
index 0000000..d000864
--- /dev/null
@@ -0,0 +1,22 @@
+// RUN: %clangxx_msan %s -o %t && %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=MISSED --allow-empty < %t.out
+// RUN: %clangxx_msan %s -Xclang -enable-noundef-analysis -mllvm -msan-eager-checks=1 -o %t && not %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+
+struct SimpleStruct {
+  int md1;
+};
+
+static int sink;
+
+static void examineValue(int x) { sink = x; }
+
+int main(int argc, char *argv[]) {
+  auto ss = new SimpleStruct;
+  examineValue(ss->md1);
+
+  return 0;
+}
+
+// CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
+// MISSED-NOT: use-of-uninitialized-value