[clang] [clang][static analyzer] ignore try statements in dead code checker (PR #91675)
https://github.com/steakhal requested changes to this pull request. Please remove the formatting changes. (Keep only the relevant lines) Add a test demonstrating that this fixes a false-positive. To find which file you need to add your test, I'd recommend braking something inside the checker to see which tests break. Then pick the file that seems to be the most relevant. https://github.com/llvm/llvm-project/pull/91675 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][static analyzer] ignore try statements in dead code checker (PR #91675)
https://github.com/soukatch deleted https://github.com/llvm/llvm-project/pull/91675 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][static analyzer] ignore try statements in dead code checker (PR #91675)
@@ -159,8 +159,10 @@ void UnreachableCodeChecker::checkEndAnalysis(ExplodedGraph &G, SL = DL.asLocation(); if (SR.isInvalid() || !SL.isValid()) continue; -} -else + + if (isa(S)) soukatch wrote: everything besides this if statement is just a clang-format change https://github.com/llvm/llvm-project/pull/91675 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][static analyzer] ignore try statements in dead code checker (PR #91675)
https://github.com/soukatch deleted https://github.com/llvm/llvm-project/pull/91675 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][static analyzer] ignore try statements in dead code checker (PR #91675)
soukatch wrote: @steakhal I believe you're the best person to tag :). https://github.com/llvm/llvm-project/pull/91675 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][static analyzer] ignore try statements in dead code checker (PR #91675)
@@ -159,8 +159,10 @@ void UnreachableCodeChecker::checkEndAnalysis(ExplodedGraph &G, SL = DL.asLocation(); if (SR.isInvalid() || !SL.isValid()) continue; -} -else + + if (isa(S)) soukatch wrote: everything above this point is just clang-format changes https://github.com/llvm/llvm-project/pull/91675 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][static analyzer] ignore try statements in dead code checker (PR #91675)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Andrew Sukach (soukatch) Changes Fixes #90162. Simplest approach I could come up with was to skip cxxtry statements. Let me know if you have any suggestions. Thanks! --- Full diff: https://github.com/llvm/llvm-project/pull/91675.diff 1 Files Affected: - (modified) clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp (+16-14) ``diff diff --git a/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp index d24a124f5ffee..205f646194f58 100644 --- a/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp @@ -12,10 +12,10 @@ // A similar flow-sensitive only check exists in Analysis/ReachableCode.cpp //===--===// -#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" #include "clang/AST/ParentMap.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/SourceManager.h" +#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h" #include "clang/StaticAnalyzer/Core/Checker.h" #include "clang/StaticAnalyzer/Core/CheckerManager.h" @@ -34,6 +34,7 @@ class UnreachableCodeChecker : public Checker { public: void checkEndAnalysis(ExplodedGraph &G, BugReporter &B, ExprEngine &Eng) const; + private: typedef llvm::SmallSet CFGBlocksSet; @@ -44,10 +45,9 @@ class UnreachableCodeChecker : public Checker { static bool isInvalidPath(const CFGBlock *CB, const ParentMap &PM); static inline bool isEmptyCFGBlock(const CFGBlock *CB); }; -} +} // namespace -void UnreachableCodeChecker::checkEndAnalysis(ExplodedGraph &G, - BugReporter &B, +void UnreachableCodeChecker::checkEndAnalysis(ExplodedGraph &G, BugReporter &B, ExprEngine &Eng) const { CFGBlocksSet reachable, visited; @@ -126,8 +126,8 @@ void UnreachableCodeChecker::checkEndAnalysis(ExplodedGraph &G, // such as llvm_unreachable. if (!CB->empty()) { bool foundUnreachable = false; - for (CFGBlock::const_iterator ci = CB->begin(), ce = CB->end(); - ci != ce; ++ci) { + for (CFGBlock::const_iterator ci = CB->begin(), ce = CB->end(); ci != ce; + ++ci) { if (std::optional S = (*ci).getAs()) if (const CallExpr *CE = dyn_cast(S->getStmt())) { if (CE->getBuiltinCallee() == Builtin::BI__builtin_unreachable || @@ -159,8 +159,10 @@ void UnreachableCodeChecker::checkEndAnalysis(ExplodedGraph &G, SL = DL.asLocation(); if (SR.isInvalid() || !SL.isValid()) continue; -} -else + + if (isa(S)) +continue; +} else continue; // Check if the SourceLocation is in a system header @@ -229,9 +231,9 @@ bool UnreachableCodeChecker::isInvalidPath(const CFGBlock *CB, // Get the predecessor block's terminator condition const Stmt *cond = pred->getTerminatorCondition(); - //assert(cond && "CFGBlock's predecessor has a terminator condition"); - // The previous assertion is invalid in some cases (eg do/while). Leaving - // reporting of these situations on at the moment to help triage these cases. + // assert(cond && "CFGBlock's predecessor has a terminator condition"); + // The previous assertion is invalid in some cases (eg do/while). Leaving + // reporting of these situations on at the moment to help triage these cases. if (!cond) return false; @@ -243,9 +245,9 @@ bool UnreachableCodeChecker::isInvalidPath(const CFGBlock *CB, // Returns true if the given CFGBlock is empty bool UnreachableCodeChecker::isEmptyCFGBlock(const CFGBlock *CB) { - return CB->getLabel() == nullptr // No labels - && CB->size() == 0 // No statements - && !CB->getTerminatorStmt(); // No terminator + return CB->getLabel() == nullptr// No labels + && CB->size() == 0 // No statements + && !CB->getTerminatorStmt(); // No terminator } void ento::registerUnreachableCodeChecker(CheckerManager &mgr) { `` https://github.com/llvm/llvm-project/pull/91675 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][static analyzer] ignore try statements in dead code checker (PR #91675)
https://github.com/soukatch created https://github.com/llvm/llvm-project/pull/91675 Fixes #90162. Simplest approach I could come up with was to skip cxxtry statements. Let me know if you have any suggestions. Thanks! >From e1fcdc37e52189abcdf8ce84ada463491d8b6c04 Mon Sep 17 00:00:00 2001 From: Andrew Sukach Date: Thu, 9 May 2024 18:49:41 -0400 Subject: [PATCH] [clang][static analyzer] ignore try statements in dead code checker --- .../Checkers/UnreachableCodeChecker.cpp | 30 ++- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp index d24a124f5ffee..205f646194f58 100644 --- a/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp @@ -12,10 +12,10 @@ // A similar flow-sensitive only check exists in Analysis/ReachableCode.cpp //===--===// -#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" #include "clang/AST/ParentMap.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/SourceManager.h" +#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h" #include "clang/StaticAnalyzer/Core/Checker.h" #include "clang/StaticAnalyzer/Core/CheckerManager.h" @@ -34,6 +34,7 @@ class UnreachableCodeChecker : public Checker { public: void checkEndAnalysis(ExplodedGraph &G, BugReporter &B, ExprEngine &Eng) const; + private: typedef llvm::SmallSet CFGBlocksSet; @@ -44,10 +45,9 @@ class UnreachableCodeChecker : public Checker { static bool isInvalidPath(const CFGBlock *CB, const ParentMap &PM); static inline bool isEmptyCFGBlock(const CFGBlock *CB); }; -} +} // namespace -void UnreachableCodeChecker::checkEndAnalysis(ExplodedGraph &G, - BugReporter &B, +void UnreachableCodeChecker::checkEndAnalysis(ExplodedGraph &G, BugReporter &B, ExprEngine &Eng) const { CFGBlocksSet reachable, visited; @@ -126,8 +126,8 @@ void UnreachableCodeChecker::checkEndAnalysis(ExplodedGraph &G, // such as llvm_unreachable. if (!CB->empty()) { bool foundUnreachable = false; - for (CFGBlock::const_iterator ci = CB->begin(), ce = CB->end(); - ci != ce; ++ci) { + for (CFGBlock::const_iterator ci = CB->begin(), ce = CB->end(); ci != ce; + ++ci) { if (std::optional S = (*ci).getAs()) if (const CallExpr *CE = dyn_cast(S->getStmt())) { if (CE->getBuiltinCallee() == Builtin::BI__builtin_unreachable || @@ -159,8 +159,10 @@ void UnreachableCodeChecker::checkEndAnalysis(ExplodedGraph &G, SL = DL.asLocation(); if (SR.isInvalid() || !SL.isValid()) continue; -} -else + + if (isa(S)) +continue; +} else continue; // Check if the SourceLocation is in a system header @@ -229,9 +231,9 @@ bool UnreachableCodeChecker::isInvalidPath(const CFGBlock *CB, // Get the predecessor block's terminator condition const Stmt *cond = pred->getTerminatorCondition(); - //assert(cond && "CFGBlock's predecessor has a terminator condition"); - // The previous assertion is invalid in some cases (eg do/while). Leaving - // reporting of these situations on at the moment to help triage these cases. + // assert(cond && "CFGBlock's predecessor has a terminator condition"); + // The previous assertion is invalid in some cases (eg do/while). Leaving + // reporting of these situations on at the moment to help triage these cases. if (!cond) return false; @@ -243,9 +245,9 @@ bool UnreachableCodeChecker::isInvalidPath(const CFGBlock *CB, // Returns true if the given CFGBlock is empty bool UnreachableCodeChecker::isEmptyCFGBlock(const CFGBlock *CB) { - return CB->getLabel() == nullptr // No labels - && CB->size() == 0 // No statements - && !CB->getTerminatorStmt(); // No terminator + return CB->getLabel() == nullptr// No labels + && CB->size() == 0 // No statements + && !CB->getTerminatorStmt(); // No terminator } void ento::registerUnreachableCodeChecker(CheckerManager &mgr) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits