`RULE-0-0-1`: "unreachable statement" false positives due to over-pruning of the control-flow graph
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
Rechercherichtung
Beginnen Sie bei RULE-0-0-1s benutzerdefiniertem isReachable-Prädikat und verfolgen Sie BasicBlock.getAPredecessor(), possiblePredecessor, potentiallyReturningFunction und reachableRecursive. Reproduzieren Sie den Bericht mit dem eigenständigen C++-Beispiel unter Verwendung von CodeQL CLI 2.26.2 und überprüfen Sie anschließend, dass erreichbare Anweisungen in update() und run() nicht mehr als unerreichbar gemeldet werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Affected rules
RULE-0-0-1
Description
RULE-0-0-1 reports plainly reachable statements as unreachable. The query does not use the standard reachable predicate; it defines its own reachability walk over BasicBlock.getAPredecessor():
predicate isReachable(BasicBlock bb) {
bb = any(Function f).getEntryPoint()
or
isReachable(bb.getAPredecessor())
or
... // special cases for &&/||, ?:, catch blocks, constexpr if
}
BasicBlock.getAPredecessor() is derived from successors_adapted , One pruning step, possiblePredecessor, removes the control-flow graph edge after a FunctionCall unless the callee is classified as potentiallyReturningFunction. That classification is itself defined recursively in terms of the adapted control-flow graph (reachableRecursive).
When this circular analysis fails to prove that a function returns the edge after the call is dropped, the rest of the function becomes "unreachable", and the function's own exit point is then considered unreachable too. The function is consequently treated as noreturn, so callers have everything after the call flagged as well. The error cascades across the translation unit.
Environment: CodeQL CLI 2.26.2, codeql/misra-cpp-coding-standards 2.62.0 (cpp-all 5.0.0), C++17.
Example
Five false positives on this self-contained file: the if in update() and every statement in run() after the call to update().
#include <unordered_map>
namespace detail {
struct Error {
Error() noexcept = default;
};
template <typename E>
struct unexpected {
E error;
explicit unexpected(E e) noexcept : error(e) {}
};
template <typename T, typename E>
struct expected {
T value_{};
E error_{};
bool has_value_ = true;
expected(T v) noexcept : value_(v), has_value_(true) {}
expected(unexpected<E> u) noexcept : error_(u.error), has_value_(false) {}
explicit operator bool() const noexcept { return has_value_; }
};
} // namespace detail
using Error = detail::Error;
using Unexpected = detail::unexpected<Error>;
template <typename T> using Result = detail::expected<T, Error>;
Result<int> update(const std::unordered_map<int, int>& keys) noexcept {
auto it = keys.find(0);
if (it == keys.end()) { // flagged as unreachable
return Result<int>{Unexpected{Error{}}};
}
return Result<int>{it->second};
}
void run() noexcept {
std::unordered_map<int, int> keys;
auto r = update(keys); // flagged as unreachable
if (r) { // flagged as unreachable
(void)0; // flagged as unreachable
}
int x = 42; // flagged as unreachable
(void)x;
}
- Vorherrschende Sprache
- CodeQL
- Sterne
- 227
- Forks
- 82
- Ø Merge
- 6 T. 7 Std.
- Gemergte PRs (30 T.)
- 9
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus github/codeql-coding-standards
-
false positive/false negative Stardard-MISRA-C++
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
github/codeql-coding-standards#1172 ·
-
Difficulty-Low false positive/false negative false-negative Impact-Low Standard-MISRA-C
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
-
Difficulty-Medium false positive/false negative false-positive Impact-Medium Standard-CERT-C
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
github/codeql-coding-standards#1200 ·
-
false positive/false negative
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 65/100
github/codeql-coding-standards#1175 ·
-
false positive/false negative Stardard-MISRA-C++
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 48/100
github/codeql-coding-standards#1165 ·
Alle Issues in github/codeql-coding-standards
Ähnliche Issues
-
sponsored
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
microsoft/navcontainerhelper#4217 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
use-agent-os/agent-os#3314 ·
-
[aw] Upgrade available Offenagentic-workflows
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
githubnext/rig#534 ·
-
documentation low-priority templates
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
jesseray718/openroot#87 ·