Author: Andy Kaylor
Date: 2025-01-22T10:11:53-08:00
New Revision: 7bf188fa991338e981e8dff120a4ed341ad7f4bd

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

LOG: [NFC] Minor fix to tryEmitAbstract type in EmitCXXNewAllocSize (#123433)

In EmitCXXNewAllocSize, when handling a constant array size, we were
calling tryEmitAbstract with the type of the object being allocated rather
than the expected type of the array size. This worked out because the
allocated type was always a pointer and tryEmitAbstract only ends up
using the size of the type to extend or truncate the constant, and in this
case the destination type should be size_t, which is usually the same
width as the pointer. This change fixes the type, but it makes no
functional difference with the current constant emitter implementation.

Added: 
    

Modified: 
    clang/lib/CodeGen/CGExprCXX.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 648b9b9ed98063..f71c18a8041b10 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -732,8 +732,8 @@ static llvm::Value *EmitCXXNewAllocSize(CodeGenFunction 
&CGF,
   // Emit the array size expression.
   // We multiply the size of all dimensions for NumElements.
   // e.g for 'int[2][3]', ElemType is 'int' and NumElements is 6.
-  numElements =
-    ConstantEmitter(CGF).tryEmitAbstract(*e->getArraySize(), e->getType());
+  numElements = ConstantEmitter(CGF).tryEmitAbstract(
+      *e->getArraySize(), (*e->getArraySize())->getType());
   if (!numElements)
     numElements = CGF.EmitScalarExpr(*e->getArraySize());
   assert(isa<llvm::IntegerType>(numElements->getType()));


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to