<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 - constinit thread_local not destroyed when type incomplete at odr-use"
href="https://bugs.llvm.org/show_bug.cgi?id=51079">51079</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>constinit thread_local not destroyed when type incomplete at odr-use
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Keywords</th>
<td>miscompilation
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++2a
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>hstong@ca.ibm.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>When an odr-use of a constinit thread_local variable of incomplete class type
occurs, Clang does not make any attempt to register the odr-use (and thus the
initialization and any associated destructor calls). The case where the
variable is a (possibly multi-dimensional) array of an incomplete class type is
similarly affected.
### SOURCE (<stdin>):
struct A;
extern constinit thread_local A a;
A &foo() { return a; }
### COMPILER INVOCATION:
clang -cc1 -emit-llvm -Wall -Wextra -Werror -pedantic-errors -std=c++20 -xc++
-std=c++20 -
### ACTUAL OUTPUT (IR snippet):
define dso_local nonnull align 1 %struct.A* @_Z3foov() #0 {
entry:
ret %struct.A* @a
}
### EXPECTED OUTPUT (IR snippet):
define dso_local nonnull align 1 dereferenceable(1) %struct.A* @_Z3foov() #0 {
entry:
%0 = call %struct.A* @_ZTW1a()
ret %struct.A* %0
}
### COMPILER VERSION INFO (clang++ -v):
clang version 13.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
c4ed142e695f14ba5675ec6d12226ee706329a0f)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/wandbox/clang-head/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.5.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64</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>