[llvm] [NFC][CodeGen] Initialize potentially uninitialized local pointers (PR #208566)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 28 10:53:28 PDT 2026
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/208566
>From ded3109b07d74e197beb17678e92edd5f7265da4 Mon Sep 17 00:00:00 2001
From: yelidris <younes.elidrissiyazami at amd.com>
Date: Thu, 9 Jul 2026 17:12:21 -0400
Subject: [PATCH] [NFC][CodeGen] Initialize potentially uninitialized local
pointers
Initialize local pointer variables that may be used before being assigned on all code paths. The variables are always set before use in practice, but initializing them to nullptr is defensive and removes potential for undefined behavior in edge cases.
---
llvm/lib/CodeGen/AtomicExpandPass.cpp | 2 +-
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 2 +-
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/CodeGen/AtomicExpandPass.cpp b/llvm/lib/CodeGen/AtomicExpandPass.cpp
index 6985a7a48147c..dd1c1b8e20e5c 100644
--- a/llvm/lib/CodeGen/AtomicExpandPass.cpp
+++ b/llvm/lib/CodeGen/AtomicExpandPass.cpp
@@ -1604,7 +1604,7 @@ bool AtomicExpandImpl::expandAtomicCmpXchg(AtomicCmpXchgInst *CI) {
MDBuilder(F->getContext()).createLikelyBranchWeights());
Builder.SetInsertPoint(ReleasedLoadBB);
- Value *SecondLoad;
+ Value *SecondLoad = nullptr;
if (HasReleasedLoadBB) {
SecondLoad =
TLI->emitLoadLinked(Builder, PMV.WordType, PMV.AlignedAddr, MemOpOrder);
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 97e64230b73d9..4f150a6ef1d61 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -455,7 +455,7 @@ void IRTranslator::findMergedConditions(
}
const Instruction *BOp = dyn_cast<Instruction>(Cond);
- const Value *BOpOp0, *BOpOp1;
+ const Value *BOpOp0 = nullptr, *BOpOp1 = nullptr;
// Compute the effective opcode for Cond, taking into account whether it needs
// to be inverted, e.g.
// and (not (or A, B)), C
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 27a6cf37807b5..d1fcc9212e5d2 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -2667,7 +2667,7 @@ void SelectionDAGBuilder::FindMergedConditions(const Value *Cond,
}
const Instruction *BOp = dyn_cast<Instruction>(Cond);
- const Value *BOpOp0, *BOpOp1;
+ const Value *BOpOp0 = nullptr, *BOpOp1 = nullptr;
// Compute the effective opcode for Cond, taking into account whether it needs
// to be inverted, e.g.
// and (not (or A, B)), C
More information about the llvm-commits
mailing list