Issues using FileCheck with MLIR tensors

Hello,

We are using FileCheck along with Lit as base test infrastructure for our MLIR dialect.
But, we get some issues due to the FileCheck regular expression syntax []

I didn’t find any workaround yet (for instance, no way to disable regular expressions, or to tell that “[[” is a string to match, and not the start of a regular expression).

Example:

# CHECK-NEXT:   data @const(dense<[[[[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]], [[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]]]]> : tensor<1x2x3x4xsi8>) : tensor<1x2x3x4xsi8>

Any idea ?

https://llvm.org/docs/CommandGuide/FileCheck.html#directive-modifiers says you can use
CHECK-NEXT{LITERAL}: whatever
to disable all regex and variable substitution for that directive.

1 Like

The alternative (before LITERAL was added to FileCheck) looks like: // CHECK: dense<{{\[}}[0, 1]]> : tensor<1x2xi32>

These are actually a big pain to match. CHECK-LITERAL will help as described above but I think it becomes more complex if you want to also match other parts of that line to a captured variable or capture a variable. I’d recommend using something like:

// CHECK-SAME: [0, 1, 2, 3]
// CHECK-SAME: [4, 5, 6, 7]
...

I don’t think there is a need to go overboard matching all the brackets — because those are things tested by other parts.

Thanks for your answers.

CHECK-NEXT{LITERAL} looks the simplest (I had missed this option in the documentation), but in case we still want to have some regex, {{\[}} is the solution.
I had tried {{[}} and \[, but it was not working.

If you’re willing to use multiple CHECK lines, you can use a CHECK-NEXT{LITERAL} to match [[ and then another regular CHECK line