================ @@ -0,0 +1,293 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "UseBitCastCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/Expr.h" +#include "clang/AST/ExprCXX.h" +#include "clang/AST/Type.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Lexer.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/TypeSwitch.h" +#include "llvm/Support/FormatVariadic.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::modernize { + +static bool isSupportedMemcpyObjectExpr(const Expr *ExprNode) { + ExprNode = ExprNode->IgnoreParenImpCasts(); + + if (isa<DeclRefExpr>(ExprNode)) + return true; + + if (const auto *MemberPointer = dyn_cast<BinaryOperator>(ExprNode)) + return MemberPointer->isPtrMemOp() && + isSupportedMemcpyObjectExpr(MemberPointer->getLHS()); + + if (const auto *Member = dyn_cast<MemberExpr>(ExprNode)) + return isa<FieldDecl>(Member->getMemberDecl()) && + isSupportedMemcpyObjectExpr(Member->getBase()); + + return false; +} + +static const Expr *extractMemcpyObjectExpr(const Expr *ExprNode) { + ExprNode = ExprNode->IgnoreParenCasts(); + const auto *AddressOf = dyn_cast<UnaryOperator>(ExprNode); + if (!AddressOf || AddressOf->getOpcode() != UO_AddrOf) + return nullptr; + + const Expr *ObjectExpr = AddressOf->getSubExpr()->IgnoreParenImpCasts(); + return isSupportedMemcpyObjectExpr(ObjectExpr) ? ObjectExpr : nullptr; +} + +static bool isBitCastableMemcpyObjectType(QualType Type, + const ASTContext &Context) { + Type = Type.getCanonicalType().getNonReferenceType(); + return !Type.isNull() && !Type.isVolatileQualified() && + !Type->isAnyPointerType() && Type.isTriviallyCopyableType(Context) && ---------------- unterumarmung wrote:
Done. The check now supports pointer objects, volatile sources, and volatile scalar destinations. It still rejects volatile record destinations because the generated assignment can be ill-formed. https://github.com/llvm/llvm-project/pull/189962 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
