[clang] [Clang][CodeGen] Emit dereferenceable and nofree for indirect arguments (PR #213347)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 31 13:03:37 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,c -- clang/lib/CodeGen/CGCall.cpp clang/test/CodeGen/AArch64/args.cpp clang/test/CodeGen/AArch64/byval-temp.c clang/test/CodeGen/AArch64/pure-scalable-args-empty-union.c clang/test/CodeGen/AArch64/pure-scalable-args.c clang/test/CodeGen/AArch64/struct-coerce-using-ptr.cpp clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp clang/test/CodeGen/LoongArch/bitint.c clang/test/CodeGen/LoongArch/lasx/builtin-alias.c clang/test/CodeGen/LoongArch/lasx/builtin-approximate-alias.c clang/test/CodeGen/LoongArch/lasx/builtin-approximate.c clang/test/CodeGen/LoongArch/lasx/builtin.c clang/test/CodeGen/PowerPC/ppc64-vector.c clang/test/CodeGen/RISCV/bitint.c clang/test/CodeGen/RISCV/riscv-abi.cpp clang/test/CodeGen/RISCV/riscv32-abi.c clang/test/CodeGen/RISCV/riscv32-vararg.c clang/test/CodeGen/RISCV/riscv64-abi.c clang/test/CodeGen/RISCV/riscv64-vararg.c clang/test/CodeGen/Sparc/sparcv9-abi.c clang/test/CodeGen/SystemZ/sync-builtins-i128-16Al.c clang/test/CodeGen/SystemZ/systemz-abi-vector.c clang/test/CodeGen/SystemZ/systemz-abi.c clang/test/CodeGen/SystemZ/systemz-inline-asm.c clang/test/CodeGen/SystemZ/zos-abi.c clang/test/CodeGen/X86/cx-complex-range.c clang/test/CodeGen/X86/x86_32-arguments-win32.c clang/test/CodeGen/X86/x86_64-arguments-win32.c clang/test/CodeGen/arm-abi-vector.c clang/test/CodeGen/arm-swiftcall.c clang/test/CodeGen/arm64-abi-vector.c clang/test/CodeGen/arm64-arguments.c clang/test/CodeGen/arm64-microsoft-arguments.cpp clang/test/CodeGen/arm64ec-varargs.c clang/test/CodeGen/armv7k-abi.c clang/test/CodeGen/atomic-arm64.c clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c clang/test/CodeGen/attr-noundef.cpp clang/test/CodeGen/cx-complex-range.c clang/test/CodeGen/ext-int-cc.c clang/test/CodeGen/isfpclass.c clang/test/CodeGen/math-libcalls-tbaa-indirect-args.c clang/test/CodeGen/mingw-long-double.c clang/test/CodeGen/ms_abi.c clang/test/CodeGen/pass-by-value-noalias.c clang/test/CodeGen/ptrauth-in-c-struct.c clang/test/CodeGen/regcall.c clang/test/CodeGen/regcall4.c clang/test/CodeGen/vectorcall.c clang/test/CodeGen/win-fp128.c clang/test/CodeGen/win64-i128.c clang/test/CodeGen/windows-seh-arg-capture-crash.cpp clang/test/CodeGen/windows-swiftcall.c clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp clang/test/CodeGenCXX/amdgcn-func-arg.cpp clang/test/CodeGenCXX/arm-cc.cpp clang/test/CodeGenCXX/arm-swiftcall.cpp clang/test/CodeGenCXX/attr-target-mv-inalloca.cpp clang/test/CodeGenCXX/blocks.cpp clang/test/CodeGenCXX/builtin-clear-padding-codegen.cpp clang/test/CodeGenCXX/copy-initialization.cpp clang/test/CodeGenCXX/cxx1z-copy-omission.cpp clang/test/CodeGenCXX/derived-to-base-conv.cpp clang/test/CodeGenCXX/empty-nontrivially-copyable.cpp clang/test/CodeGenCXX/fastcall.cpp clang/test/CodeGenCXX/homogeneous-aggregates.cpp clang/test/CodeGenCXX/inalloca-lambda.cpp clang/test/CodeGenCXX/inalloca-overaligned.cpp clang/test/CodeGenCXX/inalloca-vector.cpp clang/test/CodeGenCXX/inheriting-constructor.cpp clang/test/CodeGenCXX/member-function-pointer-calls.cpp clang/test/CodeGenCXX/microsoft-abi-arg-order.cpp clang/test/CodeGenCXX/microsoft-abi-byval-thunks.cpp clang/test/CodeGenCXX/microsoft-abi-member-pointers.cpp clang/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp clang/test/CodeGenCXX/microsoft-abi-unknown-arch.cpp clang/test/CodeGenCXX/ms-property.cpp clang/test/CodeGenCXX/nrvo.cpp clang/test/CodeGenCXX/pass-by-value-noalias.cpp clang/test/CodeGenCXX/powerpc-byval.cpp clang/test/CodeGenCXX/ptrauth-qualifier-struct.cpp clang/test/CodeGenCXX/regcall.cpp clang/test/CodeGenCXX/regcall4.cpp clang/test/CodeGenCXX/regparm.cpp clang/test/CodeGenCXX/temporaries.cpp clang/test/CodeGenCXX/trivial_abi.cpp clang/test/CodeGenCXX/uncopyable-args.cpp clang/test/CodeGenCXX/wasm-args-returns.cpp clang/test/CodeGenCXX/windows-x86-swiftcall.cpp clang/test/CodeGenCXX/x86_32-arguments.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/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 5117cd37b..b6b0bc1e6 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3235,18 +3235,21 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
assert(!Align.isZero());
Attrs.addAlignmentAttr(Align.getQuantity());
- // According to [basic.stc.auto], parameters have automatic storage duration.
- // Therefore, the underlying object of this pointer will not be freed during
- // the function's execution. If the parameter is realigned, this may not be true,
- // but realignment does not currently occur for non-byval. Hmm....
+ // According to [basic.stc.auto], parameters have automatic storage
+ // duration. Therefore, the underlying object of this pointer will not be
+ // freed during the function's execution. If the parameter is realigned,
+ // this may not be true, but realignment does not currently occur for
+ // non-byval. Hmm....
//
- // We can already infer noalias and nofree like optimization behavior if the
- // byval attribute is present.
+ // We can already infer noalias and nofree like optimization behavior if
+ // the byval attribute is present.
if (!AI.getIndirectByVal()) {
- assert(!AI.getIndirectRealign() && "Pointer copied from realign legal to be freed?");
+ assert(!AI.getIndirectRealign() &&
+ "Pointer copied from realign legal to be freed?");
Attrs.addAttribute(llvm::Attribute::NoFree);
if (!ParamType->isIncompleteType() && ParamType->isConstantSizeType())
- Attrs.addDereferenceableAttr(getMinimumObjectSize(ParamType).getQuantity());
+ Attrs.addDereferenceableAttr(
+ getMinimumObjectSize(ParamType).getQuantity());
}
// byval disables readnone and readonly.
``````````
</details>
https://github.com/llvm/llvm-project/pull/213347
More information about the cfe-commits
mailing list