[all-commits] [llvm/llvm-project] 0aa5ba: [mlir] Fix DistinctAttributeUniquer deleting attri...

Artemiy Bulavin via All-commits all-commits at lists.llvm.org
Thu Mar 13 07:01:02 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0aa5ba43a0d11ce8e7f143380ae75fea516b6841
      https://github.com/llvm/llvm-project/commit/0aa5ba43a0d11ce8e7f143380ae75fea516b6841
  Author: Artemiy Bulavin <artemiyb at graphcore.ai>
  Date:   2025-03-13 (Thu, 13 Mar 2025)

  Changed paths:
    M mlir/include/mlir/IR/MLIRContext.h
    M mlir/lib/IR/AttributeDetail.h
    M mlir/lib/IR/MLIRContext.cpp
    M mlir/lib/Pass/PassCrashRecovery.cpp
    A mlir/test/Dialect/LLVMIR/add-debuginfo-func-scope-with-crash-reproduction.mlir
    A mlir/test/IR/test-builtin-distinct-attrs-with-crash-reproduction.mlir

  Log Message:
  -----------
  [mlir] Fix DistinctAttributeUniquer deleting attribute storage when crash reproduction is enabled (#128566)

Currently, `DistinctAttr` uses an allocator wrapped in a
`ThreadLocalCache` to manage attribute storage allocations. This ensures
all allocations are freed when the allocator is destroyed.

However, this setup can cause use-after-free errors when
`mlir::PassManager` runs its passes on a separate thread as a result of
crash reproduction being enabled. Distinct attribute storages are
created in the child thread's local storage and freed once the thread
joins. Attempting to access these attributes after this can result in
segmentation faults, such as during printing or alias analysis.

Example: This invocation of `mlir-opt` demonstrates the segfault issue
due to distinct attributes being created in a child thread and their
storage being freed once the thread joins:
```
mlir-opt --mlir-pass-pipeline-crash-reproducer=. --test-distinct-attrs mlir/test/IR/test-builtin-distinct-attrs.mlir
```

This pull request changes the distinct attribute allocator to use
different allocators depending on whether or not threading is enabled
and whether or not the pass manager is running its passes in a separate
thread. If multithreading is disabled, a non thread-local allocator is
used. If threading remains enabled and the pass manager invokes its pass
pipelines in a child thread, then a non-thread local but synchronised
allocator is used. This ensures that the lifetime of allocated storage
persists beyond the lifetime of the child thread.

I have added two tests for the `-test-distinct-attrs` pass and the
`-enable-debug-info-on-llvm-scope` passes that run them with crash
reproduction enabled.



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