[all-commits] [llvm/llvm-project] 73440c: [mlir] Define proper DenseMapInfo for Interfaces
zero9178 via All-commits
all-commits at lists.llvm.org
Wed Jul 6 03:39:22 PDT 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 73440ca9f878f9c4150b339bdd56b234d9167ee9
https://github.com/llvm/llvm-project/commit/73440ca9f878f9c4150b339bdd56b234d9167ee9
Author: Markus Böck <markus.boeck02 at gmail.com>
Date: 2022-07-06 (Wed, 06 Jul 2022)
Changed paths:
M mlir/include/mlir/IR/Attributes.h
M mlir/include/mlir/IR/OpDefinition.h
M mlir/include/mlir/IR/Types.h
M mlir/include/mlir/Support/InterfaceSupport.h
M mlir/unittests/IR/CMakeLists.txt
A mlir/unittests/IR/InterfaceTest.cpp
Log Message:
-----------
[mlir] Define proper DenseMapInfo for Interfaces
Prior to this patch, using any kind of interface (op interface, attr interface, type interface) as the key of a llvm::DenseSet, llvm::DenseMap or other related containers, leads to invalid pointer dereferences, despite compiling.
The gist of the problem is that a llvm::DenseMapInfo specialization for the base type (aka one of Operation*, Type or Attribute) are selected when using an interface as a key, which uses getFromOpaquePointer with invalid pointer addresses to construct instances for the empty key and tombstone key values. The interface is then constructed with this invalid base type and an attempt is made to lookup the implementation in the interface map, which then dereferences the invalid pointer address. (For more details and the exact call chain involved see the GitHub issue below)
The current workaround is to use the more generic base type (eg. instead of DenseSet<FunctionOpInterface>, DenseSet<Operation*>), but this is strictly worse from a code perspective (doesn't enforce the invariant, code is less self documenting, having to insert casts etc).
This patch fixes that issue by defining a DenseMapInfo specialization of Interface subclasses which uses a new constructor to construct an instance without querying a concept. That allows getEmptyKey and getTombstoneKey to construct an interface with invalid pointer values.
Fixes https://github.com/llvm/llvm-project/issues/54908
Differential Revision: https://reviews.llvm.org/D129038
More information about the All-commits
mailing list