[clang] [analyzer] Detect leaks of stack addresses via output params, indirect globals 3/3 (PR #105648)

2024-08-26 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/105648 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Detect leaks of stack addresses via output params, indirect globals 3/3 (PR #105648)

2024-08-26 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: I read the commit once and I have a serious question about using `getOriginRegion` in the invalidation logic (see inline comment for details). Apart from that, the code LGTM (I might return later with a few additional comments from a more through review,

[clang] [analyzer] Detect leaks of stack addresses via output params, indirect globals 3/3 (PR #105648)

2024-08-26 Thread Donát Nagy via cfe-commits
@@ -313,7 +321,8 @@ std::optional printReferrer(const MemRegion *Referrer) { if (isa(Space)) return "global"; assert(isa(Space)); -return "stack"; +// This case covers top-level and inlined analyses. +return "caller"; NagyDonat wrote:

[clang] [analyzer] Check the correct first and last elements in cstring.UninitializedRead (PR #95408)

2024-06-24 Thread Donát Nagy via cfe-commits
@@ -393,6 +401,162 @@ ProgramStateRef CStringChecker::checkNonNull(CheckerContext &C, return stateNonNull; } +static std::optional getIndex(ProgramStateRef State, + const ElementRegion *ER, CharKind CK) { + SValBuilder &SVB = State->get

[clang] [clang][analyzer] Improve PointerSubChecker (PR #96501)

2024-06-25 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM. I'm a bit surprised to see that this checker duplicates the logic of the array bounds checkers (in the special case when the indexing operation is within a pointer subtraction). Right now this is OK but we'll need to delete this on

[clang] [clang][analyzer] Improve PointerSubChecker (PR #96501)

2024-06-25 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/96501 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][analyzer] Improve PointerSubChecker (PR #96501)

2024-06-26 Thread Donát Nagy via cfe-commits
NagyDonat wrote: > These results look correct according to the checker, but I am not sure if > such results are useful or really invalid: > https://codechecker-demo.eastus.cloudapp.azure.com/Default/reports?run=vim_v8.2.1920_pointersub1&is-unique=on&diff-type=New&checker-name=alpha.core.Pointer

[clang] [clang][analyzer] Improve PointerSubChecker (PR #96501)

2024-06-27 Thread Donát Nagy via cfe-commits
NagyDonat wrote: > The warning message may be still misleading if the LHS or RHS "arrays" are > non-array variables. I think that the warning message is OK: "Subtraction of two pointers that do not point into the same array is undefined behavior." -- this also covers the case when one or both

[clang] [clang][analyzer] Improve documentation of checker 'cplusplus.Move' (NFC) (PR #96295)

2024-06-27 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. The new changes also LGTM, feel free to merge this when you want. https://github.com/llvm/llvm-project/pull/96295 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cg

[clang] [analyzer] Model overflow builtins (PR #102602)

2024-09-12 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: I re-reviewed the commit and added two very minor remarks, otherwise LGTM. https://github.com/llvm/llvm-project/pull/102602 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/m

[clang] [analyzer] Model overflow builtins (PR #102602)

2024-09-12 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/102602 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Model overflow builtins (PR #102602)

2024-09-12 Thread Donát Nagy via cfe-commits
@@ -327,6 +327,8 @@ Static Analyzer New features +- Now CSA models `builtin_*_overflow` functions. NagyDonat wrote: ```suggestion - Now CSA models `__builtin_*_overflow` functions. ``` https://github.com/llvm/llvm-project/pull/102602 ___

[clang] [analyzer] Model overflow builtins (PR #102602)

2024-09-12 Thread Donát Nagy via cfe-commits
@@ -16,21 +16,93 @@ #include "clang/Basic/Builtins.h" #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" +#include "clang/StaticAnalyzer/Checkers/Taint.h" #include "clang/StaticAnalyzer/Core/Checker.h" #include "clang/StaticAnalyzer/Core/CheckerManager.h"

[clang] [analyzer] Refactor MallocChecker to use `BindExpr` in `evalCall` (PR #106081)

2024-09-12 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM, feel free to merge this patch. I'm glad that you implemented this; and sorry for this final review delay. https://github.com/llvm/llvm-project/pull/106081 ___ cfe-commits mailing list cfe-

[clang] [analyzer] Fix StreamChecker crash in fread modeling (PR #108393)

2024-09-12 Thread Donát Nagy via cfe-commits
@@ -443,3 +443,33 @@ void test_unaligned_start_read(void) { fclose(fp); } } + +void no_crash_if_count_is_negative(long s, unsigned char *buffer) { + FILE *fp = fopen("path", "r"); + if (fp) { +if (s * s == -1) { NagyDonat wrote: Nitpick: $s^2 = -1$

[clang] [analyzer] Fix StreamChecker crash in fread modeling (PR #108393)

2024-09-12 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/108393 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Fix StreamChecker crash in fread modeling (PR #108393)

2024-09-12 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM, thanks for catching this! https://github.com/llvm/llvm-project/pull/108393 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commit

[clang] [clang][analyzer] Move 'alpha.core.PointerSub' checker into 'core.PointerSub' (PR #107596)

2024-09-12 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: I think this checker is definitely good enough to be moved out of `alpha`, but I'm not sure that it should be placed in the `core` group, where we have a strong requirement that "These checkers must be always switched on as other checker rely on them.".

[clang] [clang][analyzer] Move 'alpha.core.PointerSub' checker into 'core.PointerSub' (PR #107596)

2024-09-12 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/107596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][analyzer] Move 'alpha.core.PointerSub' checker into 'core.PointerSub' (PR #107596)

2024-09-12 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/107596 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Explicitly register NoStoreFuncVisitor from alpha.unix.cst… (PR #108373)

2024-09-12 Thread Donát Nagy via cfe-commits
@@ -69,6 +69,7 @@ class CheckerContext { /// the state of the program before the checker ran. Note, checkers should /// not retain the node in their state since the nodes might get invalidated. ExplodedNode *getPredecessor() { return Pred; } + const ProgramPoint getLocat

[clang] [analyzer] Explicitly register NoStoreFuncVisitor from alpha.unix.cst… (PR #108373)

2024-09-12 Thread Donát Nagy via cfe-commits
@@ -718,6 +718,91 @@ class NoStateChangeFuncVisitor : public BugReporterVisitor { PathSensitiveBugReport &R) final; }; +/// Put a diagnostic on return statement of all inlined functions +/// for which the region of interest \p RegionOfInter

[clang] [analyzer] Explicitly register NoStoreFuncVisitor from alpha.unix.cst… (PR #108373)

2024-09-12 Thread Donát Nagy via cfe-commits
@@ -538,7 +541,8 @@ ProgramStateRef CStringChecker::checkInit(CheckerContext &C, OS << ") in the "; printIdxWithOrdinalSuffix(OS, Buffer.ArgumentIndex + 1); OS << " argument is undefined"; -emitUninitializedReadBug(C, State, Buffer.Expression, OS.str()); +em

[clang] [analyzer] Explicitly register NoStoreFuncVisitor from alpha.unix.cst… (PR #108373)

2024-09-12 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: I like this simplified variant, it's really straightforward now. I added a few inline comments (mostly copied from #106982), but after that I'm satisfied with the change. https://github.com/llvm/llvm-project/pull/108373 __

[clang] [analyzer] Explicitly register NoStoreFuncVisitor from alpha.unix.cst… (PR #108373)

2024-09-12 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/108373 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Explicitly register NoStoreFuncVisitor from alpha.unix.cst… (PR #108373)

2024-09-12 Thread Donát Nagy via cfe-commits
@@ -263,6 +263,23 @@ bool SVal::isZeroConstant() const { // Pretty-Printing. //===--===// +StringRef SVal::getKindStr() const { + switch (getKind()) { +#define BASIC_SVAL(Id, Parent)

[clang] [clang][NFC] declare internal linkage function static (PR #108759)

2024-09-15 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: The `static`ifying LGTM, my only concern is a seemingly unrelated `include` change. https://github.com/llvm/llvm-project/pull/108759 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org

[clang] [clang][NFC] declare internal linkage function static (PR #108759)

2024-09-15 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/108759 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][NFC] declare internal linkage function static (PR #108759)

2024-09-15 Thread Donát Nagy via cfe-commits
@@ -12,6 +12,7 @@ // //===--===// +#include "Move.h" NagyDonat wrote: Why is this include added here? https://github.com/llvm/llvm-project/pull/108759 __

[clang] [analyzer] Refactor MallocChecker to use `BindExpr` in `evalCall` (PR #106081)

2024-09-15 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/106081 From 82e3d871766b132d0ce0b9e8e74371d8598d2431 Mon Sep 17 00:00:00 2001 From: Pavel Skripkin Date: Tue, 6 Aug 2024 19:12:01 +0300 Subject: [PATCH 1/4] wip --- .../Core/PathSensitive/DynamicExtent.h|

[clang] [analyzer] Refactor MallocChecker to use `BindExpr` in `evalCall` (PR #106081)

2024-09-15 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/106081 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Refactor MallocChecker to use `BindExpr` in `evalCall` (PR #106081)

2024-09-15 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat closed https://github.com/llvm/llvm-project/pull/106081 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Refactor MallocChecker to use `BindExpr` in `evalCall` (PR #106081)

2024-09-15 Thread Donát Nagy via cfe-commits
NagyDonat wrote: I merged the commit (after slightly clarifying the PR description / commit message -- I hope you don't mind that). https://github.com/llvm/llvm-project/pull/106081 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.

[clang] [clang][NFC] declare internal linkage function static (PR #108759)

2024-09-15 Thread Donát Nagy via cfe-commits
@@ -12,6 +12,7 @@ // //===--===// +#include "Move.h" NagyDonat wrote: Oh, I see -- thanks for the explanation! https://github.com/llvm/llvm-project/pull/108759 _

[clang] [clang][NFC] declare internal linkage function static (PR #108759)

2024-09-15 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. https://github.com/llvm/llvm-project/pull/108759 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer][NFC] Add ArrayBoundV2 testcase to document bad cast modeling (PR #108799)

2024-09-16 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/108799 Add a FIXME testcase which documents less than ideal behavior of the analyzer when a `const char *` is converted to `const unsigned char *`. This testcase is motivated by an ArrayBoundV2 report produced on th

[clang] [analyzer][NFC] Add ArrayBoundV2 testcase to document bad cast modeling (PR #108799)

2024-09-16 Thread Donát Nagy via cfe-commits
NagyDonat wrote: This PR is primarily a "note to self", but it *is* NFC and ready to be merged if we think that it'd be better to keep this reminder within the repository. https://github.com/llvm/llvm-project/pull/108799 ___ cfe-commits mailing list c

[clang] [analyzer] Explicitly register NoStoreFuncVisitor from alpha.unix.cst… (PR #108373)

2024-09-16 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. The change looks good to me and as it is fairly innocent, I think we can merge it soon (assuming that we don't get additional remarks from somebody else). When you're merging this change please write a commit message that is self-contain

[clang] [analyzer] [MallocChecker] suspect all release functions as candidate for suppression (PR #104599)

2024-09-16 Thread Donát Nagy via cfe-commits
NagyDonat wrote: > sorry to bother, but seems like this pr is stalled for 2 weeks I'm sorry that my comment delayed this PR -- next time when I write "wait a few days", feel free to merge the ticket after a few days :smile: https://github.com/llvm/llvm-project/pull/104599

[clang] [analyzer] Suppress out of bounds reports after weak loop assumptions (PR #109804)

2024-10-15 Thread Donát Nagy via cfe-commits
@@ -212,6 +212,25 @@ typedef llvm::ImmutableMap REGISTER_TRAIT_WITH_PROGRAMSTATE(PendingArrayDestruction, PendingArrayDestructionMap) +// This trait is used to heuristically filter out results produced from +// execution paths that took "weak"

[clang] [analyzer] Suppress out of bounds reports after weak loop assumptions (PR #109804)

2024-10-15 Thread Donát Nagy via cfe-commits
@@ -121,6 +121,34 @@ struct EvalCallOptions { EvalCallOptions() {} }; +/// Simple control flow statements like `if` can only produce a single two-way +/// state split, so when the analyzer cannot determine the value of the +/// condition, it can assume either of the two opti

[clang] [clang-tools-extra] [analyzer][clang-tidy][NFC] Clean up eagerly-assume handling (PR #112209)

2024-10-15 Thread Donát Nagy via cfe-commits
@@ -3742,23 +3742,20 @@ void ExprEngine::evalLocation(ExplodedNodeSet &Dst, BldrTop.addNodes(Tmp); } -std::pair -ExprEngine::geteagerlyAssumeBinOpBifurcationTags() { - static SimpleProgramPointTag - eagerlyAssumeBinOpBifurcationTrue(TagProviderName, -

[clang] [clang-tools-extra] [analyzer][clang-tidy][NFC] Clean up eagerly-assume handling (PR #112209)

2024-10-15 Thread Donát Nagy via cfe-commits
@@ -3742,23 +3742,20 @@ void ExprEngine::evalLocation(ExplodedNodeSet &Dst, BldrTop.addNodes(Tmp); } -std::pair -ExprEngine::geteagerlyAssumeBinOpBifurcationTags() { - static SimpleProgramPointTag - eagerlyAssumeBinOpBifurcationTrue(TagProviderName, -

[clang] [analyzer] Suppress out of bounds reports after weak loop assumptions (PR #109804)

2024-10-15 Thread Donát Nagy via cfe-commits
@@ -583,11 +603,11 @@ class ExprEngine { ExplodedNode *Pred, ExplodedNodeSet &Dst); - /// evalEagerlyAssumeBinOpBifurcation - Given the nodes in 'Src', eagerly assume symbolic - /// expressions of the form 'x

[clang] [analyzer] Suppress out of bounds reports after weak loop assumptions (PR #109804)

2024-10-15 Thread Donát Nagy via cfe-commits
@@ -194,3 +199,99 @@ char test_comparison_with_extent_symbol(struct incomplete *p) { return ((char *)p)[-1]; // no-warning } +// WeakLoopAssumption suppression +/// + +int GlobalArray[100]; +int loop_suppre

[clang] [clang-tools-extra] [analyzer][clang-tidy][NFC] Clean up eagerly-assume handling (PR #112209)

2024-10-15 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/112209 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Suppress out of bounds reports after weak loop assumptions (PR #109804)

2024-10-15 Thread Donát Nagy via cfe-commits
NagyDonat wrote: @steakhal I'm sorry that I disappeared for more than a week when you dropped your alternative implementation. I thought a lot about the advantages and limitations of my implementation, your implementation and even "third way" alternatives (but unfortunately `check::BranchCondi

[clang] [analyzer] Suppress out of bounds reports after weak loop assumptions (PR #109804)

2024-10-15 Thread Donát Nagy via cfe-commits
NagyDonat wrote: By the way, my plans for the "how do we get an accurate iteration count?" and the "how do we handle complex loop conditions that contain short-circuit operators?" issues is that in this first patch I want to go with the rough approximation that's easiest to implement, and I'll

[clang] [clang-tools-extra] [analyzer][clang-tidy][NFC] Clean up eagerly-assume handling (PR #112209)

2024-10-15 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/112209 From ea6ab3fe84e5ac89f82def877c37c8409889d01d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Mon, 14 Oct 2024 15:34:55 +0200 Subject: [PATCH 1/5] [analyzer][clang-tidy][NFC] Clean up eagerl

[clang] [clang-tools-extra] [analyzer][clang-tidy][NFC] Clean up eagerly-assume handling (PR #112209)

2024-10-15 Thread Donát Nagy via cfe-commits
@@ -299,13 +299,12 @@ ANALYZER_OPTION( ANALYZER_OPTION( bool, ShouldEagerlyAssume, "eagerly-assume", -"Whether we should eagerly assume evaluations of conditionals, thus, " -"bifurcating the path. This indicates how the engine should handle " -"expressions such

[clang] [clang-tools-extra] [analyzer][clang-tidy][NFC] Clean up eagerly-assume handling (PR #112209)

2024-10-15 Thread Donát Nagy via cfe-commits
@@ -3767,28 +3764,26 @@ void ExprEngine::evalEagerlyAssumeBinOpBifurcation(ExplodedNodeSet &Dst, continue; } -ProgramStateRef state = Pred->getState(); -SVal V = state->getSVal(Ex, Pred->getLocationContext()); +ProgramStateRef State = Pred->getState(); +

[clang] [analyzer] Modernize FuchsiaHandleChecker (PR #111588)

2024-10-09 Thread Donát Nagy via cfe-commits
@@ -314,6 +329,193 @@ getFuchsiaHandleSymbols(QualType QT, SVal Arg, ProgramStateRef State) { return {}; } +FuchsiaHandleChecker::Note FuchsiaHandleChecker::createNote( +SymbolRef Sym, +std::function Message) const { + return [Sym, Message](BugReport &BR) -> std::s

[clang] [clang][analyzer] Introduce MutexModeling checker (PR #111381)

2024-10-08 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,773 @@ +//===--- MutexModeling.cpp - Modeling of mutexes --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Ap

[clang] [clang][analyzer] Introduce MutexModeling checker (PR #111381)

2024-10-08 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,126 @@ +//===--- MutexModelingDomain.h - Common vocabulary for modeling mutexes ---===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Ap

[clang] [clang][analyzer] Introduce MutexModeling checker (PR #111381)

2024-10-08 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,169 @@ +//===--- MutexModelingGDM.h - Modeling of mutexes in GDM --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Ap

[clang] [clang][analyzer] Introduce MutexModeling checker (PR #111381)

2024-10-08 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,773 @@ +//===--- MutexModeling.cpp - Modeling of mutexes --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Ap

[clang] [clang][analyzer] Introduce MutexModeling checker (PR #111381)

2024-10-08 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,773 @@ +//===--- MutexModeling.cpp - Modeling of mutexes --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Ap

[clang] [clang][analyzer] Introduce MutexModeling checker (PR #111381)

2024-10-08 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,139 @@ +//===--- MutexRegionExtractor.h - Modeling of mutexes -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Ap

[clang] [clang][analyzer] Introduce MutexModeling checker (PR #111381)

2024-10-08 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,773 @@ +//===--- MutexModeling.cpp - Modeling of mutexes --===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Ap

[clang] [clang][analyzer] Introduce MutexModeling checker (PR #111381)

2024-10-08 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/111381 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][analyzer] Introduce MutexModeling checker (PR #111381)

2024-10-08 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,139 @@ +//===--- MutexRegionExtractor.h - Modeling of mutexes -===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Ap

[clang] [clang][analyzer] Introduce MutexModeling checker (PR #111381)

2024-10-08 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: Nice well-designed code; I added several remarks, but they are all minor. https://github.com/llvm/llvm-project/pull/111381 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/ma

[clang] [analyzer] Fix crash when casting the result of a malformed fptr call (PR #111390)

2024-10-09 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM. Let's not crash. https://github.com/llvm/llvm-project/pull/111390 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Modernize FuchsiaHandleChecker (PR #111588)

2024-10-09 Thread Donát Nagy via cfe-commits
@@ -314,6 +449,127 @@ getFuchsiaHandleSymbols(QualType QT, SVal Arg, ProgramStateRef State) { return {}; } +bool FuchsiaHandleChecker::needsInvalidate(const CallEvent &Call) const { + const FunctionDecl *FuncDecl = dyn_cast_or_null(Call.getDecl()); + + assert(FuncDecl &&

[clang] [analyzer] Modernize FuchsiaHandleChecker (PR #111588)

2024-10-09 Thread Donát Nagy via cfe-commits
@@ -127,26 +135,30 @@ class HandleState { bool isEscaped() const { return K == Kind::Escaped; } bool isUnowned() const { return K == Kind::Unowned; } - static HandleState getMaybeAllocated(SymbolRef ErrorSym) { -return HandleState(Kind::MaybeAllocated, ErrorSym); + s

[clang] [analyzer] Modernize FuchsiaHandleChecker (PR #111588)

2024-10-09 Thread Donát Nagy via cfe-commits
@@ -336,141 +592,55 @@ void FuchsiaHandleChecker::checkPreCall(const CallEvent &Call, SmallVector Handles = getFuchsiaHandleSymbols(PVD->getType(), Call.getArgSVal(Arg), State); -// Handled in checkPostCall. -if (hasFuchsiaAttr(PVD) || -hasFuchsiaA

[clang] [analyzer] Modernize FuchsiaHandleChecker (PR #111588)

2024-10-09 Thread Donát Nagy via cfe-commits
@@ -267,12 +286,128 @@ class FuchsiaHandleSymbolVisitor final : public SymbolVisitor { private: SmallVector Symbols; }; + +class FuchsiaBugVisitor final : public BugReporterVisitor { + // Handle that caused a problem. + SymbolRef Sym; + + bool IsLeak; + +public: + Fuchsi

[clang] [analyzer] Modernize FuchsiaHandleChecker (PR #111588)

2024-10-09 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/111588 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Modernize FuchsiaHandleChecker (PR #111588)

2024-10-09 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: I read the patch and added my suggestions in inline comments, but I don't promise that I found every little corner case. Moreover, I'm strongly opposed to introducing a `BugReporterVisitor` instead of directly creating the notes, because in this case you

[clang] [analyzer] Modernize FuchsiaHandleChecker (PR #111588)

2024-10-09 Thread Donát Nagy via cfe-commits
@@ -99,6 +99,7 @@ #include "clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h" #include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h" #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h" +#include "clang/StaticAnalyzer/Core/PathSensitive/Progr

[clang] [analyzer] Modernize FuchsiaHandleChecker (PR #111588)

2024-10-09 Thread Donát Nagy via cfe-commits
@@ -314,6 +449,127 @@ getFuchsiaHandleSymbols(QualType QT, SVal Arg, ProgramStateRef State) { return {}; } +bool FuchsiaHandleChecker::needsInvalidate(const CallEvent &Call) const { + const FunctionDecl *FuncDecl = dyn_cast_or_null(Call.getDecl()); + + assert(FuncDecl &&

[clang] [analyzer] Modernize FuchsiaHandleChecker (PR #111588)

2024-10-09 Thread Donát Nagy via cfe-commits
@@ -267,12 +286,128 @@ class FuchsiaHandleSymbolVisitor final : public SymbolVisitor { private: SmallVector Symbols; }; + +class FuchsiaBugVisitor final : public BugReporterVisitor { + // Handle that caused a problem. + SymbolRef Sym; + + bool IsLeak; + +public: + Fuchsi

[clang] [analyzer] Modernize FuchsiaHandleChecker (PR #111588)

2024-10-09 Thread Donát Nagy via cfe-commits
@@ -267,12 +286,128 @@ class FuchsiaHandleSymbolVisitor final : public SymbolVisitor { private: SmallVector Symbols; }; + +class FuchsiaBugVisitor final : public BugReporterVisitor { + // Handle that caused a problem. + SymbolRef Sym; + + bool IsLeak; + +public: + Fuchsi

[clang] [analyzer] Modernize FuchsiaHandleChecker (PR #111588)

2024-10-09 Thread Donát Nagy via cfe-commits
@@ -314,6 +449,127 @@ getFuchsiaHandleSymbols(QualType QT, SVal Arg, ProgramStateRef State) { return {}; } +bool FuchsiaHandleChecker::needsInvalidate(const CallEvent &Call) const { + const FunctionDecl *FuncDecl = dyn_cast_or_null(Call.getDecl()); + + assert(FuncDecl &&

[clang] [analyzer] Modernize FuchsiaHandleChecker (PR #111588)

2024-10-09 Thread Donát Nagy via cfe-commits
NagyDonat wrote: > I just saw it in various easy checkers like `ValistChecker`, so I thought > it's "standard" way of reporting. Yes, ValistChecker is another example where it's useless. By the way that's the first checker that I wrote (not completely alone) when I was an intern many years ag

[clang] [clang][analyzer] PointerSubChecker should not warn on pointers converted to numerical type (PR #111846)

2024-10-11 Thread Donát Nagy via cfe-commits
NagyDonat wrote: > > The change LGTM, I think we can merge it. > > I guess the testcase pointer-sub.c have to be fixed to work on the windows > buildbot, also. Right? Right, thanks for catching my mistake! https://github.com/llvm/llvm-project/pull/111846 __

[clang] [clang][analyzer] PointerSubChecker should not warn on pointers converted to numerical type (PR #111846)

2024-10-11 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/111846 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][analyzer] PointerSubChecker should not warn on pointers converted to numerical type (PR #111846)

2024-10-11 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. The change LGTM, I think we can merge it. My only nitpick was that I tweaked the PR title to make it a bit more accurate. (Feel free to tweak it further / discuss this if you disagree with my choice.) https://github.com/llvm/llvm-project

[clang] [analyzer] Suppress out of bounds reports after weak loop assumptions (PR #109804)

2024-10-10 Thread Donát Nagy via cfe-commits
@@ -212,6 +212,25 @@ typedef llvm::ImmutableMap REGISTER_TRAIT_WITH_PROGRAMSTATE(PendingArrayDestruction, PendingArrayDestructionMap) +// This trait is used to heuristically filter out results produced from +// execution paths that took "weak"

[clang] [analyzer] Fix wrong `builtin_*_overflow` return type (PR #111253)

2024-10-07 Thread Donát Nagy via cfe-commits
NagyDonat wrote: @pskrgag Thanks for fixing this issue quickly! :smile: https://github.com/llvm/llvm-project/pull/111253 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][analyzer] Check initialization and argument passing in FixedAddressChecker (PR #110977)

2024-10-04 Thread Donát Nagy via cfe-commits
NagyDonat wrote: > I was thinking about using `check::Location` in this checker. The real > problem is when the fixed address is used (to store or load), not if it is > assigned to a pointer. (Or a fixed address becomes escaped.) I agree that a checker that activates when a fixed address is _d

[clang] [analyzer] Suppress out of bounds reports after weak loop assumptions (PR #109804)

2024-09-30 Thread Donát Nagy via cfe-commits
@@ -2808,27 +2825,63 @@ void ExprEngine::processBranch(const Stmt *Condition, std::tie(StTrue, StFalse) = *KnownCondValueAssumption; else { assert(!isa(Condition)); + // TODO: instead of this shortcut perhaps it would be better to "rejoin" + // the com

[clang] [clang][analyzer] Less redundant warnings from FixedAddressChecker (PR #110458)

2024-09-30 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/110458 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][analyzer] Less redundant warnings from FixedAddressChecker (PR #110458)

2024-09-30 Thread Donát Nagy via cfe-commits
@@ -43,6 +43,12 @@ void FixedAddressChecker::checkPreStmt(const BinaryOperator *B, if (!T->isPointerType()) return; + // Omit warning if the RHS has already pointer type. + // The value may come from a variable and is candidate for a previous warning + // from the ch

[clang] [clang][analyzer] Less redundant warnings from FixedAddressChecker (PR #110458)

2024-09-30 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. Looks good to me, nice little improvement :) I reworded a comment in an inline suggestion because I felt that it was a bit difficult to understand; but feel free to change it further if you'd prefer. https://github.com/llvm/llvm-project/

[clang] [analyzer][NFC] Remove dangling method declaration from ErrnoChecker (PR #110820)

2024-10-02 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/110820 Remove the declaration of `ErrnoChecker::checkBranchCondition()` because this method is not defined or used anywhere. (It's probably a leftover from some old refactoring.) From 72bc17b87a7955a58210dfe42d7d73

[clang] [analyzer][NFC] Remove dangling method declaration from ErrnoChecker (PR #110820)

2024-10-02 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat closed https://github.com/llvm/llvm-project/pull/110820 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-tools-extra] [analyzer][clang-tidy][NFC] Clean up eagerly-assume handling (PR #112209)

2024-10-16 Thread Donát Nagy via cfe-commits
NagyDonat wrote: @steakhal May I merge this commit? https://github.com/llvm/llvm-project/pull/112209 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-tools-extra] [analyzer][clang-tidy][NFC] Clean up eagerly-assume handling (PR #112209)

2024-10-16 Thread Donát Nagy via cfe-commits
@@ -299,13 +299,12 @@ ANALYZER_OPTION( ANALYZER_OPTION( bool, ShouldEagerlyAssume, "eagerly-assume", -"Whether we should eagerly assume evaluations of conditionals, thus, " -"bifurcating the path. This indicates how the engine should handle " -"expressions such

[clang] [clang-tools-extra] [analyzer][clang-tidy][NFC] Clean up eagerly-assume handling (PR #112209)

2024-10-16 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat closed https://github.com/llvm/llvm-project/pull/112209 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Suppress out of bounds reports after weak loop assumptions (PR #109804)

2024-10-16 Thread Donát Nagy via cfe-commits
NagyDonat wrote: > > * I think it's likely (although not guaranteed) that this heuristic would > > be helpful for other checkers as well, and if we want to activate it for > > all checkers, then it must be done in an eager way (because eagerly sinking > > lots of paths is significantly better

[clang] [clang-tools-extra] [analyzer][clang-tidy][NFC] Clean up eagerly-assume handling (PR #112209)

2024-10-16 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/112209 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang-tools-extra] [analyzer][clang-tidy][NFC] Clean up eagerly-assume handling (PR #112209)

2024-10-16 Thread Donát Nagy via cfe-commits
@@ -458,7 +458,6 @@ ClangTidyASTConsumerFactory::createASTConsumer( if (!AnalyzerOptions.CheckersAndPackages.empty()) { setStaticAnalyzerCheckerOpts(Context.getOptions(), AnalyzerOptions); AnalyzerOptions.AnalysisDiagOpt = PD_NONE; -AnalyzerOptions.eagerlyAssumeBi

[clang] [analyzer][Solver] Teach SymbolicRangeInferrer about commutativity (2/2) (PR #112887)

2024-10-18 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM. I already reviewed this together with the first step. https://github.com/llvm/llvm-project/pull/112887 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin

[clang] [analyzer][Solver][NFC] Cleanup const-correctness inside range-based solver (PR #112891)

2024-10-18 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM, straightforward NFC improvement. Thanks for cleaning this up! (Currently the diff is a bit confusing, because this cleanup builds on the not-yet-merged commit https://github.com/llvm/llvm-project/pull/112887, but that's just GUI aw

[clang] [analyzer] Improve solver (PR #112583)

2024-10-17 Thread Donát Nagy via cfe-commits
@@ -2866,12 +2877,14 @@ ConditionTruthVal RangeConstraintManager::checkNull(ProgramStateRef State, const llvm::APSInt *RangeConstraintManager::getSymVal(ProgramStateRef St, SymbolRef Sym) const { - const RangeSet *T = get

[clang] [analyzer] Improve solver (PR #112583)

2024-10-17 Thread Donát Nagy via cfe-commits
@@ -1485,6 +1487,18 @@ class SymbolicRangeInferrer Sym->getType()); } + std::optional getRangeCommutativeSymSym(const SymSymExpr *SSE) { +bool IsCommutative = llvm::is_contained({BO_Add, BO_Mul}, SSE->getOpcode()); +if (!IsCommutative) + return std::nu

[clang] [analyzer] Improve solver (PR #112583)

2024-10-17 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/112583 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Improve solver (PR #112583)

2024-10-17 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM overall, see inline remarks for details. https://github.com/llvm/llvm-project/pull/112583 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listi

[clang] [analyzer] Improve solver (PR #112583)

2024-10-17 Thread Donát Nagy via cfe-commits
@@ -50,28 +50,17 @@ void test2() { b = d; a -= d; + clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}} + if (a != 0) return; - clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} - - /* The BASELINE passes these checks ('wrning' is

<    1   2   3   4   5   6   7   8   9   10   >