When a global is requested for definition but a definition with the same mangled name already exists, return it as is instead of creating a fresh global and erasing the defined one, even if its type differs from the requested type. The type can legitimately differ when the initializer folded to a different (e.g. anonymous) type, as happens with unions. Erasing the defined global dangles pointers held by callers, e.g. the `AssociatedData` of entries in `llvm.global_ctors`, leading to a use-after-free crash during `EmitCtorList`. This also keeps the deferred-decls "already emitted" check sound, since it queries with `IsForDefinition`, which must be non-destructive. Add a header-unit regression test: an inline variable with an anonymous-union member, constant-initialized but requiring dynamic destructor registration, must be emitted exactly once when imported from header units. The folded initializer has an anonymous type that differs from the declared type; a second emission used to replace (and erase) the already-defined global, leaving a dangling pointer in `llvm.global_ctors` (use-after-free, observable as a crash under ASan). Assisted-By: Meta Muse 1.3 Co-authored-by: Michael Park <mcypark@gmail.com> (cherry picked from commit 2a6fdac960de3a6bae854474f12e8f1edfcd9a04)
The LLVM Compiler Infrastructure
Welcome to the LLVM project!
This repository contains the source code for LLVM, a toolkit for the construction of highly optimized compilers, optimizers, and run-time environments.
The LLVM project has multiple components. The core of the project is itself called "LLVM". This contains all of the tools, libraries, and header files needed to process intermediate representations and convert them into object files. Tools include an assembler, disassembler, bitcode analyzer, and bitcode optimizer.
C-like languages use the Clang frontend. This component compiles C, C++, Objective-C, and Objective-C++ code into LLVM bitcode -- and from there into object files, using LLVM.
Other components include: the libc++ C++ standard library, the LLD linker, and more.
Getting the Source Code and Building LLVM
Consult the Getting Started with LLVM page for information on building and running LLVM.
For information on how to contribute to the LLVM project, please take a look at the Contributing to LLVM guide.
Getting in touch
Join the LLVM Discourse forums, Discord chat, LLVM Office Hours or Regular sync-ups.
The LLVM project has adopted a code of conduct for participants to all modes of communication within the project.