[clang] [Clang][CodeGen] Use ptrtoaddr for pointer diff (PR #210729)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 20 07:53:39 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 c,cpp,cl -- clang/lib/CodeGen/CGExprScalar.cpp clang/test/CodeGen/glibc_ptr_align.c clang/test/CodeGen/vla.c clang/test/CodeGenOpenCL/address-spaces-conversions.cl clang/test/CodeGenOpenCL/nullptr.cl clang/test/CodeGenOpenCL/size_t.cl clang/test/OpenMP/depobj_codegen.cpp clang/test/OpenMP/for_range_loop_codegen.cpp clang/test/OpenMP/fuse_codegen.cpp clang/test/OpenMP/interchange_codegen.cpp clang/test/OpenMP/parallel_for_codegen.cpp clang/test/OpenMP/reverse_codegen.cpp clang/test/OpenMP/split_codegen.cpp clang/test/OpenMP/stripe_codegen.cpp clang/test/OpenMP/tile_codegen.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/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 78d905c69..dcb155b2e 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -4978,10 +4978,8 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &op) {
   // Otherwise, this is a pointer subtraction.
 
   // Do the raw subtraction part.
-  llvm::Value *LHS
-    = Builder.CreatePtrToAddr(op.LHS, "sub.ptr.lhs.cast");
-  llvm::Value *RHS
-    = Builder.CreatePtrToAddr(op.RHS, "sub.ptr.rhs.cast");
+  llvm::Value *LHS = Builder.CreatePtrToAddr(op.LHS, "sub.ptr.lhs.cast");
+  llvm::Value *RHS = Builder.CreatePtrToAddr(op.RHS, "sub.ptr.rhs.cast");
   if (LHS->getType() != CGF.PtrDiffTy)
     LHS = Builder.CreateZExtOrTrunc(LHS, CGF.PtrDiffTy, "sub.ptr.lhs.ext");
   if (RHS->getType() != CGF.PtrDiffTy)

``````````

</details>


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


More information about the cfe-commits mailing list