Skip to content

Commit 94647ee

Browse files
authored
[mlir][spirv] Remove destroyed values from ValueIDMap (llvm#164098)
When serializing SPIR-V MLIR containing externally linked function with debug enabled, the serialization crashes as `printValueIDMap` tries to print a key value that has been already destroyed. This happen as for externally linked function the body of the function is erased, that causes arguments to be destroyed as well, but the valueIDMap was never updated.
1 parent 136c406 commit 94647ee

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,14 @@ LogicalResult Serializer::processFuncOp(spirv::FuncOp op) {
311311
op.addEntryBlock();
312312
if (failed(processFuncParameter(op)))
313313
return failure();
314+
315+
// Erasing the body of the function destroys arguments, so we need to remove
316+
// them from the map to avoid problems when processing invalid values used
317+
// as keys. We have already serialized function arguments so we probably can
318+
// remove them from the map as external function will not have any uses.
319+
for (Value arg : op.getArguments())
320+
valueIDMap.erase(arg);
321+
314322
// Don't need to process the added block, there is nothing to process,
315323
// the fake body was added just to get the arguments, remove the body,
316324
// since it's use is done.

mlir/test/Target/SPIRV/function-decorations.mlir

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: mlir-translate -no-implicit-module -test-spirv-roundtrip -split-input-file -verify-diagnostics %s | FileCheck %s
1+
// RUN: mlir-translate --no-implicit-module --test-spirv-roundtrip --split-input-file %s | FileCheck %s
2+
// RUN: mlir-translate --no-implicit-module --test-spirv-roundtrip --split-input-file --debug %s | FileCheck %s
23

34
spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Shader, Linkage], []> {
45
spirv.func @linkage_attr_test_kernel() "DontInline" attributes {} {

0 commit comments

Comments
 (0)