Skip to content

Commit 907335c

Browse files
[mlir:python] Prevent crash in DenseElementsAttr. (llvm#163564)
This PR fixes a crash in the `bf_getbuffer` implementation of `PyDenseElementsAttribute` that occurred when an element type was not supported, such as `bf16`. I believe that supportion `bf16` is not possible with that protocol but that's out of the scope of this PR. Previsouly, the code raised an `std::exception` out of `bf_getbuffer` that nanobind does not catch (see also pybind/pybind11#3336). The PR makes the function catch all `std::exception`s and manually raises a Python exception instead. Signed-off-by: Ingo Müller <[email protected]>
1 parent 3590a91 commit 907335c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mlir/lib/Bindings/Python/IRAttributes.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,10 @@ PyType_Slot PyDenseElementsAttribute::slots[] = {
13061306
e.restore();
13071307
nb::chain_error(PyExc_BufferError, "Error converting attribute to buffer");
13081308
return -1;
1309+
} catch (std::exception &e) {
1310+
nb::chain_error(PyExc_BufferError,
1311+
"Error converting attribute to buffer: %s", e.what());
1312+
return -1;
13091313
}
13101314
view->obj = obj;
13111315
view->ndim = 1;

0 commit comments

Comments
 (0)