[clang] [clang] warn_{cstruct, cxxstruct}_memaccess are too agressive about initializers (PR #170577)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 3 16:10:30 PST 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,c -- clang/lib/Sema/SemaChecking.cpp clang/test/Sema/warn-nontrivial-struct-memaccess-ptrauth.c clang/test/SemaCXX/warn-memaccess.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/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 51c9010fc..f978a4068 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -10362,15 +10362,18 @@ void Sema::CheckMemaccessArguments(const CallExpr *Call,
if (BId == Builtin::BImemset) {
const Expr *Initializer = Call->getArg(1)->IgnoreImpCasts();
auto IntegerConstant = dyn_cast<IntegerLiteral>(Initializer);
- IsNonZeroInitMemcall = !IntegerConstant || IntegerConstant->getValue() != 0;
+ IsNonZeroInitMemcall =
+ !IntegerConstant || IntegerConstant->getValue() != 0;
}
- if (IsNonZeroInitMemcall && RD->isNonTrivialToPrimitiveDefaultInitialize()) {
+ if (IsNonZeroInitMemcall &&
+ RD->isNonTrivialToPrimitiveDefaultInitialize()) {
DiagRuntimeBehavior(Dest->getExprLoc(), Dest,
PDiag(diag::warn_cstruct_memaccess)
<< ArgIdx << FnName << PointeeTy << 0);
SearchNonTrivialToInitializeField::diag(PointeeTy, Dest, *this);
- } else if (IsNonZeroInitMemcall && NonTriviallyCopyableCXXRecord && ArgIdx == 0) {
+ } else if (IsNonZeroInitMemcall && NonTriviallyCopyableCXXRecord &&
+ ArgIdx == 0) {
// FIXME: Limiting this warning to dest argument until we decide
// whether it's valid for source argument too.
DiagRuntimeBehavior(Dest->getExprLoc(), Dest,
``````````
</details>
https://github.com/llvm/llvm-project/pull/170577
More information about the cfe-commits
mailing list