[Mlir-commits] [mlir] 42f87a0 - [mlir][ods] NFC Fix ASAN error in FormatParser

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Feb 1 20:30:59 PST 2022


Author: Mogball
Date: 2022-02-02T04:29:57Z
New Revision: 42f87a0354562b6bfb3a35480677ff07c377d482

URL: https://github.com/llvm/llvm-project/commit/42f87a0354562b6bfb3a35480677ff07c377d482
DIFF: https://github.com/llvm/llvm-project/commit/42f87a0354562b6bfb3a35480677ff07c377d482.diff

LOG: [mlir][ods] NFC Fix ASAN error in FormatParser

Some FormatElement subclasses contain `std::vector`. Since these use
BumpPtrAllocator, they need to be converted to trailing objects.
However, this is not a trivial fix so I will leave it as a FIXME and use
a workaround.

Added: 
    

Modified: 
    mlir/tools/mlir-tblgen/FormatGen.cpp
    mlir/tools/mlir-tblgen/FormatGen.h

Removed: 
    


################################################################################
diff  --git a/mlir/tools/mlir-tblgen/FormatGen.cpp b/mlir/tools/mlir-tblgen/FormatGen.cpp
index 006995d7a5d6..a4c9dcf28981 100644
--- a/mlir/tools/mlir-tblgen/FormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/FormatGen.cpp
@@ -181,6 +181,8 @@ FormatToken FormatLexer::lexIdentifier(const char *tokStart) {
 // FormatParser
 //===----------------------------------------------------------------------===//
 
+FormatElement::~FormatElement() = default;
+
 FormatParser::~FormatParser() = default;
 
 FailureOr<std::vector<FormatElement *>> FormatParser::parse() {

diff  --git a/mlir/tools/mlir-tblgen/FormatGen.h b/mlir/tools/mlir-tblgen/FormatGen.h
index d03ceec43942..4ad591d49ebc 100644
--- a/mlir/tools/mlir-tblgen/FormatGen.h
+++ b/mlir/tools/mlir-tblgen/FormatGen.h
@@ -158,7 +158,9 @@ class FormatLexer {
 /// dialect.
 class FormatElement {
 public:
-  /// The top-level kinds of format elements.
+  virtual ~FormatElement();
+
+  // The top-level kinds of format elements.
   enum Kind { Literal, Variable, Whitespace, Directive, Optional };
 
   /// Support LLVM-style RTTI.
@@ -410,8 +412,12 @@ class FormatParser {
   /// Allocate and construct a format element.
   template <typename FormatElementT, typename... Args>
   FormatElementT *create(Args &&...args) {
-    FormatElementT *ptr = allocator.Allocate<FormatElementT>();
-    ::new (ptr) FormatElementT(std::forward<Args>(args)...);
+    // FormatElementT *ptr = allocator.Allocate<FormatElementT>();
+    // ::new (ptr) FormatElementT(std::forward<Args>(args)...);
+    // return ptr;
+    auto mem = std::make_unique<FormatElementT>(std::forward<Args>(args)...);
+    FormatElementT *ptr = mem.get();
+    allocator.push_back(std::move(mem));
     return ptr;
   }
 
@@ -493,7 +499,10 @@ class FormatParser {
 private:
   /// The format parser retains ownership of the format elements in a bump
   /// pointer allocator.
-  llvm::BumpPtrAllocator allocator;
+  // FIXME: FormatElement with `std::vector` need to be converted to use
+  // trailing objects.
+  // llvm::BumpPtrAllocator allocator;
+  std::vector<std::unique_ptr<FormatElement>> allocator;
   /// The format lexer to use.
   FormatLexer lexer;
   /// The current token in the lexer.


        


More information about the Mlir-commits mailing list