[clang] [NFC] Minor fix to tryEmitAbstract type in EmitCXXNewAllocSize (PR #123433)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 21 11:12:19 PST 2025
https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/123433
>From 25edfca991d195687afe4fb18c0ece6244d67497 Mon Sep 17 00:00:00 2001
From: Andy Kaylor <akaylor at nvidia.com>
Date: Fri, 17 Jan 2025 17:39:22 -0800
Subject: [PATCH 1/2] [NFC] Minor fix to tryEmitAbstract type in
EmitCXXNewAllocSize
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.
---
clang/lib/CodeGen/CGExprCXX.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
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()));
>From 3bab57b2eeb53880d341a55f352cebdf6a5f1a02 Mon Sep 17 00:00:00 2001
From: Andy Kaylor <akaylor at nvidia.com>
Date: Tue, 21 Jan 2025 11:10:44 -0800
Subject: [PATCH 2/2] Get the size from e->getArraySize() rather than using
size_t
---
clang/lib/CodeGen/CGExprCXX.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index 83b28a16ab76b6..f71c18a8041b10 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -733,7 +733,7 @@ static llvm::Value *EmitCXXNewAllocSize(CodeGenFunction &CGF,
// 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(), CGF.getContext().getSizeType());
+ *e->getArraySize(), (*e->getArraySize())->getType());
if (!numElements)
numElements = CGF.EmitScalarExpr(*e->getArraySize());
assert(isa<llvm::IntegerType>(numElements->getType()));
More information about the cfe-commits
mailing list