[clang-tools-extra] 869c066 - [clang-tidy] RedundantControlFlowCheck::issueDiagnostic - use cast<> instead of dyn_cast<> to avoid dereference of nullptr

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 12 03:06:09 PST 2022


Author: Simon Pilgrim
Date: 2022-02-12T11:05:59Z
New Revision: 869c066ca8a4231b950b5367f90758de0c6768a3

URL: https://github.com/llvm/llvm-project/commit/869c066ca8a4231b950b5367f90758de0c6768a3
DIFF: https://github.com/llvm/llvm-project/commit/869c066ca8a4231b950b5367f90758de0c6768a3.diff

LOG: [clang-tidy] RedundantControlFlowCheck::issueDiagnostic - use cast<> instead of dyn_cast<> to avoid dereference of nullptr

The pointer is referenced immediately, so assert the cast is correct instead of returning nullptr

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
index 6af77635aa2b..dd63de3f048e 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
@@ -79,7 +79,7 @@ void RedundantControlFlowCheck::issueDiagnostic(
   SourceLocation Start;
   if (Previous != Block->body_rend())
     Start = Lexer::findLocationAfterToken(
-        dyn_cast<Stmt>(*Previous)->getEndLoc(), tok::semi, SM, getLangOpts(),
+        cast<Stmt>(*Previous)->getEndLoc(), tok::semi, SM, getLangOpts(),
         /*SkipTrailingWhitespaceAndNewLine=*/true);
   if (!Start.isValid())
     Start = StmtRange.getBegin();


        


More information about the cfe-commits mailing list