================ @@ -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; ---------------- Sirraide 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 Yeah, I don’t think we need to care about that because there is no good way of doing that (and presumably we’d end up suggesting ‘include this header to get it’ anyway like we do w/ other functions which is fine imo). But in that case, imo we can just always suggest `std::trivially_relocate` in C++26 mode even if the `memcpy` we’re calling isn’t in the `std` namespace. https://github.com/llvm/llvm-project/pull/139104 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits