[llvm] In-class initialize DenseMapBase members to avoid Coverity. (PR #177168)
Matt Davis via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 21 05:43:28 PST 2026
https://github.com/enferex created https://github.com/llvm/llvm-project/pull/177168
I've seen a number of false positive defects in Coverity regarding uninitialized instances of some of these members. I've decided to in-class initialize 3 scalar members of `DenseMapBase` to hopefully silence Coverity.
Since the initialization is performed through `initWithExactBucketCount` I think it makes sense to just zero init them. I assume the original intent was to avoid some initialization overhead; however, that seems negligible from my last compile-time tracker results (If I'm reading the results correctly).
I do see some of the insn size percentages jump around but that might be noise. I had run an earlier compile time tracker on the same data, and I think the timing results were a bit different, the most recent run information is below.
Compile time tracker is showing the following output:
Metric | Old | New
-- | -- | --
instructions:u | 35718151M | 35718325M (+0.00%)
wall-time | 614.01s | 613.82s (-0.03%)
size-file | 132278KiB | 132278KiB (+0.00%)
size-file (stage1) | 151065KiB | 151065KiB (-0.00%)
clang build:
Metric Old New
[instructions:u](https://llvm-compile-time-tracker.com/compare_clang.php?from=f97f53e1d925fe702c23ad3a120ad3ab40b4eb51&to=d925643ace32566ea76a60d0642180d077f476f5&stat=instructions%3Au) 35718151M 35718325M (+0.00%)
[wall-time](https://llvm-compile-time-tracker.com/compare_clang.php?from=f97f53e1d925fe702c23ad3a120ad3ab40b4eb51&to=d925643ace32566ea76a60d0642180d077f476f5&stat=wall-time) 614.01s 613.82s (-0.03%)
[size-file](https://llvm-compile-time-tracker.com/compare_clang.php?from=f97f53e1d925fe702c23ad3a120ad3ab40b4eb51&to=d925643ace32566ea76a60d0642180d077f476f5&stat=size-file) 132278KiB 132278KiB (+0.00%)
size-file (stage1) 151065KiB 151065KiB (-0.00%)`
>From d925643ace32566ea76a60d0642180d077f476f5 Mon Sep 17 00:00:00 2001
From: Matt Davis <mattd at nvidia.com>
Date: Wed, 14 Jan 2026 18:00:47 +0000
Subject: [PATCH] In-class initialize DenseMapBase members.
I have seen a number of false positive defects in Coverity regarding
uninitialized instances of some of these members. I've decided to
in-class initialize these to hopefully silence Coverity.
---
llvm/include/llvm/ADT/DenseMap.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index fe8868619730e..d967a231804f6 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -751,10 +751,10 @@ class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
// simplicity of referring to them.
using BaseT = DenseMapBase<DenseMap, KeyT, ValueT, KeyInfoT, BucketT>;
- BucketT *Buckets;
- unsigned NumEntries;
- unsigned NumTombstones;
- unsigned NumBuckets;
+ BucketT *Buckets = nullptr;
+ unsigned NumEntries = 0;
+ unsigned NumTombstones = 0;
+ unsigned NumBuckets = 0;
explicit DenseMap(unsigned NumBuckets, typename BaseT::ExactBucketCount) {
this->initWithExactBucketCount(NumBuckets);
More information about the llvm-commits
mailing list