[Mlir-commits] [mlir] [ADT] Initialize function_ref::callable (PR #216686)

Sylvestre Ledru llvmlistbot at llvm.org
Tue Aug 18 03:05:07 PDT 2026


https://github.com/sylvestre updated https://github.com/llvm/llvm-project/pull/216686

>From 817ab1b4f14333dfd383420cf67c58544e65d2ab Mon Sep 17 00:00:00 2001
From: Sylvestre Ledru <sylvestre at debian.org>
Date: Mon, 10 Aug 2026 09:23:11 +0200
Subject: [PATCH] [MLIR] Document the OperationState properties invariant

OperationState keeps `properties` together with the `propertiesDeleter`
and `propertiesSetter` hooks: the two `function_ref`s are non-null
whenever `properties` is non-null, and they are only ever called after
checking `properties`.

Static analyzers do not see that invariant. Because an empty
`function_ref` leaves its `callable` field indeterminate, Coverity
reports 'Uninitialized scalar variable' at every site that copies an
OperationState, which is 6,436 of the 7,201 outstanding findings in the
LLVM Coverity project (nearly all of them in tblgen-generated
Op::create methods).

Rather than initializing the ADT field to appease the checker, document
the invariant and suppress the false positive here.
---
 mlir/include/mlir/IR/OperationSupport.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h
index 942b55e8f7a76..e948a90389569 100644
--- a/mlir/include/mlir/IR/OperationSupport.h
+++ b/mlir/include/mlir/IR/OperationSupport.h
@@ -984,6 +984,13 @@ struct OperationState {
   Attribute propertiesAttr;
 
 private:
+  /// The properties storage, and the hooks used to delete and copy it. These
+  /// three fields are set together (see `getOrAddProperties` and
+  /// `setProperties`) and share the invariant that the two `function_ref`s are
+  /// non-null whenever `properties` is non-null; they are only ever called
+  /// after checking `properties`. Static analyzers do not see this invariant
+  /// and report the empty `function_ref`s as uses of an uninitialized value.
+  // coverity[uninit_member]
   PropertyRef properties;
   llvm::function_ref<void(PropertyRef)> propertiesDeleter;
   llvm::function_ref<void(PropertyRef, const PropertyRef)> propertiesSetter;



More information about the Mlir-commits mailing list