[PATCH] D19238: Additional test for use-after-scope

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 18 14:23:41 PDT 2016


vitalybuka created this revision.
vitalybuka added reviewers: aizatsky, kcc.
vitalybuka added a subscriber: llvm-commits.

Test that asan detects access to the dead variable captured by lambda.

http://reviews.llvm.org/D19238

Files:
  test/asan/TestCases/use-after-scope-capture.cc

Index: test/asan/TestCases/use-after-scope-capture.cc
===================================================================
--- /dev/null
+++ test/asan/TestCases/use-after-scope-capture.cc
@@ -0,0 +1,14 @@
+// RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && %run %t
+// XFAIL: *
+
+int main() {
+  std::function<int()> f;
+  {
+    int x = 0;
+    f = [&x]() {
+      return x;
+    }
+  }
+  return f();  // BOOM
+  // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19238.54116.patch
Type: text/x-patch
Size: 489 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160418/7ecf1d27/attachment.bin>


More information about the llvm-commits mailing list