[llvm] Initialize function_ref::callable (PR #216686)

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 03:29:13 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-adt

Author: Sylvestre Ledru (sylvestre)

<details>
<summary>Changes</summary>

A default-constructed function_ref initialized callback but left the callable field indeterminate. The value is then copied whenever such an empty function_ref is copied or moved (e.g. OperationState's propertiesDeleter/propertiesSetter members in every generated MLIR Op::create method), and operator== reads it, which is undefined behavior for empty refs.

Coverity reports this as 'Uninitialized scalar variable' at every use site: 7,201 outstanding findings in the LLVM Coverity project, 6,436 of them in tblgen-generated Op::create methods. Initializing the field fixes the entire class at the root for one store.

---
Full diff: https://github.com/llvm/llvm-project/pull/216686.diff


1 Files Affected:

- (modified) llvm/include/llvm/ADT/STLFunctionalExtras.h (+1-1) 


``````````diff
diff --git a/llvm/include/llvm/ADT/STLFunctionalExtras.h b/llvm/include/llvm/ADT/STLFunctionalExtras.h
index a4d50dc3648be..f6dbd8b1840ac 100644
--- a/llvm/include/llvm/ADT/STLFunctionalExtras.h
+++ b/llvm/include/llvm/ADT/STLFunctionalExtras.h
@@ -39,7 +39,7 @@ template<typename Fn> class function_ref;
 template <typename Ret, typename... Params>
 class LLVM_GSL_POINTER function_ref<Ret(Params...)> {
   Ret (*callback)(intptr_t callable, Params ...params) = nullptr;
-  intptr_t callable;
+  intptr_t callable = 0;
 
   template<typename Callable>
   static Ret callback_fn(intptr_t callable, Params ...params) {

``````````

</details>


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


More information about the llvm-commits mailing list