[clang] [clang] apply clang-tidy's llvm-redundant-casting (NFC) (PR #191322)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 9 16:35:00 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-modules
Author: Henrik G. Olsson (hnrklssn)
<details>
<summary>Changes</summary>
This applies the clang-tidy check recently added in https://github.com/llvm/llvm-project/pull/189274 to the `clang/` subdirectory. A few false positives had to be filtered out:
- casting the two branches of a ternary expression to match each other
- casting for an argument that participates in template deduction
I will address those cases in a separate PR to clang-tidy to avoid false positives going forward.
---
Patch is 57.61 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/191322.diff
60 Files Affected:
- (modified) clang/lib/AST/ASTImporter.cpp (+5-5)
- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+1-2)
- (modified) clang/lib/AST/ByteCode/Interp.cpp (+2-2)
- (modified) clang/lib/AST/CXXInheritance.cpp (+1-2)
- (modified) clang/lib/AST/ComputeDependence.cpp (+1-2)
- (modified) clang/lib/AST/DeclCXX.cpp (+5-10)
- (modified) clang/lib/AST/DeclObjC.cpp (+2-4)
- (modified) clang/lib/AST/ExprCXX.cpp (+1-1)
- (modified) clang/lib/AST/ExprConstant.cpp (+1-1)
- (modified) clang/lib/AST/ItaniumMangle.cpp (+1-3)
- (modified) clang/lib/AST/MicrosoftMangle.cpp (+3-3)
- (modified) clang/lib/AST/StmtCXX.cpp (+1-1)
- (modified) clang/lib/AST/StmtPrinter.cpp (+1-1)
- (modified) clang/lib/AST/TextNodeDumper.cpp (+1-1)
- (modified) clang/lib/Analysis/AnalysisDeclContext.cpp (+1-1)
- (modified) clang/lib/Analysis/CFG.cpp (+1-1)
- (modified) clang/lib/Analysis/Consumed.cpp (+1-1)
- (modified) clang/lib/Analysis/LifetimeSafety/Checker.cpp (+1-1)
- (modified) clang/lib/Analysis/ThreadSafetyCommon.cpp (+3-4)
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+1-1)
- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+4-5)
- (modified) clang/lib/CodeGen/CGDecl.cpp (+2-2)
- (modified) clang/lib/CodeGen/CGExprConstant.cpp (+1-1)
- (modified) clang/lib/CodeGen/CGObjCGNU.cpp (+3-2)
- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+3-6)
- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+2-3)
- (modified) clang/lib/CodeGen/CGStmtOpenMP.cpp (+2-2)
- (modified) clang/lib/CodeGen/CodeGenSYCL.cpp (+1-1)
- (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+2-3)
- (modified) clang/lib/CodeGen/TargetBuiltins/ARM.cpp (+2-4)
- (modified) clang/lib/ExtractAPI/DeclarationFragments.cpp (+2-4)
- (modified) clang/lib/Interpreter/Interpreter.cpp (+1-1)
- (modified) clang/lib/Interpreter/InterpreterUtils.cpp (+1-1)
- (modified) clang/lib/Parse/ParseCXXInlineMethods.cpp (+1-2)
- (modified) clang/lib/Sema/AnalysisBasedWarnings.cpp (+3-3)
- (modified) clang/lib/Sema/ScopeInfo.cpp (+1-1)
- (modified) clang/lib/Sema/SemaAvailability.cpp (+1-2)
- (modified) clang/lib/Sema/SemaBoundsSafety.cpp (+1-2)
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (+2-4)
- (modified) clang/lib/Sema/SemaConcept.cpp (+1-1)
- (modified) clang/lib/Sema/SemaCoroutine.cpp (+1-1)
- (modified) clang/lib/Sema/SemaExpr.cpp (+1-1)
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+3-3)
- (modified) clang/lib/Sema/SemaInit.cpp (+2-3)
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+3-4)
- (modified) clang/lib/Sema/SemaOverload.cpp (+2-2)
- (modified) clang/lib/Sema/SemaTemplate.cpp (+9-13)
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+2-3)
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+3-4)
- (modified) clang/lib/Sema/SemaType.cpp (+3-4)
- (modified) clang/lib/Serialization/ASTReader.cpp (+4-3)
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+3-3)
- (modified) clang/lib/Serialization/ASTReaderStmt.cpp (+1-1)
- (modified) clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp (+2-3)
- (modified) clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (+1-1)
- (modified) clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp (+1-1)
- (modified) clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (+1-1)
- (modified) clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp (+1-1)
- (modified) clang/lib/StaticAnalyzer/Core/MemRegion.cpp (+1-1)
- (modified) clang/lib/Tooling/Refactoring/Lookup.cpp (+1-2)
``````````diff
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 41ba98c53247d..e507ed5ba4894 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -8525,7 +8525,7 @@ ASTNodeImporter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E) {
return std::move(Err);
if (!ToTemporaryExpr)
- ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
+ ToTemporaryExpr = ToMaterializedDecl->getTemporaryExpr();
auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
@@ -8880,7 +8880,7 @@ ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
UnresolvedSet<8> ToDecls;
for (auto *D : E->decls())
if (auto ToDOrErr = import(D))
- ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
+ ToDecls.addDecl(*ToDOrErr);
else
return ToDOrErr.takeError();
@@ -9364,8 +9364,8 @@ Error ASTNodeImporter::ImportOverriddenMethods(CXXMethodDecl *ToMethod,
Error ImportErrors = Error::success();
for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
if (auto ImportedOrErr = import(FromOverriddenMethod))
- ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>(
- (*ImportedOrErr)->getCanonicalDecl()));
+ ToMethod->getCanonicalDecl()->addOverriddenMethod(
+ (*ImportedOrErr)->getCanonicalDecl());
else
ImportErrors =
joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
@@ -10033,7 +10033,7 @@ Expected<DeclContext *> ASTImporter::ImportContext(DeclContext *FromDC) {
}
Expected<Expr *> ASTImporter::Import(Expr *FromE) {
- if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
+ if (ExpectedStmt ToSOrErr = Import(FromE))
return cast_or_null<Expr>(*ToSOrErr);
else
return ToSOrErr.takeError();
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 9d970651a9e65..50a7790c6353e 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -2464,8 +2464,7 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
if (D1->getAccessControl() != D2->getAccessControl())
return false;
- return IsStructurallyEquivalent(Context, cast<FieldDecl>(D1),
- cast<FieldDecl>(D2), Owner2Type);
+ return IsStructurallyEquivalent(Context, D1, D2, Owner2Type);
}
static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 8cc3c9216f7f4..49033d5adb914 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -444,7 +444,7 @@ bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
// If we're evaluating the initializer for a constexpr variable in C23, we may
// only read other contexpr variables. Abort here since this one isn't
// constexpr.
- if (const auto *VD = dyn_cast_if_present<VarDecl>(S.EvaluatingDecl);
+ if (const auto *VD = S.EvaluatingDecl;
VD && VD->isConstexpr() && S.getLangOpts().C23)
return Invalid(S, OpPC);
@@ -1772,7 +1772,7 @@ bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
return false;
assert(DynamicDecl);
- const auto *StaticDecl = cast<CXXRecordDecl>(Func->getParentDecl());
+ const auto *StaticDecl = Func->getParentDecl();
const auto *InitialFunction = cast<CXXMethodDecl>(Callee);
const CXXMethodDecl *Overrider;
diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index 29f5916284ebb..dc1be286455e3 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -452,8 +452,7 @@ void FinalOverriderCollector::Collect(const CXXRecordDecl *RD,
CXXFinalOverriderMap &Overriders) {
unsigned SubobjectNumber = 0;
if (!VirtualBase)
- SubobjectNumber
- = ++SubobjectCount[cast<CXXRecordDecl>(RD->getCanonicalDecl())];
+ SubobjectNumber = ++SubobjectCount[RD->getCanonicalDecl()];
for (const auto &Base : RD->bases()) {
if (const auto *BaseDecl = Base.getType()->getAsCXXRecordDecl()) {
diff --git a/clang/lib/AST/ComputeDependence.cpp b/clang/lib/AST/ComputeDependence.cpp
index 34167eee8d8f2..0c50d4fe5c73b 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -153,8 +153,7 @@ ExprDependence clang::computeDependence(ExplicitCastExpr *E) {
// because when the type as written is a deduced type, that type is not
// dependent, but it may be deduced as a dependent type.
ExprDependence D =
- toExprDependenceAsWritten(
- cast<ExplicitCastExpr>(E)->getTypeAsWritten()->getDependence()) |
+ toExprDependenceAsWritten(E->getTypeAsWritten()->getDependence()) |
toExprDependenceForImpliedType(E->getType()->getDependence());
if (auto *S = E->getSubExpr())
D |= S->getDependence() & ~ExprDependence::Type;
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 3b9d888bb2c0a..8d78894cceec2 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1778,8 +1778,7 @@ CXXMethodDecl *CXXRecordDecl::getLambdaStaticInvoker(CallingConv CC) const {
DeclContext::lookup_result Invoker = getLambdaStaticInvokers(*this);
for (NamedDecl *ND : Invoker) {
- const auto *FTy =
- cast<ValueDecl>(ND->getAsFunction())->getType()->castAs<FunctionType>();
+ const auto *FTy = ND->getAsFunction()->getType()->castAs<FunctionType>();
if (FTy->getCallConv() == CC)
return getInvokerAsMethod(ND);
}
@@ -3169,8 +3168,7 @@ void CXXDestructorDecl::setOperatorDelete(FunctionDecl *OD, Expr *ThisArg) {
this, OD, ASTContext::OperatorDeleteKind::Regular);
getCanonicalDecl()->OperatorDeleteThisArg = ThisArg;
if (auto *L = getASTMutationListener())
- L->ResolvedOperatorDelete(cast<CXXDestructorDecl>(getCanonicalDecl()), OD,
- ThisArg);
+ L->ResolvedOperatorDelete(getCanonicalDecl(), OD, ThisArg);
}
}
@@ -3187,8 +3185,7 @@ void CXXDestructorDecl::setOperatorGlobalDelete(FunctionDecl *OD) {
getASTContext().addOperatorDeleteForVDtor(
this, OD, ASTContext::OperatorDeleteKind::GlobalRegular);
if (auto *L = getASTMutationListener())
- L->ResolvedOperatorGlobDelete(cast<CXXDestructorDecl>(getCanonicalDecl()),
- OD);
+ L->ResolvedOperatorGlobDelete(getCanonicalDecl(), OD);
}
}
@@ -3200,8 +3197,7 @@ void CXXDestructorDecl::setOperatorArrayDelete(FunctionDecl *OD) {
getASTContext().addOperatorDeleteForVDtor(
this, OD, ASTContext::OperatorDeleteKind::Array);
if (auto *L = getASTMutationListener())
- L->ResolvedOperatorArrayDelete(
- cast<CXXDestructorDecl>(getCanonicalDecl()), OD);
+ L->ResolvedOperatorArrayDelete(getCanonicalDecl(), OD);
}
}
@@ -3214,8 +3210,7 @@ void CXXDestructorDecl::setGlobalOperatorArrayDelete(FunctionDecl *OD) {
getASTContext().addOperatorDeleteForVDtor(
this, OD, ASTContext::OperatorDeleteKind::ArrayGlobal);
if (auto *L = getASTMutationListener())
- L->ResolvedOperatorGlobArrayDelete(
- cast<CXXDestructorDecl>(getCanonicalDecl()), OD);
+ L->ResolvedOperatorGlobArrayDelete(getCanonicalDecl(), OD);
}
}
diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp
index a66eb72981084..fc4c7ea70cf71 100644
--- a/clang/lib/AST/DeclObjC.cpp
+++ b/clang/lib/AST/DeclObjC.cpp
@@ -264,8 +264,7 @@ ObjCPropertyDecl *ObjCContainerDecl::FindPropertyDeclaration(
}
if (ObjCPropertyDecl *PD =
- ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId,
- QueryKind))
+ ObjCPropertyDecl::findPropertyDecl(this, PropertyId, QueryKind))
return PD;
switch (getKind()) {
@@ -386,8 +385,7 @@ ObjCPropertyDecl *ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass(
LoadExternalDefinition();
if (ObjCPropertyDecl *PD =
- ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId,
- QueryKind))
+ ObjCPropertyDecl::findPropertyDecl(this, PropertyId, QueryKind))
return PD;
// Look through protocols.
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index dd603bf548926..4ac7aa5355f8b 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -1351,7 +1351,7 @@ Stmt *LambdaExpr::getBody() const {
const CompoundStmt *LambdaExpr::getCompoundStmtBody() const {
Stmt *Body = getBody();
if (const auto *CoroBody = dyn_cast<CoroutineBodyStmt>(Body))
- return cast<CompoundStmt>(CoroBody->getBody());
+ return CoroBody->getBody();
return cast<CompoundStmt>(Body);
}
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 4f45fa728c605..56154fd0e9eca 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -9392,7 +9392,7 @@ bool LValueExprEvaluator::VisitDeclRefExpr(const DeclRefExpr *E) {
if (isa<FunctionDecl, MSGuidDecl, TemplateParamObjectDecl,
UnnamedGlobalConstantDecl>(D))
- return Success(cast<ValueDecl>(D));
+ return Success(D);
if (const VarDecl *VD = dyn_cast<VarDecl>(D))
return VisitVarDecl(E, VD);
if (const BindingDecl *BD = dyn_cast<BindingDecl>(D))
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index d21faaa87558d..c725e4e23c3e9 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -4619,9 +4619,7 @@ void CXXNameMangler::mangleType(const DependentBitIntType *T) {
Out << "_";
}
-void CXXNameMangler::mangleType(const ArrayParameterType *T) {
- mangleType(cast<ConstantArrayType>(T));
-}
+void CXXNameMangler::mangleType(const ArrayParameterType *T) { mangleType(T); }
void CXXNameMangler::mangleType(const HLSLAttributedResourceType *T) {
llvm::SmallString<64> Str("_Res");
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index 20c52969d7024..d0e15e9bbad57 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -3246,11 +3246,11 @@ void MicrosoftCXXNameMangler::mangleTagTypeKind(TagTypeKind TTK) {
}
void MicrosoftCXXNameMangler::mangleType(const EnumType *T, Qualifiers,
SourceRange) {
- mangleType(cast<TagType>(T)->getDecl());
+ mangleType(T->getDecl());
}
void MicrosoftCXXNameMangler::mangleType(const RecordType *T, Qualifiers,
SourceRange) {
- mangleType(cast<TagType>(T)->getDecl());
+ mangleType(T->getDecl());
}
void MicrosoftCXXNameMangler::mangleType(const TagDecl *TD) {
// MSVC chooses the tag kind of the definition if it exists, otherwise it
@@ -3347,7 +3347,7 @@ void MicrosoftCXXNameMangler::mangleArrayType(const ArrayType *T) {
void MicrosoftCXXNameMangler::mangleType(const ArrayParameterType *T,
Qualifiers, SourceRange) {
- mangleArrayType(cast<ConstantArrayType>(T));
+ mangleArrayType(T);
}
// <type> ::= <pointer-to-member-type>
diff --git a/clang/lib/AST/StmtCXX.cpp b/clang/lib/AST/StmtCXX.cpp
index 6a69fe75136f3..6ba5b7450cafd 100644
--- a/clang/lib/AST/StmtCXX.cpp
+++ b/clang/lib/AST/StmtCXX.cpp
@@ -75,7 +75,7 @@ const Expr *CXXForRangeStmt::getRangeInit() const {
}
VarDecl *CXXForRangeStmt::getLoopVariable() {
- Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl();
+ Decl *LV = getLoopVarStmt()->getSingleDecl();
assert(LV && "No loop variable in CXXForRangeStmt");
return cast<VarDecl>(LV);
}
diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index 4d364fdcd5502..e060775127ec2 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -2121,7 +2121,7 @@ void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) {
PrintExpr(Node->getImplicitObjectArgument());
return;
}
- VisitCallExpr(cast<CallExpr>(Node));
+ VisitCallExpr(Node);
}
void StmtPrinter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *Node) {
diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp
index 250ec8b666e05..b3b3e500f62d9 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -831,7 +831,7 @@ void TextNodeDumper::Visit(const APValue &Value, QualType Ty) {
{
ColorScope Color(OS, ShowColors, ASTDumpColor::Value);
if (const FieldDecl *FD = Value.getUnionField())
- OS << " ." << *cast<NamedDecl>(FD);
+ OS << " ." << *FD;
}
// If the union value is considered to be simple, fold it into the
// current line to save some vertical space.
diff --git a/clang/lib/Analysis/AnalysisDeclContext.cpp b/clang/lib/Analysis/AnalysisDeclContext.cpp
index 266d20632e3cc..c3065b35f156e 100644
--- a/clang/lib/Analysis/AnalysisDeclContext.cpp
+++ b/clang/lib/Analysis/AnalysisDeclContext.cpp
@@ -119,7 +119,7 @@ Stmt *AnalysisDeclContext::getBody(bool &IsAutosynthesized) const {
return FunTmpl->getTemplatedDecl()->getBody();
else if (const auto *VD = dyn_cast_or_null<VarDecl>(D)) {
if (VD->isFileVarDecl()) {
- return const_cast<Stmt *>(dyn_cast_or_null<Stmt>(VD->getInit()));
+ return const_cast<Expr *>(VD->getInit());
}
}
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 543b9d8424488..07233f8328638 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -6124,7 +6124,7 @@ static void print_elem(raw_ostream &OS, StmtPrinterHelper &Helper,
return;
CXXDeleteExpr *DelExpr =
const_cast<CXXDeleteExpr*>(DE.getDeleteExpr());
- Helper.handledStmt(cast<Stmt>(DelExpr->getArgument()), OS);
+ Helper.handledStmt(DelExpr->getArgument(), OS);
OS << "->~" << RD->getName().str() << "()";
OS << " (Implicit destructor)";
break;
diff --git a/clang/lib/Analysis/Consumed.cpp b/clang/lib/Analysis/Consumed.cpp
index efc7098e52042..67930e38da885 100644
--- a/clang/lib/Analysis/Consumed.cpp
+++ b/clang/lib/Analysis/Consumed.cpp
@@ -804,7 +804,7 @@ void ConsumedStmtVisitor::VisitCXXMemberCallExpr(
void ConsumedStmtVisitor::VisitCXXOperatorCallExpr(
const CXXOperatorCallExpr *Call) {
- const auto *FunDecl = dyn_cast_or_null<FunctionDecl>(Call->getDirectCallee());
+ const auto *FunDecl = Call->getDirectCallee();
if (!FunDecl) return;
if (Call->getOperator() == OO_Equal) {
diff --git a/clang/lib/Analysis/LifetimeSafety/Checker.cpp b/clang/lib/Analysis/LifetimeSafety/Checker.cpp
index 36477c6f67b52..7b7d1c1bec78e 100644
--- a/clang/lib/Analysis/LifetimeSafety/Checker.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/Checker.cpp
@@ -344,7 +344,7 @@ class LifetimeChecker {
for (auto [Target, EscapeExpr] : AnnotationWarningsMap) {
if (const auto *MD = Target.dyn_cast<const CXXMethodDecl *>()) {
if (!implicitObjectParamIsLifetimeBound(MD))
- SemaHelper->addLifetimeBoundToImplicitThis(cast<CXXMethodDecl>(MD));
+ SemaHelper->addLifetimeBoundToImplicitThis(MD);
} else if (const auto *PVD = Target.dyn_cast<const ParmVarDecl *>()) {
const auto *FD = dyn_cast<FunctionDecl>(PVD->getDeclContext());
if (!FD)
diff --git a/clang/lib/Analysis/ThreadSafetyCommon.cpp b/clang/lib/Analysis/ThreadSafetyCommon.cpp
index b43a986521f99..83c337e769042 100644
--- a/clang/lib/Analysis/ThreadSafetyCommon.cpp
+++ b/clang/lib/Analysis/ThreadSafetyCommon.cpp
@@ -480,7 +480,7 @@ til::SExpr *SExprBuilder::translateObjCIVarRefExpr(const ObjCIvarRefExpr *IVRE,
til::SExpr *BE = translate(IVRE->getBase(), Ctx);
til::SExpr *E = new (Arena) til::SApply(BE);
- const auto *D = cast<ObjCIvarDecl>(IVRE->getDecl()->getCanonicalDecl());
+ const auto *D = IVRE->getDecl()->getCanonicalDecl();
til::Project *P = new (Arena) til::Project(E, D);
if (hasAnyPointerType(BE))
@@ -526,8 +526,7 @@ til::SExpr *SExprBuilder::translateCXXMemberCallExpr(
// return E;
}
}
- return translateCallExpr(cast<CallExpr>(ME), Ctx,
- ME->getImplicitObjectArgument());
+ return translateCallExpr(ME, Ctx, ME->getImplicitObjectArgument());
}
til::SExpr *SExprBuilder::translateCXXOperatorCallExpr(
@@ -541,7 +540,7 @@ til::SExpr *SExprBuilder::translateCXXOperatorCallExpr(
// return E;
}
}
- return translateCallExpr(cast<CallExpr>(OCE), Ctx);
+ return translateCallExpr(OCE, Ctx);
}
til::SExpr *SExprBuilder::translateUnaryOperator(const UnaryOperator *UO,
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 4d74d681cd320..0418503ea8066 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -4235,7 +4235,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
// requires the reassoc FMF flag.
llvm::FastMathFlags FMF;
FMF.setAllowReassoc();
- cast<llvm::CallBase>(Reduce)->setFastMathFlags(FMF);
+ Reduce->setFastMathFlags(FMF);
}
return RValue::get(Reduce);
}
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index c5a92a8e7ceb0..ad0fdd8646c56 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2702,7 +2702,7 @@ CGDebugInfo::CollectTemplateParams(std::optional<TemplateArgs> OArgs,
V = V->stripPointerCasts();
}
TemplateParams.push_back(DBuilder.createTemplateValueParameter(
- TheCU, Name, TTy, defaultParameter, cast_or_null<llvm::Constant>(V)));
+ TheCU, Name, TTy, defaultParameter, V));
} break;
case TemplateArgument::NullPtr: {
QualType T = TA.getNullPtrType();
@@ -3268,7 +3268,7 @@ void CGDebugInfo::completeRequiredType(const RecordDecl *RD) {
llvm::DIType *CGDebugInfo::CreateType(const RecordType *Ty) {
RecordDecl *RD = Ty->getDecl()->getDefinitionOrSelf();
- llvm::DIType *T = cast_or_null<llvm::DIType>(getTypeOrNull(QualType(Ty, 0)));
+ llvm::DIType *T = getTypeOrNull(QualType(Ty, 0));
if (T || shouldOmitDefinition(DebugKind, DebugTypeExtRefs, RD,
CGM.getLangOpts())) {
if (!T)
@@ -4663,8 +4663,7 @@ CGDebugInfo::getGlobalVariableForwardDeclaration(const VarDecl *VD) {
DContext, Name, LinkageName, Unit, Line, getOrCreateType(T, Unit),
!VD->isExternallyVisible(), nullptr, TemplateParameters, Align);
FwdDeclReplaceMap.emplace_back(
- std::piecewise_construct,
- std::make_tuple(cast<VarDecl>(VD->getCanonicalDecl())),
+ std::piecewise_construct, std::make_tuple(VD->getCanonicalDecl()),
std::make_tuple(static_cast<llvm::Metadata *>(GV)));
return GV;
}
@@ -4694,7 +4693,7 @@ llvm::DINode *CGDebugInfo::getDeclarationOrDefinition(const Decl *D) {
if (IE != ImportedDeclCache.end()) {
auto N = IE->second;
if (auto *GVE = dyn_cast_or_null<llvm::DIImportedEntity>(N))
- return cast<llvm::DINode>(GVE);
+ return GVE;
return dyn_cast_or_null<llvm::DINode>(N);
}
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 748362105cb02..486891eac21b7 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -297,7 +297,7 @@ llvm::Constant *CodeGenModule::getOrCreateStaticVarDecl(
setTLSMode(GV, D);
setGVProperties(GV, &D);
- getTargetCodeGenInfo().setTargetAttributes(cast<Decl>(&D), GV, *this);
+ getTargetCodeGenInfo().setTargetAttributes(&D, GV, *this);
// Make sure the result is of the correct type.
LangAS ExpectedAS = Ty.getAddressSpace();
@@ -1073,7 +1073,7 @@ static llvm::Constant *constStructWithPadding(CodeGenModule &CGM,
if (constant->isNullValue())
CurOp = llvm::Constant::getNullValue(STy->getElementType(i));
else
- CurOp = cast<llvm::Constant>(constant->getAggregateElement(i));
+ CurOp = constant->getAggregateElement(i);
auto *NewOp = constWithPadding(CGM, isPattern, CurOp);
if (CurOp != NewOp)
NestedIntact = false;
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp
index 24712d3325b2e..4dabf3f5a...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/191322
More information about the cfe-commits
mailing list