LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 51079 - constinit thread_local not destroyed when type incomplete at odr-use
Summary: constinit thread_local not destroyed when type incomplete at odr-use
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: C++2a (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords: miscompilation
Depends on:
Blocks:
 
Reported: 2021-07-13 09:55 PDT by hstong
Modified: 2021-10-08 18:47 PDT (History)
4 users (show)

See Also:
Fixed By Commit(s): 222305d6ff6f6d156145d7de4f06d1c368383e41


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description hstong 2021-07-13 09:55:38 PDT
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 (https://github.com/llvm/llvm-project.git 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
Comment 1 Richard Smith 2021-10-08 18:47:05 PDT
We were incorrectly assuming incomplete class types were trivially destructible.