Use-list assertion failure during secret to mod arith conversion
- Dominant language
- MLIR
- Stars
- 906
- Forks
- 171
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 32
Description
**Test commit**
[a413796feb31eb6a1e70160308defe4d0250d09e](https://github.com/google/heir/commit/a413796feb31eb6a1e70160308defe4d0250d09e)
**Description**
The `--secret-to-mod-arith` pass triggers an assertion failure: `Cannot destroy a value that still has uses!`; this occurs when `secret.generic` contains nested regions (like `scf.if`).
**Steps to reproduce**
- Minimal MLIR program (test.mlir)
```
"builtin.module"() ({
"func.func"() <{
function_type = (!secret.secret, !secret.secret) -> !secret.secret,
sym_name = "cond"
}> ({
^bb0(%arg0: !secret.secret, %arg1: !secret.secret):
%0 = "secret.generic"(%arg0, %arg1) ({
^bb0(%arg2: i16, %arg3: i1):
%1 = "scf.if"(%arg3) ({
"scf.yield"(%arg2) : (i16) -> ()
}, {
"scf.yield"(%arg2) : (i16) -> ()
}) : (i1) -> i16
"secret.yield"(%1) : (i16) -> ()
}) : (!secret.secret, !secret.secret) -> !secret.secret
"func.return"(%0) : (!secret.secret) -> ()
}) : () -> ()
}) : () -> ()
```
**Command**
```
heir-opt --secret-to-mod-arith=modulus=17 test.mlir
```
**Output**
```
heir-opt: external/llvm-project/mlir/include/mlir/IR/UseDefLists.h:198: mlir::IRObjectWithUseList::~IRObjectWithUseList() [OperandType = mlir::OpOperand]: Assertion `use_empty() && "Cannot destroy a value that still has uses!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: /workdir/heir/bin/heir-opt --secret-to-mod-arith=modulus=17 test.mlir
#0 0x000055811515b9c6 ___interceptor_backtrace (/workdir/heir/bin/heir-opt+0x5b549c6)
#1 0x00005581209141c2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /proc/self/cwd/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:838:8
#2 0x0000558120915001 llvm::sys::RunSignalHandlers() /proc/self/cwd/external/llvm-project/llvm/lib/Support/Signals.cpp:105:18
#3 0x0000558120915001 SignalHandler(int, siginfo_t*, void*) /proc/self/cwd/external/llvm-project/llvm/lib/Support/Unix/Signals.inc:409:3
#4 0x00007f6a68323520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x00007f6a683779fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#6 0x00007f6a68323476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#7 0x00007f6a683097f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#8 0x00007f6a6830971b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#9 0x00007f6a6831ae96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x000055811fe29a8e mlir::Block::~Block() /proc/self/cwd/external/llvm-project/mlir/lib/IR/Block.cpp:21:3
#11 0x00005581200709cc llvm::ilist_alloc_traits::deleteNode(mlir::Block*) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:42:39
#12 0x00005581200709cc llvm::iplist_impl, llvm::ilist_traits >::erase(llvm::ilist_iterator, false, false>) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:205:5
#13 0x000055812006e0d0 llvm::iplist_impl, llvm::ilist_traits >::erase(llvm::ilist_iterator, false, false>, llvm::ilist_iterator, false, false>) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:0:15
#14 0x000055812006e0d0 llvm::iplist_impl, llvm::ilist_traits >::clear() /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:246:18
#15 0x000055812006e0d0 llvm::iplist_impl, llvm::ilist_traits >::~iplist_impl() /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:147:20
#16 0x000055812006e0d0 mlir::Region::~Region() /proc/self/cwd/external/llvm-project/mlir/lib/IR/Region.cpp:20:1
#17 0x000055812002fcef mlir::Operation::~Operation() /proc/self/cwd/external/llvm-project/mlir/lib/IR/Operation.cpp:200:21
#18 0x000055812004a5c4 mlir::Operation::destroy() /proc/self/cwd/external/llvm-project/mlir/lib/IR/Operation.cpp:213:3
#19 0x000055812004a5c4 llvm::ilist_traits::deleteNode(mlir::Operation*) /proc/self/cwd/external/llvm-project/mlir/lib/IR/Operation.cpp:491:7
#20 0x000055812004a5c4 llvm::iplist_impl, llvm::ilist_traits >::erase(llvm::ilist_iterator, false, false>) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:205:5
#21 0x0000558120067e2e mlir::RewriterBase::eraseOp(mlir::Operation*) /proc/self/cwd/external/llvm-project/mlir/lib/IR/PatternMatch.cpp:0:9
#22 0x00005581200675b6 mlir::RewriterBase::replaceOp(mlir::Operation*, mlir::ValueRange) /proc/self/cwd/external/llvm-project/mlir/lib/IR/PatternMatch.cpp:136:1
#23 0x000055811f377e0c mlir::detail::ConversionPatternRewriterImpl::replaceOp(mlir::Operation*, llvm::SmallVector, 1u>&&) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:0:23
#24 0x000055811f37e913 llvm::SmallVectorBase::size() const /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/SmallVector.h:79:32
#25 0x000055811f37e913 llvm::SmallVectorTemplateCommon, void>::end() /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/SmallVector.h:272:37
#26 0x000055811f37e913 llvm::SmallVector, 1u>::~SmallVector() /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/SmallVector.h:1205:46
#27 0x000055811f37e913 mlir::ConversionPatternRewriter::replaceOp(mlir::Operation*, mlir::ValueRange) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2090:1
#28 0x000055811f37ded5 mlir::ConversionPatternRewriter::replaceOp(mlir::Operation*, mlir::Operation*) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2070:1
#29 0x00005581156da9f6 mlir::heir::ConvertAnyNestedGeneric::matchAndRewrite(mlir::heir::secret::GenericOp, mlir::heir::secret::GenericOpAdaptor, mlir::ConversionPatternRewriter&) const /proc/self/cwd/lib/Dialect/Secret/Conversions/SecretToModArith/SecretToModArith.cpp:0:14
#30 0x00005581152de6c1 llvm::LogicalResult mlir::ConversionPattern::dispatchTo1To1, mlir::heir::secret::GenericOp>(mlir::OpConversionPattern const&, mlir::heir::secret::GenericOp, mlir::heir::secret::GenericOp::GenericAdaptor >, mlir::ConversionPatternRewriter&) /proc/self/cwd/external/llvm-project/mlir/include/mlir/Transforms/DialectConversion.h:1025:15
#31 0x00005581152de3b3 mlir::OpConversionPattern::matchAndRewrite(mlir::heir::secret::GenericOp, mlir::heir::secret::GenericOpGenericAdaptor >, mlir::ConversionPatternRewriter&) const /proc/self/cwd/external/llvm-project/mlir/include/mlir/Transforms/DialectConversion.h:727:12
#32 0x00005581152de005 mlir::OpConversionPattern::matchAndRewrite(mlir::Operation*, llvm::ArrayRef, mlir::ConversionPatternRewriter&) const /proc/self/cwd/external/llvm-project/mlir/include/mlir/Transforms/DialectConversion.h:713:12
#33 0x000055811f385771 mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:0:10
#34 0x000055811f4b4112 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref, llvm::function_ref, llvm::function_ref)::$_0::operator()() const /proc/self/cwd/external/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:0:31
#35 0x000055811f4b4112 void llvm::function_ref::callback_fn, llvm::function_ref, llvm::function_ref)::$_0>(long) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#36 0x000055811f4b0375 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref, llvm::function_ref, llvm::function_ref) /proc/self/cwd/external/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:197:5
#37 0x000055811f389c5c (anonymous namespace)::OperationLegalizer::legalizeWithPattern(mlir::Operation*) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2767:21
#38 0x000055811f389c5c (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2533:17
#39 0x000055811f388170 mlir::OperationConverter::convert(mlir::Operation*) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:3288:7
#40 0x000055811f38aa80 mlir::OperationConverter::convertOperations(llvm::ArrayRef) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:3385:0
#41 0x000055811f3ab5af applyConversion(llvm::ArrayRef, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode)::$_0::operator()() const /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:4107:9
#42 0x000055811f3ab5af void llvm::function_ref::callback_fn, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode)::$_0>(long) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#43 0x000055811f398633 applyConversion(llvm::ArrayRef, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:0:12
#44 0x000055811f39895a mlir::applyPartialConversion(llvm::ArrayRef, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:4120:10
#45 0x000055811f39895a mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) /proc/self/cwd/external/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:4127:10
#46 0x00005581156ca0d8 mlir::heir::SecretToModArith::runOnOperation() /proc/self/cwd/lib/Dialect/Secret/Conversions/SecretToModArith/SecretToModArith.cpp:421:16
#47 0x000055811fc3b537 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_3::operator()() const /proc/self/cwd/external/llvm-project/mlir/lib/Pass/Pass.cpp:610:22
#48 0x000055811fc3b537 void llvm::function_ref::callback_fn(long) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#49 0x000055811fc29270 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /proc/self/cwd/external/llvm-project/mlir/lib/Pass/Pass.cpp:603:3
#50 0x000055811fc2ad95 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /proc/self/cwd/external/llvm-project/mlir/lib/Pass/Pass.cpp:682:9
#51 0x000055811fc38b06 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /proc/self/cwd/external/llvm-project/mlir/lib/Pass/Pass.cpp:1117:10
#52 0x000055811fc37263 mlir::PassManager::run(mlir::Operation*) /proc/self/cwd/external/llvm-project/mlir/lib/Pass/Pass.cpp:0:60
#53 0x0000558118d194b1 performActions(llvm::raw_ostream&, std::shared_ptr const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) /proc/self/cwd/external/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:568:7
#54 0x0000558118d1778e processBuffer(llvm::raw_ostream&, std::unique_ptr >, llvm::MemoryBufferRef, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, mlir::SourceMgrDiagnosticVerifierHandler*, llvm::ThreadPoolInterface*) /proc/self/cwd/external/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:0:12
#55 0x0000558118d1778e mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr >, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0::operator()(std::unique_ptr >, llvm::MemoryBufferRef, llvm::raw_ostream&) const /proc/self/cwd/external/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:733:12
#56 0x0000558118d1778e llvm::LogicalResult llvm::function_ref >, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::callback_fn >, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0>(long, std::unique_ptr >, llvm::MemoryBufferRef const&, llvm::raw_ostream&) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#57 0x00005581200daa79 llvm::function_ref >, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::operator()(std::unique_ptr >, llvm::MemoryBufferRef const&, llvm::raw_ostream&) const /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:0
#58 0x00005581200daa79 mlir::splitAndProcessBuffer(std::unique_ptr >, llvm::function_ref >, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef)::$_0::operator()(llvm::StringRef) const /proc/self/cwd/external/llvm-project/mlir/lib/Support/ToolUtilities.cpp:94:13
#59 0x00005581200d9cef void llvm::interleave >, llvm::function_ref >, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef)::$_0, void llvm::interleave, mlir::splitAndProcessBuffer(std::unique_ptr >, llvm::function_ref >, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef)::$_0, llvm::raw_ostream, llvm::StringRef>(llvm::SmallVector const&, llvm::raw_ostream&, mlir::splitAndProcessBuffer(std::unique_ptr >, llvm::function_ref >, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef)::$_0, llvm::StringRef const&)::'lambda'(), void>(llvm::SmallVector, llvm::SmallVector, mlir::splitAndProcessBuffer(std::unique_ptr >, llvm::function_ref >, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef)::$_0, llvm::raw_ostream) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLExtras.h:2179:16
#60 0x00005581200d9cef void llvm::interleave, mlir::splitAndProcessBuffer(std::unique_ptr >, llvm::function_ref >, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef)::$_0, llvm::raw_ostream, llvm::StringRef>(llvm::SmallVector const&, llvm::raw_ostream&, mlir::splitAndProcessBuffer(std::unique_ptr >, llvm::function_ref >, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef)::$_0, llvm::StringRef const&) /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/STLExtras.h:2199:3
#61 0x00005581200d9cef mlir::splitAndProcessBuffer(std::unique_ptr >, llvm::function_ref >, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) /proc/self/cwd/external/llvm-project/mlir/lib/Support/ToolUtilities.cpp:97:3
#62 0x0000558118d0ffff mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr >, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) /proc/self/cwd/external/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:738:26
#63 0x0000558118d10b99 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) /proc/self/cwd/external/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:784:0
#64 0x0000558118d113ce mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) /proc/self/cwd/external/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:800:10
#65 0x00005581151f7be1 mlir::asMainReturnCode(llvm::LogicalResult) /proc/self/cwd/external/llvm-project/mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h:0:0
#66 0x00005581151f7be1 main /proc/self/cwd/tools/heir-opt.cpp:463:10
#67 0x00007f6a6830ad90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#68 0x00007f6a6830ae40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#69 0x0000558115115025 _start (/workdir/heir/bin/heir-opt+0x5b0e025)
Aborted
```
Contributor guide
Assessment
This issue has not been assessed yet.