[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 09:54:52 PST 2025


================
@@ -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(
----------------
andykaylor wrote:

If I understand what tryEmitAbstract is doing correctly, the type here is the type to which we intend the constant to be converted when translating an expression of the form 'new T[C]'. In this case C is a literal, but we need to assign a type to it. The tryEmitAbstract code is creating a constant unsigned integer and truncating or extending it to the width of the type passed in as the second argument.

I _think_ this rule from 5.3.4 of the C++11 standard applies:

```
Every constant-expression in a noptr-new-declarator shall be a converted constant expression (5.19) of type
std::size_t and shall evaluate to a strictly positive value.
```

If there is a target that clang supports for which the size of size_t is not equal to the size of ptr, that would show a change in behavior with this change. Is there such a target?

https://github.com/llvm/llvm-project/pull/123433


More information about the cfe-commits mailing list