[mlir] Initialize the Region::container field to nullptr by default
authorAlex Zinenko <zinenko@google.com>
Sun, 10 May 2020 12:14:04 +0000 (14:14 +0200)
committerAlex Zinenko <zinenko@google.com>
Sun, 10 May 2020 12:23:35 +0000 (14:23 +0200)
Region has a default constructor that is called when a region is constructed
while an operation is being created, and therefore before the region can be
attached to this operation. The `container` field is uninitialized, which makes
it impossible to check programmatically if a Region is attached to an operation
or not, leading to sly memory errors when this field is read. Initialize it to
nullptr by default and thus make sure one can check if a region is attached to
an operation or not.

mlir/include/mlir/IR/Region.h

index 0efa58c..35e773d 100644 (file)
@@ -231,7 +231,7 @@ private:
   BlockListType blocks;
 
   /// This is the object we are part of.
-  Operation *container;
+  Operation *container = nullptr;
 };
 
 /// This class provides an abstraction over the different types of ranges over