<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - ASAN use-after-scope for thread-local variables"
   href="https://bugs.llvm.org/show_bug.cgi?id=47616">47616</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ASAN use-after-scope for thread-local variables
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>compiler-rt
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>asan
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mvanotti@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>It seems like asan is not keeping track of thread-local variables.

```cpp
#include <iostream>
#include <thread>

thread_local int x;

extern "C" int __asan_address_is_poisoned(void const volatile *addr);
extern "C" void __asan_describe_address(void *addr);
extern "C" void __asan_poison_memory_region(void const volatile *addr, size_t
size);


int main() {
  std::cout << __asan_address_is_poisoned(&x) << " " << 
  __asan_address_is_poisoned(&x + 1) << " " << __asan_address_is_poisoned(&x -
1) << std::endl;

  int* p = nullptr;
  x = 1;
  std::thread([&p]() {
    x = 2;
    p = &x;
    std::cout << __asan_address_is_poisoned(p) << " " << 
    __asan_address_is_poisoned(p + 1) << " " << __asan_address_is_poisoned(p -
1) << std::endl;
    __asan_poison_memory_region(p, sizeof(*p));
    std::cout << __asan_address_is_poisoned(p) << " " << 
    __asan_address_is_poisoned(p + 1) << " " << __asan_address_is_poisoned(p -
1) << std::endl;
    __asan_describe_address(p);
  }).join();

  std::cout << &x << " " << &p << std::endl;
  std::cout << __asan_address_is_poisoned(&x) << " " <<
__asan_address_is_poisoned(p) << std::endl;
  __asan_describe_address(&x);
  __asan_describe_address(p);
  std::cout << x << " " << *p << std::endl;
  return 0;
}
```

In this example, we are running a thread that takes the address of a
thread-local variable and it checks whether the local variable is poisoned
after the thread ends. It is not.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>