[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-03-25 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt created https://github.com/llvm/llvm-project/pull/86618 ## Intro This attribute would allow for more granular control over what expressions can emit integer overflow warnings or integer overflow sanitizer errors. Here are some examples: _copy-pasted from m

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-03-25 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 0fa8f07c722f9d7f80a90824f961ae6e9c5bdef7 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 5 Mar 2024 03:14:49 + Subject: [PATCH 1/2] implement wraps attribute Signed-off-by: Justin Stitt ---

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-03-26 Thread Justin Stitt via cfe-commits
JustinStitt wrote: cc: @MaskRay (since they also reviewed https://github.com/llvm/llvm-project/pull/82432) https://github.com/llvm/llvm-project/pull/86618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/l

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-03-27 Thread Justin Stitt via cfe-commits
JustinStitt wrote: > Adding attributes to types as type sugar (not part of the canonical type) is > generally problematic: non-canonical types are not reliably preserved > throughout the compiler, particularly in cases involving templates. I see, here's an example that currently breaks my attr

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-08 Thread Justin Stitt via cfe-commits
JustinStitt wrote: ping! https://github.com/llvm/llvm-project/pull/80089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-13 Thread Justin Stitt via cfe-commits
@@ -0,0 +1,77 @@ +// Check that -fsanitize=signed-integer-wrap instruments with -fwrapv +// RUN: %clang_cc1 -fwrapv -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=signed-integer-wrap | FileCheck %s --check-prefix=CHECKSIW + +// Check that -fsanitize=signed-integer-over

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-13 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/80089 >From 7774e4036ac1de7fdf5fe4c6b3208b492853ffc5 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 23 Jan 2024 23:28:42 + Subject: [PATCH 1/6] add signed-integer-wrap sanitizer --- clang/include/clan

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-13 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/80089 >From 7774e4036ac1de7fdf5fe4c6b3208b492853ffc5 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 23 Jan 2024 23:28:42 + Subject: [PATCH 1/8] add signed-integer-wrap sanitizer --- clang/include/clan

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-13 Thread Justin Stitt via cfe-commits
@@ -3554,12 +3572,20 @@ Value *ScalarExprEmitter::EmitOverflowCheckedBinOp(const BinOpInfo &Ops) { const std::string *handlerName = &CGF.getLangOpts().OverflowHandler; if (handlerName->empty()) { -// If the signed-integer-overflow sanitizer is enabled, emit a call

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-13 Thread Justin Stitt via cfe-commits
@@ -0,0 +1,77 @@ +// Check that -fsanitize=signed-integer-wrap instruments with -fwrapv +// RUN: %clang_cc1 -fwrapv -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=signed-integer-wrap | FileCheck %s --check-prefix=CHECKSIW + +// Check that -fsanitize=signed-integer-over

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-13 Thread Justin Stitt via cfe-commits
@@ -0,0 +1,77 @@ +// Check that -fsanitize=signed-integer-wrap instruments with -fwrapv +// RUN: %clang_cc1 -fwrapv -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=signed-integer-wrap | FileCheck %s --check-prefix=CHECKSIW + +// Check that -fsanitize=signed-integer-over

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-13 Thread Justin Stitt via cfe-commits
@@ -0,0 +1,77 @@ +// Check that -fsanitize=signed-integer-wrap instruments with -fwrapv JustinStitt wrote: Gotcha, I did just that in [5497e8b](https://github.com/llvm/llvm-project/pull/80089/commits/5497e8bc6849bf64c1158ff16b4aa04fd9141920). Thanks Nick! http

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-13 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/80089 >From 7774e4036ac1de7fdf5fe4c6b3208b492853ffc5 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 23 Jan 2024 23:28:42 + Subject: [PATCH 1/9] add signed-integer-wrap sanitizer --- clang/include/clan

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-13 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/80089 >From 7774e4036ac1de7fdf5fe4c6b3208b492853ffc5 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 23 Jan 2024 23:28:42 + Subject: [PATCH 01/10] add signed-integer-wrap sanitizer --- clang/include/cl

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-13 Thread Justin Stitt via cfe-commits
JustinStitt wrote: > UBSan is documented clang/docs/UndefinedBehaviorSanitizer.rst > https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html > > Please make sure to update the list [of available > checks](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks). > >

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-30 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt created https://github.com/llvm/llvm-project/pull/80089 **Reasoning** Clang has a `signed-integer-overflow` sanitizer to catch arithmetic overflow; however, most* of its instrumentation [fails to apply](https://godbolt.org/z/ee41rE8o6) when `-fwrapv` is enabled.

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/80089 >From 68805d7871230033be43c1d87dfcd2aa2b668589 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 23 Jan 2024 23:28:42 + Subject: [PATCH 1/4] add signed-integer-wrap sanitizer --- clang/include/clan

[compiler-rt] [clang] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/80089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/80089 >From 68805d7871230033be43c1d87dfcd2aa2b668589 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 23 Jan 2024 23:28:42 + Subject: [PATCH 1/5] add signed-integer-wrap sanitizer --- clang/include/clan

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
@@ -0,0 +1,66 @@ +// Check that -fsanitize=signed-integer-wrap instruments with -fwrapv +// RUN: %clang_cc1 -fwrapv -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=signed-integer-wrap | FileCheck %s --check-prefix=CHECK + +// Check that -fsanitize=signed-integer-overflo

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/80089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
@@ -0,0 +1,77 @@ +// Check that -fsanitize=signed-integer-wrap instruments with -fwrapv JustinStitt wrote: I must be doing something wrong because it suggest I remove all my `Check: ...`'s and replcae them with `Check: {{.*}}` https://github.com/llvm/llvm-proje

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/80089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/80089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
@@ -0,0 +1,77 @@ +// Check that -fsanitize=signed-integer-wrap instruments with -fwrapv +// RUN: %clang_cc1 -fwrapv -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=signed-integer-wrap | FileCheck %s --check-prefix=CHECK JustinStitt wrote: > `CHECK` is

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/80089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
JustinStitt wrote: Hey, does anyone know why the CI bot (buildkite) fails my builds for a trailing whitespace in a file I did not touch? https://github.com/llvm/llvm-project/pull/80089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://li

[compiler-rt] [clang] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/80089 >From 68805d7871230033be43c1d87dfcd2aa2b668589 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 23 Jan 2024 23:28:42 + Subject: [PATCH 1/6] add signed-integer-wrap sanitizer --- clang/include/clan

[compiler-rt] [clang] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
@@ -0,0 +1,77 @@ +// Check that -fsanitize=signed-integer-wrap instruments with -fwrapv +// RUN: %clang_cc1 -fwrapv -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=signed-integer-wrap | FileCheck %s --check-prefix=CHECK JustinStitt wrote: Gotcha. Fixed

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
@@ -0,0 +1,77 @@ +// Check that -fsanitize=signed-integer-wrap instruments with -fwrapv +// RUN: %clang_cc1 -fwrapv -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=signed-integer-wrap | FileCheck %s --check-prefix=CHECKSIW + +// Check that -fsanitize=signed-integer-over

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
@@ -0,0 +1,77 @@ +// Check that -fsanitize=signed-integer-wrap instruments with -fwrapv JustinStitt wrote: I believe @tschuett was saying that to be confident we are instrumenting the arithmetic (and the correct operands therein) we should check the overflow bit

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt deleted https://github.com/llvm/llvm-project/pull/80089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
@@ -0,0 +1,77 @@ +// Check that -fsanitize=signed-integer-wrap instruments with -fwrapv +// RUN: %clang_cc1 -fwrapv -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=signed-integer-wrap | FileCheck %s --check-prefix=CHECKSIW + +// Check that -fsanitize=signed-integer-over

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-01-31 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/80089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CodeGen] Respect pointer-overflow sanitizer for void pointers (PR #67772)

2023-09-29 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt approved this pull request. LGTM! FWIW, here's a test file that does not trip the sanitizer before this PR and _does_ trip after the PR: ```c #include int main(int argc, char **argv) { void *p = NULL; printf("p: %p\n", p); p = p - argc; printf("p: %p\n"

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-14 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/80089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-14 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/80089 >From 7774e4036ac1de7fdf5fe4c6b3208b492853ffc5 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 23 Jan 2024 23:28:42 + Subject: [PATCH 01/11] add signed-integer-wrap sanitizer --- clang/include/cl

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-14 Thread Justin Stitt via cfe-commits
JustinStitt wrote: > I think this patch is good to go. Thanks for working on it! Thanks for the review Nick! BTW, I forgot to update the `ReleaseNotes.rst`, I've done so now (hopefully not voiding your previous review) https://github.com/llvm/llvm-project/pull/80089 _

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-14 Thread Justin Stitt via cfe-commits
JustinStitt wrote: My original idea was to get the SIO sanitizer working with `-fwrapv`, the issue [here](https://github.com/KSPP/linux/issues/26) even suggests it as a viable option. However, after seeing literal checks like: ```cpp case LangOptions::SOB_Undefined: if (!CGF.SanOpts.ha

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-20 Thread Justin Stitt via cfe-commits
JustinStitt wrote: > I believe we can move forward by reusing > `-fsanitize=signed-integer-overflow`, which adds least complexity to Clang > and is very reasonable. I see a few problems with changing `-fsanitize=signed-integer-overflow`: 1) Clang no longer matches GCC's SIO functionality 2)

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-20 Thread Justin Stitt via cfe-commits
@@ -193,7 +193,14 @@ Available checks are: signed division overflow (``INT_MIN/-1``), but not checks for lossy implicit conversions performed before the computation (see ``-fsanitize=implicit-conversion``). Both of these two issues are - handled by ``-fsaniti

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-20 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/80089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-20 Thread Justin Stitt via cfe-commits
@@ -193,7 +193,14 @@ Available checks are: signed division overflow (``INT_MIN/-1``), but not checks for lossy implicit conversions performed before the computation (see ``-fsanitize=implicit-conversion``). Both of these two issues are - handled by ``-fsaniti

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-20 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/80089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-20 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/80089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-20 Thread Justin Stitt via cfe-commits
@@ -193,7 +193,14 @@ Available checks are: signed division overflow (``INT_MIN/-1``), but not checks for lossy implicit conversions performed before the computation (see ``-fsanitize=implicit-conversion``). Both of these two issues are - handled by ``-fsaniti

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-20 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/80089 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Sanitizer: Support -fwrapv with -fsanitize=signed-integer-overflow (PR #82432)

2024-02-20 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt created https://github.com/llvm/llvm-project/pull/82432 **Reasoning** Clang has a `signed-integer-overflow` sanitizer to catch arithmetic overflow; however, most of its instrumentation [fails to apply](https://godbolt.org/z/ee41rE8o6) when `-fwrapv` is enabled; t

[clang] Sanitizer: Support -fwrapv with -fsanitize=signed-integer-overflow (PR #82432)

2024-02-20 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/82432 >From b02b09b9eb4f9a8ac60dd077d95c67b959db3b70 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 20 Feb 2024 22:21:02 + Subject: [PATCH 1/2] support fwrapv with signed int overflow sanitizer --- cl

[clang] Sanitizer: Support -fwrapv with -fsanitize=signed-integer-overflow (PR #82432)

2024-02-20 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/82432 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] Sanitizer: Support -fwrapv with -fsanitize=signed-integer-overflow (PR #82432)

2024-02-20 Thread Justin Stitt via cfe-commits
JustinStitt wrote: > ⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️ > > You can test this locally with the following command: > View the diff from clang-format here. Fixed in [e5e92e6](https://github.com/llvm/llvm-project/pull/82432/commits/e5e92e6c07a9fbbac698a3b6bb4422f2

[clang] Sanitizer: Support -fwrapv with -fsanitize=signed-integer-overflow (PR #82432)

2024-02-20 Thread Justin Stitt via cfe-commits
@@ -723,7 +723,9 @@ class ScalarExprEmitter if (Ops.Ty->isSignedIntegerOrEnumerationType()) { switch (CGF.getLangOpts().getSignedOverflowBehavior()) { case LangOptions::SOB_Defined: -return Builder.CreateMul(Ops.LHS, Ops.RHS, "mul"); +if (!CGF.Sa

[clang] Sanitizer: Support -fwrapv with -fsanitize=signed-integer-overflow (PR #82432)

2024-02-20 Thread Justin Stitt via cfe-commits
@@ -399,6 +399,9 @@ Moved checkers Sanitizers -- +- ``-fsanitize=signed-integer-overflow`` now instruments signed arithmetic even + when ``-fwrapv`` is enabled. Previously, only division checks were enabled. JustinStitt wrote: Doesn't `-fno-sanitizer

[clang] Sanitizer: Support -fwrapv with -fsanitize=signed-integer-overflow (PR #82432)

2024-02-20 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/82432 >From b02b09b9eb4f9a8ac60dd077d95c67b959db3b70 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 20 Feb 2024 22:21:02 + Subject: [PATCH 1/3] support fwrapv with signed int overflow sanitizer --- cl

[clang] Sanitizer: Support -fwrapv with -fsanitize=signed-integer-overflow (PR #82432)

2024-02-20 Thread Justin Stitt via cfe-commits
@@ -399,6 +399,9 @@ Moved checkers Sanitizers -- +- ``-fsanitize=signed-integer-overflow`` now instruments signed arithmetic even + when ``-fwrapv`` is enabled. Previously, only division checks were enabled. JustinStitt wrote: Gotcha, resolved with

[clang] Sanitizer: Support -fwrapv with -fsanitize=signed-integer-overflow (PR #82432)

2024-02-20 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/82432 >From b02b09b9eb4f9a8ac60dd077d95c67b959db3b70 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 20 Feb 2024 22:21:02 + Subject: [PATCH 1/4] support fwrapv with signed int overflow sanitizer --- cl

[clang] Sanitizer: Support -fwrapv with -fsanitize=signed-integer-overflow (PR #82432)

2024-02-20 Thread Justin Stitt via cfe-commits
@@ -70,6 +77,7 @@ void test1(void) { // WRAPV: add i8 {{.*}}, 1 JustinStitt wrote: How's [1d9cb0a](https://github.com/llvm/llvm-project/pull/82432/commits/1d9cb0aca8985aa1636780b3ff9a863962cc2d57) look? https://github.com/llvm/llvm-project/pull/82432 __

[clang] Sanitizer: Support -fwrapv with -fsanitize=signed-integer-overflow (PR #82432)

2024-02-20 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/82432 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-09-04 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 06250aa308d1662848726528bd31395fb2ad3ea0 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 5 Mar 2024 03:14:49 + Subject: [PATCH] implement wraps attribute Signed-off-by: Justin Stitt --- cl

[clang] [Clang] Implement type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)

2024-09-04 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt created https://github.com/llvm/llvm-project/pull/107332 [Related RFC](https://discourse.llvm.org/t/rfc-support-globpattern-add-operator-to-invert-matches/80683/5?u=justinstitt) ### Summary Implement type-based filtering via [Sanitizer Special Case Lists](https

[clang] [Clang] Implement type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)

2024-09-04 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/107332 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-08 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/100272 >From 154d3505ab13275086b3dffed67bcdcac52f79a3 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 23 Jul 2024 20:21:49 + Subject: [PATCH 1/8] implement idiom exclusions Add flag `-fno-sanitize-overf

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-08 Thread Justin Stitt via cfe-commits
@@ -4248,6 +4248,22 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val; } + if (auto *A = Args.getLastArg(OPT_fsanitize_overflow_pattern_exclusion_EQ)) { +for (int i

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-08 Thread Justin Stitt via cfe-commits
@@ -0,0 +1,83 @@ +// Check for potential false positives from patterns that _almost_ match classic overflow-dependent or overflow-prone code patterns JustinStitt wrote: resolved in 4b3efbb41ff86eeff15671b1d876e1ef6a58a536 https://github.com/llvm/llvm-project/pu

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-08 Thread Justin Stitt via cfe-commits
@@ -293,6 +293,40 @@ To silence reports from unsigned integer overflow, you can set ``-fsanitize-recover=unsigned-integer-overflow``, is particularly useful for providing fuzzing signal without blowing up logs. +Disabling instrumentation for common overflow patterns +

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-08 Thread Justin Stitt via cfe-commits
@@ -555,6 +570,11 @@ class LangOptions : public LangOptionsBase { /// The default stream kind used for HIP kernel launching. GPUDefaultStreamKind GPUDefaultStream; + /// Which overflow patterns should be excluded from sanitizer instrumentation + int OverflowPatternExclus

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-08 Thread Justin Stitt via cfe-commits
@@ -293,6 +293,40 @@ To silence reports from unsigned integer overflow, you can set ``-fsanitize-recover=unsigned-integer-overflow``, is particularly useful for providing fuzzing signal without blowing up logs. +Disabling instrumentation for common overflow patterns +

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-08 Thread Justin Stitt via cfe-commits
@@ -2877,6 +2888,17 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, } else if (type->isIntegerType()) { QualType promotedType; bool canPerformLossyDemotionCheck = false; + +// Is the pattern "while (i--)" and overflow exclusion? +

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-08 Thread Justin Stitt via cfe-commits
JustinStitt wrote: @bwendling I tried to address all your feedback points with 4b3efbb41ff86eeff15671b1d876e1ef6a58a536 Let me know how that looks 👍 https://github.com/llvm/llvm-project/pull/100272 ___ cfe-commits mailing list cfe-commits@lists.llvm.

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-12 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/100272 >From 154d3505ab13275086b3dffed67bcdcac52f79a3 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 23 Jul 2024 20:21:49 + Subject: [PATCH 1/9] implement idiom exclusions Add flag `-fno-sanitize-overf

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-12 Thread Justin Stitt via cfe-commits
@@ -4759,6 +4759,55 @@ ParenListExpr *ParenListExpr::CreateEmpty(const ASTContext &Ctx, return new (Mem) ParenListExpr(EmptyShell(), NumExprs); } +namespace { JustinStitt wrote: resolved by https://github.com/llvm/llvm-project/pull/100272/commits/2e3d4795

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-12 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/100272 >From 154d3505ab13275086b3dffed67bcdcac52f79a3 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 23 Jul 2024 20:21:49 + Subject: [PATCH 01/10] implement idiom exclusions Add flag `-fno-sanitize-ove

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-12 Thread Justin Stitt via cfe-commits
@@ -195,13 +196,23 @@ static bool CanElideOverflowCheck(const ASTContext &Ctx, const BinOpInfo &Op) { if (!Op.mayHaveIntegerOverflow()) return true; + const UnaryOperator *UO = dyn_cast(Op.E); + + if (UO && UO->getOpcode() == UO_Minus && UO->isIntegerConstantExpr(Ctx)

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-12 Thread Justin Stitt via cfe-commits
@@ -3860,6 +3860,7 @@ class CStyleCastExpr final class BinaryOperator : public Expr { enum { LHS, RHS, END_EXPR }; Stmt *SubExprs[END_EXPR]; + bool ExcludedOverflowPattern = false; JustinStitt wrote: Ok, I think I found a spare bit in `BinaryOperatorBits`

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-13 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/100272 >From 154d3505ab13275086b3dffed67bcdcac52f79a3 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 23 Jul 2024 20:21:49 + Subject: [PATCH 01/11] implement idiom exclusions Add flag `-fno-sanitize-ove

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-13 Thread Justin Stitt via cfe-commits
@@ -649,6 +649,8 @@ class alignas(void *) Stmt { /// It is 0 otherwise. LLVM_PREFERRED_TYPE(bool) unsigned HasFPFeatures : 1; +LLVM_PREFERRED_TYPE(bool) JustinStitt wrote: Good idea, see https://github.com/llvm/llvm-project/pull/100272/commits

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-14 Thread Justin Stitt via cfe-commits
JustinStitt wrote: > I think serialization is missing for the new bit on BinaryOperator. How do I add this? > I'm not sure why we're storing it in the first place, though; it's queried in > exactly one place, so there isn't really any benefit to precomputing it. It's queried when we check

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-08-14 Thread Justin Stitt via cfe-commits
JustinStitt wrote: A good example of a Linux kernel contributor running into an overflow that should really have its type marked as wrapping : https://lore.kernel.org/all/zrzk8hiladaj+...@gmail.com/ They could use this feature to mark the suspected field `percpu_ref->percpu_ref_data->count` a

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-14 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/100272 >From 154d3505ab13275086b3dffed67bcdcac52f79a3 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 23 Jul 2024 20:21:49 + Subject: [PATCH 01/12] implement idiom exclusions Add flag `-fno-sanitize-ove

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-14 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/100272 >From 154d3505ab13275086b3dffed67bcdcac52f79a3 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 23 Jul 2024 20:21:49 + Subject: [PATCH 01/13] implement idiom exclusions Add flag `-fno-sanitize-ove

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-14 Thread Justin Stitt via cfe-commits
JustinStitt wrote: @bwendling we want to use `-triple` not `-target`, can you cherry pick 3ef83ad323dfbe99028c774c3716706671ba7b8b I also reordered the tests and added labels so the tests are actually checking the right stuff -- debugging was really difficult but will be easier now. https://g

[clang] [Clang] Overflow Pattern Exclusions (PR #100272)

2024-08-15 Thread Justin Stitt via cfe-commits
JustinStitt wrote: > Sorry, but I am not sure why this didn't show up my > https://github.com/llvm/llvm-project/pulls?q=is%3Aopen+is%3Apr+review-requested%3A%40me+sort%3Aupdated-desc > I wanted to review this patch. Did I do something wrong with my PR or fork settings? I am not sure why you w

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-09 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 0fa8f07c722f9d7f80a90824f961ae6e9c5bdef7 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 5 Mar 2024 03:14:49 + Subject: [PATCH 1/4] implement wraps attribute Signed-off-by: Justin Stitt ---

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-09 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 10ee32826fc2acb6bd993c88bdb7142360b6f263 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 5 Mar 2024 03:14:49 + Subject: [PATCH 1/3] implement wraps attribute Signed-off-by: Justin Stitt ---

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-09 Thread Justin Stitt via cfe-commits
JustinStitt wrote: Hi, I've made some changes and am looking for some more review on this PR: * This attribute no longer supports C++ as there are other solutions for that language [1] that allow for the same fine-grained wrapping control without changing syntax patterns. * Add bypass for impl

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-09 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/86618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-09 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/86618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-09 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/86618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-09 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 10ee32826fc2acb6bd993c88bdb7142360b6f263 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 5 Mar 2024 03:14:49 + Subject: [PATCH 1/4] implement wraps attribute Signed-off-by: Justin Stitt ---

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-10 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 10ee32826fc2acb6bd993c88bdb7142360b6f263 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 5 Mar 2024 03:14:49 + Subject: [PATCH 1/7] implement wraps attribute Signed-off-by: Justin Stitt ---

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-10 Thread Justin Stitt via cfe-commits
@@ -4077,6 +4077,9 @@ class BinaryOperator : public Expr { static unsigned sizeOfTrailingObjects(bool HasFPFeatures) { return HasFPFeatures * sizeof(FPOptionsOverride); } + + /// Do one of the subexpressions have the wraps attribute? + bool oneOfWraps(const ASTContext

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-10 Thread Justin Stitt via cfe-commits
@@ -4506,3 +4506,9 @@ def CodeAlign: StmtAttr { static constexpr int MaximumAlignment = 4096; }]; } + +def Wraps : DeclOrTypeAttr { + let Spellings = [GNU<"wraps">]; JustinStitt wrote: Right, I had that originally. I shouldn't have changed it :) Anyway

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-10 Thread Justin Stitt via cfe-commits
@@ -4506,3 +4506,9 @@ def CodeAlign: StmtAttr { static constexpr int MaximumAlignment = 4096; }]; } + +def Wraps : DeclOrTypeAttr { + let Spellings = [GNU<"wraps">]; + let Subjects = SubjectList<[Var, TypedefName, Field]>; + let Documentation = [WrapsDocs]; +}

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-10 Thread Justin Stitt via cfe-commits
@@ -2237,6 +2237,21 @@ bool BinaryOperator::isNullPointerArithmeticExtension(ASTContext &Ctx, return true; } +bool BinaryOperator::oneOfWraps(const ASTContext &Ctx) const { + llvm::SmallVector Both = {getLHS(), getRHS()}; JustinStitt wrote: I had trouble

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-10 Thread Justin Stitt via cfe-commits
@@ -147,6 +147,15 @@ struct BinOpInfo { return UnOp->getSubExpr()->getType()->isFixedPointType(); return false; } + + /// Does the BinaryOperator have the wraps attribute? + /// If so, we can ellide overflow sanitizer checks. + bool oneOfWraps() const { +cons

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-10 Thread Justin Stitt via cfe-commits
@@ -6954,6 +6954,23 @@ static void HandleBTFTypeTagAttribute(QualType &Type, const ParsedAttr &Attr, ::new (Ctx) BTFTypeTagAttr(Ctx, Attr, BTFTypeTag), Type); } +static void handleWrapsAttr(QualType &Type, const ParsedAttr &Attr, +TypeProcess

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-10 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 10ee32826fc2acb6bd993c88bdb7142360b6f263 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 5 Mar 2024 03:14:49 + Subject: [PATCH 1/8] implement wraps attribute Signed-off-by: Justin Stitt ---

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-10 Thread Justin Stitt via cfe-commits
JustinStitt wrote: The most recent commits have massively simplified checking for the wrapping attributes. FWIW, the tests I am running are: ✅ `$ llvm-lit clang/test/CodeGen/integer-overflow.c -v` ✅ `$ llvm-lit clang/test/CodeGen/unsigned-overflow.c -v` ✅ `$ llvm-lit clang/test/Sema/attr-wraps.

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-10 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 10ee32826fc2acb6bd993c88bdb7142360b6f263 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 5 Mar 2024 03:14:49 + Subject: [PATCH 1/9] implement wraps attribute Signed-off-by: Justin Stitt ---

[clang] [Clang] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-04-11 Thread Justin Stitt via cfe-commits
JustinStitt wrote: > > Forbidding usage in C++ probably avoids the worst of the canonical-type > > issues, but there's still some potential for weird results. Particularly > > with type merging; for example, if you write `a ? (wrap_int)x : 1`, is the > > result a wrapping type? > > I had a si

  1   2   3   >