[clang] [NFC] Minor fix to tryEmitAbstract type in EmitCXXNewAllocSize (PR #123433)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 17 17:46:19 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clang-codegen
Author: Andy Kaylor (andykaylor)
<details>
<summary>Changes</summary>
In EmitCXXNewAllocSize, when handling a constant array size, we were calling tryEmitAbstract with the type of the object being allocated. This worked out because the 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 the same size as the pointer. So, this change fixes the type, but it makes no functional difference with the current constant emitter implementation.
---
Full diff: https://github.com/llvm/llvm-project/pull/123433.diff
1 Files Affected:
- (modified) clang/lib/CodeGen/CGExprCXX.cpp (+2-2)
``````````diff
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 648b9b9ed98063..83b28a16ab76b6 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(), CGF.getContext().getSizeType());
if (!numElements)
numElements = CGF.EmitScalarExpr(*e->getArraySize());
assert(isa<llvm::IntegerType>(numElements->getType()));
``````````
</details>
https://github.com/llvm/llvm-project/pull/123433
More information about the cfe-commits
mailing list