[Mlir-commits] [mlir] [MLIR][Tensor] Fix out-of-bounds FoldEmptyTensorWithDimOp crash #111270 (PR #112196)

Mehdi Amini llvmlistbot at llvm.org
Wed Oct 16 13:55:43 PDT 2024


================
@@ -979,7 +979,9 @@ struct FoldEmptyTensorWithDimOp : public OpRewritePattern<DimOp> {
     auto emptyTensorOp = dimOp.getSource().getDefiningOp<EmptyOp>();
     if (!emptyTensorOp || !maybeConstantIndex)
       return failure();
-    if (!emptyTensorOp.getType().isDynamicDim(*maybeConstantIndex))
+    auto emptyTensorType = emptyTensorOp.getType();
----------------
joker-eph wrote:

>  when it is constant and you can flag it as UB in the compiler we are essentially chosing not to. 

You can absolutely write a pass that would abort compilation in this case if you want. This just does not belong to the IR verifier because UB isn't invalid IR. 

Your local observation of UB in the program isn't even a sign of an incorrect program, because UB is a runtime construct: that is it is very possible that what you see is dead-code.

For example (pseudo IR):
```
%a = constant .... tensor<10xf32>
if (cond) {
 ... = tensor.dim %a, 2
 ....
}
```

Is only an invalid program if at runtime the condition is true. However this isn't an incorrect program if the code-path is never executed. 
Hence it can't be "invalid IR".

https://github.com/llvm/llvm-project/pull/112196


More information about the Mlir-commits mailing list