Re: [PATCH 03/10] tree-object-size: Use tree instead of HOST_WIDE_INT

2021-11-19 Thread Siddhesh Poyarekar
On 11/19/21 22:36, Jakub Jelinek wrote: On Wed, Nov 10, 2021 at 12:31:29AM +0530, Siddhesh Poyarekar wrote: * tree-object-size.h (compute_builtin_object_size): Return tree instead of HOST_WIDE_INT. * builtins.c (fold_builtin_object_size): Adjust. * gimple-fold.c

Re: [PATCH 03/10] tree-object-size: Use tree instead of HOST_WIDE_INT

2021-11-22 Thread Siddhesh Poyarekar
On 11/20/21 00:31, Siddhesh Poyarekar wrote: This doesn't match what the code did and I'm surprised if it works at all. TREE_OPERAND (pt_var, 1), while it is an INTEGER_CST or POLY_INT_CST, has in its type encoded the type for aliasing, so the type is some pointer type.  Performing

Re: [PATCH 03/10] tree-object-size: Use tree instead of HOST_WIDE_INT

2021-11-22 Thread Siddhesh Poyarekar
On 11/22/21 16:01, Jakub Jelinek wrote: On Mon, Nov 22, 2021 at 03:41:57PM +0530, Siddhesh Poyarekar wrote: So I played around a bit with this. Basically: char buf[8]; __SIZE_TYPE__ test (void) { char *p = &buf[0x9004]; return __builtin_object_size (p + 2, 0); } when built

Re: [PATCH 03/10] tree-object-size: Use tree instead of HOST_WIDE_INT

2021-11-22 Thread Siddhesh Poyarekar
On 11/22/21 17:30, Siddhesh Poyarekar wrote: So I've got patch 10/10, which handles dynamic (and consequently negative) offsets.  It basically computes a "whole size", which then gives the extent to which a negative offset is valid, making the estimates a bit more precise.  I d

Re: [PATCH 03/10] tree-object-size: Use tree instead of HOST_WIDE_INT

2021-11-23 Thread Siddhesh Poyarekar
On 11/23/21 17:28, Jakub Jelinek wrote: On Mon, Nov 22, 2021 at 01:32:22PM +0100, Jakub Jelinek via Gcc-patches wrote: On Mon, Nov 22, 2021 at 06:01:08PM +0530, Siddhesh Poyarekar wrote: On 11/22/21 17:30, Siddhesh Poyarekar wrote: So I've got patch 10/10, which handles dynamic

Re: [PATCH 04/10] tree-object-size: Single pass dependency loop resolution

2021-11-23 Thread Siddhesh Poyarekar
On 11/23/21 17:37, Jakub Jelinek wrote: On Wed, Nov 10, 2021 at 12:31:30AM +0530, Siddhesh Poyarekar wrote: Use SSA names as placeholders self-referencing variables to generate expressions for object sizes and then reduce those size expressions to constants instead of repeatedly walking through

Re: [PATCH 05/10] __builtin_dynamic_object_size: Recognize builtin

2021-11-23 Thread Siddhesh Poyarekar
On 11/23/21 18:11, Jakub Jelinek wrote: On Wed, Nov 10, 2021 at 12:31:31AM +0530, Siddhesh Poyarekar wrote: Recognize the __builtin_dynamic_object_size builtin and add paths in the object size path to deal with it, but treat it like __builtin_object_size for now. Also add tests to provide the

Re: [PATCH 06/10] tree-object-size: Support dynamic sizes in conditions

2021-11-23 Thread Siddhesh Poyarekar
On 11/23/21 20:42, Jakub Jelinek wrote: On Wed, Nov 10, 2021 at 12:31:32AM +0530, Siddhesh Poyarekar wrote: (object_sizes_execute): Don't insert min/max for dynamic sizes. I'm worried about this. I'd say what we might want to do is in the early pass for __bdos compute

Re: [PATCH 06/10] tree-object-size: Support dynamic sizes in conditions

2021-11-23 Thread Siddhesh Poyarekar
On 11/23/21 21:06, Siddhesh Poyarekar wrote: On 11/23/21 20:42, Jakub Jelinek wrote: On Wed, Nov 10, 2021 at 12:31:32AM +0530, Siddhesh Poyarekar wrote: (object_sizes_execute): Don't insert min/max for dynamic sizes. I'm worried about this. I'd say what we might want

Re: [PATCH 06/10] tree-object-size: Support dynamic sizes in conditions

2021-11-23 Thread Siddhesh Poyarekar
On 11/23/21 21:22, Jakub Jelinek wrote: Evaluating __bdos in both passes is undesirable, certainly for the same SSA_NAME, but even for different SSA_NAMEs, if everything is done in a single pass it can easily share temporaries (object sizes for SSA_NAMEs it uses), while if some __bdos is evaluate

[PATCH v3 0/8] __builtin_dynamic_object_size

2021-11-25 Thread Siddhesh Poyarekar
fset support (10/10 in v2) into 3/8 and support static object sizes - Merge dynamic offset (10/10 in v2) support into 8/8 Siddhesh Poyarekar (8): tree-object-size: Replace magic numbers with enums tree-object-size: Abstract object_sizes array tree-object-size: Save sizes as t

[PATCH v3 1/8] tree-object-size: Replace magic numbers with enums

2021-11-25 Thread Siddhesh Poyarekar
, collect_object_sizes_for, init_object_sizes, fini_object_sizes, object_sizes_execute): Replace magic numbers with enums. Signed-off-by: Siddhesh Poyarekar --- Changes from v2: - Incorporated review suggestions. gcc/tree-object-size.c | 59

[PATCH v3 2/8] tree-object-size: Abstract object_sizes array

2021-11-25 Thread Siddhesh Poyarekar
, fini_object_sizes): Adjust. Signed-off-by: Siddhesh Poyarekar --- Changes from v2: - Incorporated review suggestions. gcc/tree-object-size.c | 177 +++-- 1 file changed, 98 insertions(+), 79 deletions(-) diff --git a/gcc/tree-object-size.c b/gcc/tree-object

[PATCH v3 3/8] tree-object-size: Save sizes as trees and support negative offsets

2021-11-25 Thread Siddhesh Poyarekar
. * gcc.dg/builtin-object-size-4.c (test8): New test. (main): Call it. * gcc.dg/builtin-object-size-5.c (test5, test6, test7): New tests. Signed-off-by: Siddhesh Poyarekar --- Changes from v2: - Incorporated review suggestions. - Added support for negative offsets. gcc

[PATCH v3 4/8] __builtin_dynamic_object_size: Recognize builtin

2021-11-25 Thread Siddhesh Poyarekar
-dynamic-object-size-9.c: Likewise. * gcc.dg/builtin-object-size-16.c: Adjust to allow inclusion from builtin-dynamic-object-size-16.c. * gcc.dg/builtin-object-size-17.c: Likewise. Signed-off-by: Siddhesh Poyarekar --- Changes from v2: - Incorporated review suggestions. gcc

[PATCH v3 6/8] tree-object-size: Handle function parameters

2021-11-25 Thread Siddhesh Poyarekar
/builtin-dynamic-object-size-0.c (test_parmsz_simple): New function. (main): Call it. Signed-off-by: Siddhesh Poyarekar --- .../gcc.dg/builtin-dynamic-object-size-0.c| 11 gcc/tree-object-size.c| 50 ++- 2 files changed, 60 insertions

[PATCH v3 5/8] tree-object-size: Support dynamic sizes in conditions

2021-11-25 Thread Siddhesh Poyarekar
. * gcc.dg/builtin-object-size-3.c [__builtin_object_size]: Likewise. * gcc.dg/builtin-object-size-4.c [__builtin_object_size]: Likewise. * gcc.dg/builtin-object-size-5.c [__builtin_object_size]: Likewise. Signed-off-by: Siddhesh Poyarekar --- Changes from

[PATCH v3 7/8] tree-object-size: Handle GIMPLE_CALL

2021-11-25 Thread Siddhesh Poyarekar
) [__builtin_object_size]: Likewise. * gcc.dg/builtin-object-size-3.c (test1) [__builtin_object_size]: Likewise. * gcc.dg/builtin-object-size-4.c (test1) [__builtin_object_size]: Likewise. Signed-off-by: Siddhesh Poyarekar --- .../gcc.dg/builtin-dynamic-object

[PATCH v3 8/8] tree-object-size: Dynamic sizes for ADDR_EXPR

2021-11-25 Thread Siddhesh Poyarekar
) [__builtin_object_size]: Likewise. Signed-off-by: Siddhesh Poyarekar --- .../gcc.dg/builtin-dynamic-object-size-0.c| 158 ++ gcc/testsuite/gcc.dg/builtin-object-size-1.c | 30 +++- gcc/testsuite/gcc.dg/builtin-object-size-2.c | 43 - gcc/testsuite/gcc.dg/builtin-object

Re: [PATCH v3 0/8] __builtin_dynamic_object_size

2021-11-25 Thread Siddhesh Poyarekar
On 11/26/21 10:58, Siddhesh Poyarekar wrote: sure it works) and saw no issues in any of those builds. I did some rudimentary analysis of the generated binaries using fortify-metrics[1] to confirm that there was a difference in coverage between the two fortification levels. Here is a summary of

Re: [PATCH v3 1/8] tree-object-size: Replace magic numbers with enums

2021-11-26 Thread Siddhesh Poyarekar
On 11/26/21 22:16, Jakub Jelinek wrote: On Fri, Nov 26, 2021 at 10:58:44AM +0530, Siddhesh Poyarekar wrote: A simple cleanup to allow inserting dynamic size code more easily. gcc/ChangeLog: * tree-object-size.c: New enum. (object_sizes, computed, addr_object_size

Re: [PATCH v3 3/8] tree-object-size: Save sizes as trees and support negative offsets

2021-11-26 Thread Siddhesh Poyarekar
On 11/26/21 22:26, Jakub Jelinek wrote: On Fri, Nov 26, 2021 at 10:58:46AM +0530, Siddhesh Poyarekar wrote: Transform tree-object-size to operate on tree objects instead of host wide integers. This makes it easier to extend to dynamic expressions for object sizes. The

Re: [PATCH v3 3/8] tree-object-size: Save sizes as trees and support negative offsets

2021-11-26 Thread Siddhesh Poyarekar
On 11/26/21 23:34, Jakub Jelinek wrote: On Fri, Nov 26, 2021 at 11:29:41PM +0530, Siddhesh Poyarekar wrote: The trees in object_sizes are each a TREE_VEC with the first element being the bytes from the pointer to the end of the object and the second, the size of the whole object. This allows

[PATCH] tree-optimization/103456 - Record only successes from object_sizes_set

2021-11-30 Thread Siddhesh Poyarekar
authored-by: Martin Liška Signed-off-by: Siddhesh Poyarekar --- gcc/testsuite/gcc.dg/pr103456.c | 21 + gcc/tree-object-size.c | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr103456.c diff --git a/gcc/testsuite/gcc.dg

[COMMITTED] tree-optimization/103456 - Record only successes from object_sizes_set

2021-12-01 Thread Siddhesh Poyarekar
456 * tree-object-size.c (merge_object_sizes): Update osi->changed only if object_sizes_set succeeded. gcc/testsuite/ChangeLog: PR tree-optimization/103456 * gcc.dg/ubsan/pr103456.c: New test. Co-authored-by: Martin Liška Signed-off-by: Siddhesh Poyarekar --- gcc/tes

[PATCH v4 4/6] tree-object-size: Handle function parameters

2021-12-01 Thread Siddhesh Poyarekar
/builtin-dynamic-object-size-0.c (test_parmsz_simple): New function. (main): Call it. Signed-off-by: Siddhesh Poyarekar --- .../gcc.dg/builtin-dynamic-object-size-0.c| 11 gcc/tree-object-size.c| 50 ++- 2 files changed, 60 insertions

[PATCH v4 0/6] __builtin_dynamic_object_size

2021-12-01 Thread Siddhesh Poyarekar
ges to individual patches have been mentioned in the patches themselves. - Dropped patch to remove check_for_plus_in_for_loops and osi->pass - Merge negative offset support (10/10 in v2) into 3/8 and support static object sizes - Merge dynamic offset (10/10 in v2) support into 8/8 Siddhesh Poyare

[PATCH v4 2/6] __builtin_dynamic_object_size: Recognize builtin

2021-12-01 Thread Siddhesh Poyarekar
-dynamic-object-size-9.c: Likewise. * gcc.dg/builtin-object-size-16.c: Adjust to allow inclusion from builtin-dynamic-object-size-16.c. * gcc.dg/builtin-object-size-17.c: Likewise. Signed-off-by: Siddhesh Poyarekar --- gcc/builtins.c| 11 +- gcc

[PATCH v4 3/6] tree-object-size: Support dynamic sizes in conditions

2021-12-01 Thread Siddhesh Poyarekar
/builtin-object-size-4.c [__builtin_object_size]: Likewise. * gcc.dg/builtin-object-size-5.c [__builtin_object_size]: Likewise. Signed-off-by: Siddhesh Poyarekar --- gcc/builtins.c| 6 +- .../gcc.dg/builtin-dynamic-object-size-0.c| 72

[PATCH v4 6/6] tree-object-size: Dynamic sizes for ADDR_EXPR

2021-12-01 Thread Siddhesh Poyarekar
) [__builtin_object_size]: Likewise. Signed-off-by: Siddhesh Poyarekar --- .../gcc.dg/builtin-dynamic-object-size-0.c| 158 ++ gcc/testsuite/gcc.dg/builtin-object-size-1.c | 30 +++- gcc/testsuite/gcc.dg/builtin-object-size-2.c | 43 - gcc/testsuite/gcc.dg/builtin-object

[PATCH v4 5/6] tree-object-size: Handle GIMPLE_CALL

2021-12-01 Thread Siddhesh Poyarekar
) [__builtin_object_size]: Likewise. * gcc.dg/builtin-object-size-3.c (test1) [__builtin_object_size]: Likewise. * gcc.dg/builtin-object-size-4.c (test1) [__builtin_object_size]: Likewise. Signed-off-by: Siddhesh Poyarekar --- .../gcc.dg/builtin-dynamic-object

[PATCH v4 1/6] tree-object-size: Use trees and support negative offsets

2021-12-01 Thread Siddhesh Poyarekar
): New test. (main): Call it. * gcc.dg/builtin-object-size-4.c (test8): New test. (main): Call it. * gcc.dg/builtin-object-size-5.c (test5, test6, test7): New tests. Signed-off-by: Siddhesh Poyarekar --- gcc/builtins.c | 10 +- gcc

Re: [PATCH] tree-object-size: Support strndup and strdup

2022-11-02 Thread Siddhesh Poyarekar
On 2022-09-23 09:02, Jakub Jelinek wrote: Oh, so can addr_object_size be simplified to use get_base_address too? You can try. As you can see in get_base_address, that function handles something that the above doesn't (looking through some MEM_REFs too). I went down this rabbithole and it ac

[PATCH] tree-object-size: Support strndup and strdup

2022-08-15 Thread Siddhesh Poyarekar
Use string length of input to strdup to determine the usable size of the resulting object. Avoid doing the same for strndup since there's a chance that the input may be too large, resulting in an unnecessary overhead or worse, the input may not be NULL terminated, resulting in a crash where there

Re: [PATCH] tree-object-size: Support strndup and strdup

2022-08-29 Thread Siddhesh Poyarekar
Ping! On 2022-08-15 15:23, Siddhesh Poyarekar wrote: Use string length of input to strdup to determine the usable size of the resulting object. Avoid doing the same for strndup since there's a chance that the input may be too large, resulting in an unnecessary overhead or worse, the inpu

Re: [PATCH] tree-object-size: Support strndup and strdup

2022-09-07 Thread Siddhesh Poyarekar
Ping! On 2022-08-29 10:16, Siddhesh Poyarekar wrote: Ping! On 2022-08-15 15:23, Siddhesh Poyarekar wrote: Use string length of input to strdup to determine the usable size of the resulting object.  Avoid doing the same for strndup since there's a chance that the input may be too

Re: [patch gcc13] middle-end/70090: Dynamic sizes for -fsanitize=object-size

2022-05-09 Thread Siddhesh Poyarekar
On 07/02/2022 17:37, Jakub Jelinek wrote: On Mon, Feb 07, 2022 at 05:31:58PM +0530, Siddhesh Poyarekar wrote: Use __builtin_dynamic_object_size to get object sizes for ubsan. gcc/ChangeLog: middle-end/70090 * ubsan.cc (ubsan_expand_objsize_ifn): Allow non-constant SIZE

Re: [patch gcc13] middle-end/70090: Dynamic sizes for -fsanitize=object-size

2022-05-10 Thread Siddhesh Poyarekar
On 10/05/2022 16:16, Martin Liška wrote: The revision caused: $ ./xgcc -B. /home/marxin/Programming/gcc/gcc/testsuite/gfortran.dg/ubsan/bind-c-intent-out-2.f90 -fsanitize=undefined -c -O during GIMPLE pass: ubsan /home/marxin/Programming/gcc/gcc/testsuite/gfortran.dg/ubsan/bind-c-intent-out-2.

[PATCH] middle-end/70090: Register __bdos for sanitizers if necessary

2022-05-10 Thread Siddhesh Poyarekar
ubsan/bind-c-intent-out-2.f90 does not crash anymore. gcc/ChangeLog: PR middle-end/70090 * asan.cc (initialize_sanitizer_builtins): Register __builtin_dynamic_object_size if necessary. Signed-off-by: Siddhesh Poyarekar --- Testing: - I realized that for some reason I was lo

[PATCH 00/10] __builtin_dynamic_object_size

2021-11-09 Thread Siddhesh Poyarekar
where the pass keeps track of nesting in the expression and either bail out or compute an estimate if nesting crosses a threshold. I'll take this up once we have more data on the nature of the bottlenecks. Siddhesh Poyarekar (10): tree-object-size: Replace magic numbers with enums t

[PATCH 01/10] tree-object-size: Replace magic numbers with enums

2021-11-09 Thread Siddhesh Poyarekar
numbers with enums. Signed-off-by: Siddhesh Poyarekar --- gcc/tree-object-size.c | 47 +- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c index 4334e05ef70..f70f95a7b29 100644 --- a/gcc

[PATCH 02/10] tree-object-size: Abstract object_sizes array

2021-11-09 Thread Siddhesh Poyarekar
, fini_object_sizes): Adjust. Signed-off-by: Siddhesh Poyarekar --- gcc/tree-object-size.c | 176 +++-- 1 file changed, 97 insertions(+), 79 deletions(-) diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c index f70f95a7b29..7a22539cc43 100644 --- a/gcc

[PATCH 03/10] tree-object-size: Use tree instead of HOST_WIDE_INT

2021-11-09 Thread Siddhesh Poyarekar
: Siddhesh Poyarekar --- gcc/builtins.c | 10 +- gcc/gimple-fold.c | 9 +- gcc/tree-object-size.c | 253 ++--- gcc/tree-object-size.h | 2 +- gcc/ubsan.c| 46 5 files changed, 168 insertions(+), 152 deletions(-) diff --git a

[PATCH 04/10] tree-object-size: Single pass dependency loop resolution

2021-11-09 Thread Siddhesh Poyarekar
gcc/testsuite/ChangeLog: * gcc.dg/builtin-object-size-1.c (test6): New test for passthrough. * gcc.dg/builtin-object-size-2.c: Likewise. * gcc.dg/builtin-object-size-3.c: Likewise. * gcc.dg/builtin-object-size-4.c: Likewise. Signed-off-by: Siddhesh Poyarekar ---

[PATCH 07/10] tree-object-size: Handle function parameters

2021-11-09 Thread Siddhesh Poyarekar
/builtin-dynamic-object-size-0.c (test_parmsz_simple): New function. (main): Call it. Signed-off-by: Siddhesh Poyarekar --- .../gcc.dg/builtin-dynamic-object-size-0.c| 10 gcc/tree-object-size.c| 55 ++- 2 files changed, 64 insertions

[PATCH 05/10] __builtin_dynamic_object_size: Recognize builtin

2021-11-09 Thread Siddhesh Poyarekar
-dynamic-object-size-8.c: Likewise. * gcc.dg/builtin-dynamic-object-size-9.c: Likewise. * gcc.dg/builtin-object-size-16.c: Adjust to allow inclusion from builtin-dynamic-object-size-16.c. * gcc.dg/builtin-object-size-17.c: Likewise. Signed-off-by: Siddhesh Poyarekar

[PATCH 06/10] tree-object-size: Support dynamic sizes in conditions

2021-11-09 Thread Siddhesh Poyarekar
e-3.c [DYNAMIC_OBJECT_SIZE]: Likewise. * gcc.dg/builtin-object-size-4.c [DYNAMIC_OBJECT_SIZE]: Likewise. * gcc.dg/builtin-object-size-5.c [DYNAMIC_OBJECT_SIZE]: Likewise. Signed-off-by: Siddhesh Poyarekar --- .../gcc.dg/builtin-dynamic-object-size-0.c

[PATCH 10/10] tree-object-size: Handle dynamic offsets

2021-11-09 Thread Siddhesh Poyarekar
/testsuite/ChangeLog: * gcc.dg/builtin-dynamic-object-size-0.c: Add new tests. Signed-off-by: Siddhesh Poyarekar --- .../gcc.dg/builtin-dynamic-object-size-0.c| 87 gcc/tree-object-size.c| 423 -- 2 files changed, 383 insertions(+), 127 deletions

[PATCH 09/10] tree-object-size: Dynamic sizes for ADDR_EXPR

2021-11-09 Thread Siddhesh Poyarekar
]: Likewise. * gcc.dg/builtin-object-size-4.c (test1) [DYNAMIC_OBJECT_SIZE]: Likewise. Signed-off-by: Siddhesh Poyarekar --- .../gcc.dg/builtin-dynamic-object-size-0.c| 71 ++ gcc/testsuite/gcc.dg/builtin-object-size-1.c | 30 +- gcc/testsuite/gcc.dg

[PATCH 08/10] tree-object-size: Handle GIMPLE_CALL

2021-11-09 Thread Siddhesh Poyarekar
) [DYNAMIC_OBJECT_SIZE]: Likewise. * gcc.dg/builtin-object-size-3.c (test1) [DYNAMIC_OBJECT_SIZE]: Likewise. * gcc.dg/builtin-object-size-4.c (test1) [DYNAMIC_OBJECT_SIZE]: Likewise. Signed-off-by: Siddhesh Poyarekar --- .../gcc.dg/builtin-dynamic-object-size-0.c| 227

[PATCH] gimple-fold: Smarter optimization of _chk variants

2021-11-10 Thread Siddhesh Poyarekar
/ChangeLog: * gcc.dg/Wobjsize-1.c: Make warning change line agnostic. * gcc.dg/builtin-chk-fold.c: New test. Signed-off-by: Siddhesh Poyarekar --- Testing: - gcc.dg shows no new regressions on x86_64, a full bootstrap and test run are in progress. gcc/gimple-fold.c

[PATCH v2] gimple-fold: Smarter optimization of _chk variants

2021-11-10 Thread Siddhesh Poyarekar
/ChangeLog: * gcc.dg/Wobjsize-1.c: Make warning change line agnostic. * gcc.dg/builtin-chk-fold.c: New test. Signed-off-by: Siddhesh Poyarekar --- Changes from v1: - Update comment that incorrectly said that known_safe emits a warning. - Add tests for strncpy and snprintf too. gcc

Re: [PATCH v2] gimple-fold: Smarter optimization of _chk variants

2021-11-10 Thread Siddhesh Poyarekar
On 11/10/21 16:15, Siddhesh Poyarekar wrote: Instead of comparing LEN and SIZE only if they are constants, use their ranges to decide if LEN will always be lower than or same as SIZE. This change ends up putting the stringop-overflow warning line number against the strcpy implementation, so

[PATCH] gimple-fold: Transform stp*cpy_chk to strcpy

2021-11-10 Thread Siddhesh Poyarekar
, gimple_fold_builtin_stxncpy_chk): Use BUILT_IN_STRNCPY if return value is not used. Signed-off-by: Siddhesh Poyarekar --- gcc/gimple-fold.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 74c9ce4bdc8..cadccfe3010 100644 --- a/gcc/gimple

Re: [PATCH] gimple-fold: Transform stp*cpy_chk to strcpy

2021-11-10 Thread Siddhesh Poyarekar
On 11/11/21 02:06, Jeff Law wrote: On 11/10/2021 10:47 AM, Siddhesh Poyarekar wrote: Use the ignore flag to transform BUILT_IN_STPCPY_CHK to BUILT_IN_STRCPY when set.  This transformation will happen in a subsequent fold anyway but do it right away and save the additional effort. gcc

[PATCH 0/3] gimple-fold improvements

2021-11-11 Thread Siddhesh Poyarekar
__memcpy_chk calls being optimized away completely in addition to a couple of memmove and strcpy chk variants being transformed into regular calls. Siddhesh Poyarekar (3): gimple-fold: Transform stp*cpy_chk to str*cpy directly gimple-fold: Use ranges to simplify _chk calls gimple-fold: Use ranges

[PATCH 1/3] gimple-fold: Transform stp*cpy_chk to str*cpy directly

2021-11-11 Thread Siddhesh Poyarekar
actually happened. gcc/ChangeLog: * gimple-fold.c (gimple_fold_builtin_stxcpy_chk, gimple_fold_builtin_stxncpy_chk): Use BUILT_IN_STRNCPY if return value is not used. gcc/testsuite/ChangeLog: * gcc.dg/fold-stringops.c: New test. Signed-off-by: Siddhesh Poyarekar

[PATCH 3/3] gimple-fold: Use ranges to simplify strncat and snprintf

2021-11-11 Thread Siddhesh Poyarekar
geLog: * gcc.dg/fold-stringops-2.c: Define size_t. (safe1): Adjust. (safe4): New test. * gcc.dg/fold-stringops-3.c: New test. Signed-off-by: Siddhesh Poyarekar --- gcc/gimple-fold.c | 76 + gcc/testsuite/gcc.dg/fold-stringops-2.c

[PATCH 2/3] gimple-fold: Use ranges to simplify _chk calls

2021-11-11 Thread Siddhesh Poyarekar
, gimple_fold_builtin_sprintf_chk): Use it. gcc/testsuite/ChangeLog: * gcc.dg/Wobjsize-1.c: Make warning change line agnostic. * gcc.dg/builtin-chk-fold.c: New test. Signed-off-by: Siddhesh Poyarekar --- gcc/gimple-fold.c | 216 +--- gcc/testsuite/gcc.dg

Re: [PATCH 1/3] gimple-fold: Transform stp*cpy_chk to str*cpy directly

2021-11-13 Thread Siddhesh Poyarekar
On 11/12/21 22:46, Prathamesh Kulkarni wrote: On Fri, 12 Nov 2021 at 01:12, Siddhesh Poyarekar wrote: Avoid going through another folding cycle and use the ignore flag to directly transform BUILT_IN_STPCPY_CHK to BUILT_IN_STRCPY when set, likewise for BUILT_IN_STPNCPY_CHK to BUILT_IN_STPNCPY

Re: [PATCH 3/3] gimple-fold: Use ranges to simplify strncat and snprintf

2021-11-15 Thread Siddhesh Poyarekar
On 11/12/21 01:11, Siddhesh Poyarekar wrote: Remove the warnings for strncat since it is already handled (and even the error messages look identical) in gimple-ssa-warn-access. Instead, use len range to determine if it is within bounds of source and destination and simplify it to strcat if it&#

[PATCH v2 0/3] gimple-fold improvements

2021-11-15 Thread Siddhesh Poyarekar
ed to strcat. - Renamed known_safe to known_lower Siddhesh Poyarekar (3): gimple-fold: Transform stp*cpy_chk to str*cpy directly gimple-fold: Use ranges to simplify _chk calls gimple-fold: Use ranges to simplify strncat and snprintf gcc/gimple-fold.c

[PATCH v2 1/3] gimple-fold: Transform stp*cpy_chk to str*cpy directly

2021-11-15 Thread Siddhesh Poyarekar
-stringops.c: New test. Signed-off-by: Siddhesh Poyarekar --- gcc/gimple-fold.c | 55 - gcc/testsuite/gcc.dg/fold-stringops-1.c | 23 +++ 2 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/fold-stringops-1

[PATCH v2 2/3] gimple-fold: Use ranges to simplify _chk calls

2021-11-15 Thread Siddhesh Poyarekar
, gimple_fold_builtin_sprintf_chk): Use it. gcc/testsuite/ChangeLog: * gcc.dg/Wobjsize-1.c: Make warning change line agnostic. * gcc.dg/builtin-chk-fold.c: New test. Signed-off-by: Siddhesh Poyarekar --- gcc/gimple-fold.c | 216 +--- gcc/testsuite/gcc.dg

[PATCH v2 3/3] gimple-fold: Use ranges to simplify strncat and snprintf

2021-11-15 Thread Siddhesh Poyarekar
. (gimple_fold_builtin_snprintf): Likewise. gcc/testsuite/ChangeLog: * gcc.dg/fold-stringops-2.c: Define size_t. (safe1): Adjust. (safe4): New test. * gcc.dg/fold-stringops-3.c: New test. Signed-off-by: Siddhesh Poyarekar --- gcc/gimple-fold.c | 102

Re: [PATCH v2 2/3] gimple-fold: Use ranges to simplify _chk calls

2021-11-15 Thread Siddhesh Poyarekar
On 11/16/21 01:55, Jeff Law wrote: On 11/15/2021 10:33 AM, Siddhesh Poyarekar wrote: Instead of comparing LEN and SIZE only if they are constants, use their ranges to decide if LEN will always be lower than or same as SIZE. This change ends up putting the stringop-overflow warning line

[committed] MAINTAINERS: Add myself to DCO section

2021-10-07 Thread Siddhesh Poyarekar
Antoniu Pop -Siddhesh Poyarekar +Siddhesh Poyarekar Vidya Praveen Thomas Preud'homme Vladimir

[PATCH] tree-object-size: Drop unused pdecl and poff arguments

2021-10-07 Thread Siddhesh Poyarekar
, compute_builtin_object_size): Drop PDECL and POFF arguments. (addr_object_size): Adjust calls. * tree-object-size.h (compute_builtin_object_size): Drop PDECL and POFF arguments. Signed-off-by: Siddhesh Poyarekar --- gcc/tree-object-size.c | 42

[PATCH 0/8] __builtin_dynamic_object_size and more

2021-10-07 Thread Siddhesh Poyarekar
mpute an estimate if nesting crosses a threshold. I'll take this up once we have more data on the nature of the bottlenecks. Siddhesh Poyarekar (8): __builtin_dynamic_object_size: Recognize builtin name tree-dynamic-object-size: New pass tree-dynamic-object-size: Handle GIMPLE_PHI

[PATCH 1/8] __builtin_dynamic_object_size: Recognize builtin name

2021-10-07 Thread Siddhesh Poyarekar
Recognize the __builtin_dynamic_object_size builtin, but simply replace it with -1 or 0 for now. gcc/ChangeLog: * builtins.c (expand_builtin, fold_builtin_2): Add BUILT_IN_DYN_OBJECT_SIZE. (fold_builtin_dyn_object_size): New function. (valid_object_size_args): New

[PATCH 2/8] tree-dynamic-object-size: New pass

2021-10-07 Thread Siddhesh Poyarekar
-off-by: Siddhesh Poyarekar --- gcc/Makefile.in | 19 +- gcc/builtins.c| 8 + gcc/doc/extend.texi | 11 + gcc/passes.def| 3 + .../gcc.dg/builtin-dynamic-object-size-0.c

[PATCH 3/8] tree-dynamic-object-size: Handle GIMPLE_PHI

2021-10-07 Thread Siddhesh Poyarekar
_malloc_condphi, test_builtin_malloc_condphi2, test_builtin_malloc_condphi3, test_builtin_calloc_condphi, test_deploop): New tests. (main): Call them. Signed-off-by: Siddhesh Poyarekar --- .../gcc.dg/builtin-dynamic-object-size-0.c| 92 +++ gcc/tree-dynamic-object-size.c

[PATCH 5/8] tree-dynamic-object-size: Handle GIMPLE_ASSIGN

2021-10-07 Thread Siddhesh Poyarekar
object_wholesizes and object_wholesize_exprs. gcc/testsuite/ChangeLog * gcc.dg/builtin-dynamic-object-size-0.c (dynarray_struct): New struct. (test_dynarray_struct, test_substring, test_substring_ptrplus): New tests. (main): Call them. Signed-off-by:

[PATCH 4/8] tree-dynamic-object-size: Support ADDR_EXPR

2021-10-07 Thread Siddhesh Poyarekar
, test_passthrough_nonssa): New tests. (main): Call them. Signed-off-by: Siddhesh Poyarekar --- gcc/builtins.c| 2 +- .../gcc.dg/builtin-dynamic-object-size-0.c| 37 +++ gcc/tree-dynamic-object-size.c| 255 +- 3

[PATCH 6/8] tree-dynamic-object-size: Handle function parameters

2021-10-07 Thread Siddhesh Poyarekar
, gimplify_size_exprs): Adjust. (parm_object_size): New function. (collect_object_sizes_for): Handle GIMPLE_NOP. gcc/testsuite/ChangeLog: * gcc.dg/builtin-dynamic-object-size-0.c (test_parmsz): New test. (main): Call it. Signed-off-by: Siddhesh Poyarekar

[PATCH 7/8] tree-dynamic-object-size: Get subobject sizes

2021-10-07 Thread Siddhesh Poyarekar
. (addr_dyn_object_size): Call it. Support subobject size computation. gcc/testsuite/ChangeLog: * gcc.dg/builtin-dynamic-object-size-0.c (test_dynarray_struct_subobj): New test. (main): Call it. Signed-off-by: Siddhesh Poyarekar --- .../gcc.dg/builtin-dynamic-object-size-0.c| 34

[PATCH 8/8] tree-dynamic-object-size: Add test wrappers to extend testing

2021-10-07 Thread Siddhesh Poyarekar
. * gcc.dg/builtin-object-size-16.c: Likewise. * gcc.dg/builtin-object-size-17.c: Likewise. * gcc.dg/builtin-object-size-2.c: Likewise. * gcc.dg/builtin-object-size-3.c: Likewise. * gcc.dg/builtin-object-size-4.c: Likewise. Signed-off-by: Siddhesh Poyarekar --- .../g

Re: [PATCH 2/8] tree-dynamic-object-size: New pass

2021-10-07 Thread Siddhesh Poyarekar
On 10/8/21 03:44, Siddhesh Poyarekar wrote: diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 133b82eef38..082d167cd65 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -12777,6 +12777,17 @@ assert (__builtin_object_size (q, 1) == sizeof (var.b)); @end smallexample

Re: [PATCH 0/8] __builtin_dynamic_object_size and more

2021-10-07 Thread Siddhesh Poyarekar
On 10/8/21 03:44, Siddhesh Poyarekar wrote: (from about 4% to 70% in bash), but that could well be due to the _chk I should also clarify that this is for memcpy. For all fortifiable functions, the coverage percentage went from 30.81% to 84.5% for bash. Below is the full table. Please note

Re: [PATCH 1/8] __builtin_dynamic_object_size: Recognize builtin name

2021-10-12 Thread Siddhesh Poyarekar
On 10/12/21 19:12, Jakub Jelinek wrote: On Fri, Oct 08, 2021 at 03:44:25AM +0530, Siddhesh Poyarekar wrote: --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -180,6 +180,7 @@ static rtx expand_builtin_memory_chk (tree, rtx, machine_mode, static void maybe_emit_chk_warning (tree, enum

Re: [PATCH 2/8] tree-dynamic-object-size: New pass

2021-10-12 Thread Siddhesh Poyarekar
On 10/12/21 19:28, Jakub Jelinek wrote: On Fri, Oct 08, 2021 at 03:44:26AM +0530, Siddhesh Poyarekar wrote: A new pass is added to execute just before the tree-object-size pass to recognize and simplify __builtin_dynamic_object_size. Some key ideas (such as multipass object size collection to

[PATCH] Warray-bounds: Warn only for generic address spaces

2021-10-12 Thread Siddhesh Poyarekar
: * gcc.target/i386/addr-space-3.c: New test case. Signed-off-by: Siddhesh Poyarekar --- gcc/gimple-array-bounds.cc | 3 +++ gcc/testsuite/gcc.target/i386/addr-space-3.c | 5 + 2 files changed, 8 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/addr-space-3.c diff --git

Re: [PATCH] Warray-bounds: Warn only for generic address spaces

2021-10-12 Thread Siddhesh Poyarekar
On 10/13/21 00:36, Martin Sebor wrote: On 10/12/21 12:33 PM, Siddhesh Poyarekar wrote: The warning is falsely triggered for THREAD_SELF in glibc when accessing TCB through the segment register. Thanks for looking into it!  The Glibc warning is being tracked in PR 102630.  The root cause

Re: [PATCH] Warray-bounds: Warn only for generic address spaces

2021-10-13 Thread Siddhesh Poyarekar
On 10/13/21 13:50, Richard Biener wrote: On Tue, Oct 12, 2021 at 8:34 PM Siddhesh Poyarekar wrote: The warning is falsely triggered for THREAD_SELF in glibc when accessing TCB through the segment register. I think this is a more generic bug - the warning is also bogus if the general address

[PATCH] tree-object-size: Avoid unnecessary processing of __builtin_object_size

2021-10-17 Thread Siddhesh Poyarekar
: Siddhesh Poyarekar --- gcc/tree-object-size.c | 12 +--- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c index 6a4dc724f34..46a976dfe10 100644 --- a/gcc/tree-object-size.c +++ b/gcc/tree-object-size.c @@ -1298,6 +1298,10

[PATCH] tree-object-size: Make unknown a computation

2021-10-18 Thread Siddhesh Poyarekar
ype). gcc/ChangeLog: * tree-object-size.c (unknown): Make into a function. Adjust all uses. (unknown_object_size): Remove function. (collect_object_sizes_for): Set object_sizes directly. Signed-off-by: Siddhesh Poyarekar --- gcc/tree-object-si

Re: [PATCH] tree-object-size: Make unknown a computation

2021-10-19 Thread Siddhesh Poyarekar
On 10/19/21 12:28, Jakub Jelinek wrote: On Tue, Oct 19, 2021 at 09:47:45AM +0530, Siddhesh Poyarekar wrote: Compute the unknown size value as a function of the min/max bit of object_size_type. This transforms into a neat little branchless sequence on x86_64: movl%edi, %eax

[PATCH v2] tree-object-size: Make unknown a computation

2021-10-19 Thread Siddhesh Poyarekar
a function. Adjust all uses. (unknown_object_size): Simplify implementation. Signed-off-by: Siddhesh Poyarekar --- gcc/tree-object-size.c | 100 ++--- 1 file changed, 43 insertions(+), 57 deletions(-) diff --git a/gcc/tree-object-size.c b/gcc/t

Re: [PATCH v2] tree-object-size: Make unknown a computation

2021-10-19 Thread Siddhesh Poyarekar
On 10/19/21 13:15, Jakub Jelinek wrote: Ok for trunk if it passes bootstrap/regtest. Pushed now, no new issues seen in bootstrap and regtest. Thanks, Siddhesh

Re: [PATCH 6/8] tree-dynamic-object-size: Handle function parameters

2021-10-20 Thread Siddhesh Poyarekar
On 10/20/21 22:26, Martin Sebor wrote: On 10/7/21 4:14 PM, Siddhesh Poyarekar wrote: Handle either static sizes in function parameters or hints provided by __attribute__ ((access (...))) to compute sizes for objects. It's been my hope to eventually teach __builtin_object_size about attr

[PATCH] analyzer: Recognize __builtin_free as a matching deallocator

2021-07-27 Thread Siddhesh Poyarekar
Recognize __builtin_free as being equivalent to free when passed into __attribute__((malloc ())), similar to how it is treated when it is encountered as a call. This fixes spurious warnings in glibc where xmalloc family of allocators as well as reallocarray, memalign, etc. are declared to have __b

[PATCH] analyzer: Handle strdup builtins

2021-07-28 Thread Siddhesh Poyarekar
Consolidate allocator builtin handling and add support for __builtin_strdup and __builtin_strndup. gcc/analyzer/ChangeLog: * analyzer.cc (is_named_call_p, is_std_named_call_p): Make first argument a const_tree. * analyzer.h (is_named_call_p, -s_std_named_call_p): Li

Re: [PATCH v6 1/5] Provide counted_by attribute to flexible array member field (PR108896)

2024-03-11 Thread Siddhesh Poyarekar
On 2024-02-16 14:47, Qing Zhao wrote: 'counted_by (COUNT)' The 'counted_by' attribute may be attached to the C99 flexible array member of a structure. It indicates that the number of the elements of the array is given by the field named "COUNT" in the same structure as th

Re: [PATCH v6 2/5] Convert references with "counted_by" attributes to/from .ACCESS_WITH_SIZE.

2024-03-11 Thread Siddhesh Poyarekar
On 2024-02-16 14:47, Qing Zhao wrote: Including the following changes: * The definition of the new internal function .ACCESS_WITH_SIZE in internal-fn.def. * C FE converts every reference to a FAM with a "counted_by" attribute to a call to the internal function .ACCESS_WITH_SIZE. (buil

Re: [PATCH v6 3/5] Use the .ACCESS_WITH_SIZE in builtin object size.

2024-03-11 Thread Siddhesh Poyarekar
On 2024-02-16 14:47, Qing Zhao wrote: gcc/ChangeLog: * tree-object-size.cc (access_with_size_object_size): New function. (call_object_size): Call the new function. gcc/testsuite/ChangeLog: * gcc.dg/builtin-object-size-common.h: Add a new macro EXPECT. * gcc.d

Re: [PATCH v6 4/5] Use the .ACCESS_WITH_SIZE in bound sanitizer.

2024-03-11 Thread Siddhesh Poyarekar
On 2024-02-16 14:47, Qing Zhao wrote: gcc/c-family/ChangeLog: * c-ubsan.cc (get_bound_from_access_with_size): New function. (ubsan_instrument_bounds): Handle call to .ACCESS_WITH_SIZE. gcc/testsuite/ChangeLog: * gcc.dg/ubsan/flex-array-counted-by-bounds-2.c: New test

Re: [PATCH v6 3/5] Use the .ACCESS_WITH_SIZE in builtin object size.

2024-03-18 Thread Siddhesh Poyarekar
On 2024-03-18 12:28, Qing Zhao wrote: This should probably bail out if object_size_type & OST_DYNAMIC == 0. Okay. Will add this. When add this into access_with_size_object_size, I found some old bugs in early_object_sizes_execute_one, and fixed them as well. Would you be able to isolate t

Re: [PATCH v8 3/5] Use the .ACCESS_WITH_SIZE in builtin object size.

2024-04-10 Thread Siddhesh Poyarekar
On 2024-03-29 12:07, Qing Zhao wrote: gcc/ChangeLog: * tree-object-size.cc (access_with_size_object_size): New function. (call_object_size): Call the new function. gcc/testsuite/ChangeLog: * gcc.dg/builtin-object-size-common.h: Add a new macro EXPECT. * gcc.dg/f

Re: [PATCH v8 4/5] Use the .ACCESS_WITH_SIZE in bound sanitizer.

2024-04-10 Thread Siddhesh Poyarekar
On 2024-03-29 12:07, Qing Zhao wrote: gcc/c-family/ChangeLog: * c-ubsan.cc (get_bound_from_access_with_size): New function. (ubsan_instrument_bounds): Handle call to .ACCESS_WITH_SIZE. gcc/testsuite/ChangeLog: * gcc.dg/ubsan/flex-array-counted-by-bounds-2.c: New test.

Re: [PATCH v8 5/5] Add the 6th argument to .ACCESS_WITH_SIZE

2024-04-10 Thread Siddhesh Poyarekar
On 2024-03-29 12:07, Qing Zhao wrote: to carry the TYPE of the flexible array. Such information is needed during tree-object-size.cc. We cannot use the result type or the type of the 1st argument of the routine .ACCESS_WITH_SIZE to decide the element type of the original array due to possible t

<    1   2   3   4   >