[all-commits] [llvm/llvm-project] 3077c1: [mlir][NFC] Make InsertionGuard properly move cons...

zero9178 via All-commits all-commits at lists.llvm.org
Thu Oct 28 23:56:59 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3077c13f91ef93bb5c1c836b167c8203fca9c26b
      https://github.com/llvm/llvm-project/commit/3077c13f91ef93bb5c1c836b167c8203fca9c26b
  Author: Markus Böck <markus.boeck02 at gmail.com>
  Date:   2021-10-29 (Fri, 29 Oct 2021)

  Changed paths:
    M mlir/include/mlir/IR/Builders.h

  Log Message:
  -----------
  [mlir][NFC] Make InsertionGuard properly move constructible

InsertionGuards move constructor is currently the compiler synthesized implementation which is very bug prone. A move constructed InsertionGuard will get the same builder and insertion point as the one it is constructed from, leading to insertion point being restored twice. This can even happen in non obvious situations on some compilers, such as when returning a move constructible struct from a function.

This patch fixes the issue by properly implementing the move constructor. An InsertionGuard that was used to move construct another InsertionGuard is simply inactive and will not restore the insertion point.

I chose to explicitly delete the move assign operator as its semantics are not clear cut. If one were to strictly follow the rule of 5, you'd have to restore the insertion point before then taking ownership of the others guards fields. I believe that to be rather confusing and/or surprising however. One may still get such semantics using llvm::Optional or std::optional and the emplace method if really needed.

Differential Revision: https://reviews.llvm.org/D112749




More information about the All-commits mailing list