-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[MLIR] Fix use-after-frees when accessing DistinctAttr storage #148666
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
Merged
gysit
merged 7 commits into
llvm:main
from
graphcore:make-distinct-attr-printable-in-crash-reproducer
Jul 16, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1cf6159
Use shared storage allocator for DistinctAttr when crash recovery
abulavin b0bfc02
fixup: use LLVM_ATOMIC_LIB to link atomics
abulavin 1d9a104
fixup: revert to synchronized allocator
abulavin 5facc37
fixup: update comments
abulavin c02a1b8
fixup: remove mutex from pass manager
abulavin 7449453
fixup: correct typos
abulavin 40fca8d
fixup: hopefully final typo
abulavin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| #include "llvm/Support/CommandLine.h" | ||
| #include "llvm/Support/Compiler.h" | ||
| #include "llvm/Support/Debug.h" | ||
| #include "llvm/Support/ManagedStatic.h" | ||
|
||
| #include "llvm/Support/Mutex.h" | ||
| #include "llvm/Support/RWMutex.h" | ||
| #include "llvm/Support/ThreadPool.h" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| //=== DistinctAttributeAllocatorTest.cpp - DistinctAttr storage alloc test ===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "gtest/gtest.h" | ||
|
|
||
| #include "mlir/IR/Builders.h" | ||
| #include "mlir/IR/BuiltinAttributes.h" | ||
| #include "mlir/IR/MLIRContext.h" | ||
| #include "llvm/Support/CrashRecoveryContext.h" | ||
| #include <thread> | ||
|
|
||
| using namespace mlir; | ||
|
|
||
| // | ||
| // Test that a DistinctAttr that is created on a separate thread does | ||
| // not have its storage deleted when the thread joins. | ||
| // | ||
| TEST(DistinctAttributeAllocatorTest, TestAttributeWellFormedAfterThreadJoin) { | ||
| MLIRContext ctx; | ||
| OpBuilder builder(&ctx); | ||
| DistinctAttr attr; | ||
|
|
||
| std::thread t([&ctx, &attr]() { | ||
| attr = DistinctAttr::create(UnitAttr::get(&ctx)); | ||
| ASSERT_TRUE(attr); | ||
| }); | ||
| t.join(); | ||
|
|
||
| // If the attribute storage got deleted after the thread joins (which we don't | ||
| // want) then trying to access it triggers an assert in Debug mode, and a | ||
| // crash otherwise. Run this in a CrashRecoveryContext to avoid bringing down | ||
| // the whole test suite if this test fails. Additionally, MSAN and/or TSAN | ||
| // should raise failures here if the attribute storage was deleted. | ||
| llvm::CrashRecoveryContext crc; | ||
| EXPECT_TRUE(crc.RunSafely([attr]() { (void)attr.getAbstractAttribute(); })); | ||
| EXPECT_TRUE( | ||
| crc.RunSafely([attr]() { (void)*cast<Attribute>(attr).getImpl(); })); | ||
|
|
||
| ASSERT_TRUE(attr); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.