This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][Tensor] Avoid crash on negative dimensions
ClosedPublic

Authored by rikhuijzer on Jul 19 2023, 10:47 AM.

Details

Summary

In https://reviews.llvm.org/D151611, a check was added to the tensor verifier to
emit an error on negative tensor dimensions. This check allowed for dynamic
dimensions, hence negative dimensions were still able to get through the verifier.
This is a problem in situations such as #60558, where the dynamic dimension is
converted to a static (and possibly negative) dimension by another pass in the
compiler. This patch fixes that by doing another check during the
StaticTensorGenerate conversion, and return a failure if the dimension is
negative.

As a side-note, I have to admit that I do not know why returning a failure in
StaticTensorGenerate gives a nice "tensor dimensions must be non-negative"
error. I suspect that the verifier runs again when return failure() is called,
but I am not sure.

Fixes #60558.

Diff Detail

Event Timeline

rikhuijzer created this revision.Jul 19 2023, 10:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2023, 10:47 AM
rikhuijzer requested review of this revision.Jul 19 2023, 10:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2023, 10:47 AM
mehdi_amini accepted this revision.Jul 19 2023, 11:42 AM
This revision is now accepted and ready to land.Jul 19 2023, 11:42 AM
This revision was automatically updated to reflect the committed changes.