[clang] [CIR] Add limited support for array new (PR #161095)

via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 28 13:50:13 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- clang/test/CIR/Lowering/new.cpp clang/lib/CIR/CodeGen/CIRGenCXXABI.cpp clang/lib/CIR/CodeGen/CIRGenCXXABI.h clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp clang/lib/CIR/CodeGen/CIRGenFunction.h clang/test/CIR/CodeGen/new.cpp
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp b/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp
index bdaf45e31..3ea402b28 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp
@@ -313,13 +313,15 @@ static mlir::Value emitCXXNewAllocSize(CIRGenFunction &cgf, const CXXNewExpr *e,
 
     // Add in the cookie, and check whether it's overflowed.
     if (cookieSize != 0) {
-      cgf.cgm.errorNYI(e->getSourceRange(), "emitCXXNewAllocSize: array cookie");
+      cgf.cgm.errorNYI(e->getSourceRange(),
+                       "emitCXXNewAllocSize: array cookie");
     }
 
     size = cgf.getBuilder().getConstInt(loc, allocationSize);
   } else {
     // TODO: Handle the variable size case
-    cgf.cgm.errorNYI(e->getSourceRange(), "emitCXXNewAllocSize: variable array size");
+    cgf.cgm.errorNYI(e->getSourceRange(),
+                     "emitCXXNewAllocSize: variable array size");
   }
 
   if (cookieSize == 0)
@@ -543,7 +545,8 @@ mlir::Value CIRGenFunction::emitCXXNewExpr(const CXXNewExpr *e) {
 
   mlir::Type elementTy;
   if (e->isArray()) {
-    // For array new, use the allocated type to handle multidimensional arrays correctly
+    // For array new, use the allocated type to handle multidimensional arrays
+    // correctly
     elementTy = convertTypeForMem(e->getAllocatedType());
   } else {
     elementTy = convertTypeForMem(allocType);

``````````

</details>


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


More information about the cfe-commits mailing list