[clang] [analyzer] New optin.taint.TaintAlloc checker for catching unbounded memory allocation calls (PR #92420)

2024-05-29 Thread Donát Nagy via cfe-commits
@@ -1779,18 +1797,76 @@ ProgramStateRef MallocChecker::MallocMemAux(CheckerContext &C, const CallEvent &Call, const Expr *SizeEx, SVal Init, Prog

[clang] [analyzer] New optin.taint.TaintAlloc checker for catching unbounded memory allocation calls (PR #92420)

2024-05-29 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM, thanks for the update! https://github.com/llvm/llvm-project/pull/92420 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [clang][analyzer] Improved PointerSubChecker (PR #93676)

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

[clang] [clang][analyzer] Improved PointerSubChecker (PR #93676)

2024-05-29 Thread Donát Nagy via cfe-commits
@@ -44,24 +44,30 @@ void PointerSubChecker::checkPreStmt(const BinaryOperator *B, const MemRegion *LR = LV.getAsRegion(); const MemRegion *RR = RV.getAsRegion(); - - if (!(LR && RR)) -return; - - const MemRegion *BaseLR = LR->getBaseRegion(); - const MemRegion *Bas

[clang] [clang][analyzer] Improved PointerSubChecker (PR #93676)

2024-05-29 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: It's nice to see that you're working on this checker; but unfortunately the language standard is very complicated in this area, so you'll need more complex code to cover it properly. https://github.com/llvm/llvm-project/pull/93676 ___

[clang] [clang][analyzer] Improved PointerSubChecker (PR #93676)

2024-05-29 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,74 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.PointerSub -verify %s + +void f1(void) { + int x, y, z[10]; + int d = &y - &x; // expected-warning{{Subtraction of two pointers that do not point into the same array is undefined behavior}} + d = z - &y;

[clang] [clang][analyzer][NFC] Add test for a limitation of alpha.unix.Bloc… (PR #93799)

2024-05-30 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. It's good to document this, the commit LGTM. Are you planning to fix this soon? https://github.com/llvm/llvm-project/pull/93799 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lis

[clang] [clang][analyzer] Improved PointerSubChecker (PR #93676)

2024-05-30 Thread Donát Nagy via cfe-commits
@@ -44,24 +44,30 @@ void PointerSubChecker::checkPreStmt(const BinaryOperator *B, const MemRegion *LR = LV.getAsRegion(); const MemRegion *RR = RV.getAsRegion(); - - if (!(LR && RR)) -return; - - const MemRegion *BaseLR = LR->getBaseRegion(); - const MemRegion *Bas

[clang] [clang][analyzer] Improved PointerSubChecker (PR #93676)

2024-05-30 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,74 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.PointerSub -verify %s + +void f1(void) { + int x, y, z[10]; + int d = &y - &x; // expected-warning{{Subtraction of two pointers that do not point into the same array is undefined behavior}} + d = z - &y;

[clang] [clang][analyzer][NFC] Improve docs of alpha.unix.BlockInCriticalSection (PR #93812)

2024-05-30 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. What's the relationship between this PR and https://github.com/llvm/llvm-project/pull/93799 ? Otherwise, the change LGTM, but you might want to either unify these two NFC changes into a single commit or ensure that they're independent.

[clang] [clang][analyzer][NFC] Improve docs of alpha.unix.BlockInCriticalSection (PR #93812)

2024-05-31 Thread Donát Nagy via cfe-commits
NagyDonat wrote: > My intention was to ease the review as much as possible by cutting them into > atomic parts. This is a good idea in general, but I feel that these two changes are so trivial, that they'd be very easy to review even together. Feel free to merge them both in whatever combinat

[clang] [analyzer][NFC] Fix comparison to True/False (PR #94038)

2024-06-03 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: This change follows both the letter and the spirit of PEP8. (Note that `True` and `False` are not "singletons like `None`" because the type `bool` has two possible values -- but different rules still claim that the original code was bad and the new code

[clang] [clang][analyzer] Improved PointerSubChecker (PR #93676)

2024-06-03 Thread Donát Nagy via cfe-commits
@@ -0,0 +1,74 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.core.PointerSub -verify %s + +void f1(void) { + int x, y, z[10]; + int d = &y - &x; // expected-warning{{Subtraction of two pointers that do not point into the same array is undefined behavior}} + d = z - &y;

[clang] [clang][analyzer] Improved PointerSubChecker (PR #93676)

2024-06-03 Thread Donát Nagy via cfe-commits
NagyDonat wrote: > With the current version I have the following observations: > > * There is a warning for `(&x + 1) - &x` and `(&x - 1) - &x`. Should this > be fixed? The expression `(&x + 1) - &x` is valid and should not produce a warning. It could appear e.g. in code that's structured

[clang] [analyzer] New optin.taint.TaintAlloc checker for catching unbounded memory allocation calls (PR #92420)

2024-06-03 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. The change LGTM. I agree with @steakhal that `TaintedAlloc` would be a slightly better name, but the current one is also acceptable. https://github.com/llvm/llvm-project/pull/92420 ___ cfe-commi

[clang-tools-extra] [clang-tidy] Add WarnOnSizeOfPointer mode to bugprone-sizeof-expression (PR #94356)

2024-06-04 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/94356 This commit reimplements the functionality of the Clang Static Analyzer checker `alpha.core.SizeofPointer` within clang-tidy by adding a new (off-by-default) option to bugprone-sizeof-expression which activate

[clang-tools-extra] [clang-tidy] Add WarnOnSizeOfPointer mode to bugprone-sizeof-expression (PR #94356)

2024-06-04 Thread Donát Nagy via cfe-commits
@@ -124,8 +124,6 @@ int Test1(const char* ptr) { // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)' sum += sizeof(ptr) / sizeof(char); // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of sizeof pointer 's

[clang-tools-extra] [clang-tidy] Add WarnOnSizeOfPointer mode to bugprone-sizeof-expression (PR #94356)

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

[clang] [analyzer] Model builtin-like functions as builtin functions (PR #99886)

2024-07-23 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: LGTM. https://github.com/llvm/llvm-project/pull/99886 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Model builtin-like functions as builtin functions (PR #99886)

2024-07-23 Thread Donát Nagy via cfe-commits
@@ -570,13 +570,8 @@ void differentBranchesTest(int i) { { A a; a.foo() > 0 ? a.foo() : A(std::move(a)).foo(); -#ifdef DFS -// peaceful-note@-2 {{Assuming the condition is false}} -// peaceful-note@-3 {{'?' condition is false}} -#else -// peaceful-note@-5

[clang] [analyzer] Assume the result of 'fopen' can't alias with 'std{in,out,err}' (PR #100085)

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

[clang] [analyzer] Assume the result of 'fopen' can't alias with 'std{in,out,err}' (PR #100085)

2024-07-23 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM, this is a nice improvement. I vaguely recall that a few months ago somebody else on our team had trouble with false positives similar false positives, so it's good to see that these will be fixed. https://github.com/llvm/llvm-proje

[clang] [analyzer] Assume the result of 'fopen' can't alias with 'std{in,out,err}' (PR #100085)

2024-07-23 Thread Donát Nagy via cfe-commits
@@ -451,6 +462,10 @@ class StreamChecker : public Checker` In your code the three standard streams have exactly identical roles (as far as I see), and I think it would be good to emphasize this by storing them in a three-element array instead of three separate independently name

[clang] [clang][ASTImporter] Fix import of template parameter default values. (PR #100100)

2024-07-23 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM, I'm very grateful that you can understand and resolve these tricky `ASTImporter` issues. https://github.com/llvm/llvm-project/pull/100100 ___ cfe-commits mailing list cfe-commits@lists.llv

[clang] [clang][ASTImporter] Fix import of template parameter default values. (PR #100100)

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

[clang] [clang][ASTImporter] Fix import of template parameter default values. (PR #100100)

2024-07-23 Thread Donát Nagy via cfe-commits
@@ -359,6 +359,31 @@ namespace clang { Params, Importer.getToContext().getTranslationUnitDecl()); } +template +void tryUpdateTemplateParmDeclInheritedFrom(NamedDecl *RecentParm, +NamedDecl *NewParm) { +

[clang] [clang][ASTImporter] Fix import of template parameter default values. (PR #100100)

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

[clang] [analyzer] Don't invalidate the super region when a std object ctor runs (PR #100405)

2024-07-25 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM, nice improvement. https://github.com/llvm/llvm-project/pull/100405 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Don't invalidate the super region when a std object ctor runs (PR #100405)

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

[clang] [analyzer] Don't invalidate the super region when a std object ctor runs (PR #100405)

2024-07-25 Thread Donát Nagy via cfe-commits
@@ -923,12 +923,31 @@ SVal AnyCXXConstructorCall::getCXXThisVal() const { return UnknownVal(); } +static bool isWithinStdNamespace(const Decl *D) { NagyDonat wrote: I think this function could be useful for other checkers as well; consider moving this to a

[clang] [analyzer] Don't invalidate the super region when a std object ctor runs (PR #100405)

2024-07-25 Thread Donát Nagy via cfe-commits
@@ -923,12 +923,31 @@ SVal AnyCXXConstructorCall::getCXXThisVal() const { return UnknownVal(); } +static bool isWithinStdNamespace(const Decl *D) { NagyDonat wrote: Of course, feel free to leave it for a followup patch. https://github.com/llvm/llvm-project

[clang] [analyzer][NFC] Minor cleanup in two test files. (PR #100570)

2024-07-25 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat created https://github.com/llvm/llvm-project/pull/100570 This commit contains two unrelated trivial changes: (1) Three unused variables are removed from `ctor.mm`. (2) A FIXME block is removed from `ctor-array.cpp` because it described an issue that was resolved

[clang] [analyzer][NFC] Minor cleanup in two test files. (PR #100570)

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

[clang] [analyzer][NFC] Minor cleanup in two test files. (PR #100570)

2024-07-25 Thread Donát Nagy via cfe-commits
NagyDonat wrote: In my opinion the "put unrelated things into separate commits" guideline is just a corollary of the "don't create commits that are too complex" rule. If a change is extremely trivial, I'm actively trying to aggregate it with other tangentially related changes, because one simp

[clang] [analyzer][NFC] Eliminate a dyn_cast (PR #100719)

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

[clang] [clang][ASTImporter] Fix import of template parameter default values. (PR #100100)

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

[clang] [clang][ASTImporter] Fix import of template parameter default values. (PR #100100)

2024-07-26 Thread Donát Nagy via cfe-commits
@@ -359,6 +359,31 @@ namespace clang { Params, Importer.getToContext().getTranslationUnitDecl()); } +template +void tryUpdateTemplateParmDeclInheritedFrom(NamedDecl *RecentParm, +NamedDecl *NewParm) { +

[clang] [analyzer] Keep alive short-circuiting condition subexpressions in a conditional (PR #100745)

2024-07-26 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. Nice fix, thanks for upstreaming this! https://github.com/llvm/llvm-project/pull/100745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe

[clang] [analyzer] Fix crash of StreamChecker when eval calling 'fopen' (PR #100990)

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

[clang] [analyzer] Fix crash of StreamChecker when eval calling 'fopen' (PR #100990)

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

[clang] [analyzer] Fix crash of StreamChecker when eval calling 'fopen' (PR #100990)

2024-07-29 Thread Donát Nagy via cfe-commits
@@ -1766,13 +1770,6 @@ are assumed to succeed.) fclose(p); } -**Limitations** - -The checker does not track the correspondence between integer file descriptors -and ``FILE *`` pointers. Operations on standard streams like ``stdin`` are not -treated specially and are theref

[clang] [analyzer] Fix crash of StreamChecker when eval calling 'fopen' (PR #100990)

2024-07-29 Thread Donát Nagy via cfe-commits
@@ -1703,7 +1703,11 @@ are detected: * Invalid 3rd ("``whence``") argument to ``fseek``. The stream operations are by this checker usually split into two cases, a success -and a failure case. However, in the case of write operations (like ``fwrite``, +and a failure case. +On

[clang] [analyzer] Fix crash of StreamChecker when eval calling 'fopen' (PR #100990)

2024-07-29 Thread Donát Nagy via cfe-commits
NagyDonat wrote: > I decided to put the fixup NFC changes along with this PR (the ones were > submitted after I merged the original commit), but on hindsight probably it > would be better to merge those NFC changes separately. If you request, I'll > split the PR. Feel free to keep the NFC cha

[clang] [analyzer] Fix crash of StreamChecker when eval calling 'fopen' (PR #100990)

2024-07-29 Thread Donát Nagy via cfe-commits
@@ -1703,7 +1703,11 @@ are detected: * Invalid 3rd ("``whence``") argument to ``fseek``. The stream operations are by this checker usually split into two cases, a success -and a failure case. However, in the case of write operations (like ``fwrite``, +and a failure case. +On

[clang] [analyzer] Fix crash of StreamChecker when eval calling 'fopen' (PR #100990)

2024-07-29 Thread Donát Nagy via cfe-commits
@@ -1766,13 +1770,6 @@ are assumed to succeed.) fclose(p); } -**Limitations** - -The checker does not track the correspondence between integer file descriptors -and ``FILE *`` pointers. Operations on standard streams like ``stdin`` are not -treated specially and are theref

[clang] [clang][ASTImporter] Fix import of anonymous enums if multiple are present (PR #99281)

2024-07-22 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM as far as I can judge this tricky situation. https://github.com/llvm/llvm-project/pull/99281 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/li

[clang] [analyzer] Improve bug report hashing, merge similar reports (PR #98621)

2024-07-22 Thread Donát Nagy via cfe-commits
NagyDonat wrote: I'm back from the vacation, so I would like to restart and conclude this review process. @steakhal or anybody else please review when it's convenient for you. https://github.com/llvm/llvm-project/pull/98621 ___ cfe-commits mailing lis

[clang] [analyzer] Improve bug report hashing, merge similar reports (PR #98621)

2024-07-22 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat unassigned https://github.com/llvm/llvm-project/pull/98621 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Improve bug report hashing, merge similar reports (PR #98621)

2024-07-22 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat unassigned https://github.com/llvm/llvm-project/pull/98621 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Improve bug report hashing, merge similar reports (PR #98621)

2024-07-22 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat unassigned https://github.com/llvm/llvm-project/pull/98621 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Improve bug report hashing, merge similar reports (PR #98621)

2024-07-22 Thread Donát Nagy via cfe-commits
NagyDonat wrote: (Btw it seems that I accidentally added everyone as an "assignee" instead of a reviewer...) https://github.com/llvm/llvm-project/pull/98621 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman

[clang] [analyzer] Improve bug report hashing, merge similar reports (PR #98621)

2024-07-22 Thread Donát Nagy via cfe-commits
@@ -2213,7 +2213,7 @@ void BasicBugReport::Profile(llvm::FoldingSetNodeID& hash) const { void PathSensitiveBugReport::Profile(llvm::FoldingSetNodeID &hash) const { hash.AddInteger(static_cast(getKind())); hash.AddPointer(&BT); - hash.AddString(Description); + hash.AddStr

[clang] [analyzer] Improve bug report hashing, merge similar reports (PR #98621)

2024-07-22 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/98621 From 2765bc97d3242d50fd73aedb9e9d38dfdcef814c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Nagy?= Date: Fri, 12 Jul 2024 13:57:53 +0200 Subject: [PATCH 1/3] [analyzer] Don't display the offset value in

[clang] [analyzer] Improve bug report hashing, merge similar reports (PR #98621)

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

[clang] [analyzer] Removing untrusted buffer size taint warning (PR #68607)

2024-04-30 Thread Donát Nagy via cfe-commits
@@ -95,22 +94,23 @@ void testReadStdIn(){ } void multipleTaintSources(void) { - int x,y,z; - scanf("%d", &x); // expected-note {{Taint originated here}} + char cmd[2048], file[1024]; + scanf ("%1022[^\n] ", cmd); // expected-note {{Taint originated here}}

[clang] [analyzer] Removing untrusted buffer size taint warning (PR #68607)

2024-04-30 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat updated https://github.com/llvm/llvm-project/pull/68607 From 143db26ffe8620c2b45eb15d331466c883bbfce0 Mon Sep 17 00:00:00 2001 From: Daniel Krupp Date: Mon, 9 Oct 2023 16:52:13 +0200 Subject: [PATCH 1/6] [analyzer] Removing untrusted buffer size taint warning alpha

[clang] [analyzer] Report violations of the "returns_nonnull" attribute (PR #106048)

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

[clang] [analyzer] Report violations of the "returns_nonnull" attribute (PR #106048)

2024-08-26 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: Thanks for the updates! https://github.com/llvm/llvm-project/pull/106048 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Report violations of the "returns_nonnull" attribute (PR #106048)

2024-08-26 Thread Donát Nagy via cfe-commits
@@ -588,8 +588,8 @@ Warns when a null pointer is passed to a pointer which has a _Nonnull type. .. _nullability-NullReturnedFromNonnull: -nullability.NullReturnedFromNonnull (ObjC) -"" +nullability.NullReturnedFromNonnull +

[clang] [analyzer] Report violations of the "returns_nonnull" attribute (PR #106048)

2024-08-26 Thread Donát Nagy via cfe-commits
@@ -51,3 +54,15 @@ int *cannot_return_null() { __attribute__((returns_nonnull)) int *passthrough(int *p) { return p; // no-warning: we have no evidence that `p` is null, i.e., violating the contract } + +__attribute__((noreturn)) +void exit(int); NagyDonat w

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

2024-08-27 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-27 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. Thanks for the clarification, the change LGTM now. https://github.com/llvm/llvm-project/pull/105648 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/

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

2024-08-27 Thread Donát Nagy via cfe-commits
@@ -305,6 +305,14 @@ static const MemSpaceRegion *getStackOrGlobalSpaceRegion(const MemRegion *R) { return nullptr; } +const MemRegion *getOriginBaseRegion(const MemRegion *Referrer) { + Referrer = Referrer->getBaseRegion(); + while (const auto *SymReg = dyn_cast(Referrer

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

2024-08-27 Thread Donát Nagy via cfe-commits
@@ -424,6 +481,9 @@ void StackAddrEscapeChecker::checkEndFunction(const ReturnStmt *RS, for (const auto &P : Cb.V) { const MemRegion *Referrer = P.first->getBaseRegion(); const MemRegion *Referred = P.second; +if (Cb.ExcludedRegions.contains(getOriginBaseRegion(R

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

2024-08-27 Thread Donát Nagy via cfe-commits
@@ -369,24 +393,48 @@ void StackAddrEscapeChecker::checkEndFunction(const ReturnStmt *RS, const auto *ReferrerStackSpace = ReferrerMemSpace->getAs(); + if (!ReferrerStackSpace) return false; - if (ReferredMemSpace->getStackFrame() == Pop

[clang] [analyzer] Report violations of the "returns_nonnull" attribute (PR #106048)

2024-08-27 Thread Donát Nagy via cfe-commits
@@ -692,6 +692,14 @@ void NullabilityChecker::checkPreStmt(const ReturnStmt *S, NullConstraint Nullness = getNullConstraint(*RetSVal, State); Nullability RequiredNullability = getNullabilityAnnotation(RequiredRetType); + if (const auto *FunDecl = C.getLocationContext()->g

[clang] [analyzer] Report violations of the "returns_nonnull" attribute (PR #106048)

2024-08-27 Thread Donát Nagy via cfe-commits
@@ -10,3 +12,42 @@ void block_arity_mismatch() { void(^b)() = ^(int a, int b) { }; b(1); // no-crash expected-warning {{Block taking 2 arguments is called with fewer (1)}} } + +int *nonnull_return_annotation_indirect() __attribute__((returns_nonnull)); +int *nonnull_retur

[clang] [analyzer] Report violations of the "returns_nonnull" attribute (PR #106048)

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

[clang] [analyzer] Report violations of the "returns_nonnull" attribute (PR #106048)

2024-08-27 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. Looks good to me now, thanks :smile:. Feel free to merge this / I can help with merging if you don't have commit access yet. https://github.com/llvm/llvm-project/pull/106048 ___ cfe-commits mail

[clang] [analyzer][NFC] Add tests for and refactor StackAddrEscapeChecker 1/3 (PR #105652)

2024-08-27 Thread Donát Nagy via cfe-commits
@@ -374,13 +395,13 @@ void StackAddrEscapeChecker::checkEndFunction(const ReturnStmt *RS, // Generate a report for this bug. const StringRef CommonSuffix = -"upon returning to the caller. This will be a dangling reference"; +" upon returning to the ca

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

2024-08-27 Thread Donát Nagy via cfe-commits
@@ -1487,56 +1545,78 @@ void MallocChecker::checkOwnershipAttr(const CallEvent &Call, C.addTransition(State); } -void MallocChecker::checkPostCall(const CallEvent &Call, - CheckerContext &C) const { - if (C.wasInlined) -return; +bool Ma

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

2024-08-27 Thread Donát Nagy via cfe-commits
@@ -1052,6 +1103,12 @@ static bool isStandardNewDelete(const FunctionDecl *FD) { // Methods of MallocChecker and MallocBugVisitor. //===--===// +bool MallocChecker::isFreeingOwnershipAttrCall(const CallEvent

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

2024-08-27 Thread Donát Nagy via cfe-commits
@@ -67,19 +67,6 @@ void testGlobalNoThrowPlacementExprNewBeforeOverload() { int *p = new(std::nothrow) int; } // leak-warning{{Potential leak of memory pointed to by 'p'}} -//- Standard pointer placement operators -void testGlobalPointerPlacementNew() {

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

2024-08-27 Thread Donát Nagy via cfe-commits
@@ -1067,15 +1124,27 @@ bool MallocChecker::isFreeingCall(const CallEvent &Call) const { if (FreeingMemFnMap.lookup(Call) || ReallocatingMemFnMap.lookup(Call)) return true; - if (const auto *Func = dyn_cast_or_null(Call.getDecl())) -return isFreeingOwnershipAttrCal

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

2024-08-27 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: The commit looks very promising :smile: I added several minor remarks, but overall I'm very satisfied with the quality of your changes and I'm relieved that I won't have to perform this refactoring. > I have only 2 failing tests now: > > Clang :: Analys

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

2024-08-27 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] [WIP] [analyzer] Refactor MallocChecker to use `BindExpr` in `evalCall` (PR #106081)

2024-08-27 Thread Donát Nagy via cfe-commits
@@ -1854,28 +1945,27 @@ static ProgramStateRef MallocUpdateRefState(CheckerContext &C, const Expr *E, // Get the return value. if (!RetVal) -RetVal = C.getSVal(E); +RetVal = State->getSVal(E, C.getLocationContext()); // We expect the malloc functions to retur

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

2024-08-27 Thread Donát Nagy via cfe-commits
@@ -1854,28 +1945,27 @@ static ProgramStateRef MallocUpdateRefState(CheckerContext &C, const Expr *E, // Get the return value. if (!RetVal) -RetVal = C.getSVal(E); +RetVal = State->getSVal(E, C.getLocationContext()); // We expect the malloc functions to retur

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

2024-08-27 Thread Donát Nagy via cfe-commits
@@ -1736,6 +1816,25 @@ MallocChecker::MallocMemReturnsAttr(CheckerContext &C, const CallEvent &Call, return MallocMemAux(C, Call, UnknownVal(), UndefinedVal(), State, Family); } +ProgramStateRef MallocChecker::MallocBindRetval(CheckerContext &C, NagyDonat w

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

2024-08-27 Thread Donát Nagy via cfe-commits
@@ -554,6 +579,17 @@ class MallocChecker [[nodiscard]] ProgramStateRef MallocMemReturnsAttr(CheckerContext &C, const CallEvent &Call, const OwnershipAttr *Att, ProgramStateRef State) const; + /// Models memory allocation. + /// + /// \param [in] C

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

2024-08-27 Thread Donát Nagy via cfe-commits
@@ -2815,7 +2906,7 @@ MallocChecker::ReallocMemAux(CheckerContext &C, const CallEvent &Call, // Get the from and to pointer symbols as in toPtr = realloc(fromPtr, size). SymbolRef FromPtr = arg0Val.getLocSymbolInBase(); -SVal RetVal = C.getSVal(CE); +SVal Ret

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

2024-08-27 Thread Donát Nagy via cfe-commits
@@ -1736,6 +1816,25 @@ MallocChecker::MallocMemReturnsAttr(CheckerContext &C, const CallEvent &Call, return MallocMemAux(C, Call, UnknownVal(), UndefinedVal(), State, Family); } +ProgramStateRef MallocChecker::MallocBindRetval(CheckerContext &C, +

[clang] [analyzer] Fix false positive for mutexes inheriting mutex_base (PR #106240)

2024-08-27 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM, nice catch! https://github.com/llvm/llvm-project/pull/106240 ___ 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-27 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. Thanks for the updates! 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] Fix false positive for mutexes inheriting mutex_base (PR #106240)

2024-08-28 Thread Donát Nagy via cfe-commits
@@ -241,10 +241,14 @@ BlockInCriticalSectionChecker::checkDescriptorMatch(const CallEvent &Call, return std::nullopt; } -static const MemRegion *skipBaseClassRegion(const MemRegion *Reg) { - while (const auto *BaseClassRegion = dyn_cast(Reg)) { +static const MemRegion *ski

[clang] [analyzer] Fix false positive for mutexes inheriting mutex_base (PR #106240)

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

[clang-tools-extra] [clang-tidy] Extend `bugprone-sizeof-expression` with matching `P +- sizeof(T)` and `P +- N * sizeof(T)` cases, add `cert-arr39-c` alias (PR #106061)

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

[clang-tools-extra] [clang-tidy] Extend `bugprone-sizeof-expression` with matching `P +- sizeof(T)` and `P +- N * sizeof(T)` cases, add `cert-arr39-c` alias (PR #106061)

2024-08-28 Thread Donát Nagy via cfe-commits
@@ -285,6 +288,50 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) { hasRHS(ignoringParenImpCasts(SizeOfExpr.bind("sizeof-ptr-div-expr" .bind("sizeof-in-ptr-arithmetic-div"), this); + + // SEI CERT ARR39-C. Do not add or subt

[clang-tools-extra] [clang-tidy] Extend `bugprone-sizeof-expression` with matching `P +- sizeof(T)` and `P +- N * sizeof(T)` cases, add `cert-arr39-c` alias (PR #106061)

2024-08-28 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat approved this pull request. LGTM, I didn't spot anything problematic. https://github.com/llvm/llvm-project/pull/106061 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/

[clang-tools-extra] [clang-tidy] Extend `bugprone-sizeof-expression` with matching `P +- sizeof(T)` and `P +- N * sizeof(T)` cases, add `cert-arr39-c` alias (PR #106061)

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

[clang] Adding optin.taint.TaintedDiv checker (PR #106389)

2024-08-29 Thread Donát Nagy via cfe-commits
@@ -48,8 +52,14 @@ static const Expr *getDenomExpr(const ExplodedNode *N) { void DivZeroChecker::reportBug(StringRef Msg, ProgramStateRef StateZero, CheckerContext &C) const { + if (!ChecksEnabled[CK_DivZeroChecker]) +return; + if (!BugType

[clang] Adding optin.taint.TaintedDiv checker (PR #106389)

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

[clang] Adding optin.taint.TaintedDiv checker (PR #106389)

2024-08-29 Thread Donát Nagy via cfe-commits
https://github.com/NagyDonat commented: LGTM overall, I added some minor inline remarks. Also consider adding a few simple testcases to distinguish the effects of DivideZero and TaintedDiv. It would also be interesting to highlight what happens in situations like ```c int test(void) { int x

[clang] Adding optin.taint.TaintedDiv checker (PR #106389)

2024-08-29 Thread Donát Nagy via cfe-commits
@@ -113,9 +130,28 @@ void DivZeroChecker::checkPreStmt(const BinaryOperator *B, } void ento::registerDivZeroChecker(CheckerManager &mgr) { - mgr.registerChecker(); + DivZeroChecker *checker = mgr.registerChecker(); + ; NagyDonat wrote: Delete this empty st

[clang] Adding optin.taint.TaintedDiv checker (PR #106389)

2024-08-29 Thread Donát Nagy via cfe-commits
@@ -25,16 +25,20 @@ using namespace ento; using namespace taint; namespace { -class DivZeroChecker : public Checker< check::PreStmt > { - const BugType BT{this, "Division by zero"}; - const BugType TaintBT{this, "Division by zero", categories::TaintedData}; +class DivZeroChe

[clang] Adding optin.taint.TaintedDiv checker (PR #106389)

2024-08-29 Thread Donát Nagy via cfe-commits
@@ -58,8 +68,15 @@ void DivZeroChecker::reportBug(StringRef Msg, ProgramStateRef StateZero, void DivZeroChecker::reportTaintBug( StringRef Msg, ProgramStateRef StateZero, CheckerContext &C, llvm::ArrayRef TaintedSyms) const { + if (!ChecksEnabled[CK_TaintedDivChecker]

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

2024-08-29 Thread Donát Nagy via cfe-commits
@@ -3648,35 +3648,38 @@ PathDiagnosticPieceRef MallocBugVisitor::VisitNode(const ExplodedNode *N, return nullptr; } - // See if we're releasing memory while inlining a destructor - // (or one of its callees). This turns on various common - //

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

2024-08-29 Thread Donát Nagy via cfe-commits
@@ -3648,35 +3648,38 @@ PathDiagnosticPieceRef MallocBugVisitor::VisitNode(const ExplodedNode *N, return nullptr; } - // See if we're releasing memory while inlining a destructor - // (or one of its callees). This turns on various common - //

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

2024-08-29 Thread Donát Nagy via cfe-commits
@@ -3558,8 +3558,8 @@ PathDiagnosticPieceRef MallocBugVisitor::VisitNode(const ExplodedNode *N, // original reference count is positive, we should not report use-after-frees NagyDonat wrote: Update the comment lines above this to be a bit more general. (Lines

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

2024-08-29 Thread Donát Nagy via cfe-commits
@@ -3648,35 +3648,38 @@ PathDiagnosticPieceRef MallocBugVisitor::VisitNode(const ExplodedNode *N, return nullptr; } - // See if we're releasing memory while inlining a destructor - // (or one of its callees). This turns on various common - //

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