From 64aa9a1dd1600e10da95a2a42d79e95ed0e53d7c Mon Sep 17 00:00:00 2001 From: Don Hinton Date: Tue, 19 Mar 2019 06:14:14 +0000 Subject: Refactor cast<>'s in if conditionals, which can only assert on failure. Summary: This patch refactors several instances of cast<> used in if conditionals. Since cast<> asserts on failure, the else branch can never be taken. In some cases, the fix is to replace cast<> with dyn_cast<>. While others required the removal of the conditional and some minor refactoring. A discussion can be seen here: http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20190318/265044.html Differential Revision: https://reviews.llvm.org/D59529 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356441 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/DeclBase.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/AST/DeclBase.cpp') diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index e1b5161b02..2f7bb5333a 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -1179,13 +1179,15 @@ DeclContext *DeclContext::getPrimaryContext() { return this; case Decl::ObjCInterface: - if (auto *Def = cast(this)->getDefinition()) - return Def; + if (auto *OID = dyn_cast(this)) + if (auto *Def = OID->getDefinition()) + return Def; return this; case Decl::ObjCProtocol: - if (auto *Def = cast(this)->getDefinition()) - return Def; + if (auto *OPD = dyn_cast(this)) + if (auto *Def = OPD->getDefinition()) + return Def; return this; case Decl::ObjCCategory: -- cgit v1.2.1