[llvm] bacba06 - [Lint] Replace getAllocatedType with getAllocationSize (#178353)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 28 19:47:03 PST 2026


Author: Jameson Nash
Date: 2026-01-28T22:46:59-05:00
New Revision: bacba0605899c2a4815e0046ff9002e3cbc2be3c

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

LOG: [Lint] Replace getAllocatedType with getAllocationSize (#178353)

This now also handles constant array allocations (getAllocationSize
returns total size for constant array allocations, whereas the old code
explicitly excluded isArrayAllocation from linting support).

Co-authored-by: Claude Opus 4.5 <noreply at anthropic.com>

Added: 
    

Modified: 
    llvm/lib/Analysis/Lint.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp
index 32a4264c0343c..09fc47e622f75 100644
--- a/llvm/lib/Analysis/Lint.cpp
+++ b/llvm/lib/Analysis/Lint.cpp
@@ -451,9 +451,9 @@ void Lint::visitMemoryReference(Instruction &I, const MemoryLocation &Loc,
     MaybeAlign BaseAlign;
 
     if (AllocaInst *AI = dyn_cast<AllocaInst>(Base)) {
-      Type *ATy = AI->getAllocatedType();
-      if (!AI->isArrayAllocation() && ATy->isSized() && !ATy->isScalableTy())
-        BaseSize = DL->getTypeAllocSize(ATy).getFixedValue();
+      std::optional<TypeSize> ATy = AI->getAllocationSize(*DL);
+      if (ATy && !ATy->isScalable())
+        BaseSize = ATy->getFixedValue();
       BaseAlign = AI->getAlign();
     } else if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Base)) {
       // If the global may be defined 
diff erently in another compilation unit


        


More information about the llvm-commits mailing list