[llvm] [NFC] Address cppcheck legacyUninitvar (PR #175417)
Konrad Kleine via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 12 01:30:01 PST 2026
https://github.com/kwk updated https://github.com/llvm/llvm-project/pull/175417
>From d38253a1ca0d70b6b58ff659d5dbc31a1d89ed6d Mon Sep 17 00:00:00 2001
From: Konrad Kleine <kkleine at redhat.com>
Date: Sun, 11 Jan 2026 09:11:09 +0100
Subject: [PATCH] [NFC] Suppress false-positive cppcheck legacyUninitvar in
SaturatingAdd
Suppress this false-positive
```
Error: CPPCHECK_WARNING (CWE-457): [#def65]
llvm-project-21.1.8.src/llvm/include/llvm/Support/MathExtras.h:620: error[legacyUninitvar]: Uninitialized variable: Dummy
# 618| SaturatingAdd(T X, T Y, bool *ResultOverflowed = nullptr) {
# 619| bool Dummy;
# 620|-> bool &Overflowed = ResultOverflowed ? *ResultOverflowed : Dummy;
# 621| // Hacker's Delight, p. 29
# 622| T Z = X + Y;
```
(Source: https://svashisht.fedorapeople.org/openscanhub/mass-scans/f44-08-Jan-2026/llvm-21.1.8-1.fc44/scan-results.html#def65)
The `Overflowed` variable is first written to.
That means the initial value in `Dummy` doesn't
matter and therfore this is a false-positive.
---
llvm/include/llvm/Support/MathExtras.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index 0a253efc2abcb..0d63b2f8f6d62 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -608,6 +608,7 @@ template <typename T>
std::enable_if_t<std::is_unsigned_v<T>, T>
SaturatingAdd(T X, T Y, bool *ResultOverflowed = nullptr) {
bool Dummy;
+ // cppcheck-suppress legacyUninitvar
bool &Overflowed = ResultOverflowed ? *ResultOverflowed : Dummy;
// Hacker's Delight, p. 29
T Z = X + Y;
More information about the llvm-commits
mailing list