Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constinit thread_local not destroyed when type incomplete at odr-use #50423

Closed
hubert-reinterpretcast opened this issue Jul 13, 2021 · 1 comment
Labels
bugzilla Issues migrated from bugzilla c++20 miscompilation

Comments

@hubert-reinterpretcast
Copy link
Collaborator

Bugzilla Link 51079
Resolution FIXED
Resolved on Oct 08, 2021 18:47
Version trunk
OS All
CC @zygoloid
Fixed by commit(s) 222305d

Extended Description

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 ():

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 c4ed142)
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

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Oct 9, 2021

We were incorrectly assuming incomplete class types were trivially destructible.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++20 miscompilation
Projects
None yet
Development

No branches or pull requests

1 participant