[clang] [Sema] Diagnose tautological bounds checks (PR #120222)

2024-12-18 Thread Nathan Chancellor via cfe-commits
nathanchance wrote: > @nathanchance You are correct, this warning should indeed respect > `-fwrapv`/`-fno-strict-overflow`. Your patch looks reasonable to me as well. Thanks for the confirmation, I have submitted https://github.com/llvm/llvm-project/pull/120480 for this. https://github.com/ll

[clang] [Sema] Diagnose tautological bounds checks (PR #120222)

2024-12-18 Thread Nikita Popov via cfe-commits
nikic wrote: @nathanchance You are correct, this warning should indeed respect `-fwrapv`/`-fno-strict-overflow`. Your patch looks reasonable to me as well. https://github.com/llvm/llvm-project/pull/120222 ___ cfe-commits mailing list cfe-commits@lists

[clang] [Sema] Diagnose tautological bounds checks (PR #120222)

2024-12-18 Thread Nathan Chancellor via cfe-commits
nathanchance wrote: @nikic I noticed your comment on #118472 (the motivator for this change AFAICT): > `-fwrapv` should already cover pointers but it does not seem like this warning takes that into account (see the last example below)? I noticed a few instances of this warning in the Linux ker

[clang] [Sema] Diagnose tautological bounds checks (PR #120222)

2024-12-18 Thread Hans Wennborg via cfe-commits
zmodem wrote: Nice, thank you! https://github.com/llvm/llvm-project/pull/120222 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Sema] Diagnose tautological bounds checks (PR #120222)

2024-12-17 Thread via cfe-commits
https://github.com/cor3ntin approved this pull request. Thanks! https://github.com/llvm/llvm-project/pull/120222 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Sema] Diagnose tautological bounds checks (PR #120222)

2024-12-17 Thread Nikita Popov via cfe-commits
https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/120222 >From 66b5b0d72b49539206794c4472ee6fb14f00c5a7 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 17 Dec 2024 13:10:30 +0100 Subject: [PATCH 1/5] [Sema] Diagnose tautological bounds checks This diagnoses comp

[clang] [Sema] Diagnose tautological bounds checks (PR #120222)

2024-12-17 Thread Nikita Popov via cfe-commits
https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/120222 >From 66b5b0d72b49539206794c4472ee6fb14f00c5a7 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 17 Dec 2024 13:10:30 +0100 Subject: [PATCH 1/4] [Sema] Diagnose tautological bounds checks This diagnoses comp

[clang] [Sema] Diagnose tautological bounds checks (PR #120222)

2024-12-17 Thread Timm Baeder via cfe-commits
@@ -11786,6 +11786,49 @@ static bool checkForArray(const Expr *E) { return D->getType()->isArrayType() && !D->isWeak(); } +/// Detect patterns ptr + size >= ptr and ptr + size < ptr, where ptr is a +/// pointer and size is an unsigned integer. Return whether the result is +/

[clang] [Sema] Diagnose tautological bounds checks (PR #120222)

2024-12-17 Thread via cfe-commits
https://github.com/cor3ntin commented: Generally looks great. Can you add - a changelog entry - a test with C arrays? https://github.com/llvm/llvm-project/pull/120222 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cg

[clang] [Sema] Diagnose tautological bounds checks (PR #120222)

2024-12-17 Thread via cfe-commits
llvmbot wrote: @llvm/pr-subscribers-clang Author: Nikita Popov (nikic) Changes This diagnoses comparisons like `ptr + unsigned_index < ptr` and `ptr + unsigned_index >= ptr`, which are always false/true because addition of a pointer and an unsigned index cannot wrap (or the behavior is u

[clang] [Sema] Diagnose tautological bounds checks (PR #120222)

2024-12-17 Thread Nikita Popov via cfe-commits
https://github.com/nikic created https://github.com/llvm/llvm-project/pull/120222 This diagnoses comparisons like `ptr + unsigned_index < ptr` and `ptr + unsigned_index >= ptr`, which are always false/true because addition of a pointer and an unsigned index cannot wrap (or the behavior is unde