================ @@ -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:
So if I’m reading this correctly this will cause us to suggest `std::trivially_relocate` if the user called `std::memcpy`, and `__builtin_trivially_relocate` if they called some other `memcpy` that isn’t defined in the `std` namespace. Is there a reason why we wouldn’t just always suggest `std::trivially_relocate` if C++26 is enabled (or is this because the header providing that function might not be included which could potentially be confusing if someone then uses `std::trivially_relocate` but then we start complaining about it not being found?). 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