[all-commits] [llvm/llvm-project] e57670: [clang][CodeGen] Keep existing global definition o...

Yuxuan Chen via All-commits all-commits at lists.llvm.org
Tue Sep 15 16:32:45 PDT 2026


  Branch: refs/heads/users/yuxuanchen1997/header-unit-double-emission-fix
  Home:   https://github.com/llvm/llvm-project
  Commit: e57670cdacbb55682a7ab83fb118a7d55b30aa83
      https://github.com/llvm/llvm-project/commit/e57670cdacbb55682a7ab83fb118a7d55b30aa83
  Author: Yuxuan Chen <i at yuxuan.ch>
  Date:   2026-09-15 (Tue, 15 Sep 2026)

  Changed paths:
    M clang/lib/CodeGen/CodeGenModule.cpp
    A clang/test/CodeGenCXX/header-unit-inline-var-double-emission.cpp

  Log Message:
  -----------
  [clang][CodeGen] Keep existing global definition on type mismatch in GetOrCreateLLVMGlobal

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



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list