1// Regression test: pointers to self should not confuse LSan into thinking the
2// object is indirectly leaked. Only external pointers count.
3// RUN: LSAN_BASE="report_objects=1:use_registers=0"
4// RUN: %clangxx_lsan %s -o %t
5// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=0" not %run %t 2>&1 | FileCheck %s
6
7#include <stdio.h>
8#include <stdlib.h>
9
10int main() {
11  void *p = malloc(1337);
12  *reinterpret_cast<void **>(p) = p;
13  fprintf(stderr, "Test alloc: %p.\n", p);
14}
15// CHECK: Test alloc: [[ADDR:.*]].
16// CHECK: LeakSanitizer: detected memory leaks
17// CHECK: [[ADDR]] (1337 bytes)
18// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer:
19