[llvm] b0e05a5 - [RISCV] Add missing check before accessing pointer

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 7 01:55:53 PST 2025


Author: Mikhail R. Gadelha
Date: 2025-01-07T17:55:37+08:00
New Revision: b0e05a5f04d3225b8ff1319064c88d0249e683d2

URL: https://github.com/llvm/llvm-project/commit/b0e05a5f04d3225b8ff1319064c88d0249e683d2
DIFF: https://github.com/llvm/llvm-project/commit/b0e05a5f04d3225b8ff1319064c88d0249e683d2.diff

LOG: [RISCV] Add missing check before accessing pointer

C2 can be null here, so we need to check it or clang may crash.

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 4a0304f3322ed4..2eeca45ac414bd 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -18385,7 +18385,7 @@ bool RISCVTargetLowering::isDesirableToCommuteWithShift(
     auto *C2 = dyn_cast<ConstantSDNode>(N->getOperand(1));
 
     // Bail if we might break a sh{1,2,3}add pattern.
-    if (Subtarget.hasStdExtZba() && C2->getZExtValue() >= 1 &&
+    if (Subtarget.hasStdExtZba() && C2 && C2->getZExtValue() >= 1 &&
         C2->getZExtValue() <= 3 && N->hasOneUse() &&
         N->user_begin()->getOpcode() == ISD::ADD &&
         !isUsedByLdSt(*N->user_begin(), nullptr) &&


        


More information about the llvm-commits mailing list