aboutsummaryrefslogtreecommitdiffstats
path: root/tools/clang/codesearch/codesearch.cpp
diff options
context:
space:
mode:
authorYulong Zhang <yulongzhang@google.com>2026-01-27 05:37:09 +0000
committerDmitry Vyukov <dvyukov@google.com>2026-01-27 07:59:32 +0000
commitb441fd80a58c6064b1333a3630367c9199fe1c99 (patch)
tree5c6be12729dc094183087cb097b5db85cc4517cd /tools/clang/codesearch/codesearch.cpp
parent9a542765834f4ba0ddcc5a28ed46f388d29d02ad (diff)
tools/clang/codesearch: migrate dyn_cast to dyn_cast_if_present
In LLVM 16+ dyn_cast is no longer null-safe and hence leads to crashes. This commit switches it to dyn_cast_if_null.
Diffstat (limited to 'tools/clang/codesearch/codesearch.cpp')
-rw-r--r--tools/clang/codesearch/codesearch.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/tools/clang/codesearch/codesearch.cpp b/tools/clang/codesearch/codesearch.cpp
index df91c84fc..11658f4ee 100644
--- a/tools/clang/codesearch/codesearch.cpp
+++ b/tools/clang/codesearch/codesearch.cpp
@@ -203,7 +203,7 @@ bool Indexer::TraverseCallExpr(CallExpr* CE) {
}
bool Indexer::VisitDeclRefExpr(const DeclRefExpr* DeclRef) {
- if (const auto* Func = dyn_cast<FunctionDecl>(DeclRef->getDecl()))
+ if (const auto* Func = dyn_cast_if_present<FunctionDecl>(DeclRef->getDecl()))
EmitReference(DeclRef->getBeginLoc(), DeclRef->getDecl(), EntityKindFunction,
InCallee ? RefKindCall : RefKindTakesAddr);
return true;
@@ -246,25 +246,25 @@ bool Indexer::VisitTypedefType(const TypedefType* T) {
return true;
EmitReference(TypeRefingLocation, T->getDecl(), EntityKindTypedef, RefKindUses);
// If it's a struct typedef, also note the struct use.
- if (const auto* Tag = dyn_cast<TagType>(T->getCanonicalTypeInternal().getTypePtr()))
+ if (const auto* Tag = dyn_cast_if_present<TagType>(T->getCanonicalTypeInternal().getTypePtr()))
VisitTagType(Tag);
return true;
}
bool Indexer::VisitMemberExpr(const MemberExpr* E) {
auto* Record = E->getBase()->getType()->getAsRecordDecl();
- if (auto* Ptr = dyn_cast<PointerType>(E->getBase()->getType()))
+ if (auto* Ptr = dyn_cast_if_present<PointerType>(E->getBase()->getType()))
Record = Ptr->getPointeeType()->getAsRecordDecl();
if (!Record)
return true;
const std::string Field = Record->getNameAsString() + "::" + E->getMemberDecl()->getNameAsString();
const char* RefKind = RefKindRead;
const Stmt* P = GetParent(E);
- if (auto* BO = dyn_cast<BinaryOperator>(P)) {
+ if (auto* BO = dyn_cast_if_present<BinaryOperator>(P)) {
if (E == BO->getLHS() && (BO->isAssignmentOp() || BO->isCompoundAssignmentOp() || BO->isShiftAssignOp()))
RefKind = RefKindWrite;
}
- if (auto* UO = dyn_cast<UnaryOperator>(P))
+ if (auto* UO = dyn_cast_if_present<UnaryOperator>(P))
RefKind = RefKindTakesAddr;
EmitReference(E->getMemberLoc(), Field, EntityKindField, RefKind);
return true;