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

2024-10-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] Implement labelled type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)

2024-09-25 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] Implement labelled type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)

2024-09-25 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] Implement labelled type filtering for overflow/truncation sanitizers w/ SSCLs (PR #107332)

2024-09-25 Thread Justin Stitt via cfe-commits
@@ -817,6 +817,37 @@ ASTContext::getCanonicalTemplateTemplateParmDecl( return CanonTTP; } +/// Check if a type can have its sanitizer instrumentation elided. +/// Determine this by its presence in a SCL alongside its specified categories. +/// For example: +/// ignorelist.tx

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

2024-09-25 Thread Justin Stitt via cfe-commits
@@ -48,6 +49,63 @@ Example $ clang -fsanitize=address -fsanitize-ignorelist=ignorelist.txt foo.c ; ./a.out # No error report here. +Usage with UndefinedBehaviorSanitizer += + +The arithmetic overflow sanitizers ``unsigned-integer-overfl

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

2024-09-25 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/107332 >From 548efc6414503f8ae005f1bd9ef2c7f15ad16241 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 3 Sep 2024 18:28:53 -0700 Subject: [PATCH 1/5] hook up sscl categories with overflow/truncation sanitize

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

2024-09-25 Thread Justin Stitt via cfe-commits
@@ -1,7 +1,28 @@ +// Verify ubsan doesn't emit checks for ignorelisted types +// RUN: echo "[{unsigned-integer-overflow,signed-integer-overflow}]" > %t-int.ignorelist +// RUN: echo "type:int" >> %t-int.ignorelist +// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=signed-int

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

2024-09-25 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/107332 >From 548efc6414503f8ae005f1bd9ef2c7f15ad16241 Mon Sep 17 00:00:00 2001 From: Justin Stitt Date: Tue, 3 Sep 2024 18:28:53 -0700 Subject: [PATCH 1/4] hook up sscl categories with overflow/truncation sanitize

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

2024-09-25 Thread Justin Stitt via cfe-commits
@@ -817,6 +817,37 @@ ASTContext::getCanonicalTemplateTemplateParmDecl( return CanonTTP; } +/// Check if a type can have its sanitizer instrumentation elided. +/// Determine this by its presence in a SCL alongside its specified categories. +/// For example: +/// ignorelist.tx

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

2024-09-25 Thread Justin Stitt via cfe-commits
@@ -48,6 +49,63 @@ Example $ clang -fsanitize=address -fsanitize-ignorelist=ignorelist.txt foo.c ; ./a.out # No error report here. +Usage with UndefinedBehaviorSanitizer += + +The arithmetic overflow sanitizers ``unsigned-integer-overfl

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

2024-09-16 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] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-09-12 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 6fb8f6841795c44471a326a9d096a226cea9f4a8 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 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] 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] 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] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-09-03 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From e73df4dedbb2e2be8b72ca3a8e847d5cbca29bed 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] Overflow Pattern Exclusion - rename some patterns, enhance docs (PR #105709)

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

[clang] [Clang] Overflow Pattern Exclusion - rename some patterns, enhance docs (PR #105709)

2024-08-25 Thread Justin Stitt via cfe-commits
@@ -4806,6 +4806,34 @@ getOverflowPatternBinOp(const BinaryOperator *E) { return {}; } +/// Compute and set the OverflowPatternExclusion bit based on whether the JustinStitt wrote: I wanted to avoid calling `getOverflowPatternBinOp()` as it is more expensiv

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

2024-08-22 Thread Justin Stitt via cfe-commits
JustinStitt wrote: > Iā€™m a little concerned about not allowing the attribute in C++ - the > existence of other options in C++ does not mean they are an option (due to > various and sundry restrictions of C++ version upgrades different projects > have), but also you trivially end up in cases wh

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

2024-08-22 Thread Justin Stitt via cfe-commits
JustinStitt wrote: > Regarding there not being a `no-wraps` attribute. What happens with code like > this? Is the attribute lost / casted away during the addition? > > ``` > wrapping_int a = INT_MAX; > a = (int) a + 1; > ``` Good question, the attribute is cast away (intentionally so). Additio

[clang] [Clang] Overflow Pattern Exclusion - rename some patterns, enhance docs (PR #105709)

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

[clang] [Clang] Overflow Pattern Exclusion - rename some patterns, enhance docs (PR #105709)

2024-08-22 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt created https://github.com/llvm/llvm-project/pull/105709 >From @vitalybuka's review on https://github.com/llvm/llvm-project/pull/104889: - [x] remove unused variable in tests - [x] rename `post-decr-while` --> `unsigned-post-decr-while` - [x] split `add-overflow-te

[clang] [Clang] Overflow Pattern Exclusion - rename some patterns, enhance docs (PR #105709)

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

[clang] [Clang] Re-land Overflow Pattern Exclusions (PR #104889)

2024-08-21 Thread Justin Stitt via cfe-commits
@@ -293,6 +293,48 @@ 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] Re-land Overflow Pattern Exclusions (PR #104889)

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

[clang] [Clang] Re-land Overflow Pattern Exclusions (PR #104889)

2024-08-21 Thread Justin Stitt via cfe-commits
@@ -0,0 +1,63 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fsanitize-undefined-ignore-overflow-pattern=all %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsanitize

[clang] [Clang] Re-land Overflow Pattern Exclusions (PR #104889)

2024-08-21 Thread Justin Stitt via cfe-commits
@@ -293,6 +293,48 @@ 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] Re-land Overflow Pattern Exclusions (PR #104889)

2024-08-21 Thread Justin Stitt via cfe-commits
@@ -293,6 +293,48 @@ 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] Re-land Overflow Pattern Exclusions (PR #104889)

2024-08-21 Thread Justin Stitt via cfe-commits
@@ -293,6 +293,48 @@ 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] Re-land Overflow Pattern Exclusions (PR #104889)

2024-08-21 Thread Justin Stitt via cfe-commits
@@ -438,6 +438,36 @@ Moved checkers Sanitizers -- +- Added the ``-fsanitize-undefined-ignore-overflow-pattern`` flag which can be + used to disable specific overflow-dependent code patterns. The supported + patterns are: ``add-overflow-test``, ``negated-unsigned-cons

[clang] [Clang] Re-land Overflow Pattern Exclusions (PR #104889)

2024-08-21 Thread Justin Stitt via cfe-commits
@@ -293,6 +293,48 @@ 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] Re-land Overflow Pattern Exclusions (PR #104889)

2024-08-21 Thread Justin Stitt via cfe-commits
@@ -293,6 +293,48 @@ 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] Re-land Overflow Pattern Exclusions (PR #104889)

2024-08-21 Thread Justin Stitt via cfe-commits
@@ -293,6 +293,48 @@ 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] Re-land Overflow Pattern Exclusions (PR #104889)

2024-08-21 Thread Justin Stitt via cfe-commits
@@ -438,6 +438,36 @@ Moved checkers Sanitizers -- +- Added the ``-fsanitize-undefined-ignore-overflow-pattern`` flag which can be + used to disable specific overflow-dependent code patterns. The supported + patterns are: ``add-overflow-test``, ``negated-unsigned-cons

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

2024-08-21 Thread Justin Stitt via cfe-commits
JustinStitt wrote: @nico > The test added here was tweaked a bit and then deleted in > [07a8cba](https://github.com/llvm/llvm-project/commit/07a8cbaf8dc16bebf6e875173d20299d9cc47cc5) > > What gives? > > Instead of deleting tests, we should revert the PR that adds them and then > reland the P

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

2024-08-20 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 97de8998e2efd2362f9119c3ceea0938347278f4 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] Re-land Overflow Pattern Exclusions (PR #104889)

2024-08-20 Thread Justin Stitt via cfe-commits
@@ -119,6 +119,10 @@ static SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A, static int parseCoverageFeatures(const Driver &D, const llvm::opt::Arg *A, bool DiagnoseErrors); +static int parseOverflowPatternExclusionValues

[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] 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-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
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] 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
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] 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-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-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-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
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
@@ -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 1/9] implement idiom exclusions Add flag `-fno-sanitize-overf

[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-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
@@ -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
@@ -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
@@ -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
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-06 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt edited https://github.com/llvm/llvm-project/pull/100272 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

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

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

2024-08-01 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/7] implement idiom exclusions Add flag `-fno-sanitize-overf

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

2024-08-01 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/6] implement idiom exclusions Add flag `-fno-sanitize-overf

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

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

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

2024-07-25 Thread Justin Stitt via cfe-commits
JustinStitt wrote: @kees @vitalybuka 3ef8d3c implements `-fsanitize=pattern-exclusion=`. It supports the following values: `all` - turn all supported pattern exclusions ON `none` - turn them all off (has precedence over others, I will add a warning soon if users try to use this with "all" or an

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

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

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

2024-07-23 Thread Justin Stitt via cfe-commits
JustinStitt wrote: > > Right, unsigned overflow is well-defined. This isn't about the semantics of > > "undefined-ness". We want the unsigned sanitizer ON but some of the things > > it reports are noisy -- that's what this PR is about > > "Idiom" seems to vague to me. kernel has own opinion on

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

2024-07-23 Thread Justin Stitt via cfe-commits
JustinStitt wrote: > I assume you are going to change fronted to avoid compiler abusing these UBs? Well, like you said, none of this is really undefined behavior and isn't getting optimized away. The exception being `if ( a + b < a )` which can definitely have some unexpected results with high

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

2024-07-23 Thread Justin Stitt via cfe-commits
JustinStitt wrote: > Actually stuff like unsigned overflows are not UB. > > Maybe instead of `-fno-sanitize-overflow-idioms` we convert into > `unsigned-integer-overflow` into ` check group` so user can > -fno-sanitize=-unsigned-integer-overflow Right, unsigned overflow is well-defined. This

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

2024-07-23 Thread Justin Stitt via cfe-commits
@@ -312,6 +312,38 @@ This attribute may not be supported by other compilers, so consider using it together with ``#if defined(__clang__)``. +Disabling instrumentation of common overflow idioms += + +There are certain overflow

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

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

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

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

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

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

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

2024-07-23 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt created https://github.com/llvm/llvm-project/pull/100272 ## Summary Introduce `-fno-sanitize-overflow-idioms` which disables sanitizer instrumentation for common overflow-dependent code idioms. ## Background For a wide selection of projects, proper overflow sanit

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

2024-06-27 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 58df542edf7d1a9f65fc804f23a2b209a49f5c5f 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] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-06-27 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From af16c497b1323983d55f92d6cfb9ab2c99a21639 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] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-06-13 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 6152bd26438a32711589424f705281291475d548 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] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-05-29 Thread Justin Stitt via cfe-commits
JustinStitt wrote: Hi, gentle ping. @efriedma-quic, do you still have concerns with the current implementation (as an attribute attached to typedefs)? After limiting `wraps` to C and adding warnings to let users know when the attribute may be stripped, I think it's in a good spot. ```c type

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

2024-05-24 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 1df2f520f6a8ab0e45b80f7a1d680d34f8ab37c9 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] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-05-20 Thread Justin Stitt via cfe-commits
JustinStitt wrote: FYI: I've rebased and handled merge conflicts (mainly in ReleaseNotes.rst). This, of course, required a force push. https://github.com/llvm/llvm-project/pull/86618 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://list

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

2024-05-20 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 1df2f520f6a8ab0e45b80f7a1d680d34f8ab37c9 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] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-05-17 Thread Justin Stitt via cfe-commits
https://github.com/JustinStitt updated https://github.com/llvm/llvm-project/pull/86618 >From 238e3242d12473a072d0d2adc51f18fbeaa927a8 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] Add wraps attribute (for granular integer overflow handling) (PR #86618)

2024-05-02 Thread Justin Stitt via cfe-commits
JustinStitt wrote: Ping! Any chance we could land this soon? I know @efriedma-quic has some different ideas for the implementation of this feature. However, adding a new type is most likely overkill for what is needed out of `wraps`. I think the implementation/documentation and testing has la

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

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

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

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

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

2024-04-26 Thread Justin Stitt via cfe-commits
JustinStitt wrote: In an effort to appease the build bot, I am adding a `-W` flag to turn of `warn_wraps_attr_var_decl_type_not_integer` which yells at users for trying to add `__attribute__((wraps))` to things that don't really wrap in the traditional sense. https://github.com/llvm/llvm-proj

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

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

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

2024-04-25 Thread Justin Stitt via cfe-commits
JustinStitt wrote: @efriedma-quic: > Attributes mostly do modify the type. The few that don't, like "aligned" and > "may_alias", are a constant source of problems because they get accidentally > stripped off. (I don't have any personal experience with "noderef".) So do you believe the current

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

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

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

2024-04-25 Thread Justin Stitt via cfe-commits
JustinStitt wrote: @efriedma-quic: > This is declaring, then defining, a global variable; sorry if that wasn't > clear. Gotcha. > Probably should be an error? It'll be confusing no matter what we do. I think it's OK for a global variable to be declared then later defined with additional att

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

2024-04-24 Thread Justin Stitt via cfe-commits
JustinStitt wrote: > > > If you declare a variable as both wrapping and non-wrapping, is it > > > wrapping? > > > > > > I am not sure how to do this. I am sure that with the magic of C anything > > is possible but I can't conceive a way to have a variable both have the > > attribute and not

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

2024-04-24 Thread Justin Stitt via cfe-commits
JustinStitt wrote: Hi @efriedma-quic, thanks for dumping all these cases! I will respond to each one individually. I understand you think adding a type would be better so I am exploring that option (I am thinking something similar to [extended vectors](https://clang.llvm.org/docs/LanguageExte

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

2024-04-22 Thread Justin Stitt via cfe-commits
JustinStitt wrote: @efriedma-quic said: > I'm still not happy with the AST representation here. The current > representation is likely to cause unpredictable results in edge cases, and > compatibility constraints mean whatever result the current version happens to > produce for those cases is

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

2024-04-22 Thread Justin Stitt via cfe-commits
@@ -0,0 +1,9 @@ +// RUN: %clang_cc1 %s -verify -fsyntax-only -triple x86_64-pc-linux-gnu +// expected-no-diagnostics +typedef int __attribute__((wraps)) wrapping_int; + +void foo(void) { + const wrapping_int A = 1; + int D = 2147483647 + A; JustinStitt wrote: O

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

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

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

2024-04-22 Thread Justin Stitt via cfe-commits
@@ -4249,6 +4270,10 @@ Value *ScalarExprEmitter::EmitFixedPointBinOp(const BinOpInfo &op) { Value *ScalarExprEmitter::EmitSub(const BinOpInfo &op) { // The LHS is always a pointer if either side is. if (!op.LHS->getType()->isPointerTy()) { +if ((op.Ty->isSignedIntegerO

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

2024-04-22 Thread Justin Stitt via cfe-commits
@@ -4455,6 +4455,14 @@ void Sema::AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E) { D->addAttr(::new (Context) AlignValueAttr(Context, CI, E)); } +static void handleWrapsAttr(Sema &S, Decl *D, const ParsedAttr &AL) { + S.AddWrapsAttr(D, AL); +} + +void S

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

2024-04-22 Thread Justin Stitt via cfe-commits
@@ -4093,6 +4109,11 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &op) { op.RHS->getType()->isPointerTy()) return emitPointerArithmetic(CGF, op, CodeGenFunction::NotSubtraction); + if ((op.Ty->isSignedIntegerOrEnumerationType() || JustinStitt

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

2024-04-22 Thread Justin Stitt via cfe-commits
@@ -2831,6 +2840,9 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, } else if (type->isIntegerType()) { QualType promotedType; bool canPerformLossyDemotionCheck = false; +BinOpInfo Ops = (createBinOpInfoFromIncDec(

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

2024-04-22 Thread Justin Stitt via cfe-commits
@@ -156,6 +156,10 @@ struct BinOpInfo { } return false; } + + /// Does the BinaryOperator have the wraps attribute? + /// If so, we can ellide overflow sanitizer checks. JustinStitt wrote: fixed in [872e5d6](https://github.com/llvm/llvm-project/pu

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

2024-04-22 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? JustinStitt wrote:

  1   2   >