[all-commits] [llvm/llvm-project] 62f429: [clang][CodeGen] Skip deleted globals in emitUsed ...

Emery Conrad via All-commits all-commits at lists.llvm.org
Tue Jul 28 08:12:57 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 62f429ec6e85224a0f7fa6d4e51595b27e5ac9c1
      https://github.com/llvm/llvm-project/commit/62f429ec6e85224a0f7fa6d4e51595b27e5ac9c1
  Author: Emery Conrad <conrade.ctc at gmail.com>
  Date:   2026-07-28 (Tue, 28 Jul 2026)

  Changed paths:
    M clang/lib/CodeGen/CodeGenModule.cpp
    A clang/test/Interpreter/used-global-after-error.cpp

  Log Message:
  -----------
  [clang][CodeGen] Skip deleted globals in emitUsed (#210959)

A global on the `llvm.used`/`llvm.compiler.used` list can be deleted
before the module is released: CodeGen erases an unreferenced
`GlobalValue` without RAUW when the same mangled name is redefined with
a different type (`GetOrCreateLLVMGlobal`), which nulls the
`WeakTrackingVH` on the used list — value handles are not uses, so the
`use_empty()` guard does not protect them.

In whole-TU compilation this is unobservable because the accompanying
`err_duplicate_mangled_name` suppresses `Release()`. The incremental
interpreter, however, clears the diagnostic state after the failed parse
and keeps building the same module, so the next successful parse runs
`Release()` and crashes in `emitUsed` dereferencing the dead handle:

```
clang-repl> __attribute__((used)) int a asm("sym") = 1; float b asm("sym") = 2.0f;
clang-repl> int ok = 0;
clang-repl: .../ValueHandle.h:95: llvm::Value& llvm::ValueHandleBase::operator*() const: Assertion `V && "Dereferencing deleted ValueHandle"' failed.
```

Out-of-tree incremental clients hit the same crash through other routes
that delete an emitted used global before module release (e.g.
CppInterOp's force-emission of reflection queries, see
compiler-research/CppInterOp#1068).

Fix: skip null handles when building the used array. The repro above is
included as a lit test; `clang/test/Interpreter`, `clang/test/CodeGen`,
and `clang/test/CodeGenCXX` pass locally.

🤖 Done with the help of [Claude Code](https://claude.com/claude-code)
(Fable 5, human in the loop)

Co-authored-by: Emery Conrad <emery.conrad at chicagotrading.com>



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