[clang] [CIR] Implement null check for CXXNewExpr (PR #192848)

via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 19 06:57:12 PDT 2026


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/CodeGen/new-null.cpp clang/include/clang/CIR/MissingFeatures.h clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp --diff_from_common_commit
``````````

: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 356198f04..78feb7624 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp
@@ -1510,8 +1510,7 @@ mlir::Value CIRGenFunction::emitCXXNewExpr(const CXXNewExpr *e) {
     enterNewDeleteCleanup(*this, e, allocation, allocSize, allocAlign,
                           allocatorArgs);
     operatorDeleteCleanup = ehStack.stable_begin();
-    cleanupDominator =
-        cir::UnreachableOp::create(builder, loc).getOperation();
+    cleanupDominator = cir::UnreachableOp::create(builder, loc).getOperation();
   }
 
   if (allocSize != allocSizeWithoutCookie) {
@@ -1533,9 +1532,8 @@ mlir::Value CIRGenFunction::emitCXXNewExpr(const CXXNewExpr *e) {
   // If we're inside a new delete cleanup, store the result pointer.
   Address resultPtr = Address::invalid();
   if (useNewDeleteCleanup) {
-    resultPtr =
-        createTempAlloca(builder.getPointerTo(elementTy), result.getAlignment(),
-                         loc, "__new_result");
+    resultPtr = createTempAlloca(builder.getPointerTo(elementTy),
+                                 result.getAlignment(), loc, "__new_result");
     builder.createStore(loc, result.getPointer(), resultPtr);
   }
 
@@ -1579,9 +1577,8 @@ mlir::Value CIRGenFunction::emitCXXNewExpr(const CXXNewExpr *e) {
     if (allocPtr.getType() != resultTy)
       allocPtr = builder.createBitcast(allocPtr, resultTy);
     mlir::Value nullPtr = builder.getNullPtr(resultTy, loc).getResult();
-    resultValue =
-        builder.createSelect(loc, nullCheckOp.getCondition(), allocPtr,
-                             nullPtr);
+    resultValue = builder.createSelect(loc, nullCheckOp.getCondition(),
+                                       allocPtr, nullPtr);
   }
 
   return resultValue;

``````````

</details>


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


More information about the cfe-commits mailing list