LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 52047 - MLIR Bufferization is generating leaky code
Summary: MLIR Bufferization is generating leaky code
Status: CONFIRMED
Alias: None
Product: MLIR
Classification: Unclassified
Component: default (show other bugs)
Version: unspecified
Hardware: PC All
: P enhancement
Assignee: Mehdi Amini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-02 20:41 PDT by Mehdi Amini
Modified: 2021-11-10 09:15 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mehdi Amini 2021-10-02 20:41:15 PDT
Many tests in Integration/Dialect/Linalg/CPU are leaky (I'll disable the leak checker in Integration/Dialect/Linalg/CPU/lit.local.cfg for now).


Looking at a simple example like Integration/Dialect/Linalg/CPU/test-subtensor-insert.mlir which looks like:

func @main() {
  %const = constant dense<10.0> : tensor<2xf32>
  %insert_val = constant dense<20.0> : tensor<1xf32>
  %inserted = tensor.insert_slice %insert_val into %const[0][1][1] : tensor<1xf32> into tensor<2xf32>

  %unranked = tensor.cast %inserted : tensor<2xf32> to tensor<*xf32>
  call @print_memref_f32(%unranked) : (tensor<*xf32>) -> ()

  return
}

Running through ` -linalg-bufferize -std-bufferize  -tensor-constant-bufferize -tensor-bufferize -func-bufferize  -finalizing-bufferize  ` yield:

module  {
  memref.global "private" constant @__constant_1xf32 : memref<1xf32> = dense<2.000000e+01>
  memref.global "private" constant @__constant_2xf32 : memref<2xf32> = dense<1.000000e+01>
  func @main() {
    %0 = memref.get_global @__constant_2xf32 : memref<2xf32>
    %1 = memref.get_global @__constant_1xf32 : memref<1xf32>
    %2 = memref.alloc() : memref<2xf32>
    linalg.copy(%0, %2) : memref<2xf32>, memref<2xf32> 
    %3 = memref.subview %2[0] [1] [1] : memref<2xf32> to memref<1xf32>
    linalg.copy(%1, %3) : memref<1xf32>, memref<1xf32> 
    %4 = memref.cast %2 : memref<2xf32> to memref<*xf32>
    call @print_memref_f32(%4) : (memref<*xf32>) -> ()
    return
  }
  func private @print_memref_f32(memref<*xf32>)
}



An alloc was created but there clearly isn't any free here.
Comment 1 Stephan Herhut 2021-11-10 00:52:25 PST
This should be fixed by https://reviews.llvm.org/D111059.

Not sure how to verify. Can you help Mehdi?
Comment 2 Mehdi Amini 2021-11-10 09:15:53 PST
You can just repro locally by adding '-DLLVM_USE_SANITIZER=Address;Undefined' to your cmake invocation (I'm also building with clang as a host tool).

See the bot here: https://lab.llvm.org/staging/#/builders/191/builds/1595/
(your patch broke it, there is still one test not fixed)