[clang] [Clang] Detect bit copies that should be relocation. (PR #139104)
via cfe-commits
cfe-commits at lists.llvm.org
Fri May 9 08:21:54 PDT 2025
================
@@ -9659,6 +9659,42 @@ void Sema::CheckMemaccessArguments(const CallExpr *Call,
if (BId == Builtin::BIbzero && !FirstArgTy->getAs<PointerType>())
return;
+ // Try to detect a relocation operation
+ if (getLangOpts().CPlusPlus &&
+ (BId == Builtin::BImemmove || BId == Builtin::BImemcpy)) {
+ const Expr *Dest = Call->getArg(0)->IgnoreParenImpCasts();
+ const Expr *Src = Call->getArg(1)->IgnoreParenImpCasts();
+ QualType DestTy = Dest->getType();
+ QualType SrcTy = Src->getType();
+
+ QualType DestPointeeTy = DestTy->getPointeeType();
+ QualType SrcPointeeTy = SrcTy->getPointeeType();
+ bool HasSameTargetAndSource =
+ !DestPointeeTy.isNull() && !SrcPointeeTy.isNull() &&
+ Context.hasSameUnqualifiedType(DestPointeeTy, SrcPointeeTy);
+
+ if (HasSameTargetAndSource &&
+ !DestPointeeTy.getUnqualifiedType()->isIncompleteType() &&
+ !DestPointeeTy.isConstQualified() && !SrcPointeeTy.isConstQualified() &&
+ !DestPointeeTy.isTriviallyCopyableType(getASTContext()) &&
+ SemaRef.IsCXXTriviallyRelocatableType(DestPointeeTy)) {
+
+ bool SuggestStd = getLangOpts().CPlusPlus26 && getStdNamespace();
+ if (const Decl *D = Call->getReferencedDeclOfCallee();
+ D && !D->isInStdNamespace())
+ SuggestStd = false;
----------------
cor3ntin wrote:
Right, the header might not be included.
I don't think we would have a way to generally detect a function exists in the STL
https://github.com/llvm/llvm-project/pull/139104
More information about the cfe-commits
mailing list